code: def test_iterable():
      """Test iterable support for simulate_raw."""
      raw = read_raw_fif(raw_fname_short).load_data()
      raw.pick(raw.ch_names[:10] + ["STI 014"])
      src = setup_volume_source_space(
          pos=dict(
              rr=[[-0.05, 0, 0], [0.1, 0, 0]],
              nn=[[0, 1.0, 0], [0, 1.0, 0]],
          )
      )
      assert src.kind == "discrete"
      trans = None
      sphere = make_sphere_model(head_radius=None, info=raw.info)
      tstep = 1.0 / raw.info["sfreq"]
      rng = np.random.RandomState(0)
      vertices = [np.array([1])]
      data = rng.randn(1, 2)
      stc = VolSourceEstimate(data, vertices, 0, tstep)
      assert isinstance(stc.vertices[0], np.ndarray)
      with pytest.raises(
          ValueError, match="at least three time points"
      ):
          simulate_raw(raw.info, stc, trans, src, sphere, None)
      data = rng.randn(1, 1000)
      n_events = (len(raw.times) - 1) // 1000 + 1
      stc = VolSourceEstimate(data, vertices, 0, tstep)
      assert isinstance(stc.vertices[0], np.ndarray)
      raw_sim = simulate_raw(
          raw.info,
          [stc] * 15,
          trans,
          src,
          sphere,
          None,
          first_samp=raw.first_samp,
      )
      raw_sim.crop(0, raw.times[-1])
      assert_allclose(raw.times, raw_sim.times)
      events = find_events(raw_sim, initial_event=True)
      assert len(events) == n_events
      assert_array_equal(events[:, 2], 1)
  
      # Degenerate STCs
      with pytest.raises(
          RuntimeError, match=r"Iterable did not provide stc\[0\]"
      ):
          simulate_raw(raw.info, [], trans, src, sphere, None)
      # tuple with ndarray
      event_data = np.zeros(len(stc.times), int)
      event_data[0] = 3
      raw_new = simulate_raw(
          raw.info,
          [(stc, event_data)] * 15,
          trans,
          src,
          sphere,
          None,
          first_samp=raw.first_samp,
      )
      assert raw_new.n_times == 15000
      raw_new.crop(0, raw.times[-1])
      _assert_iter_sim(raw_sim, raw_new, 3)
      with pytest.raises(
          ValueError, match="event data had shape .* but need"
      ):
          simulate_raw(
              raw.info,
              [(stc, event_data[:-1])],
              trans,
              src,
              sphere,
              None,
          )
      with pytest.raises(
          ValueError, match="stim_data in a stc tuple .* int"
      ):
          simulate_raw(
              raw.info,
              [(stc, event_data * 1.0)],
              trans,
              src,
              sphere,
              None,
          )
  
      # iterable
      def stc_iter():
          stim_data = np.zeros(len(stc.times), int)
          stim_data[0] = 4
          ii = 0
          while ii < 15:
              ii += 1
              yield (stc, stim_data)
  
      raw_new = simulate_raw(
          raw.info,
          stc_iter(),
          trans,
          src,
          sphere,
          None,
          first_samp=raw.first_samp,
      )
      raw_new.crop(0, raw.times[-1])
      _assert_iter_sim(raw_sim, raw_new, 4)
  
      def stc_iter_bad():
          ii = 0
          while ii < 100:
              ii += 1
              yield (stc, 4, 3)
  
      with pytest.raises(
          ValueError, match="stc, if tuple, must be length"
      ):
          simulate_raw(
              raw.info, stc_iter_bad(), trans, src, sphere, None
          )
      _assert_iter_sim(raw_sim, raw_new, 4)
  
      def stc_iter_bad():
          ii = 0
          while ii < 100:
              ii += 1
              stc_new = stc.copy()
              stc_new.vertices[0] = np.array([ii % 2])
              yield stc_new
  
      with pytest.raises(
          RuntimeError, match=r"Vertex mismatch for stc\[1\]"
      ):
          simulate_raw(
              raw.info, stc_iter_bad(), trans, src, sphere, None
          )
  
      # Forward omission
      vertices = [np.array([0, 1])]
      data = rng.randn(2, 1000)
      stc = VolSourceEstimate(data, vertices, 0, tstep)
      assert isinstance(stc.vertices[0], np.ndarray)
      # XXX eventually we should support filtering based on sphere radius, too,
      # by refactoring the code in source_space.py that does it!
      surf = _get_ico_surface(3)
      surf["rr"] *= 60  # mm
      model = _surfaces_to_bem(
          [surf], [FIFF.FIFFV_BEM_SURF_ID_BRAIN], [0.3]
      )
      bem = make_bem_solution(model)
      with pytest.warns(
          RuntimeWarning, match="1 of 2 SourceEstimate vertices"
      ):
          simulate_raw(raw.info, stc, trans, src, bem, None)
  
imports: from copy import deepcopy
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from mne import Epochs, SourceEstimate, VolSourceEstimate, convert_forward_solution, create_info, find_events, fit_dipole, make_ad_hoc_cov, make_bem_solution, make_forward_solution, make_sphere_model, pick_types, read_bem_solution, read_cov, read_source_spaces, read_trans, setup_source_space, setup_volume_source_space, transform_surface_to
  from mne._fiff.constants import FIFF
  from mne.bem import _surfaces_to_bem
  from mne.chpi import compute_chpi_amplitudes, compute_chpi_locs, compute_head_pos, get_chpi_info, read_head_pos
  from mne.datasets import testing
  from mne.io import RawArray, read_raw_fif
  from mne.label import Label
  from mne.simulation import add_chpi, add_ecg, add_eog, add_noise, simulate_raw, simulate_sparse_stc
  from mne.simulation.source import SourceSimulator
  from mne.source_space._source_space import _compare_source_spaces
  from mne.surface import _get_ico_surface
  from mne.tests.test_chpi import _assert_quats
  from mne.utils import catch_logging
label_desc: Use image node_id 2 for calling a global function with example usage: test_iterable() without return types