There are two alternative solutions already built into xarray for solving the problems of this package.
You have time series data with metadata that spans intervals of time (e.g., words spoken during a recording). You want to:
Select data by time range
Select data by metadata (e.g., “give me all data during word X”)
Keep the time and metadata dimensions synchronized
| Approach | Pros | Cons |
|---|---|---|
| Direct Coords | Simple to understand; works with standard xarray | Must construct dense arrays; loses interval boundary info; no isel by metadata |
| MultiIndex | Built-in pandas/xarray support; familiar API | Awkward slicing behavior; duplicates time values; can’t easily get interval boundaries |
| Linked Indices (this library) | Preserves interval structure; automatic cross-slicing; natural representation | Requires custom Index; newer xarray feature |
If either of MultiIndex or direct coords works for your use case then you should prefer to use them over this custom index.
Use MultiIndex when:¶
You’re already familiar with pandas MultiIndex
Your intervals perfectly tile the time axis (no gaps)
You don’t need to query interval boundaries
Use Direct Coords when:¶
You have simple, non-overlapping intervals
You don’t need
iselaccess by metadataYou want to avoid dependencies
Use Linked Indices when:¶
You need to preserve interval boundary information
You have hierarchical intervals (e.g., words containing phonemes)
You need natural
sel()andisel()on both time and metadata
Detailed Examples¶
MultiIndex Approach - Using pandas MultiIndex with xarray
Direct Coords Approach - Encoding metadata as coordinates on the time dimension