code: def save_peaks(fname, pam, affine=None, verbose=False):
      """Save all important attributes of object PeaksAndMetrics in a PAM5 file
      (HDF5).
  
      Parameters
      ----------
      fname : string
          Filename of PAM5 file
      pam : PeaksAndMetrics
          Object holding peak_dirs, shm_coeffs and other attributes
      affine : array
          The 4x4 matrix transforming the date from native to world coordinates.
          PeaksAndMetrics should have that attribute but if not it can be
          provided here. Default None.
      verbose : bool
          Print summary information about the saved file.
      """
  
      if os.path.splitext(fname)[1] != ".pam5":
          raise OSError("This function saves only PAM5 (HDF5) files")
  
      if not (
          hasattr(pam, "peak_dirs")
          and hasattr(pam, "peak_values")
          and hasattr(pam, "peak_indices")
      ):
          msg = "Cannot save object without peak_dirs, peak_values"
          msg += " and peak_indices"
          raise ValueError(msg)
  
      f = h5py.File(fname, "w")
  
      group = f.create_group("pam")
      f.attrs["version"] = "0.0.1"
  
      version_string = f.attrs["version"]
  
      affine = pam.affine if hasattr(pam, "affine") else affine
      shm_coeff = pam.shm_coeff if hasattr(pam, "shm_coeff") else None
      odf = pam.odf if hasattr(pam, "odf") else None
  
      _safe_save(group, affine, "affine")
      _safe_save(group, pam.peak_dirs, "peak_dirs")
      _safe_save(group, pam.peak_values, "peak_values")
      _safe_save(group, pam.peak_indices, "peak_indices")
      _safe_save(group, shm_coeff, "shm_coeff")
      _safe_save(group, pam.sphere.vertices, "sphere_vertices")
      _safe_save(group, pam.B, "B")
      _safe_save(group, np.array([pam.total_weight]), "total_weight")
      _safe_save(group, np.array([pam.ang_thr]), "ang_thr")
      _safe_save(group, pam.gfa, "gfa")
      _safe_save(group, pam.qa, "qa")
      _safe_save(group, odf, "odf")
  
      f.close()
  
      if verbose:
          print("PAM5 version")
          print(version_string)
          print("Affine")
          print(affine)
          print("Dirs shape")
          print(pam.peak_dirs.shape)
          print("SH shape")
          if shm_coeff is not None:
              print(shm_coeff.shape)
          else:
              print("None")
          print("ODF shape")
          if odf is not None:
              print(pam.odf.shape)
          else:
              print("None")
          print("Total weight")
          print(pam.total_weight)
          print("Angular threshold")
          print(pam.ang_thr)
          print("Sphere vertices shape")
          print(pam.sphere.vertices.shape)
  
      return pam
  
file_path: dipy/dipy/io/peaks.py
imports: import os
  import numpy
  from dipy.direction.peaks import PeaksAndMetrics, reshape_peaks_for_visualization
  from dipy.core.sphere import Sphere
  from dipy.io.image import save_nifti
  import h5py
label_desc: Use image node_id 3 for calling a global function with example usage: save_peaks(fname, pam, affine, verbose) and returns: pam