-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Is your feature request related to a problem?
If I have a 2D coord like abs_time below
<xarray.Dataset> Size: 28kB
Dimensions: (trial: 3, rel_time: 500)
Coordinates:
* trial (trial) <U8 96B 'cosine' 'square' 'sawtooth'
* rel_time (rel_time) float64 4kB 0.0 0.01 0.02 0.03 ... 4.96 4.97 4.98 4.99
abs_time (trial, rel_time) float64 12kB 0.0 0.01 0.02 ... 14.97 14.98 14.99
Data variables:
data (trial, rel_time) float64 12kB 1.0 0.9995 0.998 ... -0.02 -0.01
which looks like this:
I cannot do set_xindex on it to make a selection such as sel(abs_time=slice(0,2.5))
Describe the solution you'd like
Xarray having a built in NDIndex object to handle this case would be fantastic. There may be some tough choices to make for what the right behavior is for some sel operations but I think overall it would be a benefit.
I've been messing around and have something that is most of what I want here: https://ianhuntisaak.com/xarray-linked-indexes/nd-index-demo/ (🤖 fair warning this me heavily using claude - i've checked lots, but definitely not all)
Describe alternatives you've considered
I thought about using NDPointIndex here but I think it's not quite the right application
ds.set_xindex('abs_time', xr.indexes.NDPointIndex) gives
ValueError: the number of variables 1 doesn't match the number of dimensions 2
and if i understand correctly i solving for a conceptually different problem. One where euclidean distance is meaningfully defined over the space of (x, y). In this case that's not meaningful inwhere the space is over (trials, time).
Additional context
No response