code: def test_predict():
      SNR = 1000
      S0 = 100
      _, fbvals, fbvecs = dpd.get_fnames("small_64D")
      bvals, bvecs = read_bvals_bvecs(fbvals, fbvecs)
      gtab = grad.gradient_table(bvals, bvecs)
      mevals = np.array(
          ([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003])
      )
      angles = [(0, 0), (60, 0)]
      S, sticks = sims.multi_tensor(
          gtab, mevals, S0, angles=angles, fractions=[10, 90], snr=SNR
      )
  
      sfmodel = sfm.SparseFascicleModel(
          gtab, response=[0.0015, 0.0003, 0.0003]
      )
      sffit = sfmodel.fit(S)
      pred = sffit.predict()
      npt.assert_(xval.coeff_of_determination(pred, S) > 97)
  
      # Should be possible to predict using a different gtab:
      new_gtab = grad.gradient_table(bvals[::2], bvecs[::2])
      new_pred = sffit.predict(new_gtab)
      npt.assert_(xval.coeff_of_determination(new_pred, S[::2]) > 97)
  
      # Should be possible to predict for a single direction:
      with warnings.catch_warnings():
          warnings.simplefilter("ignore", category=UserWarning)
          new_gtab = grad.gradient_table(
              bvals[1][None], bvecs[1][None, :]
          )
      new_pred = sffit.predict(new_gtab)
  
      # Fitting and predicting with a volume of data:
      fdata, fbval, fbvec = dpd.get_fnames("small_25")
      gtab = grad.gradient_table(fbval, fbvec)
      data = load_nifti_data(fdata)
      sfmodel = sfm.SparseFascicleModel(
          gtab, response=[0.0015, 0.0003, 0.0003]
      )
      sffit = sfmodel.fit(data)
      pred = sffit.predict()
  
      # Should be possible to predict using a different gtab:
      new_gtab = grad.gradient_table(bvals[::2], bvecs[::2])
      new_pred = sffit.predict(new_gtab)
      npt.assert_equal(
          new_pred.shape,
          data.shape[:-1] + bvals[::2].shape,
      )
  
      # Should be possible to predict for a single direction:
      with warnings.catch_warnings():
          warnings.simplefilter("ignore", category=UserWarning)
          new_gtab = grad.gradient_table(
              bvals[1][None], bvecs[1][None, :]
          )
      new_pred = sffit.predict(new_gtab)
      npt.assert_equal(new_pred.shape, data.shape[:-1])
  
      # Fitting and predicting with masked data:
      mask = np.zeros(data.shape[:3])
      mask[2:5, 2:5, :] = 1
      sffit = sfmodel.fit(data, mask=mask)
      pred = sffit.predict()
      npt.assert_equal(pred.shape, data.shape)
  
      # Should be possible to predict using a different gtab:
      new_gtab = grad.gradient_table(bvals[::2], bvecs[::2])
      new_pred = sffit.predict(new_gtab)
      npt.assert_equal(
          new_pred.shape,
          data.shape[:-1] + bvals[::2].shape,
      )
      npt.assert_equal(new_pred[0, 0, 0], 0)
  
      # Should be possible to predict for a single direction:
      with warnings.catch_warnings():
          warnings.simplefilter("ignore", category=UserWarning)
          new_gtab = grad.gradient_table(
              bvals[1][None], bvecs[1][None, :]
          )
      new_pred = sffit.predict(new_gtab)
      npt.assert_equal(new_pred.shape, data.shape[:-1])
      npt.assert_equal(new_pred[0, 0, 0], 0)
  
file_path: dipy/dipy/reconst/tests/test_sfm.py
imports: import warnings
  import numpy
  import numpy.testing
  import pytest
  import dipy.reconst.sfm
  import dipy.data
  import dipy.core.gradients
  import dipy.sims.voxel
  import dipy.core.optimize
  import dipy.reconst.cross_validation
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.io.image import load_nifti_data
  from dipy.utils.optpkg import optional_package
label_desc: Use image node_id 3 for calling a global function with example usage: test_predict() without return types