Coordinates#

DataArray combines an N-dimensional array with a set of Coordinate objects gathered in a Coordinates dict-like container, accessible via DataArray.coords. Each coordinate labels one axis (or attaches scalar metadata) and supports both integer-index access and label-based selection.

xdas ships four concrete coordinate types:

Type

Description

name

data

ScalarCoordinate

Scalar metadata, not tied to any axis

scalar

scalar-like

DenseCoordinate

One stored value per element

dense

array-like

InterpCoordinate

Piecewise-linear from tie points

interpolated

{"tie_indices": array-like[int], "tie_values": array-like}

SampledCoordinate

Uniform grid with optional gaps

sampled

{"tie_values": array-like, "tie_lengths": array-like[int], "sampling_interval": scalar}

Creating coordinates#

Coordinate acts as a factory: it inspects the shape and structure of data and returns the correct subclass automatically.

import numpy as np
import xdas as xd

# DenseCoordinate — one stored value per index
xd.Coordinate([0.0, 500.0, 1000.0, 1500.0])
[   0. ... 1500.]
# InterpCoordinate — piecewise-linear between tie points
xd.Coordinate({"tie_indices": [0, 999], "tie_values": [0.0, 5000.0]})
0.000 to 5000.000
# SampledCoordinate — uniform sampling with a fixed interval
xd.Coordinate(
    {"tie_values": [0.0], "tie_lengths": [1000], "sampling_interval": 5.0}
)
0.000 to 4995.000
# ScalarCoordinate — a single metadata value (not an axis)
xd.Coordinate(42.0)
42.

Subclasses can also be instantiated directly when you need the specific type explicitly:

from xdas.coordinates import SampledCoordinate

SampledCoordinate(
    {"tie_values": [0.0, 600.0], "tie_lengths": [100, 100], "sampling_interval": 5.0}
)
0.000 to 1095.000

Coordinates in a DataArray#

Coordinates are attached to a DataArray through the coords argument. A dimensional coordinate shares its name with the dimension it labels; a non-dimensional coordinate (or a ScalarCoordinate) can use a different name.

da = xd.DataArray(
    data=np.zeros((1000, 500)),
    coords={
        "time": {
            "tie_values": [np.datetime64("2024-01-01T00:00:00", "ms")],
            "tie_lengths": [1000],
            "sampling_interval": np.timedelta64(4, "ms"),
        },
        "distance": {"tie_indices": [0, 499], "tie_values": [0.0, 9980.0]},
        "network": (None, "DAS-NET"),
    },
)
da
<xdas.DataArray (time: 1000, distance: 500)>
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]
Coordinates:
  * time (time): 2024-01-01T00:00:00.000 to 2024-01-01T00:00:03.996
  * distance (distance): 0.000 to 9980.000
    network: 'DAS-NET'

Per-type details#