xarray icon indicating copy to clipboard operation
xarray copied to clipboard

support 1-dimensional coordinates in `NDPointIndex`

Open keewis opened this issue 1 month ago • 1 comments

What is your issue?

NDPointIndex supports indexing along multiple indexed coordinates at the same time, but only for coordinates that have 2 or more dimensions (usually curvilinear grids, like the one used by the ROMS_example tutorial dataset).

This excludes indexing scattered points or trajectories.

For example, what I'd like to index is something like this:

import xarray as xr
import numpy as np

ds = xr.Dataset(
    coords={
        "x": ("points", np.linspace(0, 10, 20)),
        "y": ("points", np.linspace(15, 8, 20)),
    }
)

cc @dcherian, @benbovy, @quentinf00

keewis avatar Nov 21 '25 11:11 keewis

Indeed NDPointIndex supports only the case where the n-dimensions of the point coordinates match the n-dimensions of the space in which they are distributed, i.e., the number of index coordinates must match the number of their dimensions.

In your example above those n-dimensions are flattened for each coordinate. This can be easily supported (NDPointIndex already does this flattening internally, we could just be bypass that) and can be automatically inferred at index creation from the input coordinate (as a fallback).

benbovy avatar Nov 24 '25 08:11 benbovy