code: def test_downsample_displacement_field_2d(rng):
      size = 32
      sh = (size, size, 2)
      for reduce_r in [True, False]:
          nr = size - 1 if reduce_r else size
          for reduce_c in [True, False]:
              nc = size - 1 if reduce_c else size
              field = np.empty((size, size, 2), dtype=floating)
              field[...] = rng.integers(0, 10, np.size(field)).reshape(
                  sh
              )
  
              if reduce_r:
                  field[-1, :, :] = 0
              if reduce_c:
                  field[:, -1, :] = 0
  
              a = field[::2, ::2, :]
              b = field[1::2, ::2, :]
              c = field[::2, 1::2, :]
              d = field[1::2, 1::2, :]
  
              expected = 0.25 * (a + b + c + d)
  
              if reduce_r:
                  expected[-1, :, :] *= 2
              if reduce_c:
                  expected[:, -1, :] *= 2
  
              actual = vfu.downsample_displacement_field_2d(
                  field[:nr, :nc, :]
              )
              assert_array_almost_equal(expected, actual)
  
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 18 for calling a global function with example usage: test_downsample_displacement_field_2d(rng) without return types