Skip to content

Commit

Permalink
Combine ERA5 and ERA5T data
Browse files Browse the repository at this point in the history
Requesting cutout data spanning recent (ERA5T)
and data older than ~3 months (ERA5) results in an
additional dimension in `cutout.data`, called `expver`,
which `atlite` currently cannot handle gracefully.

This change collapses the two dimensions into a single dimension.

See discussion in PyPSA#190
  • Loading branch information
zoltanmaric committed Nov 17, 2022
1 parent 3b6e736 commit 5d03808
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Upcoming Release
See `#256 <https://github.com/PyPSA/atlite/issues/256#issuecomment-1271446531>`_ 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 <https://discord.gg/AnuJBk23FU>`_
* 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 <https://github.com/PyPSA/atlite/issues/190>`_ for details.

Version 0.2.9
=============
Expand Down
8 changes: 8 additions & 0 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 5d03808

Please sign in to comment.