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

WIP: Ensure rectilinear rasters support geometry selections #5414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

philippjfr
Copy link
Member

Somewhat hacky fix to ensure that:

  • Image correctly implements dim expression selections
  • Geometry selections work on rectilinear coordinates

if keep_index:
da = dataset.data[dataset.vdims[0].name].copy().rename(dim.name)
da.data[:] = data
return da
Copy link
Member Author

@philippjfr philippjfr Sep 1, 2022

Choose a reason for hiding this comment

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

Need to find a better solution here. This basically ensures that keep_index + expanded returns a 2D coordinate DataArray even for a rectilinear (i.e. 1D coordinate) array. This implementation does not handle:

  • packed vdims
  • dask backed value arrays

@@ -73,7 +73,7 @@ def spatial_select_gridded(xvals, yvals, geometry):
target = Image((xs, ys, np.empty(ys.shape+xs.shape)))
poly = Polygons([geometry])
mask = rasterize(poly, target=target, dynamic=False, aggregator='any')
return mask.dimension_values(2, flat=False)
return mask.interface.values(mask, mask.vdims[0], keep_index=True)
else:
mask = spatial_select_columnar(xvals.flatten(), yvals.flatten(), geometry)
return mask.reshape(xvals.shape)
Copy link
Member Author

Choose a reason for hiding this comment

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

This branch should also ensure that the mask that is returned is still an xarray object if the input is an xarray object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant