-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add NDPointIndex (KDTree) #10478
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
base: main
Are you sure you want to change the base?
Add NDPointIndex (KDTree) #10478
Conversation
Nice! Would be good to add a section to this gallery example |
While I agree that it would be nice to showcase |
This is ready for review. I can do one pass over the doc's user guide and examples to see if we can use or mention this. I can also do that in a follow-up PR. Any better idea for the index name than |
We can also see later if there's a need to implement |
Display the name of the wrapper index adapter type.
I renamed it to The index inline repr now displays the underlying structure:
|
Very nice! At the meeting, there was uniform support for merging this. |
A few ideas for further improvements (I'll reference this comment in a new issue):
|
Integration with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excited to see this in.
The tests look good to me. Later we should create some kind of integration test suite for custom indexes that tests all the various flavors of indexing Xarray supports.
whats-new.rst
api.rst
.sel()
with scalar values and plain array values (implicit n-dimensions => coordinate variable n-dimensions)This PR adds an
xarray.indexes.TreeIndex
for point-wise label-based indexing of irregular data (n-dimensional coordinates). By default it is usingscipy.spatial.KDTree
under the hood.It is heavily inspired from xoak. Actually it could eventually replace it, or alternatively xoak could be built on top of this. There's no support for (dask) chunked coordinates here, although in xoak that feature is experimental and not working well anyway.
TreeIndex
shares some similarities withCoordinateTransformIndex
in its implementation and supported features:CoordinateTransform
, there's a smallTreeAdapter
abstraction layer that allows plugging in alternative index objects likesklearn.neighbors.KDTree
,sklearn.neighbors.BallTree
, etc. We can keep that private for now and publicly expose it later.scipy.spatial.KDTree
objects is done here based on the fact that they hold a view to their original data points (i.e., that's basically equivalent to comparing the associated coordinate variables).DataArray
orVariable
objects) is supported.