code: def test_reorient_vector_field_3d():
      sh = (16, 16, 16)
      d, dinv = vfu.create_harmonic_fields_3d(
          sh[0], sh[1], sh[2], 0.2, 4
      )
      d = np.array(d, dtype=floating)
      dinv = np.array(dinv, dtype=floating)
  
      # the vector field rotated 90 degrees around the last axis
      expected = np.empty(shape=sh + (3,), dtype=floating)
      expected[..., 0] = -1 * d[..., 1]
      expected[..., 1] = d[..., 0]
      expected[..., 2] = d[..., 2]
  
      # rotate 45 degrees twice around the last axis
      c = np.sqrt(0.5)
      affine = np.array([[c, -c, 0, 0], [c, c, 0, 0], [0, 0, 1, 0]])
      vfu.reorient_vector_field_3d(d, affine)
      vfu.reorient_vector_field_3d(d, affine)
  
      # verify almost equal
      assert_array_almost_equal(d, expected)
  
      # the vector field rotated 90 degrees around the first axis
      expected[..., 0] = dinv[..., 0]
      expected[..., 1] = -1 * dinv[..., 2]
      expected[..., 2] = dinv[..., 1]
  
      # rotate 45 degrees twice around the first axis
      affine = np.array([[1, 0, 0, 0], [0, c, -c, 0], [0, c, c, 0]])
      vfu.reorient_vector_field_3d(dinv, affine)
      vfu.reorient_vector_field_3d(dinv, affine)
  
      # verify almost equal
      assert_array_almost_equal(dinv, expected)
  
      # Test exception is raised when the affine transform matrix is not valid
      invalid = np.zeros((3, 3), dtype=np.float64)
      assert_raises(
          ValueError, vfu.reorient_vector_field_3d, d, invalid
      )
  
imports: import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_raises
  from scipy.ndimage import map_coordinates
  from nibabel.affines import apply_affine, from_matvec
  from dipy.core import geometry
  from dipy.align import floating
  from dipy.align import imwarp
  from dipy.align import vector_fields
  from dipy.align.transforms import regtransforms
  from dipy.align.parzenhist import sample_domain_regular
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 22 for calling a global function with example usage: test_reorient_vector_field_3d() without return types