-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧐 Subset WeatherBench2 to one year and select variables #3
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Saving a one year subset (with select data variables) of | ||
[WeatherBench2](https://weatherbench2.readthedocs.io/en/latest/data-guide.html) | ||
to a local Zarr store. | ||
|
||
python 0_weatherbench2zarr.py | ||
|
||
Full dataset(s) can be downloaded from | ||
https://console.cloud.google.com/storage/browser/weatherbench2 | ||
""" | ||
import os | ||
|
||
import xarray as xr | ||
|
||
# %% | ||
# Temporal subset of WeatherBench2 dataset to 2 years | ||
store_name: str = "2020-full_37-6h-0p25deg-chunk-1_zuv500.zarr" | ||
if not os.path.exists(path=store_name): | ||
# Open WeatherBench2 Zarr store from Google Cloud Storage | ||
ds: xr.Dataset = xr.open_dataset( | ||
filename_or_obj="gs://weatherbench2/datasets/era5/1959-2022-full_37-6h-0p25deg-chunk-1.zarr-v2", | ||
engine="zarr", | ||
chunks="auto", | ||
consolidated=True, | ||
) | ||
|
||
# Subset to year 2000, 500hPa pressure level | ||
ds_500hpa = ds.sel(time=slice("2000-01-01", "2000-12-31"), level=500, drop=True) | ||
|
||
# Get data variable z500, u500, v500 | ||
ds_500hpa_zuv = ds_500hpa.get( | ||
key=["geopotential", "u_component_of_wind", "v_component_of_wind"] | ||
) | ||
|
||
# Disable LZ4 compression, since cupy-xarray cannot handle it yet | ||
for var in ds_500hpa_zuv.variables: | ||
ds_500hpa_zuv[var].encoding["compressor"] = None | ||
|
||
# Save to Zarr with chunks of size 1 along time dimension | ||
# Can take about 1 hour to save 10.7GB of data at 40MB/s | ||
ds_rechunked: xr.Dataset = ds_500hpa_zuv.chunk( | ||
time=1, | ||
latitude=len(ds_500hpa_zuv.latitude), | ||
longitude=len(ds_500hpa_zuv.longitude), | ||
) | ||
ds_rechunked.to_zarr(store=store_name, consolidated=True, zarr_version=2) | ||
|
||
# Read back Zarr store using kvikIO engine to | ||
# ensure things were saved correctly and can be loaded into GPU directly | ||
ds_zarr: xr.Dataset = xr.open_dataset( | ||
filename_or_obj=store_name, engine="kvikio", consolidated=False | ||
) | ||
print(ds_zarr) | ||
print(ds_zarr.u_component_of_wind) | ||
print(f"Loaded as {ds_zarr.u_component_of_wind.isel(time=0).data.__class__}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, forgot to update this line 😅
Benchmark download time at commit c63bc43 for 10.7GB of data was:
At commit a904131, dataset is 18.2GB and took:
Internet speeds on my side was averaging at around 40MB/s, and rechunking on the fly probably took some time 🙂