code: def test_dti_xval():
      data = load_nifti_data(fdata)
      gtab = gt.gradient_table(fbval, fbvec)
      dm = dti.TensorModel(gtab, "LS")
      # The data has 102 directions, so will not divide neatly into 10 bits
      npt.assert_raises(ValueError, xval.kfold_xval, dm, data, 10)
  
      # In simulation with no noise, COD should be perfect:
      psphere = dpd.get_sphere("symmetric362")
      bvecs = np.concatenate(([[0, 0, 0]], psphere.vertices))
      bvals = np.zeros(len(bvecs)) + 1000
      bvals[0] = 0
      gtab = gt.gradient_table(bvals, bvecs)
      mevals = np.array(
          ([0.0015, 0.0003, 0.0001], [0.0015, 0.0003, 0.0003])
      )
      mevecs = [
          np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
          np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]),
      ]
      S = sims.single_tensor(gtab, 100, mevals[0], mevecs[0], snr=None)
  
      dm = dti.TensorModel(gtab, "LS")
      kf_xval = xval.kfold_xval(dm, S, 2)
      cod = xval.coeff_of_determination(S, kf_xval)
      npt.assert_array_almost_equal(
          cod, np.ones(kf_xval.shape[:-1]) * 100
      )
  
      # Test with 2D data for use of a mask
      S = np.array([[S, S], [S, S]])
      mask = np.ones(S.shape[:-1], dtype=bool)
      mask[1, 1] = 0
      kf_xval = xval.kfold_xval(dm, S, 2, mask=mask)
      cod2d = xval.coeff_of_determination(S, kf_xval)
      npt.assert_array_almost_equal(np.round(cod2d[0, 0]), cod)
  
file_path: dipy/dipy/reconst/tests/test_cross_validation.py
imports: import warnings
  import numpy
  import numpy.testing
  import dipy.reconst.cross_validation
  import dipy.data
  import dipy.reconst.dti
  import dipy.core.gradients
  import dipy.sims.voxel
  import dipy.reconst.csdeconv
  import dipy.reconst.base
  from dipy.io.image import load_nifti_data
  from dipy.reconst.shm import descoteaux07_legacy_msg
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 2 for calling a global function with example usage: test_dti_xval() without return types