class_docstr: Deform an image using a random smooth field and Pytorch's grid_sample.
  
  The amount of deformation is given by `def_range` in fractions of the size of the image. The size of each dimension
  of the input image is always defined as 2 regardless of actual image voxel dimensions, that is the coordinates in
  every dimension range from -1 to 1. A value of 0.1 means pixels/voxels can be moved by up to 5% of the image's size.
  
  Args:
      spatial_size: input array size to which deformation grid is interpolated
      rand_size: size of the randomized field to start from
      pad: number of pixels/voxels along the edges of the field to pad with 0
      field_mode: interpolation mode to use when upsampling the deformation field
      align_corners: if True align the corners when upsampling field
      prob: probability transform is applied
      def_range: value of the deformation range in image size fractions, single min/max value  or min/max pair
      grid_dtype: type for the deformation grid calculated from the field
      grid_mode: interpolation mode used for sampling input using deformation grid
      grid_padding_mode: padding mode used for sampling input using deformation grid
      grid_align_corners: if True align the corners when sampling the deformation grid
      device: Pytorch device to define field on
class_docstr_tok: ["Deform","an","image","using","a","random","smooth","field","and","Pytorch","'s","grid_sample",".","The","amount","of","deformation","is","given","by","`","def_range","`","in","fractions","of","the","size","of","the","image",".","The","size","of","each","dimension","of","the","input","image","is","always","defined","as","2","regardless","of","actual","image","voxel","dimensions",",","that","is","the","coordinates","in","every","dimension","range","from","-1","to","1",".","A","value","of","0.1","means","pixels\/voxels","can","be","moved","by","up","to","5","%","of","the","image","'s","size",".","Args",":","spatial_size",":","input","array","size","to","which","deformation","grid","is","interpolated","rand_size",":","size","of","the","randomized","field","to","start","from","pad",":","number","of","pixels\/voxels","along","the","edges","of","the","field","to","pad","with","0","field_mode",":","interpolation","mode","to","use","when","upsampling","the","deformation","field","align_corners",":","if","True","align","the","corners","when","upsampling","field","prob",":","probability","transform","is","applied","def_range",":","value","of","the","deformation","range","in","image","size","fractions",",","single","min\/max","value","or","min\/max","pair","grid_dtype",":","type","for","the","deformation","grid","calculated","from","the","field","grid_mode",":","interpolation","mode","used","for","sampling","input","using","deformation","grid","grid_padding_mode",":","padding","mode","used","for","sampling","input","using","deformation","grid","grid_align_corners",":","if","True","align","the","corners","when","sampling","the","deformation","grid","device",":","Pytorch","device","to","define","field","on"]
code: def __init__(
      self,
      spatial_size: Sequence[int],
      rand_size: Sequence[int],
      pad: int = 0,
      field_mode: str = InterpolateMode.AREA,
      align_corners: bool | None = None,
      prob: float = 0.1,
      def_range: Sequence[float] | float = 1.0,
      grid_dtype=torch.float32,
      grid_mode: str = GridSampleMode.NEAREST,
      grid_padding_mode: str = GridSamplePadMode.BORDER,
      grid_align_corners: bool | None = False,
      device: torch.device | None = None,
  ):
      super().__init__(prob)
  
      self.grid_dtype = grid_dtype
      self.grid_mode = grid_mode
      self.def_range = def_range
      self.device = device
      self.grid_align_corners = grid_align_corners
      self.grid_padding_mode = grid_padding_mode
  
      if isinstance(def_range, (int, float)):
          self.def_range = (-def_range, def_range)
      else:
          if len(def_range) != 2:
              raise ValueError(
                  "Argument `def_range` should be a number or pair of numbers."
              )
  
          self.def_range = (min(def_range), max(def_range))
  
      self.sfield = SmoothField(
          spatial_size=spatial_size,
          rand_size=rand_size,
          pad=pad,
          low=self.def_range[0],
          high=self.def_range[1],
          channels=len(rand_size),
          mode=field_mode,
          align_corners=align_corners,
          device=device,
      )
  
      grid_space = (
          tuple(spatial_size)
          if spatial_size is not None
          else self.sfield.field.shape[2:]
      )
      grid_ranges = [torch.linspace(-1, 1, d) for d in grid_space]
  
      grid = meshgrid_ij(*grid_ranges)
  
      self.grid = (
          torch.stack(grid)
          .unsqueeze(0)
          .to(self.device, self.grid_dtype)
      )
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  from typing import Any
  import numpy
  import torch
  from torch.nn.functional import grid_sample, interpolate
  from monai.config.type_definitions import NdarrayOrTensor
  from monai.data.meta_obj import get_track_meta
  from monai.networks.utils import meshgrid_ij
  from monai.transforms.transform import Randomizable, RandomizableTransform
  from monai.transforms.utils_pytorch_numpy_unification import moveaxis
  from monai.utils import GridSampleMode, GridSamplePadMode, InterpolateMode
  from monai.utils.enums import TransformBackends
  from monai.utils.module import look_up_option
  from monai.utils.type_conversion import convert_to_dst_type, convert_to_tensor
label_desc: Use image node_id 1 to create a new RandSmoothDeform object from inherited base classes: RandomizableTransform with example: obj = RandSmoothDeform(spatial_size, rand_size, pad, field_mode, align_corners, prob, def_range, grid_dtype, grid_mode, grid_padding_mode, grid_align_corners, device)