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

Apply spatial mask across non-spatial dimensions #156

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions odc/geo/_xr_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,17 @@ def mask(
value_inside=not invert,
)

# Repeat rasterized mask across all non-spatial dims
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using spatial_dims method to get names of spatial dimensions, can you please use xx.odc.ydim to obtain location of the y-axis (x-axis always follows y) and expand rasterized using that.

non_sdims = (*xx.dims[:ydim], xx.dims[ydim+2:])

sdims = spatial_dims(xx, relaxed=True)
non_sdims = {}
non_sdims_axis = []
for i, (k, v) in enumerate(xx.sizes.items()):
if k not in sdims:
non_sdims[k] = v
non_sdims_axis.append(i)
if non_sdims:
rasterized = rasterized.expand_dims(non_sdims, axis=non_sdims_axis)

# Mask data outside rasterized `poly`
xx_masked = xx.where(rasterized.data)

Expand Down
Loading