code: def test_diffeomorphic_map_simplification_2d():
      r"""Test simplification of 2D diffeomorphic maps
  
      Create an invertible deformation field, and define a DiffeomorphicMap
      using different voxel-to-space transforms for domain, codomain, and
      reference discretizations, also use a non-identity pre-aligning matrix.
      Warp a circle using the diffeomorphic map to obtain the expected warped
      circle. Now simplify the DiffeomorphicMap and warp the same circle
      using this simplified map. Verify that the two warped circles are equal
      up to numerical precision.
      """
      # create a simple affine transformation
      dom_shape = (64, 64)
      cod_shape = (80, 80)
      nr = dom_shape[0]
      nc = dom_shape[1]
      s = 1.1
      t = 0.25
      trans = np.array([[1, 0, -t * nr], [0, 1, -t * nc], [0, 0, 1]])
      trans_inv = np.linalg.inv(trans)
      scale = np.array([[1 * s, 0, 0], [0, 1 * s, 0], [0, 0, 1]])
      gt_affine = trans_inv.dot(scale.dot(trans))
      # Create the invertible displacement fields and the circle
      radius = 16
      circle = vfu.create_circle(cod_shape[0], cod_shape[1], radius)
      d, dinv = vfu.create_harmonic_fields_2d(
          dom_shape[0], dom_shape[1], 0.3, 6
      )
      # Define different voxel-to-space transforms for domain, codomain and
      # reference grid, also, use a non-identity pre-align transform
      D = gt_affine
      C = imwarp.mult_aff(gt_affine, gt_affine)
      R = np.eye(3)
      P = gt_affine
  
      # Create the original diffeomorphic map
      diff_map = imwarp.DiffeomorphicMap(
          2, dom_shape, R, dom_shape, D, cod_shape, C, P
      )
      diff_map.forward = np.array(d, dtype=floating)
      diff_map.backward = np.array(dinv, dtype=floating)
      # Warp the circle to obtain the expected image
      expected = diff_map.transform(circle, "linear")
  
      # Simplify
      simplified = diff_map.get_simplified_transform()
      # warp the circle
      warped = simplified.transform(circle, "linear")
      # verify that the simplified map is equivalent to the
      # original one
      assert_array_almost_equal(warped, expected)
      # And of course, it must be simpler...
      assert_equal(simplified.domain_grid2world, None)
      assert_equal(simplified.codomain_grid2world, None)
      assert_equal(simplified.disp_grid2world, None)
      assert_equal(simplified.domain_world2grid, None)
      assert_equal(simplified.codomain_world2grid, None)
      assert_equal(simplified.disp_world2grid, None)
  
imports: import numpy
  import nibabel.eulerangles
  from numpy.testing import assert_equal, assert_array_equal, assert_array_almost_equal, assert_raises
  from dipy.core.interpolation import interpolate_scalar_2d, interpolate_scalar_3d
  from dipy.data import get_fnames
  from dipy.align import floating
  from dipy.align import imwarp
  from dipy.align import metrics
  from dipy.align import vector_fields
  from dipy.align import VerbosityLevels
  from dipy.align.imwarp import DiffeomorphicMap
  from dipy.tracking.streamline import deform_streamlines
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 3 for calling a global function with example usage: test_diffeomorphic_map_simplification_2d() without return types