xdas.coordinates.Coordinate#
- class xdas.coordinates.Coordinate(data=None, dim=None, dtype=None)[source]#
Base class and factory for all coordinate types.
A coordinate maps the integer positions of one array axis to physical values (e.g. timestamps, distances). It supports two complementary directions of lookup:
Index-based selection —
coord[i]orcoord[start:stop]: given integer position(s), return the corresponding physical value(s) as a new coordinate.Label-based selection —
coord.to_index(v): given a physical value (or slice of values), return the integer index (or slice) at that label. An optional method argument controls nearest/forward/ backward matching for values that fall between samples. The returned index can then be passed tocoord[idx]to retrieve the coordinate subset, and is also used internally to index into the parent data array.
Factory behaviour — calling
Coordinate(data)directly acts as a factory: it inspects data and returns an instance of the most suitable registered subclass (SampledCoordinate,InterpCoordinate,DenseCoordinate, orScalarCoordinate).Subclassing — register a new subclass by passing
ctype=in the class definition:class MyCoord(Coordinate, ctype="mycoord"): ...
- Parameters:
data (array-like or mapping) – The coordinate data. Interpretation is subclass-specific.
dim (str, optional) – Name of the dimension this coordinate is associated with.
dtype (dtype-like, optional) – Desired dtype for the underlying data array.
- abstractmethod __init__(data=None, dim=None, dtype=None)[source]#
Initialise the coordinate from subclass-specific data.
Methods
__init__([data, dim, dtype])Initialise the coordinate from subclass-specific data.
copy([deep])Return a copy of this coordinate.
equals(other)Return
Trueif other is the same coordinate type with identical dim and data.from_block(start, size, step[, dim, dtype])Construct a coordinate from a start value, element count, and step size.
isdim()Return
Trueif this coordinate is a dimensional coordinate.isscalar()Return
Trueif this is aScalarCoordinate.Convert this coordinate to a
DataArraywith a single dimension.to_index(item[, method, endpoint])Convert a label-based selector to an integer index or slice.
Attributes
Name of the dimension this coordinate is associated with, or
None.NumPy dtype of the underlying coordinate values.
Trueif the coordinate has zero length.Value at the last element.
Integer array
[0, 1, ..., len(self) - 1].The name under which this coordinate is stored in its parent container.
Number of dimensions (always 1 for dimensional coordinates).
parentThe parent
Coordinatescontainer, orNoneif unattached.Shape tuple
(len(self),).Number of elements along this coordinate's axis.
Value at index 0 (first element).
Materialised numpy array of coordinate values.