diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index 827bb1ca..d3a0f80f 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -19,6 +19,9 @@ Upcoming Release See `#256 `_ for details. * Bugfix: The hydro inflow calculation was relying on a wrong distance calculation in `atlite.hydro.shift_and_aggregate_runoff_for_plants`. This is now fixed. * Add a reference to the PyPSA ecosystem community server hosted on `Discord `_ +* Bugfix: building cutouts spanning the most recent few months resulted in errors due to the + mixing of `ERA5` and `ERA5T` data returned from the CDSAPI. + See `#190 `_ for details. Version 0.2.9 ============= diff --git a/atlite/datasets/era5.py b/atlite/datasets/era5.py index c65ac71e..001124c2 100644 --- a/atlite/datasets/era5.py +++ b/atlite/datasets/era5.py @@ -91,6 +91,14 @@ def _rename_and_clean_coords(ds, add_lon_lat=True): ds = maybe_swap_spatial_dims(ds) if add_lon_lat: ds = ds.assign_coords(lon=ds.coords["x"], lat=ds.coords["y"]) + + # 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)) + return ds