code: def test_simulate_evoked():
      """Test simulation of evoked data."""
      raw = read_raw_fif(raw_fname)
      fwd = read_forward_solution(fwd_fname)
      fwd = convert_forward_solution(
          fwd, force_fixed=True, use_cps=False
      )
      fwd = pick_types_forward(
          fwd, meg=True, eeg=True, exclude=raw.info["bads"]
      )
      cov = read_cov(cov_fname)
  
      evoked_template = read_evokeds(
          ave_fname, condition=0, baseline=None
      )
      evoked_template.pick(["meg", "eeg"], exclude=raw.info["bads"])
  
      cov = regularize(cov, evoked_template.info)
      nave = evoked_template.nave
  
      tmin = -0.1
      sfreq = 1000.0  # Hz
      tstep = 1.0 / sfreq
      n_samples = 600
      times = np.linspace(tmin, tmin + n_samples * tstep, n_samples)
  
      # Generate times series for 2 dipoles
      stc = simulate_sparse_stc(
          fwd["src"], n_dipoles=2, times=times, random_state=42
      )
  
      # Generate noisy evoked data
      iir_filter = [1, -0.9]
      evoked = simulate_evoked(
          fwd,
          stc,
          evoked_template.info,
          cov,
          iir_filter=iir_filter,
          nave=nave,
          random_state=0,
      )
      assert_array_almost_equal(evoked.times, stc.times)
      assert len(evoked.data) == len(fwd["sol"]["data"])
      assert_equal(evoked.nave, nave)
      assert len(evoked.info["projs"]) == len(cov["projs"])
      evoked_white = whiten_evoked(evoked, cov)
      assert abs(evoked_white.data[:, 0].std() - 1.0) < 0.1
  
      # make a vertex that doesn't exist in fwd, should throw error
      stc_bad = stc.copy()
      mv = np.max(fwd["src"][0]["vertno"][fwd["src"][0]["inuse"]])
      stc_bad.vertices[0][0] = mv + 1
  
      pytest.raises(
          ValueError,
          simulate_evoked,
          fwd,
          stc_bad,
          evoked_template.info,
          cov,
      )
      evoked_1 = simulate_evoked(
          fwd, stc, evoked_template.info, cov, nave=np.inf
      )
      evoked_2 = simulate_evoked(
          fwd, stc, evoked_template.info, cov, nave=np.inf
      )
      assert_array_equal(evoked_1.data, evoked_2.data)
  
      cov["names"] = cov.ch_names[:-2]  # Error channels are different.
      with pytest.raises(
          RuntimeError, match="Not all channels present"
      ):
          simulate_evoked(fwd, stc, evoked_template.info, cov)
  
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 1 for calling a global function with example usage: test_simulate_evoked() without return types