diff --git a/atlite/data.py b/atlite/data.py index 60dadcad..f424988a 100644 --- a/atlite/data.py +++ b/atlite/data.py @@ -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. @@ -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 ------- @@ -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))