Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve memory load efficiency for shape_availability calculation #243

Merged
merged 12 commits into from
Jun 14, 2022
13 changes: 6 additions & 7 deletions atlite/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,14 @@ def shape_availability(geometry, excluder):
Affine transform of the mask.

"""
exclusions = []
if not excluder.all_open:
excluder.open_files()
assert geometry.crs == excluder.crs

bounds = rio.features.bounds(geometry)
transform, shape = padded_transform_and_shape(bounds, res=excluder.res)
masked = geometry_mask(geometry, shape, transform).astype(int)
exclusions.append(masked)
masked = geometry_mask(geometry, shape, transform)
exclusions = masked

# For the following: 0 is eligible, 1 in excluded
raster = None
Expand All @@ -459,15 +458,15 @@ def shape_availability(geometry, excluder):
masked_ = ~(masked_).astype(bool)
if d["buffer"]:
iterations = int(d["buffer"] / excluder.res) + 1
masked_ = dilation(masked_, iterations=iterations).astype(int)
masked_ = dilation(masked_, iterations=iterations)

exclusions.append(masked_.astype(int))
exclusions = exclusions | masked_

for d in excluder.geometries:
masked = ~geometry_mask(d["geometry"], shape, transform, invert=d["invert"])
exclusions.append(masked.astype(int))
exclusions = exclusions | masked

return (sum(exclusions) == 0).astype(float), transform
return ~exclusions, transform
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved


def shape_availability_reprojected(
Expand Down