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
16 changes: 8 additions & 8 deletions atlite/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ def shape_availability(geometry, excluder):

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
for d in excluder.rasters:
for idx, d in enumerate(excluder.rasters, start=1):
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved
# allow reusing preloaded raster with different post-processing
if raster != d["raster"]:
raster = d["raster"]
Expand All @@ -459,15 +459,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:
for idx, d in enumerate(excluder.geometries, start=1):
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved
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 == False), transform
calvintr marked this conversation as resolved.
Show resolved Hide resolved


def shape_availability_reprojected(
Expand Down