code: def test_peaksFromModel():
      data = np.zeros((10, 2))
  
      for sphere in [_sphere, get_sphere("symmetric642")]:
          # Test basic case
          model = SimpleOdfModel(_gtab)
          _odf = (sphere.vertices * [1, 2, 3]).sum(-1)
          odf_argmax = _odf.argmax()
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore",
                  message=descoteaux07_legacy_msg,
                  category=PendingDeprecationWarning,
              )
              pam = peaks_from_model(
                  model, data, sphere, 0.5, 45, normalize_peaks=True
              )
  
          assert_array_equal(pam.gfa, gfa(_odf))
          assert_array_equal(pam.peak_values[:, 0], 1.0)
          assert_array_equal(pam.peak_values[:, 1:], 0.0)
          mn, mx = _odf.min(), _odf.max()
          assert_array_equal(pam.qa[:, 0], (mx - mn) / mx)
          assert_array_equal(pam.qa[:, 1:], 0.0)
          assert_array_equal(pam.peak_indices[:, 0], odf_argmax)
          assert_array_equal(pam.peak_indices[:, 1:], -1)
  
          # Test that odf array matches and is right shape
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore",
                  message=descoteaux07_legacy_msg,
                  category=PendingDeprecationWarning,
              )
              pam = peaks_from_model(
                  model, data, sphere, 0.5, 45, return_odf=True
              )
          expected_shape = (len(data), len(_odf))
          assert_equal(pam.odf.shape, expected_shape)
          assert_((_odf == pam.odf).all())
          assert_array_equal(pam.peak_values[:, 0], _odf.max())
  
          # Test mask
          mask = (np.arange(10) % 2) == 1
  
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore",
                  message=descoteaux07_legacy_msg,
                  category=PendingDeprecationWarning,
              )
              pam = peaks_from_model(
                  model,
                  data,
                  sphere,
                  0.5,
                  45,
                  mask=mask,
                  normalize_peaks=True,
              )
          assert_array_equal(pam.gfa[~mask], 0)
          assert_array_equal(pam.qa[~mask], 0)
          assert_array_equal(pam.peak_values[~mask], 0)
          assert_array_equal(pam.peak_indices[~mask], -1)
  
          assert_array_equal(pam.gfa[mask], gfa(_odf))
          assert_array_equal(pam.peak_values[mask, 0], 1.0)
          assert_array_equal(pam.peak_values[mask, 1:], 0.0)
          mn, mx = _odf.min(), _odf.max()
          assert_array_equal(pam.qa[mask, 0], (mx - mn) / mx)
          assert_array_equal(pam.qa[mask, 1:], 0.0)
          assert_array_equal(pam.peak_indices[mask, 0], odf_argmax)
          assert_array_equal(pam.peak_indices[mask, 1:], -1)
  
          # Test serialization and deserialization:
          for normalize_peaks in [True, False]:
              for return_odf in [True, False]:
                  for return_sh in [True, False]:
                      with warnings.catch_warnings():
                          warnings.filterwarnings(
                              "ignore",
                              message=descoteaux07_legacy_msg,
                              category=PendingDeprecationWarning,
                          )
                          pam = peaks_from_model(
                              model,
                              data,
                              sphere,
                              0.5,
                              45,
                              normalize_peaks=normalize_peaks,
                              return_odf=return_odf,
                              return_sh=return_sh,
                          )
  
                      b = BytesIO()
                      pickle.dump(pam, b)
                      b.seek(0)
                      new_pam = pickle.load(b)
                      b.close()
  
                      for attr in [
                          "peak_dirs",
                          "peak_values",
                          "peak_indices",
                          "gfa",
                          "qa",
                          "shm_coeff",
                          "B",
                          "odf",
                      ]:
                          assert_array_equal(
                              getattr(pam, attr), getattr(new_pam, attr)
                          )
                          assert_array_equal(
                              pam.sphere.vertices,
                              new_pam.sphere.vertices,
                          )
  
imports: import warnings
  import numpy
  import pickle
  from io import BytesIO
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_
  from dipy.reconst.odf import OdfFit, OdfModel, gfa
  from dipy.direction.peaks import peaks_from_model, peak_directions, peak_directions_nl, reshape_peaks_for_visualization
  from dipy.core.subdivide_octahedron import create_unit_hemisphere
  from dipy.core.sphere import unit_icosahedron
  from dipy.sims.voxel import multi_tensor, multi_tensor_odf
  from dipy.data import get_fnames, get_sphere, default_sphere
  from dipy.core.gradients import gradient_table, GradientTable
  from dipy.core.sphere_stats import angular_similarity
  from dipy.core.sphere import HemiSphere
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.reconst.shm import descoteaux07_legacy_msg, tournier07_legacy_msg
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 8 for calling a global function with example usage: test_peaksFromModel() without return types