docstr: Workflow for fitting the MAPMRI model (with optional Laplacian
  regularization). Generates rtop, lapnorm, msd, qiv, rtap, rtpp,
  non-gaussian (ng), parallel ng, perpendicular ng saved in a nifti
  format in input files provided by `data_files` and saves the nifti
  files to an output directory specified by `out_dir`.
  
  In order for the MAPMRI workflow to work in the way
  intended either the Laplacian or positivity or both must
  be set to True.
  
  Parameters
  ----------
  data_files : string
      Path to the input volume.
  bvals_files : string
      Path to the bval files.
  bvecs_files : string
      Path to the bvec files.
  small_delta : float
      Small delta value used in generation of gradient table of provided
      bval and bvec.
  big_delta : float
      Big delta value used in generation of gradient table of provided
      bval and bvec.
  b0_threshold : float, optional
      Threshold used to find b0 volumes.
  laplacian : bool, optional
      Regularize using the Laplacian of the MAP-MRI basis.
  positivity : bool, optional
      Constrain the propagator to be positive.
  bval_threshold : float, optional
      Sets the b-value threshold to be used in the scale factor
      estimation. In order for the estimated non-Gaussianity to have
      meaning this value should set to a lower value (b<2000 s/mm^2)
      such that the scale factors are estimated on signal points that
      reasonably represent the spins at Gaussian diffusion.
  save_metrics : variable string, optional
      List of metrics to save.
      Possible values: rtop, laplacian_signal, msd, qiv, rtap, rtpp,
      ng, perng, parng
  laplacian_weighting : float, optional
      Weighting value used in fitting the MAPMRI model in the Laplacian
      and both model types.
  radial_order : unsigned int, optional
      Even value used to set the order of the basis.
  out_dir : string, optional
      Output directory. (default: current directory)
  out_rtop : string, optional
      Name of the rtop to be saved.
  out_lapnorm : string, optional
      Name of the norm of Laplacian signal to be saved.
  out_msd : string, optional
      Name of the msd to be saved.
  out_qiv : string, optional
      Name of the qiv to be saved.
  out_rtap : string, optional
      Name of the rtap to be saved.
  out_rtpp : string, optional
      Name of the rtpp to be saved.
  out_ng : string, optional
      Name of the Non-Gaussianity to be saved.
  out_perng :  string, optional
      Name of the Non-Gaussianity perpendicular to be saved.
  out_parng : string, optional
      Name of the Non-Gaussianity parallel to be saved.
docstr_tok: ["Workflow","for","fitting","the","MAPMRI","model","(","with","optional","Laplacian","regularization",")",".","Generates","rtop",",","lapnorm",",","msd",",","qiv",",","rtap",",","rtpp",",","non-gaussian","(","ng",")",",","parallel","ng",",","perpendicular","ng","saved","in","a","nifti","format","in","input","files","provided","by","`","data_files","`","and","saves","the","nifti","files","to","an","output","directory","specified","by","`","out_dir","`",".","In","order","for","the","MAPMRI","workflow","to","work","in","the","way","intended","either","the","Laplacian","or","positivity","or","both","must","be","set","to","True",".","Parameters","--","--","--","--","--","data_files",":","string","Path","to","the","input","volume",".","bvals_files",":","string","Path","to","the","bval","files",".","bvecs_files",":","string","Path","to","the","bvec","files",".","small_delta",":","float","Small","delta","value","used","in","generation","of","gradient","table","of","provided","bval","and","bvec",".","big_delta",":","float","Big","delta","value","used","in","generation","of","gradient","table","of","provided","bval","and","bvec",".","b0_threshold",":","float",",","optional","Threshold","used","to","find","b0","volumes",".","laplacian",":","bool",",","optional","Regularize","using","the","Laplacian","of","the","MAP-MRI","basis",".","positivity",":","bool",",","optional","Constrain","the","propagator","to","be","positive",".","bval_threshold",":","float",",","optional","Sets","the","b-value","threshold","to","be","used","in","the","scale","factor","estimation",".","In","order","for","the","estimated","non-Gaussianity","to","have","meaning","this","value","should","set","to","a","lower","value","(","b","<","2000","s\/mm^2",")","such","that","the","scale","factors","are","estimated","on","signal","points","that","reasonably","represent","the","spins","at","Gaussian","diffusion",".","save_metrics",":","variable","string",",","optional","List","of","metrics","to","save",".","Possible","values",":","rtop",",","laplacian_signal",",","msd",",","qiv",",","rtap",",","rtpp",",","ng",",","perng",",","parng","laplacian_weighting",":","float",",","optional","Weighting","value","used","in","fitting","the","MAPMRI","model","in","the","Laplacian","and","both","model","types",".","radial_order",":","unsigned","int",",","optional","Even","value","used","to","set","the","order","of","the","basis",".","out_dir",":","string",",","optional","Output","directory",".","(","default",":","current","directory",")","out_rtop",":","string",",","optional","Name","of","the","rtop","to","be","saved",".","out_lapnorm",":","string",",","optional","Name","of","the","norm","of","Laplacian","signal","to","be","saved",".","out_msd",":","string",",","optional","Name","of","the","msd","to","be","saved",".","out_qiv",":","string",",","optional","Name","of","the","qiv","to","be","saved",".","out_rtap",":","string",",","optional","Name","of","the","rtap","to","be","saved",".","out_rtpp",":","string",",","optional","Name","of","the","rtpp","to","be","saved",".","out_ng",":","string",",","optional","Name","of","the","Non-Gaussianity","to","be","saved",".","out_perng",":","string",",","optional","Name","of","the","Non-Gaussianity","perpendicular","to","be","saved",".","out_parng",":","string",",","optional","Name","of","the","Non-Gaussianity","parallel","to","be","saved","."]
code: def run(
      self,
      data_files,
      bvals_files,
      bvecs_files,
      small_delta,
      big_delta,
      b0_threshold=50.0,
      laplacian=True,
      positivity=True,
      bval_threshold=2000,
      save_metrics=(),
      laplacian_weighting=0.05,
      radial_order=6,
      out_dir="",
      out_rtop="rtop.nii.gz",
      out_lapnorm="lapnorm.nii.gz",
      out_msd="msd.nii.gz",
      out_qiv="qiv.nii.gz",
      out_rtap="rtap.nii.gz",
      out_rtpp="rtpp.nii.gz",
      out_ng="ng.nii.gz",
      out_perng="perng.nii.gz",
      out_parng="parng.nii.gz",
  ):
      """Workflow for fitting the MAPMRI model (with optional Laplacian
      regularization). Generates rtop, lapnorm, msd, qiv, rtap, rtpp,
      non-gaussian (ng), parallel ng, perpendicular ng saved in a nifti
      format in input files provided by `data_files` and saves the nifti
      files to an output directory specified by `out_dir`.
  
      In order for the MAPMRI workflow to work in the way
      intended either the Laplacian or positivity or both must
      be set to True.
  
      Parameters
      ----------
      data_files : string
          Path to the input volume.
      bvals_files : string
          Path to the bval files.
      bvecs_files : string
          Path to the bvec files.
      small_delta : float
          Small delta value used in generation of gradient table of provided
          bval and bvec.
      big_delta : float
          Big delta value used in generation of gradient table of provided
          bval and bvec.
      b0_threshold : float, optional
          Threshold used to find b0 volumes.
      laplacian : bool, optional
          Regularize using the Laplacian of the MAP-MRI basis.
      positivity : bool, optional
          Constrain the propagator to be positive.
      bval_threshold : float, optional
          Sets the b-value threshold to be used in the scale factor
          estimation. In order for the estimated non-Gaussianity to have
          meaning this value should set to a lower value (b<2000 s/mm^2)
          such that the scale factors are estimated on signal points that
          reasonably represent the spins at Gaussian diffusion.
      save_metrics : variable string, optional
          List of metrics to save.
          Possible values: rtop, laplacian_signal, msd, qiv, rtap, rtpp,
          ng, perng, parng
      laplacian_weighting : float, optional
          Weighting value used in fitting the MAPMRI model in the Laplacian
          and both model types.
      radial_order : unsigned int, optional
          Even value used to set the order of the basis.
      out_dir : string, optional
          Output directory. (default: current directory)
      out_rtop : string, optional
          Name of the rtop to be saved.
      out_lapnorm : string, optional
          Name of the norm of Laplacian signal to be saved.
      out_msd : string, optional
          Name of the msd to be saved.
      out_qiv : string, optional
          Name of the qiv to be saved.
      out_rtap : string, optional
          Name of the rtap to be saved.
      out_rtpp : string, optional
          Name of the rtpp to be saved.
      out_ng : string, optional
          Name of the Non-Gaussianity to be saved.
      out_perng :  string, optional
          Name of the Non-Gaussianity perpendicular to be saved.
      out_parng : string, optional
          Name of the Non-Gaussianity parallel to be saved.
      """
      io_it = self.get_io_iterator()
      for (
          dwi,
          bval,
          bvec,
          out_rtop,
          out_lapnorm,
          out_msd,
          out_qiv,
          out_rtap,
          out_rtpp,
          out_ng,
          out_perng,
          out_parng,
      ) in io_it:
          logging.info("Computing MAPMRI metrics for {0}".format(dwi))
          data, affine = load_nifti(dwi)
  
          bvals, bvecs = read_bvals_bvecs(bval, bvec)
          # If all b-values are smaller or equal to the b0 threshold, it is
          # assumed that no thresholding is requested
          if any(mask_non_weighted_bvals(bvals, b0_threshold)):
              if b0_threshold < bvals.min():
                  warn(
                      "b0_threshold (value: {0}) is too low, increase your "
                      "b0_threshold. It should be higher than the first b0 "
                      "value({1}).".format(b0_threshold, bvals.min())
                  )
          gtab = gradient_table(
              bvals=bvals,
              bvecs=bvecs,
              small_delta=small_delta,
              big_delta=big_delta,
              b0_threshold=b0_threshold,
          )
  
          if not save_metrics:
              save_metrics = [
                  "rtop",
                  "laplacian_signal",
                  "msd",
                  "qiv",
                  "rtap",
                  "rtpp",
                  "ng",
                  "perng",
                  "parng",
              ]
  
          if laplacian and positivity:
              map_model_aniso = mapmri.MapmriModel(
                  gtab,
                  radial_order=radial_order,
                  laplacian_regularization=True,
                  laplacian_weighting=laplacian_weighting,
                  positivity_constraint=True,
                  bval_threshold=bval_threshold,
              )
  
              mapfit_aniso = map_model_aniso.fit(data)
  
          elif positivity:
              map_model_aniso = mapmri.MapmriModel(
                  gtab,
                  radial_order=radial_order,
                  laplacian_regularization=False,
                  positivity_constraint=True,
                  bval_threshold=bval_threshold,
              )
              mapfit_aniso = map_model_aniso.fit(data)
  
          elif laplacian:
              map_model_aniso = mapmri.MapmriModel(
                  gtab,
                  radial_order=radial_order,
                  laplacian_regularization=True,
                  laplacian_weighting=laplacian_weighting,
                  bval_threshold=bval_threshold,
              )
              mapfit_aniso = map_model_aniso.fit(data)
  
          else:
              map_model_aniso = mapmri.MapmriModel(
                  gtab,
                  radial_order=radial_order,
                  laplacian_regularization=False,
                  positivity_constraint=False,
                  bval_threshold=bval_threshold,
              )
              mapfit_aniso = map_model_aniso.fit(data)
  
          # for name, fname, func in [('rtop', out_rtop, mapfit_aniso.rtop),
          #                           ]:
          #     if name in save_metrics:
          #         r = func()
          #         save_nifti(fname, r.astype(np.float32), affine)
  
          if "rtop" in save_metrics:
              r = mapfit_aniso.rtop()
              save_nifti(out_rtop, r.astype(np.float32), affine)
  
          if "laplacian_signal" in save_metrics:
              ll = mapfit_aniso.norm_of_laplacian_signal()
              save_nifti(out_lapnorm, ll.astype(np.float32), affine)
  
          if "msd" in save_metrics:
              m = mapfit_aniso.msd()
              save_nifti(out_msd, m.astype(np.float32), affine)
  
          if "qiv" in save_metrics:
              q = mapfit_aniso.qiv()
              save_nifti(out_qiv, q.astype(np.float32), affine)
  
          if "rtap" in save_metrics:
              r = mapfit_aniso.rtap()
              save_nifti(out_rtap, r.astype(np.float32), affine)
  
          if "rtpp" in save_metrics:
              r = mapfit_aniso.rtpp()
              save_nifti(out_rtpp, r.astype(np.float32), affine)
  
          if "ng" in save_metrics:
              n = mapfit_aniso.ng()
              save_nifti(out_ng, n.astype(np.float32), affine)
  
          if "perng" in save_metrics:
              n = mapfit_aniso.ng_perpendicular()
              save_nifti(out_perng, n.astype(np.float32), affine)
  
          if "parng" in save_metrics:
              n = mapfit_aniso.ng_parallel()
              save_nifti(out_parng, n.astype(np.float32), affine)
  
          logging.info(
              "MAPMRI saved in {0}".format(os.path.dirname(out_dir))
          )
  
imports: import logging
  import numpy
  import os.path
  from ast import literal_eval
  from warnings import warn
  import nibabel
  from dipy.core.gradients import mask_non_weighted_bvals, gradient_table
  from dipy.data import default_sphere, get_sphere
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.io.peaks import save_peaks, peaks_to_niftis
  from dipy.io.image import load_nifti, save_nifti, load_nifti_data
  from dipy.io.utils import nifti1_symmat
  from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel, auto_response_ssst
  from dipy.reconst.dti import TensorModel, color_fa, fractional_anisotropy, geodesic_anisotropy, mean_diffusivity, axial_diffusivity, radial_diffusivity, lower_triangular, mode
  from dipy.direction.peaks import peaks_from_model
  from dipy.reconst.shm import CsaOdfModel
  from dipy.workflows.workflow import Workflow
  from dipy.reconst.dki import DiffusionKurtosisModel, split_dki_param
  from dipy.reconst.ivim import IvimModel
  from dipy.reconst.rumba import RumbaSDModel
  from dipy.reconst import mapmri
  from dipy.utils.deprecator import deprecated_params
label_desc: Use image node_id 2 for calling the ReconstMAPMRIFlow obj's underlying member method code with example usage: obj.run(data_files, bvals_files, bvecs_files, small_delta, big_delta, b0_threshold, laplacian, positivity, bval_threshold, save_metrics, laplacian_weighting, radial_order, out_dir, out_rtop, out_lapnorm, out_msd, out_qiv, out_rtap, out_rtpp, out_ng, out_perng, out_parng) without return types