docstr: Workflow for Intra-voxel Incoherent Motion reconstruction and for
  computing IVIM metrics. Performs a IVIM reconstruction on the files
  by 'globing' ``input_files`` and saves the IVIM metrics in a directory
  specified by ``out_dir``.
  
  Parameters
  ----------
  input_files : string
      Path to the input volumes. This path may contain wildcards to
      process multiple inputs at once.
  bvalues_files : string
      Path to the bvalues files. This path may contain wildcards to use
      multiple bvalues files at once.
  bvectors_files : string
      Path to the bvalues files. This path may contain wildcards to use
      multiple bvalues files at once.
  mask_files : string
      Path to the input masks. This path may contain wildcards to use
      multiple masks at once. (default: No mask used)
  split_b_D : int, optional
      Value to split the bvals to estimate D for the two-stage process of
      fitting.
  split_b_S0 : int, optional
      Value to split the bvals to estimate S0 for the two-stage process
      of fitting.
  b0_threshold : int, optional
      Threshold value for the b0 bval.
  save_metrics : variable string, optional
      List of metrics to save.
      Possible values: S0_predicted, perfusion_fraction, D_star, D
  out_dir : string, optional
      Output directory. (default current directory)
  out_S0_predicted : string, optional
      Name of the S0 signal estimated to be saved.
  out_perfusion_fraction : string, optional
      Name of the estimated volume fractions to be saved.
  out_D_star : string, optional
      Name of the estimated pseudo-diffusion parameter to be saved.
  out_D : string, optional
      Name of the estimated diffusion parameter to be saved.
  
  References
  ----------
  .. [Stejskal65] Stejskal, E. O.; Tanner, J. E. (1 January 1965).
                  "Spin Diffusion Measurements: Spin Echoes in the
                  Presence of a Time-Dependent Field Gradient". The
                  Journal of Chemical Physics 42 (1): 288.
                  Bibcode: 1965JChPh..42..288S. doi:10.1063/1.1695690.
  
  .. [LeBihan84] Le Bihan, Denis, et al. "Separation of diffusion
                 and perfusion in intravoxel incoherent motion MR
                 imaging." Radiology 168.2 (1988): 497-505.
docstr_tok: ["Workflow","for","Intra-voxel","Incoherent","Motion","reconstruction","and","for","computing","IVIM","metrics",".","Performs","a","IVIM","reconstruction","on","the","files","by","'globing","'","``","input_files","``","and","saves","the","IVIM","metrics","in","a","directory","specified","by","``","out_dir","``",".","Parameters","--","--","--","--","--","input_files",":","string","Path","to","the","input","volumes",".","This","path","may","contain","wildcards","to","process","multiple","inputs","at","once",".","bvalues_files",":","string","Path","to","the","bvalues","files",".","This","path","may","contain","wildcards","to","use","multiple","bvalues","files","at","once",".","bvectors_files",":","string","Path","to","the","bvalues","files",".","This","path","may","contain","wildcards","to","use","multiple","bvalues","files","at","once",".","mask_files",":","string","Path","to","the","input","masks",".","This","path","may","contain","wildcards","to","use","multiple","masks","at","once",".","(","default",":","No","mask","used",")","split_b_D",":","int",",","optional","Value","to","split","the","bvals","to","estimate","D","for","the","two-stage","process","of","fitting",".","split_b_S0",":","int",",","optional","Value","to","split","the","bvals","to","estimate","S0","for","the","two-stage","process","of","fitting",".","b0_threshold",":","int",",","optional","Threshold","value","for","the","b0","bval",".","save_metrics",":","variable","string",",","optional","List","of","metrics","to","save",".","Possible","values",":","S0_predicted",",","perfusion_fraction",",","D_star",",","D","out_dir",":","string",",","optional","Output","directory",".","(","default","current","directory",")","out_S0_predicted",":","string",",","optional","Name","of","the","S0","signal","estimated","to","be","saved",".","out_perfusion_fraction",":","string",",","optional","Name","of","the","estimated","volume","fractions","to","be","saved",".","out_D_star",":","string",",","optional","Name","of","the","estimated","pseudo-diffusion","parameter","to","be","saved",".","out_D",":","string",",","optional","Name","of","the","estimated","diffusion","parameter","to","be","saved",".","References","--","--","--","--","--","..","[","Stejskal65","]","Stejskal",",","E.","O.",";","Tanner",",","J.","E.","(","1","January","1965",")",".","``","Spin","Diffusion","Measurements",":","Spin","Echoes","in","the","Presence","of","a","Time-Dependent","Field","Gradient","''",".","The","Journal","of","Chemical","Physics","42","(","1",")",":","288",".","Bibcode",":","1965JChPh","..","42","..","288S",".","doi:10.1063\/1.1695690",".","..","[","LeBihan84","]","Le","Bihan",",","Denis",",","et","al",".","``","Separation","of","diffusion","and","perfusion","in","intravoxel","incoherent","motion","MR","imaging",".","''","Radiology","168.2","(","1988",")",":","497-505","."]
code: def run(
      self,
      input_files,
      bvalues_files,
      bvectors_files,
      mask_files,
      split_b_D=400,
      split_b_S0=200,
      b0_threshold=0,
      save_metrics=None,
      out_dir="",
      out_S0_predicted="S0_predicted.nii.gz",
      out_perfusion_fraction="perfusion_fraction.nii.gz",
      out_D_star="D_star.nii.gz",
      out_D="D.nii.gz",
  ):
      """Workflow for Intra-voxel Incoherent Motion reconstruction and for
      computing IVIM metrics. Performs a IVIM reconstruction on the files
      by 'globing' ``input_files`` and saves the IVIM metrics in a directory
      specified by ``out_dir``.
  
      Parameters
      ----------
      input_files : string
          Path to the input volumes. This path may contain wildcards to
          process multiple inputs at once.
      bvalues_files : string
          Path to the bvalues files. This path may contain wildcards to use
          multiple bvalues files at once.
      bvectors_files : string
          Path to the bvalues files. This path may contain wildcards to use
          multiple bvalues files at once.
      mask_files : string
          Path to the input masks. This path may contain wildcards to use
          multiple masks at once. (default: No mask used)
      split_b_D : int, optional
          Value to split the bvals to estimate D for the two-stage process of
          fitting.
      split_b_S0 : int, optional
          Value to split the bvals to estimate S0 for the two-stage process
          of fitting.
      b0_threshold : int, optional
          Threshold value for the b0 bval.
      save_metrics : variable string, optional
          List of metrics to save.
          Possible values: S0_predicted, perfusion_fraction, D_star, D
      out_dir : string, optional
          Output directory. (default current directory)
      out_S0_predicted : string, optional
          Name of the S0 signal estimated to be saved.
      out_perfusion_fraction : string, optional
          Name of the estimated volume fractions to be saved.
      out_D_star : string, optional
          Name of the estimated pseudo-diffusion parameter to be saved.
      out_D : string, optional
          Name of the estimated diffusion parameter to be saved.
  
      References
      ----------
      .. [Stejskal65] Stejskal, E. O.; Tanner, J. E. (1 January 1965).
                      "Spin Diffusion Measurements: Spin Echoes in the
                      Presence of a Time-Dependent Field Gradient". The
                      Journal of Chemical Physics 42 (1): 288.
                      Bibcode: 1965JChPh..42..288S. doi:10.1063/1.1695690.
  
      .. [LeBihan84] Le Bihan, Denis, et al. "Separation of diffusion
                     and perfusion in intravoxel incoherent motion MR
                     imaging." Radiology 168.2 (1988): 497-505.
      """
      save_metrics = save_metrics or []
  
      io_it = self.get_io_iterator()
  
      for (
          dwi,
          bval,
          bvec,
          mask,
          oS0_predicted,
          operfusion_fraction,
          oD_star,
          oD,
      ) in io_it:
          logging.info("Computing IVIM metrics for {0}".format(dwi))
          data, affine = load_nifti(dwi)
  
          if mask is not None:
              mask = load_nifti_data(mask).astype(bool)
  
          ivimfit, _ = self.get_fitted_ivim(
              data, mask, bval, bvec, b0_threshold
          )
  
          if not save_metrics:
              save_metrics = [
                  "S0_predicted",
                  "perfusion_fraction",
                  "D_star",
                  "D",
              ]
  
          if "S0_predicted" in save_metrics:
              save_nifti(
                  oS0_predicted,
                  ivimfit.S0_predicted.astype(np.float32),
                  affine,
              )
  
          if "perfusion_fraction" in save_metrics:
              save_nifti(
                  operfusion_fraction,
                  ivimfit.perfusion_fraction.astype(np.float32),
                  affine,
              )
  
          if "D_star" in save_metrics:
              save_nifti(
                  oD_star, ivimfit.D_star.astype(np.float32), affine
              )
  
          if "D" in save_metrics:
              save_nifti(oD, ivimfit.D.astype(np.float32), affine)
  
          logging.info(
              "IVIM metrics saved in {0}".format(os.path.dirname(oD))
          )
  
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 ReconstIvimFlow obj's underlying member method code with example usage: obj.run(input_files, bvalues_files, bvectors_files, mask_files, split_b_D, split_b_S0, b0_threshold, save_metrics, out_dir, out_S0_predicted, out_perfusion_fraction, out_D_star, out_D) without return types