docstr: Workflow wrapping Marcenko-Pastur PCA denoising method.
  
  Parameters
  ----------
  input_files : string
      Path to the input volumes. This path may contain wildcards to
      process multiple inputs at once.
  patch_radius : variable int, optional
      The radius of the local patch to be taken around each voxel (in
      voxels) For example, for a patch radius with value 2, and assuming
      the input image is a 3D image, the denoising will take place in
      blocks of 5x5x5 voxels.
  pca_method : string, optional
      Use either eigenvalue decomposition ('eig') or singular value
      decomposition ('svd') for principal component analysis. The default
      method is 'eig' which is faster. However, occasionally 'svd' might
      be more accurate.
  return_sigma : bool, optional
      If true, a noise standard deviation estimate based on the
      Marcenko-Pastur distribution is returned [2]_.
  out_dir : string, optional
      Output directory. (default current directory)
  out_denoised : string, optional
      Name of the resulting denoised volume.
  out_sigma : string, optional
      Name of the resulting sigma volume.
  
  References
  ----------
  .. [1] Veraart J, Novikov DS, Christiaens D, Ades-aron B, Sijbers,
  Fieremans E, 2016. Denoising of Diffusion MRI using random matrix
  theory. Neuroimage 142:394-406.
  doi: 10.1016/j.neuroimage.2016.08.016
  
  .. [2] Veraart J, Fieremans E, Novikov DS. 2016. Diffusion MRI noise
  mapping using random matrix theory. Magnetic Resonance in Medicine.
  doi: 10.1002/mrm.26059.
docstr_tok: ["Workflow","wrapping","Marcenko-Pastur","PCA","denoising","method",".","Parameters","--","--","--","--","--","input_files",":","string","Path","to","the","input","volumes",".","This","path","may","contain","wildcards","to","process","multiple","inputs","at","once",".","patch_radius",":","variable","int",",","optional","The","radius","of","the","local","patch","to","be","taken","around","each","voxel","(","in","voxels",")","For","example",",","for","a","patch","radius","with","value","2",",","and","assuming","the","input","image","is","a","3D","image",",","the","denoising","will","take","place","in","blocks","of","5x5x5","voxels",".","pca_method",":","string",",","optional","Use","either","eigenvalue","decomposition","(","'eig","'",")","or","singular","value","decomposition","(","'svd","'",")","for","principal","component","analysis",".","The","default","method","is","'eig","'","which","is","faster",".","However",",","occasionally","'svd","'","might","be","more","accurate",".","return_sigma",":","bool",",","optional","If","true",",","a","noise","standard","deviation","estimate","based","on","the","Marcenko-Pastur","distribution","is","returned","[","2","]","_.","out_dir",":","string",",","optional","Output","directory",".","(","default","current","directory",")","out_denoised",":","string",",","optional","Name","of","the","resulting","denoised","volume",".","out_sigma",":","string",",","optional","Name","of","the","resulting","sigma","volume",".","References","--","--","--","--","--","..","[","1","]","Veraart","J",",","Novikov","DS",",","Christiaens","D",",","Ades-aron","B",",","Sijbers",",","Fieremans","E",",","2016",".","Denoising","of","Diffusion","MRI","using","random","matrix","theory",".","Neuroimage","142:394-406.","doi",":","10.1016\/j.neuroimage.2016.08.016","..","[","2","]","Veraart","J",",","Fieremans","E",",","Novikov","DS",".","2016",".","Diffusion","MRI","noise","mapping","using","random","matrix","theory",".","Magnetic","Resonance","in","Medicine",".","doi",":","10.1002\/mrm.26059","."]
code: def run(
      self,
      input_files,
      patch_radius=2,
      pca_method="eig",
      return_sigma=False,
      out_dir="",
      out_denoised="dwi_mppca.nii.gz",
      out_sigma="dwi_sigma.nii.gz",
  ):
      r"""Workflow wrapping Marcenko-Pastur PCA denoising method.
  
      Parameters
      ----------
      input_files : string
          Path to the input volumes. This path may contain wildcards to
          process multiple inputs at once.
      patch_radius : variable int, optional
          The radius of the local patch to be taken around each voxel (in
          voxels) For example, for a patch radius with value 2, and assuming
          the input image is a 3D image, the denoising will take place in
          blocks of 5x5x5 voxels.
      pca_method : string, optional
          Use either eigenvalue decomposition ('eig') or singular value
          decomposition ('svd') for principal component analysis. The default
          method is 'eig' which is faster. However, occasionally 'svd' might
          be more accurate.
      return_sigma : bool, optional
          If true, a noise standard deviation estimate based on the
          Marcenko-Pastur distribution is returned [2]_.
      out_dir : string, optional
          Output directory. (default current directory)
      out_denoised : string, optional
          Name of the resulting denoised volume.
      out_sigma : string, optional
          Name of the resulting sigma volume.
  
      References
      ----------
      .. [1] Veraart J, Novikov DS, Christiaens D, Ades-aron B, Sijbers,
      Fieremans E, 2016. Denoising of Diffusion MRI using random matrix
      theory. Neuroimage 142:394-406.
      doi: 10.1016/j.neuroimage.2016.08.016
  
      .. [2] Veraart J, Fieremans E, Novikov DS. 2016. Diffusion MRI noise
      mapping using random matrix theory. Magnetic Resonance in Medicine.
      doi: 10.1002/mrm.26059.
  
      """
      io_it = self.get_io_iterator()
      if isinstance(patch_radius, list) and len(patch_radius) == 1:
          patch_radius = int(patch_radius[0])
  
      for dwi, odenoised, osigma in io_it:
          logging.info("Denoising %s", dwi)
          data, affine, image = load_nifti(dwi, return_img=True)
  
          denoised_data, sigma = mppca(
              data,
              patch_radius=patch_radius,
              pca_method=pca_method,
              return_sigma=True,
          )
  
          save_nifti(odenoised, denoised_data, affine, image.header)
          logging.info("Denoised volume saved as %s", odenoised)
          if return_sigma:
              save_nifti(osigma, sigma, affine, image.header)
              logging.info("Sigma volume saved as %s", osigma)
  
imports: import logging
  import shutil
  import numpy
  from dipy.core.gradients import gradient_table
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.io.image import load_nifti, save_nifti
  from dipy.denoise.patch2self import patch2self
  from dipy.denoise.nlmeans import nlmeans
  from dipy.denoise.localpca import localpca, mppca
  from dipy.denoise.gibbs import gibbs_removal
  from dipy.denoise.noise_estimate import estimate_sigma
  from dipy.denoise.pca_noise_estimate import pca_noise_estimate
  from dipy.workflows.workflow import Workflow
  from dipy.utils.deprecator import deprecated_params
label_desc: Use image node_id 2 for calling the MPPCAFlow obj's underlying member method code with example usage: obj.run(input_files, patch_radius, pca_method, return_sigma, out_dir, out_denoised, out_sigma) without return types