code: def simulate_raw(
      info,
      stc=None,
      trans=None,
      src=None,
      bem=None,
      head_pos=None,
      mindist=1.0,
      interp="cos2",
      n_jobs=None,
      use_cps=True,
      forward=None,
      first_samp=0,
      max_iter=10000,
      verbose=None,
  ):
      """Simulate raw data.
  
      Head movements can optionally be simulated using the ``head_pos``
      parameter.
  
      Parameters
      ----------
      %(info_not_none)s Used for simulation.
  
          .. versionchanged:: 0.18
             Support for :class:`mne.Info`.
      stc : iterable | SourceEstimate | SourceSimulator
          The source estimates to use to simulate data. Each must have the same
          sample rate as the raw data, and the vertices of all stcs in the
          iterable must match. Each entry in the iterable can also be a tuple of
          ``(SourceEstimate, ndarray)`` to allow specifying the stim channel
          (e.g., STI001) data accompany the source estimate.
          See Notes for details.
  
          .. versionchanged:: 0.18
             Support for tuple, iterable of tuple or `~mne.SourceEstimate`,
             or `~mne.simulation.SourceSimulator`.
      trans : dict | str | None
          Either a transformation filename (usually made using mne_analyze)
          or an info dict (usually opened using read_trans()).
          If string, an ending of ``.fif`` or ``.fif.gz`` will be assumed to
          be in FIF format, any other ending will be assumed to be a text
          file with a 4x4 transformation matrix (like the ``--trans`` MNE-C
          option). If trans is None, an identity transform will be used.
      src : path-like | instance of SourceSpaces | None
          Source space corresponding to the stc. If string, should be a source
          space filename. Can also be an instance of loaded or generated
          SourceSpaces. Can be None if ``forward`` is provided.
      bem : path-like | dict | None
          BEM solution  corresponding to the stc. If string, should be a BEM
          solution filename (e.g., "sample-5120-5120-5120-bem-sol.fif").
          Can be None if ``forward`` is provided.
      %(head_pos)s
          See for example :footcite:`LarsonTaulu2017`.
      mindist : float
          Minimum distance between sources and the inner skull boundary
          to use during forward calculation.
      %(interp)s
      %(n_jobs)s
      %(use_cps)s
      forward : instance of Forward | None
          The forward operator to use. If None (default) it will be computed
          using ``bem``, ``trans``, and ``src``. If not None,
          ``bem``, ``trans``, and ``src`` are ignored.
  
          .. versionadded:: 0.17
      first_samp : int
          The first_samp property in the output Raw instance.
  
          .. versionadded:: 0.18
      max_iter : int
          The maximum number of STC iterations to allow.
          This is a sanity parameter to prevent accidental blowups.
  
          .. versionadded:: 0.18
      %(verbose)s
  
      Returns
      -------
      raw : instance of Raw
          The simulated raw file.
  
      See Also
      --------
      mne.chpi.read_head_pos
      add_chpi
      add_noise
      add_ecg
      add_eog
      simulate_evoked
      simulate_stc
      simulate_sparse_stc
  
      Notes
      -----
      **Stim channel encoding**
  
      By default, the stimulus channel will have the head position number
      (starting at 1) stored in the trigger channel (if available) at the
      t=0 point in each repetition of the ``stc``. If ``stc`` is a tuple of
      ``(SourceEstimate, ndarray)`` the array values will be placed in the
      stim channel aligned with the :class:`mne.SourceEstimate`.
  
      **Data simulation**
  
      In the most advanced case where ``stc`` is an iterable of tuples the output
      will be concatenated in time as:
  
      .. table:: Data alignment and stim channel encoding
  
         +---------+--------------------------+--------------------------+---------+
         | Channel | Data                                                          |
         +=========+==========================+==========================+=========+
         | M/EEG   | ``fwd @ stc[0][0].data`` | ``fwd @ stc[1][0].data`` | ``...`` |
         +---------+--------------------------+--------------------------+---------+
         | STIM    | ``stc[0][1]``            | ``stc[1][1]``            | ``...`` |
         +---------+--------------------------+--------------------------+---------+
         |         | *time →*                                                      |
         +---------+--------------------------+--------------------------+---------+
  
      .. versionadded:: 0.10.0
  
      References
      ----------
      .. footbibliography::
      """  # noqa: E501
      _validate_type(info, Info, "info")
  
      if len(pick_types(info, meg=False, stim=True)) == 0:
          event_ch = None
      else:
          event_ch = pick_channels(
              info["ch_names"], _get_stim_channel(None, info)
          )[0]
  
      if forward is not None:
          if any(x is not None for x in (trans, src, bem, head_pos)):
              raise ValueError(
                  "If forward is not None then trans, src, bem, "
                  "and head_pos must all be None"
              )
          if not np.allclose(
              forward["info"]["dev_head_t"]["trans"],
              info["dev_head_t"]["trans"],
              atol=1e-6,
          ):
              raise ValueError(
                  "The forward meg<->head transform "
                  'forward["info"]["dev_head_t"] does not match '
                  'the one in raw.info["dev_head_t"]'
              )
          src = forward["src"]
  
      dev_head_ts, offsets = _check_head_pos(
          head_pos, info, first_samp, None
      )
  
      src = _ensure_src(src, verbose=False)
      if isinstance(bem, str):
          bem = read_bem_solution(bem, verbose=False)
  
      # Extract necessary info
      meeg_picks = pick_types(info, meg=True, eeg=True, exclude=[])
      logger.info(
          'Setting up raw simulation: %s position%s, "%s" interpolation'
          % (len(dev_head_ts), _pl(dev_head_ts), interp)
      )
  
      if (
          isinstance(stc, SourceSimulator)
          and stc.first_samp != first_samp
      ):
          logger.info(
              "SourceSimulator first_samp does not match argument."
          )
  
      stc_enum, stc_counted, verts = _check_stc_iterable(stc, info)
      if forward is not None:
          forward = restrict_forward_to_stc(forward, verts)
          src = forward["src"]
      else:
          _stc_src_sel(src, verts, on_missing="warn", extra="")
          src = _set_source_space_vertices(src.copy(), verts)
  
      # array used to store result
      raw_datas = list()
      _log_ch("Event information", info, event_ch)
      # don't process these any more if no MEG present
      n = 1
      get_fwd = _SimForwards(
          dev_head_ts,
          offsets,
          info,
          trans,
          src,
          bem,
          mindist,
          n_jobs,
          meeg_picks,
          forward,
          use_cps,
      )
      interper = _Interp2(offsets, get_fwd, interp)
  
      this_start = 0
      for n in range(max_iter):
          if isinstance(stc_counted[1], (list, tuple)):
              this_n = stc_counted[1][0].data.shape[1]
          else:
              this_n = stc_counted[1].data.shape[1]
          this_stop = this_start + this_n
          logger.info(
              "    Interval %0.3f–%0.3f s"
              % (this_start / info["sfreq"], this_stop / info["sfreq"])
          )
          n_doing = this_stop - this_start
          assert n_doing > 0
          this_data = np.zeros((len(info["ch_names"]), n_doing))
          raw_datas.append(this_data)
          # Stim channel
          fwd, fi = interper.feed(this_stop - this_start)
          fi = fi[0]
          stc_data, stim_data, _ = _stc_data_event(
              stc_counted,
              fi,
              info["sfreq"],
              get_fwd.src,
              None if n == 0 else verts,
          )
          if event_ch is not None:
              this_data[event_ch, :] = stim_data[:n_doing]
          this_data[meeg_picks] = np.einsum("svt,vt->st", fwd, stc_data)
          try:
              stc_counted = next(stc_enum)
          except StopIteration:
              logger.info(
                  "    %d STC iteration%s provided"
                  % (n + 1, _pl(n + 1))
              )
              break
          del fwd
      else:
          raise RuntimeError(
              "Maximum number of STC iterations (%d) " "exceeded" % (n,)
          )
      raw_data = np.concatenate(raw_datas, axis=-1)
      raw = RawArray(
          raw_data, info, first_samp=first_samp, verbose=False
      )
      raw.set_annotations(raw.annotations)
      logger.info("[done]")
      return raw
  
imports: import os
  from collections.abc import Iterable
  from pathlib import Path
  import numpy
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._ola import _Interp2
  from ..bem import fit_sphere_to_headshape, make_sphere_model, read_bem_solution
  from ..chpi import _get_hpi_initial_fit, get_chpi_info, head_pos_to_trans_rot_t, read_head_pos
  from ..cov import Covariance, make_ad_hoc_cov, read_cov
  from ..event import _get_stim_channel
  from ..forward import _compute_forwards, _magnetic_dipole_field_vec, _merge_fwds, _prep_meg_channels, _prepare_for_forward, _stc_src_sel, _to_forward_dict, _transform_orig_meg_coils, convert_forward_solution, restrict_forward_to_stc
  from ..io import BaseRaw, RawArray
  from ..source_estimate import _BaseSourceEstimate
  from ..source_space._source_space import _ensure_src, _set_source_space_vertices, setup_volume_source_space
  from ..surface import _CheckInside
  from ..transforms import _get_trans, transform_surface_to
  from ..utils import _check_preload, _pl, _validate_type, check_random_state, logger, verbose
  from .source import SourceSimulator
label_desc: Use image node_id 5 for calling a global function with example usage: simulate_raw(info, stc, trans, src, bem, head_pos, mindist, interp, n_jobs, use_cps, forward, first_samp, max_iter, verbose) and returns: raw