Skip to content

Commit

Permalink
accelerated reducer lookup #171
Browse files Browse the repository at this point in the history
  • Loading branch information
hcwinsemius committed Jun 21, 2024
1 parent e425cd9 commit 6f03c11
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pyorc/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,14 @@ def project_numpy(
idx = np.array(idx_y) * len(x) + np.array(idx_x)

# flatten points within mask
da_point = da.where(mask).stack(points=("y", "x"))
da_point["points_idx"] = "points", np.arange(len(da_point.points))
da_point = da_point.dropna(dim="points")

da_point = da.stack(
points=("y", "x")
).where(
mask.stack(points=("y", "x")),
drop=True
)
# da_point = da.where(mask, drop=True).stack(points=("y", "x"))
da_point["points_idx"] = "points", np.where(mask.values.flatten())[0]
# ensure any values that may be outside of target grid are dropped
da_point = da_point.isel(points=idx_inside)

Expand All @@ -260,5 +264,5 @@ def project_numpy(
)
# replace the nearest by mean values where relevant
da_point["group"] = da_new.group[classes]
da_new[..., classes] = da_point.values
da_new[..., classes] = da_point
return da_new.unstack()

0 comments on commit 6f03c11

Please sign in to comment.