coordinates.mixins.core.CoordinateSystemAxesMixin.get_axes_order#

static CoordinateSystemAxesMixin.get_axes_order(src_axes: Sequence[str], dst_axes: Sequence[str]) List[int][source]#

Compute the reordering indices that will reorder src_axes into the order of dst_axes.

This function returns a list of indices that can be used to rearrange src_axes so that its elements appear in the same order as in dst_axes, skipping any elements of dst_axes that are not present in src_axes.

Parameters:
  • src_axes (list of str) – The current ordering of a subset of axes (e.g., axes labeling a tensor).

  • dst_axes (list of str) – The desired target ordering (typically canonical order).

Returns:

A permutation P such that [src_axes[i] for i in P] gives the axes in dst_axes order.

Return type:

list of int

Raises:

ValueError – If any element of src_axes is not found in dst_axes.

Examples

>>> get_axes_order(["phi", "r"], ["r", "theta", "phi"])
[1, 0]  # "r" comes before "phi" in dst_axes
>>> get_axes_order(["x", "y"], ["y", "z", "x"])
[1, 0]  # reorder to ["y", "x"]