code: def test_patch2self_random_noise(rng):
      S0 = 30 + 2 * rng.standard_normal((20, 20, 20, 50))
  
      bvals = np.repeat(30, 50)
  
      # shift = True
      S0den_shift = p2s.patch2self(
          S0, bvals, model="ols", shift_intensity=True
      )
  
      assert_greater_equal(S0den_shift.min(), S0.min())
      assert_less_equal(np.round(S0den_shift.mean()), 30)
  
      # clip = True
      msg = "Both `clip_negative_vals` and `shift_intensity` .*"
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore", message=msg, category=UserWarning
          )
          S0den_clip = p2s.patch2self(
              S0, bvals, model="ols", clip_negative_vals=True
          )
  
      assert_greater(S0den_clip.min(), S0.min())
      assert_equal(np.round(S0den_clip.mean()), 30)
  
      # both clip and shift = True, and int patch_radius
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore", message=msg, category=UserWarning
          )
          S0den_clip = p2s.patch2self(
              S0,
              bvals,
              patch_radius=0,
              model="ols",
              clip_negative_vals=True,
              shift_intensity=True,
          )
  
      assert_greater(S0den_clip.min(), S0.min())
      assert_equal(np.round(S0den_clip.mean()), 30)
  
      # both clip and shift = False
      S0den_clip = p2s.patch2self(
          S0,
          bvals,
          model="ols",
          clip_negative_vals=False,
          shift_intensity=False,
      )
  
      assert_greater(S0den_clip.min(), S0.min())
      assert_equal(np.round(S0den_clip.mean()), 30)
  
file_path: dipy/dipy/denoise/tests/test_patch2self.py
imports: import warnings
  import numpy
  from dipy.denoise import patch2self
  from dipy.testing import assert_greater, assert_less, assert_greater_equal, assert_less_equal
  from numpy.testing import assert_array_almost_equal, assert_raises, assert_equal
  import pytest
  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
  from dipy.utils.optpkg import optional_package
label_desc: Use image node_id 1 for calling a global function with example usage: test_patch2self_random_noise(rng) without return types