Skip to content
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

era5: update to new CDS infrastructure #364

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def _rename_and_clean_coords(ds, add_lon_lat=True):
longitude columns as 'lat' and 'lon'.
"""
ds = ds.rename({"longitude": "x", "latitude": "y"})
if "valid_time" in ds.sizes:
ds = ds.rename({"valid_time": "time"}).unify_chunks()
# round coords since cds coords are float32 which would lead to mismatches
ds = ds.assign_coords(
x=np.round(ds.x.astype(float), 5), y=np.round(ds.y.astype(float), 5)
Expand All @@ -96,10 +98,24 @@ def _rename_and_clean_coords(ds, add_lon_lat=True):

# Combine ERA5 and ERA5T data into a single dimension.
# See https://github.com/PyPSA/atlite/issues/190
if "expver" in ds.dims.keys():
# expver=1 is ERA5 data, expver=5 is ERA5T data
# This combines both by filling in NaNs from ERA5 data with values from ERA5T.
ds = ds.sel(expver=1).combine_first(ds.sel(expver=5))
if "expver" in ds.coords:
unique_expver = np.unique(ds["expver"].values)
if len(unique_expver) > 1:
expver_dim = xr.DataArray(
unique_expver, dims=["expver"], coords={"expver": unique_expver}
)
ds = (
ds.assign_coords({"expver_dim": expver_dim})
.drop_vars("expver")
.rename({"expver_dim": "expver"})
.set_index(expver="expver")
)
for var in ds.data_vars:
ds[var] = ds[var].expand_dims("expver")
# expver=1 is ERA5 data, expver=5 is ERA5T data This combines both
# by filling in NaNs from ERA5 data with values from ERA5T.
ds = ds.sel(expver="0001").combine_first(ds.sel(expver="0005"))
ds = ds.drop_vars(["expver", "number"], errors="ignore")

return ds

Expand Down Expand Up @@ -316,7 +332,7 @@ def retrieve_data(product, chunks=None, tmpdir=None, lock=None, **updates):
Download data like ERA5 from the Climate Data Store (CDS).

If you want to track the state of your request go to
https://cds.climate.copernicus.eu/cdsapp#!/yourrequests
https://cds-beta.climate.copernicus.eu/requests?tab=all
"""
request = {"product_type": "reanalysis", "format": "netcdf"}
request.update(updates)
Expand Down
Loading