code: def test_global_fit():
      # Test fODF results on ideal examples in global fitting paradigm.
  
      sphere = default_sphere  # repulsion 724
  
      btable = np.loadtxt(get_fnames("dsi515btable"))
      bvals = btable[:, 0]
      bvecs = btable[:, 1:]
      gtab = gradient_table(bvals, bvecs)
      data, golden_directions = sticks_and_ball(
          gtab,
          d=0.0015,
          S0=100,
          angles=[(0, 0), (90, 0)],
          fractions=[50, 50],
          snr=None,
      )
  
      # global_fit requires 4D argument
      data = data[None, None, None, :]
      # TV requires non-singleton size in all volume dimensions
      data_mvoxel = np.tile(data, (2, 2, 2, 1))
  
      # Model to validate
      rumba = RumbaSDModel(
          gtab,
          n_iter=20,
          recon_type="smf",
          n_coils=1,
          R=2,
          voxelwise=False,
          sphere=sphere,
      )
      rumba_tv = RumbaSDModel(
          gtab,
          n_iter=20,
          recon_type="smf",
          n_coils=1,
          R=2,
          voxelwise=False,
          use_tv=True,
          sphere=sphere,
      )
  
      # Testing input validation
      assert_raises(
          ValueError, rumba.fit, data[:, :, :, 0]
      )  # Must be 4D
      # TV can't work with singleton dimensions in data volume
      assert_raises(ValueError, rumba_tv.fit, data)
      # Mask must match first 3 dimensions of data
      assert_raises(
          ValueError, rumba.fit, data, mask=np.ones(data.shape)
      )
      # Recon type validation
      rumba_broken = RumbaSDModel(
          gtab, recon_type="test", voxelwise=False
      )
      assert_raises(ValueError, rumba_broken.fit, data)
  
      # Test on repulsion 724 sphere, with/without TV regularization
      for ix, model in enumerate([rumba, rumba_tv]):
          if ix:
              model_fit = model.fit(data_mvoxel)
          else:
              model_fit = model.fit(data)
  
          odf = model_fit.odf(sphere)
  
          directions, _, _ = peak_directions(
              odf[0, 0, 0], sphere, 0.35, 25
          )
          assert_equal(len(directions), 2)
          assert_almost_equal(
              angular_similarity(directions, golden_directions), 2, 1
          )
  
      # Test on data with 1, 2, 3, or no peaks
      sb_dummies = sticks_and_ball_dummies(gtab)
      for sbd in sb_dummies:
          data, golden_directions = sb_dummies[sbd]
          data = data[None, None, None, :]  # make 4D
  
          rumba_fit = rumba.fit(data)
          odf = rumba_fit.odf(sphere)
          f_iso = rumba_fit.f_iso
  
          directions, _, _ = peak_directions(
              odf[0, 0, 0], sphere, 0.35, 25
          )
          if len(directions) <= 3:
              # Verify small isotropic fraction in anisotropic case
              assert_equal(f_iso[0, 0, 0] < 0.1, True)
              assert_equal(len(directions), len(golden_directions))
          if len(directions) > 3:
              # Verify large isotropic fraction in isotropic case
              assert_equal(f_iso[0, 0, 0] > 0.8, True)
  
imports: import warnings
  import numpy
  from numpy.testing import assert_equal, assert_almost_equal, assert_array_equal, assert_allclose, assert_raises
  from numpy.testing import assert_
  from dipy.reconst.rumba import RumbaSDModel, generate_kernel
  from dipy.reconst.csdeconv import AxSymShResponse
  from dipy.data import get_fnames, dsi_voxels, default_sphere, get_sphere
  from dipy.core.gradients import gradient_table, unique_bvals_tolerance
  from dipy.core.geometry import cart2sphere
  from dipy.core.sphere_stats import angular_similarity
  from dipy.reconst.tests.test_dsi import sticks_and_ball_dummies
  from dipy.sims.voxel import sticks_and_ball, multi_tensor, single_tensor
  from dipy.direction.peaks import peak_directions
  from dipy.reconst.shm import descoteaux07_legacy_msg
label_desc: Use image node_id 6 for calling a global function with example usage: test_global_fit() without return types