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 selectioncoord[i] or coord[start:stop]: given integer position(s), return the corresponding physical value(s) as a new coordinate.

  • Label-based selectioncoord.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 to coord[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, or ScalarCoordinate).

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 True if 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 True if this coordinate is a dimensional coordinate.

isscalar()

Return True if this is a ScalarCoordinate.

to_dataarray()

Convert this coordinate to a DataArray with a single dimension.

to_index(item[, method, endpoint])

Convert a label-based selector to an integer index or slice.

Attributes

dim

Name of the dimension this coordinate is associated with, or None.

dtype

NumPy dtype of the underlying coordinate values.

empty

True if the coordinate has zero length.

end

Value at the last element.

indices

Integer array [0, 1, ..., len(self) - 1].

name

The name under which this coordinate is stored in its parent container.

ndim

Number of dimensions (always 1 for dimensional coordinates).

parent

The parent Coordinates container, or None if unattached.

shape

Shape tuple (len(self),).

size

Number of elements along this coordinate's axis.

start

Value at index 0 (first element).

values

Materialised numpy array of coordinate values.