docstr: Workflow wrapping LPCA denoising method.
  
  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 bvectors files. This path may contain wildcards to use
      multiple bvectors files at once.
  sigma : float, optional
      Standard deviation of the noise estimated from the data.
      Default 0: it means sigma value estimation with the Manjon2013
      algorithm [3]_.
  b0_threshold : float, optional
      Threshold used to find b0 volumes.
  bvecs_tol : float, optional
      Threshold used to check that norm(bvec) = 1 +/- bvecs_tol
      b-vectors are unit vectors.
  patch_radius : 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.
  tau_factor : float, optional
      Thresholding of PCA eigenvalues is done by nulling out eigenvalues
      that are smaller than:
  
      .. math ::
  
              \tau = (\tau_{factor} \sigma)^2
  
      \tau_{factor} can be change to adjust the relationship between the
      noise standard deviation and the threshold \tau. If \tau_{factor}
      is set to None, it will be automatically calculated using the
      Marcenko-Pastur distribution [2]_.
  out_dir : string, optional
      Output directory. (default current directory)
  out_denoised : string, optional
      Name of the resulting denoised 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.
  
  .. [3] Manjon JV, Coupe P, Concha L, Buades A, Collins DL (2013)
  Diffusion Weighted Image Denoising Using Overcomplete Local
  PCA. PLoS ONE 8(9): e73021.
  https://doi.org/10.1371/journal.pone.0073021
docstr_tok: ["Workflow","wrapping","LPCA","denoising","method",".","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","bvectors","files",".","This","path","may","contain","wildcards","to","use","multiple","bvectors","files","at","once",".","sigma",":","float",",","optional","Standard","deviation","of","the","noise","estimated","from","the","data",".","Default","0",":","it","means","sigma","value","estimation","with","the","Manjon2013","algorithm","[","3","]","_.","b0_threshold",":","float",",","optional","Threshold","used","to","find","b0","volumes",".","bvecs_tol",":","float",",","optional","Threshold","used","to","check","that","norm","(","bvec",")","=","1","+\/-","bvecs_tol","b-vectors","are","unit","vectors",".","patch_radius",":","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",".","tau_factor",":","float",",","optional","Thresholding","of","PCA","eigenvalues","is","done","by","nulling","out","eigenvalues","that","are","smaller","than",":","..","math",":",":","\\tau","=","(","\\tau_","{","factor","}","\\sigma",")","^2","\\tau_","{","factor","}","can","be","change","to","adjust","the","relationship","between","the","noise","standard","deviation","and","the","threshold","\\tau",".","If","\\tau_","{","factor","}","is","set","to","None",",","it","will","be","automatically","calculated","using","the","Marcenko-Pastur","distribution","[","2","]","_.","out_dir",":","string",",","optional","Output","directory",".","(","default","current","directory",")","out_denoised",":","string",",","optional","Name","of","the","resulting","denoised","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",".","..","[","3","]","Manjon","JV",",","Coupe","P",",","Concha","L",",","Buades","A",",","Collins","DL","(","2013",")","Diffusion","Weighted","Image","Denoising","Using","Overcomplete","Local","PCA",".","PLoS","ONE","8","(","9",")",":","e73021",".","https",":","\/\/doi.org\/10.1371\/journal.pone.0073021"]
code: def run(
      self,
      input_files,
      bvalues_files,
      bvectors_files,
      sigma=0,
      b0_threshold=50,
      bvecs_tol=0.01,
      patch_radius=2,
      pca_method="eig",
      tau_factor=2.3,
      out_dir="",
      out_denoised="dwi_lpca.nii.gz",
  ):
      r"""Workflow wrapping LPCA denoising method.
  
      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 bvectors files. This path may contain wildcards to use
          multiple bvectors files at once.
      sigma : float, optional
          Standard deviation of the noise estimated from the data.
          Default 0: it means sigma value estimation with the Manjon2013
          algorithm [3]_.
      b0_threshold : float, optional
          Threshold used to find b0 volumes.
      bvecs_tol : float, optional
          Threshold used to check that norm(bvec) = 1 +/- bvecs_tol
          b-vectors are unit vectors.
      patch_radius : 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.
      tau_factor : float, optional
          Thresholding of PCA eigenvalues is done by nulling out eigenvalues
          that are smaller than:
  
          .. math ::
  
                  \tau = (\tau_{factor} \sigma)^2
  
          \tau_{factor} can be change to adjust the relationship between the
          noise standard deviation and the threshold \tau. If \tau_{factor}
          is set to None, it will be automatically calculated using the
          Marcenko-Pastur distribution [2]_.
      out_dir : string, optional
          Output directory. (default current directory)
      out_denoised : string, optional
          Name of the resulting denoised 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.
  
      .. [3] Manjon JV, Coupe P, Concha L, Buades A, Collins DL (2013)
      Diffusion Weighted Image Denoising Using Overcomplete Local
      PCA. PLoS ONE 8(9): e73021.
      https://doi.org/10.1371/journal.pone.0073021
  
      """
      io_it = self.get_io_iterator()
      if isinstance(patch_radius, list) and len(patch_radius) == 1:
          patch_radius = int(patch_radius[0])
      for dwi, bval, bvec, odenoised in io_it:
          logging.info("Denoising %s", dwi)
          data, affine, image = load_nifti(dwi, return_img=True)
  
          if not sigma:
              logging.info("Estimating sigma")
              bvals, bvecs = read_bvals_bvecs(bval, bvec)
              gtab = gradient_table(
                  bvals,
                  bvecs,
                  b0_threshold=b0_threshold,
                  atol=bvecs_tol,
              )
              sigma = pca_noise_estimate(
                  data, gtab, correct_bias=True, smooth=3
              )
              logging.debug("Found sigma %s", sigma)
  
          denoised_data = localpca(
              data,
              sigma=sigma,
              patch_radius=patch_radius,
              pca_method=pca_method,
              tau_factor=tau_factor,
          )
          save_nifti(odenoised, denoised_data, affine, image.header)
  
          logging.info("Denoised volume saved as %s", odenoised)
  
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 LPCAFlow obj's underlying member method code with example usage: obj.run(input_files, bvalues_files, bvectors_files, sigma, b0_threshold, bvecs_tol, patch_radius, pca_method, tau_factor, out_dir, out_denoised) without return types