Skip to content

Commit

Permalink
Merge pull request #326 from PyPSA/unchunk-spatial
Browse files Browse the repository at this point in the history
aggregate: unchunk spatial dimension before apply_ufunc
  • Loading branch information
FabianHofmann authored Oct 20, 2023
2 parents 2555d81 + 104d252 commit 9ea305e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ atlite.egg-info/
doc/.vscode/settings.json
.vscode/settings.json
test/*.nc
dev-scripts/
examples/*.nc
examples/*.csv
examples/*.zip
Expand Down
14 changes: 9 additions & 5 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ 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 <https://github.com/PyPSA/atlite/pull/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.
* Bug fix: Some wind turbine models did not include a cut-out wind speed, potentially causing overestimated power generation in windy conditions. Cut-out wind speeds were added to the following affected wind turbine models (`#316 <https://github.com/PyPSA/atlite/issues/314>`_):
* NREL_ReferenceTurbine_2016CACost_10MW_offshore
* NREL_ReferenceTurbine_2016CACost_6MW_offshore
Expand All @@ -21,9 +25,9 @@ Release Notes
* NREL_ReferenceTurbine_2020ATB_12MW_offshore
* NREL_ReferenceTurbine_2020ATB_15MW_offshore
* NREL_ReferenceTurbine_2020ATB_18MW_offshore
.. * 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 <https://github.com/PyPSA/atlite/pull/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 <https://github.com/PyPSA/atlite/pull/316>`_)


Version 0.2.11
Expand Down
1 change: 1 addition & 0 deletions atlite/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions atlite/cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 9ea305e

Please sign in to comment.