code: def test_pca_noise_estimate(rng):
      # MUBE:
      bvals1 = np.concatenate([np.zeros(17), np.ones(3) * 1000])
      bvecs1 = np.concatenate([np.zeros((17, 3)), np.eye(3)])
      gtab1 = dpg.gradient_table(bvals1, bvecs1)
      # SIBE:
      bvals2 = np.concatenate([np.zeros(1), np.ones(3) * 1000])
      bvecs2 = np.concatenate([np.zeros((1, 3)), np.eye(3)])
      gtab2 = dpg.gradient_table(bvals2, bvecs2)
  
      for images_as_samples in [True, False]:
          for patch_radius in [1, 2]:
              for gtab in [gtab1, gtab2]:
                  for dtype in [np.int16, np.float64]:
                      signal = np.ones(
                          (20, 20, 20, gtab.bvals.shape[0])
                      )
                      for correct_bias in [True, False]:
                          if not correct_bias:
                              # High signal for no bias correction
                              signal = signal * 100
  
                          sigma = 1
                          noise1 = rng.normal(
                              0, sigma, size=signal.shape
                          )
                          noise2 = rng.normal(
                              0, sigma, size=signal.shape
                          )
  
                          # Rician noise:
                          data = np.sqrt(
                              (signal + noise1) ** 2 + noise2**2
                          )
  
                          sigma_est = pca_noise_estimate(
                              data.astype(dtype),
                              gtab,
                              correct_bias=correct_bias,
                              patch_radius=patch_radius,
                              images_as_samples=images_as_samples,
                          )
                          # print("sigma_est:", sigma_est)
                          assert_array_almost_equal(
                              np.mean(sigma_est), sigma, decimal=1
                          )
  
          # check that Rician corrects produces larger noise estimate
          assert_(
              np.mean(
                  pca_noise_estimate(
                      data,
                      gtab,
                      correct_bias=True,
                      images_as_samples=images_as_samples,
                  )
              )
              > np.mean(
                  pca_noise_estimate(
                      data,
                      gtab,
                      correct_bias=False,
                      images_as_samples=images_as_samples,
                  )
              )
          )
  
          assert_warns(
              UserWarning,
              pca_noise_estimate,
              data,
              gtab,
              patch_radius=0,
          )
  
file_path: dipy/dipy/denoise/tests/test_noise_estimate.py
imports: import numpy
  from numpy.testing import assert_almost_equal, assert_equal, assert_, assert_array_almost_equal, assert_warns
  from dipy.denoise.noise_estimate import _inv_nchi_cdf, piesno, estimate_sigma
  from dipy.denoise.noise_estimate import _piesno_3D
  from dipy.denoise.pca_noise_estimate import pca_noise_estimate
  import dipy.data
  import dipy.core.gradients
  from dipy.io.image import load_nifti_data
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 5 for calling a global function with example usage: test_pca_noise_estimate(rng) without return types