shnitsel.core.indexes

Classes

TrajIndex

Base class inherited by all xarray-compatible indexes.

Module Contents

class TrajIndex(traj_sizes)

Bases: xarray.Index

Base class inherited by all xarray-compatible indexes.

Do not use this class directly for creating index objects. Xarray indexes are created exclusively from subclasses of Index, mostly via Xarray’s public API like Dataset.set_xindex.

Every subclass must at least implement Index.from_variables(). The (re)implementation of the other methods of this base class is optional but mostly required in order to support operations relying on indexes such as label-based selection or alignment.

The Index API closely follows the Dataset() and DataArray() API, e.g., for an index to support .sel() it needs to implement Index.sel(), to support .stack() and .unstack() it needs to implement Index.stack() and Index.unstack(), etc.

When a method is not (re)implemented, depending on the case the corresponding operation on a Dataset() or DataArray() either will raise a NotImplementedError or will simply drop/pass/copy the index from/to the result.

Do not use this class directly for creating index objects.

Parameters:

traj_sizes (List[Tuple[Hashable, int]])

classmethod from_variables(variables)

Create a new index object from one or more coordinate variables.

This factory method must be implemented in all subclasses of Index.

The coordinate variables may be passed here in an arbitrary number and order and each with arbitrary dimensions. It is the responsibility of the index to check the consistency and validity of these coordinates.

Parameters:

variables (dict-like) – Mapping of Variable objects holding the coordinate labels to index.

Returns:

index – A new Index object.

Return type:

Index

sel(labels)

Query the index with arbitrary coordinate label indexers.

Implementation is optional but required in order to support label-based selection. Otherwise it will raise an error when trying to call Dataset.sel() with labels for this index coordinates.

Coordinate label indexers can be of many kinds, e.g., scalar, list, tuple, array-like, slice, Variable, DataArray, etc. It is the responsibility of the index to handle those indexers properly.

Parameters:

labels (dict) – A dictionary of coordinate label indexers passed from Dataset.sel() and where the entries have been filtered for the current index.

Returns:

sel_results – An index query result object that contains dimension positional indexers. It may also contain new indexes, coordinate variables, etc.

Return type:

IndexSelResult