Skip to content

Commit

Permalink
era5: Enable creating global cutouts
Browse files Browse the repository at this point in the history
One needs to use: x=slice(None), y=slice(None)
  • Loading branch information
coroa committed Sep 19, 2019
1 parent 75d04e8 commit 3e7b434
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def _add_height(ds):

def _area(xs, ys):
# North, West, South, East. Default: global
return [ys.start, xs.start, ys.stop, xs.stop]
area = [ys.start, xs.start, ys.stop, xs.stop]
if all(a is not None for a in area):
return area
elif all(a is None for a in area):
return None
else:
raise RuntimeError(f"All bounds for x and y must be specified (or none)")

def _rename_and_clean_coords(ds, add_lon_lat=True):
"""Rename 'longitude' and 'latitude' columns to 'x' and 'y'
Expand Down Expand Up @@ -183,11 +189,13 @@ def get_data(coords, period, feature, sanitize=True, tmpdir=None, **creation_par
assert tmpdir is not None

retrieval_params = {'product': 'reanalysis-era5-single-levels',
'area': _area(creation_parameters.pop('x'),
creation_parameters.pop('y')),
'tmpdir': tmpdir,
'chunks': creation_parameters.pop('chunks', None)}

area = _area(creation_parameters.pop('x'), creation_parameters.pop('y'))
if area is not None:
retrieval_params['area'] = area

if {'dx', 'dy'}.issubset(creation_parameters):
retrieval_params['grid'] = [creation_parameters.pop('dx'), creation_parameters.pop('dy')]

Expand Down

0 comments on commit 3e7b434

Please sign in to comment.