diff --git a/atlite/datasets/era5.py b/atlite/datasets/era5.py index 58a62dda..4e4e2337 100644 --- a/atlite/datasets/era5.py +++ b/atlite/datasets/era5.py @@ -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) @@ -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 @@ -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)