Avoid memory explosion using chunked arrays and indexers with small memory footprint. #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to improve the
disaggregate_polygon_to_rasterby removing thegroupbynormalisation operation, and instead rasterising the shapes and then performing the normalisation in a vectorised way.The improvements significantly reduce the memory footprint, and allow 'larger than memory' cases to execute thanks to the "chunked" approach.
Here are two examples of the results on a 16 GB RAM laptop with an i7 13k core.
Please ignore the figure titles, I had a small bug that did not display the coarsened pixel count 😬
Key changes:
disaggregate_polygon_to_rasternow expects a DataArray (not aDataset). If aDatasetis given, it'll only process it if it contains one variable.daskto the dependencies.Proxy of all of Europe (estimated 'missing' PV rooftop capacity)
This case was previously impossible to run. Both RAM and Swap were filled, leading to a crash.
With
dask, the memory footprint never exceeds the available memory capacity.Proxy of Montenegro
A smaller case that I was able to run in the previous approach.
Before
After