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 Sep 30, 2022
1 parent a0bd4b0 commit b37135c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion atlite/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def wrapper(*args, **kwargs):


@maybe_remove_tmpdir
def cutout_prepare(cutout, features=None, tmpdir=None, overwrite=False):
def cutout_prepare(cutout, features=None, tmpdir=None, overwrite=False, flatten_expver=True):
"""
Prepare all or a selection of features in a cutout.
Expand All @@ -133,6 +133,11 @@ def cutout_prepare(cutout, features=None, tmpdir=None, overwrite=False):
overwrite : bool, optional
Whether to overwrite variables which are already included in the
cutout. The default is False.
flatten_expver: bool, default True
If true, data for time periods spanning both ERA5 and ERA5T data
will be combined into a single dimension.
See https://confluence.ecmwf.int/pages/viewpage.action?pageId=173385064
for details.
Returns
-------
Expand Down Expand Up @@ -169,6 +174,11 @@ def cutout_prepare(cutout, features=None, tmpdir=None, overwrite=False):
attrs.update(ds.attrs)
ds = cutout.data.merge(ds[missing_vars.values]).assign_attrs(**attrs)

# Combine ERA5 and ERA5T data into a single dimension.
# See https://github.com/PyPSA/atlite/issues/190
if flatten_expver and 'expver' in ds.dims.mapping.keys():
ds = ds.sel(expver=1).combine_first(ds.sel(expver=5))

# write data to tmp file, copy it to original data, this is much safer
# than appending variables
directory, filename = os.path.split(str(cutout.path))
Expand Down

0 comments on commit b37135c

Please sign in to comment.