code: def test_bdg_residual(rng):
      """This tests the bootstrapping residual."""
  
      hsph_updated = HemiSphere.from_sphere(unit_icosahedron).subdivide(
          2
      )
      vertices = hsph_updated.vertices
      bvecs = vertices
      bvals = np.ones(len(vertices)) * 1000
      bvecs = np.insert(bvecs, 0, np.array([0, 0, 0]), axis=0)
      bvals = np.insert(bvals, 0, 0)
      gtab = gradient_table(bvals, bvecs)
      r, theta, phi = cart2sphere(*vertices.T)
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=shm.descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          B, m, n = shm.real_sh_descoteaux(6, theta, phi)
      shm_coeff = rng.random(B.shape[1])
  
      # sphere_func is sampled of the spherical function for each point of
      # the sphere
      sphere_func = np.dot(shm_coeff, B.T)
  
      response = (np.array([1.5e3, 0.3e3, 0.3e3]), 1)
      voxel = np.concatenate((np.zeros(1), sphere_func))
      data = np.tile(voxel, (3, 3, 3, 1))
  
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=shm.descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          csd_model = ConstrainedSphericalDeconvModel(
              gtab, response, sh_order=6
          )
          boot_dg = BootDirectionGetter.from_data(
              data,
              model=csd_model,
              max_angle=60,
              sphere=hsph_updated,
              sh_order=6,
          )
  
          # Two boot samples should be the same
          odf1 = boot_dg.get_pmf(np.array([1.5, 1.5, 1.5]))
          odf2 = boot_dg.get_pmf(np.array([1.5, 1.5, 1.5]))
          npt.assert_array_almost_equal(odf1, odf2)
  
      # A boot sample with less sh coeffs should have residuals, thus the two
      # should be different
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=shm.descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          boot_dg2 = BootDirectionGetter.from_data(
              data,
              model=csd_model,
              max_angle=60,
              sphere=hsph_updated,
              sh_order=4,
          )
      odf1 = boot_dg2.get_pmf(np.array([1.5, 1.5, 1.5]))
      odf2 = boot_dg2.get_pmf(np.array([1.5, 1.5, 1.5]))
      npt.assert_(np.any(odf1 != odf2))
  
      # test with a gtab with two shells and assert you get an error
      bvals[-1] = 2000
      gtab = gradient_table(bvals, bvecs)
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=shm.descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          csd_model = ConstrainedSphericalDeconvModel(
              gtab, response, sh_order=6
          )
      npt.assert_raises(
          ValueError,
          BootDirectionGetter,
          data,
          csd_model,
          60,
          hsph_updated,
          6,
      )
  
file_path: dipy/dipy/direction/tests/test_bootstrap_direction_getter.py
imports: import warnings
  import numpy
  import numpy.testing
  from dipy.core.geometry import cart2sphere
  from dipy.core.gradients import gradient_table
  from dipy.core.sphere import HemiSphere, unit_icosahedron
  from dipy.data import get_sphere, get_fnames
  from dipy.direction.bootstrap_direction_getter import BootDirectionGetter
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.reconst import dti, shm
  from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel, TensorModel
  from dipy.sims.voxel import multi_tensor, single_tensor
  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_bdg_residual(rng) without return types