docstr: AffineMap.
  
  Implements an affine transformation whose domain is given by
  `domain_grid` and `domain_grid2world`, and whose co-domain is
  given by `codomain_grid` and `codomain_grid2world`.
  
  The actual transform is represented by the `affine` matrix, which
  operate in world coordinates. Therefore, to transform a moving image
  towards a static image, we first map each voxel (i,j,k) of the static
  image to world coordinates (x,y,z) by applying `domain_grid2world`.
  Then we apply the `affine` transform to (x,y,z) obtaining (x', y', z')
  in moving image's world coordinates. Finally, (x', y', z') is mapped
  to voxel coordinates (i', j', k') in the moving image by multiplying
  (x', y', z') by the inverse of `codomain_grid2world`. The
  `codomain_grid_shape` is used analogously to transform the static
  image towards the moving image when calling `transform_inverse`.
  
  If the domain/co-domain information is not provided (None) then the
  sampling information needs to be specified each time the `transform`
  or `transform_inverse` is called to transform images. Note that such
  sampling information is not necessary to transform points defined in
  physical space, such as stream lines.
  
  Parameters
  ----------
  affine : array, shape (dim + 1, dim + 1)
      the matrix defining the affine transform, where `dim` is the
      dimension of the space this map operates in (2 for 2D images,
      3 for 3D images). If None, then `self` represents the identity
      transformation.
  domain_grid_shape : sequence, shape (dim,), optional
      the shape of the default domain sampling grid. When `transform`
      is called to transform an image, the resulting image will have
      this shape, unless a different sampling information is provided.
      If None, then the sampling grid shape must be specified each time
      the `transform` method is called.
  domain_grid2world : array, shape (dim + 1, dim + 1), optional
      the grid-to-world transform associated with the domain grid.
      If None (the default), then the grid-to-world transform is assumed
      to be the identity.
  codomain_grid_shape : sequence of integers, shape (dim,)
      the shape of the default co-domain sampling grid. When
      `transform_inverse` is called to transform an image, the resulting
      image will have this shape, unless a different sampling
      information is provided. If None (the default), then the sampling
      grid shape must be specified each time the `transform_inverse`
      method is called.
  codomain_grid2world : array, shape (dim + 1, dim + 1)
      the grid-to-world transform associated with the co-domain grid.
      If None (the default), then the grid-to-world transform is assumed
      to be the identity.
docstr_tok: ["AffineMap",".","Implements","an","affine","transformation","whose","domain","is","given","by","`","domain_grid","`","and","`","domain_grid2world","`",",","and","whose","co-domain","is","given","by","`","codomain_grid","`","and","`","codomain_grid2world","`",".","The","actual","transform","is","represented","by","the","`","affine","`","matrix",",","which","operate","in","world","coordinates",".","Therefore",",","to","transform","a","moving","image","towards","a","static","image",",","we","first","map","each","voxel","(","i",",","j",",","k",")","of","the","static","image","to","world","coordinates","(","x",",","y",",","z",")","by","applying","`","domain_grid2world","`",".","Then","we","apply","the","`","affine","`","transform","to","(","x",",","y",",","z",")","obtaining","(","x","'",",","y","'",",","z","'",")","in","moving","image","'s","world","coordinates",".","Finally",",","(","x","'",",","y","'",",","z","'",")","is","mapped","to","voxel","coordinates","(","i","'",",","j","'",",","k","'",")","in","the","moving","image","by","multiplying","(","x","'",",","y","'",",","z","'",")","by","the","inverse","of","`","codomain_grid2world","`",".","The","`","codomain_grid_shape","`","is","used","analogously","to","transform","the","static","image","towards","the","moving","image","when","calling","`","transform_inverse","`",".","If","the","domain\/co-domain","information","is","not","provided","(","None",")","then","the","sampling","information","needs","to","be","specified","each","time","the","`","transform","`","or","`","transform_inverse","`","is","called","to","transform","images",".","Note","that","such","sampling","information","is","not","necessary","to","transform","points","defined","in","physical","space",",","such","as","stream","lines",".","Parameters","--","--","--","--","--","affine",":","array",",","shape","(","dim","+","1",",","dim","+","1",")","the","matrix","defining","the","affine","transform",",","where","`","dim","`","is","the","dimension","of","the","space","this","map","operates","in","(","2","for","2D","images",",","3","for","3D","images",")",".","If","None",",","then","`","self","`","represents","the","identity","transformation",".","domain_grid_shape",":","sequence",",","shape","(","dim",",",")",",","optional","the","shape","of","the","default","domain","sampling","grid",".","When","`","transform","`","is","called","to","transform","an","image",",","the","resulting","image","will","have","this","shape",",","unless","a","different","sampling","information","is","provided",".","If","None",",","then","the","sampling","grid","shape","must","be","specified","each","time","the","`","transform","`","method","is","called",".","domain_grid2world",":","array",",","shape","(","dim","+","1",",","dim","+","1",")",",","optional","the","grid-to-world","transform","associated","with","the","domain","grid",".","If","None","(","the","default",")",",","then","the","grid-to-world","transform","is","assumed","to","be","the","identity",".","codomain_grid_shape",":","sequence","of","integers",",","shape","(","dim",",",")","the","shape","of","the","default","co-domain","sampling","grid",".","When","`","transform_inverse","`","is","called","to","transform","an","image",",","the","resulting","image","will","have","this","shape",",","unless","a","different","sampling","information","is","provided",".","If","None","(","the","default",")",",","then","the","sampling","grid","shape","must","be","specified","each","time","the","`","transform_inverse","`","method","is","called",".","codomain_grid2world",":","array",",","shape","(","dim","+","1",",","dim","+","1",")","the","grid-to-world","transform","associated","with","the","co-domain","grid",".","If","None","(","the","default",")",",","then","the","grid-to-world","transform","is","assumed","to","be","the","identity","."]
code: def __init__(
      self,
      affine,
      domain_grid_shape=None,
      domain_grid2world=None,
      codomain_grid_shape=None,
      codomain_grid2world=None,
  ):
      """AffineMap.
  
      Implements an affine transformation whose domain is given by
      `domain_grid` and `domain_grid2world`, and whose co-domain is
      given by `codomain_grid` and `codomain_grid2world`.
  
      The actual transform is represented by the `affine` matrix, which
      operate in world coordinates. Therefore, to transform a moving image
      towards a static image, we first map each voxel (i,j,k) of the static
      image to world coordinates (x,y,z) by applying `domain_grid2world`.
      Then we apply the `affine` transform to (x,y,z) obtaining (x', y', z')
      in moving image's world coordinates. Finally, (x', y', z') is mapped
      to voxel coordinates (i', j', k') in the moving image by multiplying
      (x', y', z') by the inverse of `codomain_grid2world`. The
      `codomain_grid_shape` is used analogously to transform the static
      image towards the moving image when calling `transform_inverse`.
  
      If the domain/co-domain information is not provided (None) then the
      sampling information needs to be specified each time the `transform`
      or `transform_inverse` is called to transform images. Note that such
      sampling information is not necessary to transform points defined in
      physical space, such as stream lines.
  
      Parameters
      ----------
      affine : array, shape (dim + 1, dim + 1)
          the matrix defining the affine transform, where `dim` is the
          dimension of the space this map operates in (2 for 2D images,
          3 for 3D images). If None, then `self` represents the identity
          transformation.
      domain_grid_shape : sequence, shape (dim,), optional
          the shape of the default domain sampling grid. When `transform`
          is called to transform an image, the resulting image will have
          this shape, unless a different sampling information is provided.
          If None, then the sampling grid shape must be specified each time
          the `transform` method is called.
      domain_grid2world : array, shape (dim + 1, dim + 1), optional
          the grid-to-world transform associated with the domain grid.
          If None (the default), then the grid-to-world transform is assumed
          to be the identity.
      codomain_grid_shape : sequence of integers, shape (dim,)
          the shape of the default co-domain sampling grid. When
          `transform_inverse` is called to transform an image, the resulting
          image will have this shape, unless a different sampling
          information is provided. If None (the default), then the sampling
          grid shape must be specified each time the `transform_inverse`
          method is called.
      codomain_grid2world : array, shape (dim + 1, dim + 1)
          the grid-to-world transform associated with the co-domain grid.
          If None (the default), then the grid-to-world transform is assumed
          to be the identity.
  
      """
      self.set_affine(affine)
      self.domain_shape = domain_grid_shape
      self.domain_grid2world = domain_grid2world
      self.codomain_shape = codomain_grid_shape
      self.codomain_grid2world = codomain_grid2world
  
imports: from warnings import warn
  import numpy
  import numpy.linalg
  import scipy.ndimage
  from dipy.core.optimize import Optimizer
  from dipy.core.interpolation import interpolate_scalar_2d, interpolate_scalar_3d
  from dipy.align import vector_fields
  from dipy.align import VerbosityLevels
  from dipy.align.parzenhist import ParzenJointHistogram, sample_domain_regular, compute_parzen_mi
  from dipy.align.imwarp import get_direction_and_spacings, ScaleSpace
  from dipy.align.scalespace import IsotropicScaleSpace
  from dipy.utils.deprecator import deprecated_params
label_desc: Use image node_id 1 to create a new AffineMap object  with example: obj = AffineMap(affine, domain_grid_shape, domain_grid2world, codomain_grid_shape, codomain_grid2world)