code: def test_reorient_vector_field_2d():
      shape = (16, 16)
      d, dinv = vfu.create_harmonic_fields_2d(
          shape[0], shape[1], 0.2, 4
      )
      d = np.array(d, dtype=floating)
  
      # the vector field rotated 90 degrees
      expected = np.empty(shape=shape + (2,), dtype=floating)
      expected[..., 0] = -1 * d[..., 1]
      expected[..., 1] = d[..., 0]
  
      # rotate 45 degrees twice
      c = np.sqrt(0.5)
      affine = np.array([[c, -c, 0.0], [c, c, 0.0]])
      vfu.reorient_vector_field_2d(d, affine)
      vfu.reorient_vector_field_2d(d, affine)
  
      # verify almost equal
      assert_array_almost_equal(d, expected)
  
      # Test exception is raised when the affine transform matrix is not valid
      invalid = np.zeros((2, 2), dtype=np.float64)
      assert_raises(
          ValueError, vfu.reorient_vector_field_2d, 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 21 for calling a global function with example usage: test_reorient_vector_field_2d() without return types