Skip to content

Commit 4de8534

Browse files
authored
Update ERA5 download example (#845)
* Update era5 download example * Update changelog
1 parent b5c2377 commit 4de8534

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Simplified CorrDiff config files, updated default values
2121
- Refactored CorrDiff losses and samplers to use the patching API
2222
- Support for non-square images and patches in patch-based diffusion
23+
- ERA5 download example updated to use current file format convention and
24+
restricts global statistics computation to the training set
2325
- Support for training custom StormCast models and various other improvements for StormCast
2426

2527
### Deprecated

examples/weather/dataset_download/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ flexibly select different meteorological variables for their training dataset.
1919
## How to Use
2020

2121
1. Make sure you have the CDS API key setup following
22-
[these instructions](https://cds.climate.copernicus.eu/api-how-to).
22+
[these instructions](https://cds.climate.copernicus.eu/how-to-api).
2323
2. Run the main script, `python start_mirror.py`. This will perform all actions to
2424
generate HDF5 files needed for training. First it will download and save all
2525
variables as Zarr arrays. This may take a substantial amount of time. If the process

examples/weather/dataset_download/era5_mirror.py

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def download_and_upload_chunk(
196196

197197
# Download the data
198198
ds = self.download_chunk(variable, year, month, hours, pressure_level)
199+
if "valid_time" in ds.dims:
200+
ds = ds.rename({"valid_time": "time"})
199201

200202
# Create the Zarr path
201203
zarr_path = self.variable_to_zarr_name(variable, pressure_level)

examples/weather/dataset_download/start_mirror.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,21 @@ def main(cfg: DictConfig) -> None:
6161

6262
# Save mean and std
6363
if cfg.compute_mean_std:
64+
train_era5_xarray = era5_xarray.sel(
65+
time=era5_xarray.time.dt.year.isin(train_years)
66+
)
6467
stats_path = os.path.join(cfg.hdf5_store_path, "stats")
6568
print(f"Saving global mean and std at {stats_path}")
6669
if not os.path.exists(stats_path):
6770
os.makedirs(stats_path)
6871
era5_mean = np.array(
69-
era5_xarray.mean(dim=("time", "latitude", "longitude")).values
72+
train_era5_xarray.mean(dim=("time", "latitude", "longitude")).values
7073
)
7174
np.save(
7275
os.path.join(stats_path, "global_means.npy"), era5_mean.reshape(1, -1, 1, 1)
7376
)
7477
era5_std = np.array(
75-
era5_xarray.std(dim=("time", "latitude", "longitude")).values
78+
train_era5_xarray.std(dim=("time", "latitude", "longitude")).values
7679
)
7780
np.save(
7881
os.path.join(stats_path, "global_stds.npy"), era5_std.reshape(1, -1, 1, 1)

0 commit comments

Comments
 (0)