Repository: Project-MONAI/MONAI
File: monai/transforms/spatial/array.py (Python)

Code before:

class Orientation(InvertibleTransform, LazyTransform):
    """
    Change the input image's orientation into the specified based on `axcodes`.

    This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
    for more information.
    """

    backend = [TransformBackends.NUMPY, TransformBackends.TORCH]

    def __init__(
        self,
        axcodes: str | None = None,
        as_closest_canonical: bool = False,
        labels: Sequence[tuple[str, str]] | None = None,
        lazy: bool = False,
    ) -> None:
        """
        Args:
            axcodes: N elements sequence for spatial ND input's orientation.
                e.g. axcodes='RAS' represents 3D orientation:
                (Left, Right), (Posterior, Anterior), (Inferior, Superior).
                default orientation labels options are: 'L' and 'R' for the first dimension,
                'P' and 'A' for the second, 'I' and 'S' for the third.
            as_closest_canonical: if True, load the image as closest to canonical axis format.
            labels: optional, None or sequence of (2,) sequences
                (2,) sequences are labels for (beginning, end) of output axis.
                Defaults to using the ``"space"`` attribute of a metatensor,
                where appliable, or (('L', 'R'), ('P', 'A'), ('I', 'S'))``
                otherwise (i.e. for plain tensors).
            lazy: a flag to indicate whether this transform should execute lazily or not.
                Defaults to False

        Raises:
            ValueError: When ``axcodes=None`` and ``as_closest_canonical=True``. Incompatible values.

        See Also: `nibabel.orientations.ornt2axcodes`.

        """
        LazyTransform.__init__(self, lazy=lazy)
        if axcodes is None and not as_closest_canonical:
            raise ValueError("Incompatible values: axcodes=None and as_closest_canonical=True.")
        if axcodes is not None and as_closest_canonical:
            warnings.warn("using as_closest_canonical=True, axcodes ignored.")
        self.axcodes = axcodes
        self.as_closest_canonical = as_closest_canonical
        self.labels = labels

    def __call__(self, data_array: torch.Tensor, lazy: bool | None = None) -> torch.Tensor:
        """

Review comment (suggestion):
As we're changing the default value for this argument, we should use [deprecated_arg_default](https://github.com/Project-MONAI/MONAI/blob/def4222152e18a70455aeebcc3142f2b9bae46d8/monai/utils/deprecate_utils.py#L230) to mark this fact and state what the difference is.

Code after:


class Orientation(InvertibleTransform, LazyTransform):
    """
    Change the input image's orientation into the specified based on `axcodes`.

    This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
    for more information.
    """

    backend = [TransformBackends.NUMPY, TransformBackends.TORCH]

    @deprecated_arg_default(
        name="labels",
        old_default=(("L", "R"), ("P", "A"), ("I", "S")),
        new_default=None,
        msg_suffix=(
            "Default value changed to None meaning that the transform now uses the 'space' of a "
            "meta-tensor, if applicable, to determine appropriate axis labels."
        ),
    )
    def __init__(
        self,
        axcodes: str | None = None,
        as_closest_canonical: bool = False,
        labels: Sequence[tuple[str, str]] | None = None,
        lazy: bool = False,
    ) -> None:
        """
        Args:
            axcodes: N elements sequence for spatial ND input's orientation.
                e.g. axcodes='RAS' represents 3D orientation:
                (Left, Right), (Posterior, Anterior), (Inferior, Superior).
                default orientation labels options are: 'L' and 'R' for the first dimension,
                'P' and 'A' for the second, 'I' and 'S' for the third.
            as_closest_canonical: if True, load the image as closest to canonical axis format.
            labels: optional, None or sequence of (2,) sequences
                (2,) sequences are labels for (beginning, end) of output axis.
                If ``None``, an appropriate value is chosen depending on the
                value of the ``"space"`` metadata item of a metatensor: if
                ``"space"`` is ``"LPS"``, the value used is ``(('R', 'L'),
                ('A', 'P'), ('I', 'S'))``, if ``"space"`` is ``"RPS"`` or the
                input is not a meta-tensor or has no ``"space"`` item, the
                value ``(('L', 'R'), ('P', 'A'), ('I', 'S'))`` is used. If not
                ``None``, the provided value is always used and the ``"space"``
                metadata item (if any) of the input is ignored.
            lazy: a flag to indicate whether this transform should execute lazily or not.
                Defaults to False

        Raises:
            ValueError: When ``axcodes=None`` and ``as_closest_canonical=True``. Incompatible values.