coordinates.mixins.core.CoordinateSystemAxesMixin.convert_axes_to_indices#

CoordinateSystemAxesMixin.convert_axes_to_indices(axes: str | Sequence[str]) int | List[int][source]#

Convert axis name(s) to their corresponding index or indices.

This method maps a single axis name or a sequence of axis names to their numeric index as defined by the order of the coordinate system’s __AXES__ attribute.

Parameters:

axes (str or Sequence[str]) – A single axis name or a list/tuple of axis names to convert.

Returns:

The index/indices corresponding to the given axis name(s). Returns an integer for a single axis and a list of integers for multiple axes.

Return type:

int or list of int

Raises:

ValueError – If any axis name is not found in the coordinate system.

Notes

This method provides the inverse of convert_indices_to_axes(), allowing user-facing axis names (like “r”, “theta”, “phi”) to be mapped to their internal numeric indices (e.g. 0, 1, 2). This is commonly used when aligning field data, slicing tensors, or resolving axis permutations for broadcasting and contraction.

Examples

Axis names may be passed individually or as sequences. Scalar inputs yield scalar outputs, and sequences yield lists:

>>> from pymetric.coordinates import SphericalCoordinateSystem
>>> u = SphericalCoordinateSystem()
>>> u.convert_axes_to_indices("r")
0
>>> u.convert_axes_to_indices(["r", "phi"])
[0, 2]
>>> u.convert_axes_to_indices(["theta"])
[1]