Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions monai/data/grid_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from monai.data.iterable_dataset import IterableDataset
from monai.data.utils import iter_patch
from monai.transforms import apply_transform
from monai.utils import NumpyPadMode, deprecated_arg, ensure_tuple, first, look_up_option
from monai.utils import NumpyPadMode, ensure_tuple, first, look_up_option

__all__ = ["PatchDataset", "GridPatchDataset", "PatchIter", "PatchIterd"]

Expand Down Expand Up @@ -175,7 +175,6 @@ class GridPatchDataset(IterableDataset):

"""

@deprecated_arg(name="dataset", new_name="data", since="0.8", msg_suffix="please use `data` instead.")
def __init__(
self,
data: Iterable | Sequence,
Expand Down Expand Up @@ -244,7 +243,6 @@ class PatchDataset(Dataset):

"""

@deprecated_arg(name="dataset", new_name="data", since="0.8", msg_suffix="please use `data` instead.")
def __init__(
self, data: Sequence, patch_func: Callable, samples_per_image: int = 1, transform: Callable | None = None
) -> None:
Expand Down
4 changes: 3 additions & 1 deletion monai/data/image_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def resample_if_needed(
if affine is not None:
data_array.affine = convert_to_tensor(affine, track_meta=False) # type: ignore
resampler = SpatialResample(mode=mode, padding_mode=padding_mode, align_corners=align_corners, dtype=dtype)
output_array = resampler(data_array[None], dst_affine=target_affine, spatial_size=output_spatial_shape)
output_array = resampler(
data_array[None], dst_affine=target_affine, spatial_size=output_spatial_shape # type: ignore
)
# convert back at the end
if isinstance(output_array, MetaTensor):
output_array.applied_operations = []
Expand Down
4 changes: 1 addition & 3 deletions monai/data/iterable_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from monai.data.utils import convert_tables_to_dicts
from monai.transforms import apply_transform
from monai.transforms.transform import Randomizable
from monai.utils import deprecated_arg, optional_import
from monai.utils import optional_import

pd, _ = optional_import("pandas")

Expand Down Expand Up @@ -200,7 +200,6 @@ class CSVIterableDataset(IterableDataset):

"""

@deprecated_arg(name="filename", new_name="src", since="0.8", msg_suffix="please use `src` instead.")
def __init__(
self,
src: str | Sequence[str] | Iterable | Sequence[Iterable],
Expand Down Expand Up @@ -231,7 +230,6 @@ def __init__(
self.iters: list[Iterable] = self.reset()
super().__init__(data=None, transform=transform) # type: ignore

@deprecated_arg(name="filename", new_name="src", since="0.8", msg_suffix="please use `src` instead.")
def reset(self, src: str | Sequence[str] | Iterable | Sequence[Iterable] | None = None):
"""
Reset the pandas `TextFileReader` iterable object to read data. For more details, please check:
Expand Down
10 changes: 9 additions & 1 deletion monai/transforms/io/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@
from monai.transforms.utility.array import EnsureChannelFirst
from monai.utils import GridSamplePadMode
from monai.utils import ImageMetaKey as Key
from monai.utils import OptionalImportError, convert_to_dst_type, ensure_tuple, look_up_option, optional_import
from monai.utils import (
OptionalImportError,
convert_to_dst_type,
deprecated_arg_default,
ensure_tuple,
look_up_option,
optional_import,
)

nib, _ = optional_import("nibabel")
Image, _ = optional_import("PIL.Image")
Expand Down Expand Up @@ -119,6 +126,7 @@ class LoadImage(Transform):

"""

@deprecated_arg_default("image_only", False, True, since="1.1", replaced="1.3")
def __init__(
self,
reader=None,
Expand Down
2 changes: 2 additions & 0 deletions monai/transforms/io/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from monai.transforms.io.array import LoadImage, SaveImage
from monai.transforms.transform import MapTransform
from monai.utils import GridSamplePadMode, ensure_tuple, ensure_tuple_rep
from monai.utils.deprecate_utils import deprecated_arg_default
from monai.utils.enums import PostFix

__all__ = ["LoadImaged", "LoadImageD", "LoadImageDict", "SaveImaged", "SaveImageD", "SaveImageDict"]
Expand Down Expand Up @@ -69,6 +70,7 @@ class LoadImaged(MapTransform):

"""

@deprecated_arg_default("image_only", False, True, since="1.1", replaced="1.3")
def __init__(
self,
keys: KeysCollection,
Expand Down
28 changes: 3 additions & 25 deletions monai/transforms/spatial/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,9 @@ def _post_process(
def update_meta(self, img, dst_affine):
img.affine = dst_affine

@deprecated_arg(
name="src_affine", since="0.9", msg_suffix="img should be `MetaTensor`, so affine can be extracted directly."
)
def __call__(
self,
img: torch.Tensor,
src_affine: NdarrayOrTensor | None = None,
dst_affine: torch.Tensor | None = None,
spatial_size: Sequence[int] | torch.Tensor | int | None = None,
mode: str | int | None = None,
Expand Down Expand Up @@ -354,35 +350,19 @@ def update_meta(self, img: torch.Tensor, dst_affine=None, img_dst=None):
img.meta = deepcopy(img_dst.meta)
img.meta[Key.FILENAME_OR_OBJ] = original_fname # keep the original name, the others are overwritten

@deprecated_arg(
name="src_meta", since="0.9", msg_suffix="img should be `MetaTensor`, so affine can be extracted directly."
)
@deprecated_arg(
name="dst_meta", since="0.9", msg_suffix="img_dst should be `MetaTensor`, so affine can be extracted directly."
)
def __call__(
def __call__( # type: ignore
self,
img: torch.Tensor,
img_dst: torch.Tensor,
src_meta: dict | None = None,
dst_meta: dict | None = None,
mode: str | int | None = None,
padding_mode: str | None = None,
align_corners: bool | None = None,
dtype: DtypeLike = None,
) -> torch.Tensor:
"""
Args:
img: input image to be resampled to match ``dst_meta``. It currently supports channel-first arrays with
img: input image to be resampled to match ``img_dst``. It currently supports channel-first arrays with
at most three spatial dimensions.
src_meta: Dictionary containing the source affine matrix in the form ``{'affine':src_affine}``.
If ``affine`` is not specified, an identity matrix is assumed. Defaults to ``None``.
See also: https://docs.monai.io/en/stable/transforms.html#spatialresample
dst_meta: Dictionary containing the target affine matrix and target spatial shape in the form
``{'affine':src_affine, 'spatial_shape':spatial_size}``. If ``affine`` is not
specified, ``src_affine`` is assumed. If ``spatial_shape`` is not specified, spatial size is
automatically computed, containing the previous field of view. Defaults to ``None``.
See also: https://docs.monai.io/en/stable/transforms.html#spatialresample
mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
Interpolation mode to calculate output values. Defaults to ``"bilinear"``.
See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
Expand All @@ -402,8 +382,6 @@ def __call__(
``np.float64`` (for best precision). If ``None``, use the data type of input data.
To be compatible with other modules, the output data type is always `float32`.
Raises:
RuntimeError: When ``src_meta`` is missing.
RuntimeError: When ``dst_meta`` is missing.
ValueError: When the affine matrix of the source image is not invertible.
Returns:
Resampled input tensor or MetaTensor.
Expand Down Expand Up @@ -608,7 +586,7 @@ def __call__(
data_array = self.sp_resample(
data_array,
dst_affine=torch.as_tensor(new_affine),
spatial_size=actual_shape,
spatial_size=actual_shape, # type: ignore
mode=mode,
padding_mode=padding_mode,
align_corners=align_corners,
Expand Down
17 changes: 0 additions & 17 deletions monai/transforms/spatial/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
ensure_tuple_rep,
fall_back_tuple,
)
from monai.utils.deprecate_utils import deprecated_arg
from monai.utils.enums import PytorchPadMode, TraceKeys
from monai.utils.module import optional_import

Expand Down Expand Up @@ -159,19 +158,13 @@ class SpatialResampled(MapTransform, InvertibleTransform):

backend = SpatialResample.backend

@deprecated_arg(name="meta_keys", since="0.9")
@deprecated_arg(name="meta_key_postfix", since="0.9")
@deprecated_arg(name="meta_src_keys", since="0.9")
def __init__(
self,
keys: KeysCollection,
mode: SequenceStr = GridSampleMode.BILINEAR,
padding_mode: SequenceStr = GridSamplePadMode.BORDER,
align_corners: Sequence[bool] | bool = False,
dtype: Sequence[DtypeLike] | DtypeLike = np.float64,
meta_keys: KeysCollection | None = None,
meta_key_postfix: str = "meta_dict",
meta_src_keys: KeysCollection | None = "src_affine",
dst_keys: KeysCollection | None = "dst_affine",
allow_missing_keys: bool = False,
) -> None:
Expand Down Expand Up @@ -238,12 +231,10 @@ class ResampleToMatchd(MapTransform, InvertibleTransform):

backend = ResampleToMatch.backend

@deprecated_arg(name="template_key", since="0.9")
def __init__(
self,
keys: KeysCollection,
key_dst: str,
template_key: str | None = None,
mode: SequenceStr = GridSampleMode.BILINEAR,
padding_mode: SequenceStr = GridSamplePadMode.BORDER,
align_corners: Sequence[bool] | bool = False,
Expand Down Expand Up @@ -323,8 +314,6 @@ class Spacingd(MapTransform, InvertibleTransform):

backend = Spacing.backend

@deprecated_arg(name="meta_keys", since="0.9")
@deprecated_arg(name="meta_key_postfix", since="0.9")
def __init__(
self,
keys: KeysCollection,
Expand All @@ -336,8 +325,6 @@ def __init__(
dtype: Sequence[DtypeLike] | DtypeLike = np.float64,
scale_extent: bool = False,
recompute_affine: bool = False,
meta_keys: KeysCollection | None = None,
meta_key_postfix: str = "meta_dict",
min_pixdim: Sequence[float] | float | None = None,
max_pixdim: Sequence[float] | float | None = None,
allow_missing_keys: bool = False,
Expand Down Expand Up @@ -444,16 +431,12 @@ class Orientationd(MapTransform, InvertibleTransform):

backend = Orientation.backend

@deprecated_arg(name="meta_keys", since="0.9")
@deprecated_arg(name="meta_key_postfix", since="0.9")
def __init__(
self,
keys: KeysCollection,
axcodes: str | None = None,
as_closest_canonical: bool = False,
labels: Sequence[tuple[str, str]] | None = (("L", "R"), ("P", "A"), ("I", "S")),
meta_keys: KeysCollection | None = None,
meta_key_postfix: str = "meta_dict",
allow_missing_keys: bool = False,
) -> None:
"""
Expand Down
4 changes: 0 additions & 4 deletions monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
convert_to_numpy,
convert_to_tensor,
deprecated,
deprecated_arg,
ensure_tuple,
look_up_option,
min_version,
Expand Down Expand Up @@ -1421,9 +1420,6 @@ class AddCoordinateChannels(Transform):

backend = [TransformBackends.NUMPY]

@deprecated_arg(
name="spatial_channels", new_name="spatial_dims", since="0.8", msg_suffix="please use `spatial_dims` instead."
)
def __init__(self, spatial_dims: Sequence[int]) -> None:
self.spatial_dims = spatial_dims

Expand Down
3 changes: 0 additions & 3 deletions monai/transforms/utility/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -1728,9 +1728,6 @@ class AddCoordinateChannelsd(MapTransform):

backend = AddCoordinateChannels.backend

@deprecated_arg(
name="spatial_channels", new_name="spatial_dims", since="0.8", msg_suffix="please use `spatial_dims` instead."
)
def __init__(self, keys: KeysCollection, spatial_dims: Sequence[int], allow_missing_keys: bool = False) -> None:
super().__init__(keys, allow_missing_keys)
self.add_coordinate_channels = AddCoordinateChannels(spatial_dims=spatial_dims)
Expand Down
10 changes: 5 additions & 5 deletions monai/utils/deprecate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,16 @@ def deprecated_arg_default(
def _decorator(func):
argname = f"{func.__module__} {func.__qualname__}:{name}"

msg_prefix = f"Default of argument `{name}`"
msg_prefix = f" Current default value of argument `{name}={old_default}`"

if is_replaced:
msg_infix = f"was replaced in version {replaced} from `{old_default}` to `{new_default}`."
msg_infix = f"was changed in version {replaced} from `{name}={old_default}` to `{name}={new_default}`."
elif is_deprecated:
msg_infix = f"has been deprecated since version {since} from `{old_default}` to `{new_default}`."
msg_infix = f"has been deprecated since version {since}."
if replaced is not None:
msg_infix += f" It will be replaced in version {replaced}."
msg_infix += f" It will be changed to `{name}={new_default}` in version {replaced}."
else:
msg_infix = f"has been deprecated from `{old_default}` to `{new_default}`."
msg_infix = f"has been deprecated from `{name}={old_default}` to `{name}={new_default}`."

msg = f"{msg_prefix} {msg_infix} {msg_suffix}".strip()

Expand Down