coordinates.mixins.core.CoordinateSystemAxesMixin.convert_indices_to_axes#
- CoordinateSystemAxesMixin.convert_indices_to_axes(axes_indices: int | Sequence[int]) str | List[str] [source]#
Convert axis index or indices to their corresponding axis name(s).
This method maps a single axis index or a sequence of axis indices to the canonical axis name(s) as defined in the coordinate system’s
__AXES__
attribute.- Parameters:
axes_indices (
int
orSequence[int]
) – An axis index or list/tuple of axis indices. Negative indices are supported and interpreted as in standard Python indexing.- Returns:
The axis name(s) corresponding to the provided index or indices. Returns a string for a single index and a list of strings for a sequence.
- Return type:
- Raises:
IndexError – If any index is out of bounds for the dimensionality of the coordinate system.
Notes
This method is useful for converting internal numeric axis representations (e.g., from grid shape or tensor slots) into symbolic or user-facing axis names (like “r”, “theta”, “z”, etc.).
Examples
This method allows for various index to axes conversions. Notably, if the input is scalar, the output will also be scalar and if the input is an iterable, then so too will the output. For example, if
0
is put in, the result will look like:>>> from pymetric.coordinates import SphericalCoordinateSystem >>> u = SphericalCoordinateSystem()
>>> u.convert_indices_to_axes(0) 'r'
Likewise, providing
[0,2]
yields>>> u.convert_indices_to_axes([0,2]) ['r', 'phi']
Scalar axes can also be provided inside of iterables to ensure consistent typing:
>>> u.convert_indices_to_axes([0]) ['r']