code: def test_add_noise():
      """Test noise addition."""
      rng = np.random.default_rng(0)
      raw = read_raw_fif(raw_fname)
      raw.del_proj()
      picks = pick_types(raw.info, meg=True, eeg=True, exclude=())
      cov = compute_raw_covariance(raw, picks=picks)
      with pytest.raises(RuntimeError, match="to be loaded"):
          add_noise(raw, cov)
      raw.crop(0, 1).load_data()
      with pytest.raises(TypeError, match="Raw, Epochs, or Evoked"):
          add_noise(0.0, cov)
      with pytest.raises(TypeError, match="Covariance"):
          add_noise(raw, 0.0)
      # test a no-op (data preserved)
      orig_data = raw[:][0]
      zero_cov = cov.copy()
      zero_cov["data"].fill(0)
      add_noise(raw, zero_cov)
      new_data = raw[:][0]
      assert_allclose(orig_data, new_data, atol=1e-30)
      # set to zero to make comparisons easier
      raw._data[:] = 0.0
      epochs = EpochsArray(
          np.zeros((1, len(raw.ch_names), 100)), raw.info.copy()
      )
      epochs.info["bads"] = []
      evoked = epochs.average(picks=np.arange(len(raw.ch_names)))
      for inst in (raw, epochs, evoked):
          with catch_logging() as log:
              add_noise(inst, cov, random_state=rng, verbose=True)
          log = log.getvalue()
          want = "to {0}/{1} channels ({0}".format(
              len(cov["names"]), len(raw.ch_names)
          )
          assert want in log
          if inst is evoked:
              inst = EpochsArray(inst.data[np.newaxis], inst.info)
          if inst is raw:
              cov_new = compute_raw_covariance(inst, picks=picks)
          else:
              cov_new = compute_covariance(inst)
          assert cov["names"] == cov_new["names"]
          r = np.corrcoef(cov["data"].ravel(), cov_new["data"].ravel())[
              0, 1
          ]
          assert r > 0.99
  
file_path: mne-python/mne/simulation/tests/test_evoked.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import EpochsArray, compute_covariance, compute_raw_covariance, convert_forward_solution, pick_channels_cov, pick_types, pick_types_forward, read_cov, read_evokeds, read_forward_solution
  from mne.cov import regularize, whiten_evoked
  from mne.datasets import testing
  from mne.io import read_raw_fif
  from mne.simulation import add_noise, simulate_evoked, simulate_sparse_stc
  from mne.utils import catch_logging
label_desc: Use image node_id 2 for calling a global function with example usage: test_add_noise() without return types