code: def test_phantom(rng):
      DWI_clean = rfiw_phantom(gtab, snr=None, rng=rng)
      DWI, sigma = rfiw_phantom(gtab, snr=30, rng=rng)
      # To test without Rician correction
      temp = (DWI_clean / sigma) ** 2
      DWI_clean_wrc = (
          sigma
          * np.sqrt(np.pi / 2)
          * np.exp(-0.5 * temp)
          * (
              (1 + 0.5 * temp) * sps.iv(0, 0.25 * temp)
              + 0.5 * temp * sps.iv(1, 0.25 * temp)
          )
          ** 2
      )
  
      DWI_den = localpca(DWI, sigma, patch_radius=3)
      rmse_den = np.sum(np.abs(DWI_clean - DWI_den)) / np.sum(
          np.abs(DWI_clean)
      )
      rmse_noisy = np.sum(np.abs(DWI_clean - DWI)) / np.sum(
          np.abs(DWI_clean)
      )
  
      rmse_den_wrc = np.sum(np.abs(DWI_clean_wrc - DWI_den)) / np.sum(
          np.abs(DWI_clean_wrc)
      )
      rmse_noisy_wrc = np.sum(np.abs(DWI_clean_wrc - DWI)) / np.sum(
          np.abs(DWI_clean_wrc)
      )
  
      assert_(np.max(DWI_clean) / sigma < np.max(DWI_den) / sigma)
      assert_(np.max(DWI_den) / sigma < np.max(DWI) / sigma)
      assert_(rmse_den < rmse_noisy)
      assert_(rmse_den_wrc < rmse_noisy_wrc)
  
      # Check if the results of different PCA methods (eig, svd) are similar
      DWI_den_svd = localpca(
          DWI, sigma, pca_method="svd", patch_radius=3
      )
      assert_array_almost_equal(DWI_den, DWI_den_svd)
  
      assert_raises(
          ValueError, localpca, DWI, sigma, pca_method="empty"
      )
  
      # Try this with a sigma volume, instead of a scalar
      sigma_vol = sigma * np.ones(DWI.shape[:-1])
      mask = np.zeros_like(DWI, dtype=bool)[..., 0]
      mask[2:-2, 2:-2, 2:-2] = True
      DWI_den = localpca(DWI, sigma_vol, mask, patch_radius=3)
      DWI_clean_masked = DWI_clean.copy()
      DWI_clean_masked[~mask] = 0
      DWI_masked = DWI.copy()
      DWI_masked[~mask] = 0
      rmse_den = np.sum(np.abs(DWI_clean_masked - DWI_den)) / np.sum(
          np.abs(DWI_clean_masked)
      )
      rmse_noisy = np.sum(
          np.abs(DWI_clean_masked - DWI_masked)
      ) / np.sum(np.abs(DWI_clean_masked))
  
      DWI_clean_wrc_masked = DWI_clean_wrc.copy()
      DWI_clean_wrc_masked[~mask] = 0
      rmse_den_wrc = np.sum(
          np.abs(DWI_clean_wrc_masked - DWI_den)
      ) / np.sum(np.abs(DWI_clean_wrc_masked))
      rmse_noisy_wrc = np.sum(
          np.abs(DWI_clean_wrc_masked - DWI_masked)
      ) / np.sum(np.abs(DWI_clean_wrc_masked))
  
      assert_(np.max(DWI_clean) / sigma < np.max(DWI_den) / sigma)
      assert_(np.max(DWI_den) / sigma < np.max(DWI) / sigma)
      assert_(rmse_den < rmse_noisy)
      assert_(rmse_den_wrc < rmse_noisy_wrc)
  
imports: import warnings
  import numpy
  import scipy.special
  from numpy.testing import assert_, assert_equal, assert_raises, assert_array_almost_equal, assert_warns
  from dipy.denoise.localpca import dimensionality_problem_message, create_patch_radius_arr, compute_patch_size, compute_num_samples, compute_suggested_patch_radius, localpca, mppca, genpca, _pca_classifier
  from dipy.sims.voxel import multi_tensor
  from dipy.core.gradients import gradient_table, generate_bvecs
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 10 for calling a global function with example usage: test_phantom(rng) without return types