From f0fdf1c20ac5d8fa4e6f93366f157cd0090a388f Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 19 Oct 2023 17:15:34 +0200 Subject: [PATCH 1/2] aggregate: unchunk spatial dimension before apply_ufunc --- .gitignore | 1 + RELEASE_NOTES.rst | 12 +++++++----- atlite/aggregate.py | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a2473d8d..4e7e88e1 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ atlite.egg-info/ doc/.vscode/settings.json .vscode/settings.json test/*.nc +dev-scripts/ examples/*.nc examples/*.csv examples/*.zip diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index 839c1443..5dd12ea3 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -9,12 +9,14 @@ Release Notes -.. Upcoming Release -.. ================ +Upcoming Release +================ -.. * Fix: the wind turbine power curve is checked for a missing cut-out wind speed and an option to add a -.. cut-out wind speed at the end of the power curve is introduced. From the next release v0.2.13, adding -.. a cut-out wind speed will be the default behavior (`GH #316 `_) + +* Fix: the wind turbine power curve is checked for a missing cut-out wind speed and an option to add a + cut-out wind speed at the end of the power curve is introduced. From the next release v0.2.13, adding + a cut-out wind speed will be the default behavior (`GH #316 `_) +* Compatibility with xarray >= 2023.09.: The chunked spatial dimension in `aggregate` was raising an error with the new xarray version. This is fixed now. Version 0.2.11 diff --git a/atlite/aggregate.py b/atlite/aggregate.py index 9f01b89e..edada33f 100644 --- a/atlite/aggregate.py +++ b/atlite/aggregate.py @@ -16,6 +16,7 @@ def aggregate_matrix(da, matrix, index): index = index.rename("dim_0") if isinstance(da.data, dask.array.core.Array): da = da.stack(spatial=("y", "x")) + da = da.chunk(dict(spatial=-1)) return xr.apply_ufunc( lambda da: da * matrix.T, da, From 104d252edc729ec78a839d6016c1596ba625a30c Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 19 Oct 2023 17:33:49 +0200 Subject: [PATCH 2/2] cutout: apply chunks after loading cutout --- atlite/cutout.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atlite/cutout.py b/atlite/cutout.py index db042be9..2b95e9b0 100644 --- a/atlite/cutout.py +++ b/atlite/cutout.py @@ -180,7 +180,8 @@ def __init__(self, path, **cutoutparams): # Three cases. First, cutout exists -> take the data. # Second, data is given -> take it. Third, else -> build a new cutout if path.is_file(): - data = xr.open_dataset(str(path), chunks=chunks) + data = xr.open_dataset(str(path)) + data = data.chunk(chunks) data.attrs.update(storable_chunks) if cutoutparams: warn( @@ -403,7 +404,8 @@ def grid(self): span = (coords[self.shape[1] + 1] - coords[0]) / 2 cells = [box(*c) for c in np.hstack((coords - span, coords + span))] return gpd.GeoDataFrame( - {"x": coords[:, 0], "y": coords[:, 1], "geometry": cells}, crs=self.crs + {"x": coords[:, 0], "y": coords[:, 1], "geometry": cells}, + crs=self.crs, ) def sel(self, path=None, bounds=None, buffer=0, **kwargs):