Built in Index for 2D (or higher) coord
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the linked ND-index demo and the behavior described for set_xindex, NDPointIndex, and sel. Compare the requested 2D coordinate selection with the existing NDPointIndex limitation. Done would require a settled design and an implemented built-in index with defined sel behavior, but the issue does not name files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100