code: def localpca(
      arr,
      sigma=None,
      mask=None,
      patch_radius=2,
      gtab=None,
      patch_radius_sigma=1,
      pca_method="eig",
      tau_factor=2.3,
      return_sigma=False,
      correct_bias=True,
      out_dtype=None,
      suppress_warning=False,
  ):
      r"""Performs local PCA denoising according to Manjon et al. [1]_.
  
      Parameters
      ----------
      arr : 4D array
          Array of data to be denoised. The dimensions are (X, Y, Z, N), where N
          are the diffusion gradient directions.
      sigma : float or 3D array (optional)
          Standard deviation of the noise estimated from the data. If not given,
          calculate using method in [1]_.
      mask : 3D boolean array (optional)
          A mask with voxels that are true inside the brain and false outside of
          it. The function denoises within the true part and returns zeros
          outside of those voxels.
      patch_radius : int or 1D array (optional)
          The radius of the local patch to be taken around each voxel (in
          voxels). E.g. patch_radius=2 gives 5x5x5 patches.
      gtab: gradient table object (optional if sigma is provided)
          gradient information for the data gives us the bvals and bvecs of
          diffusion data, which is needed to calculate noise level if sigma is
          not provided.
      patch_radius_sigma : int (optional)
          The radius of the local patch to be taken around each voxel (in
          voxels) for estimating sigma. E.g. patch_radius_sigma=2 gives
          5x5x5 patches.
      pca_method : 'eig' or 'svd' (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]_. Default: 2.3 according to [1]_.
      return_sigma : bool (optional)
          If true, a noise standard deviation estimate based on the
          Marcenko-Pastur distribution is returned [2]_.
      correct_bias : bool (optional)
          Whether to correct for bias due to Rician noise. This is an
          implementation of equation 8 in [1]_.
      out_dtype : str or dtype (optional)
          The dtype for the output array. Default: output has the same dtype as
          the input.
      suppress_warning : bool (optional)
          If true, suppress warning caused by patch_size < arr.shape[-1].
  
      Returns
      -------
      denoised_arr : 4D array
          This is the denoised array of the same size as that of the input data,
          clipped to non-negative values
  
      References
      ----------
      .. [1] 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
      .. [2] 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
      """
      # check gtab is given, if sigma is not given
      if sigma is None and gtab is None:
          raise ValueError(
              "gtab must be provided if sigma is not given"
          )
  
      # calculate sigma
      if sigma is None:
          sigma = pca_noise_estimate(
              arr,
              gtab,
              correct_bias=correct_bias,
              patch_radius=patch_radius_sigma,
              images_as_samples=True,
          )
  
      return genpca(
          arr,
          sigma=sigma,
          mask=mask,
          patch_radius=patch_radius,
          pca_method=pca_method,
          tau_factor=tau_factor,
          return_sigma=return_sigma,
          out_dtype=out_dtype,
          suppress_warning=suppress_warning,
      )
  
file_path: dipy/dipy/denoise/localpca.py
imports: import copy
  from packaging.version import Version
  from warnings import warn
  import numpy
  import scipy
  from scipy.linalg import eigh
  from dipy.denoise.pca_noise_estimate import pca_noise_estimate
label_desc: Use image node_id 8 for calling a global function with example usage: localpca(arr, sigma, mask, patch_radius, gtab, patch_radius_sigma, pca_method, tau_factor, return_sigma, correct_bias, out_dtype, suppress_warning) and returns: genpca