code: def test_simulate_raw_sphere(raw_data, tmp_path):
      """Test simulation of raw data with sphere model."""
      pytest.importorskip("nibabel")
      seed = 42
      raw, src, stc, trans, sphere = raw_data
      assert len(pick_types(raw.info, meg=False, ecg=True)) == 1
  
      # head pos
      head_pos_sim = _get_head_pos_sim(raw)
  
      #
      # Test raw simulation with basic parameters
      #
      raw.info.normalize_proj()
      cov = read_cov(cov_fname)
      cov["projs"] = raw.info["projs"]
      raw.info["bads"] = raw.ch_names[:1]
      sphere_norad = make_sphere_model("auto", None, raw.info)
      raw_meg = raw.copy().pick("meg")
      raw_sim = simulate_raw(
          raw_meg.info,
          stc,
          trans,
          src,
          sphere_norad,
          head_pos=head_pos_sim,
      )
      # Test IO on processed data
      test_outname = tmp_path / "sim_test_raw.fif"
      raw_sim.save(test_outname)
  
      raw_sim_loaded = read_raw_fif(test_outname, preload=True)
      assert_allclose(
          raw_sim_loaded[:][0], raw_sim[:][0], rtol=1e-6, atol=1e-20
      )
      del raw_sim
  
      # make sure it works with EEG-only and MEG-only
      raw_sim_meg = simulate_raw(
          raw.copy().pick("meg").info, stc, trans, src, sphere
      )
      raw_sim_eeg = simulate_raw(
          raw.copy().pick("eeg").info, stc, trans, src, sphere
      )
      raw_sim_meeg = simulate_raw(
          raw.copy().pick(["meg", "eeg"]).info, stc, trans, src, sphere
      )
      for this_raw in (raw_sim_meg, raw_sim_eeg, raw_sim_meeg):
          add_eog(this_raw, random_state=seed)
      for this_raw in (raw_sim_meg, raw_sim_meeg):
          add_ecg(this_raw, random_state=seed)
      with pytest.raises(
          RuntimeError, match="only add ECG artifacts if MEG"
      ):
          add_ecg(raw_sim_eeg)
      assert_allclose(
          np.concatenate((raw_sim_meg[:][0], raw_sim_eeg[:][0])),
          raw_sim_meeg[:][0],
          rtol=1e-7,
          atol=1e-20,
      )
      del raw_sim_meg, raw_sim_eeg, raw_sim_meeg
  
      # check that raw-as-info is supported
      n_samp = len(stc.times)
      raw_crop = raw.copy().crop(
          0.0, (n_samp - 1.0) / raw.info["sfreq"]
      )
      assert len(raw_crop.times) == len(stc.times)
      raw_sim = simulate_raw(raw_crop.info, stc, trans, src, sphere)
      with catch_logging() as log:
          raw_sim_2 = simulate_raw(
              raw_crop.info, stc, trans, src, sphere, verbose=True
          )
      log = log.getvalue()
      assert "1 STC iteration provided" in log
      assert len(raw_sim_2.times) == n_samp
      assert_allclose(
          raw_sim[:, :n_samp][0],
          raw_sim_2[:, :n_samp][0],
          rtol=1e-5,
          atol=1e-30,
      )
      del raw_sim, raw_sim_2
  
      # check that different interpolations are similar given small movements
      raw_sim = simulate_raw(
          raw.info,
          stc,
          trans,
          src,
          sphere,
          head_pos=head_pos_sim,
          interp="linear",
      )
      raw_sim_hann = simulate_raw(
          raw.info,
          stc,
          trans,
          src,
          sphere,
          head_pos=head_pos_sim,
          interp="hann",
      )
      assert_allclose(
          raw_sim[:][0], raw_sim_hann[:][0], rtol=1e-1, atol=1e-14
      )
      del raw_sim_hann
  
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 6 for calling a global function with example usage: test_simulate_raw_sphere(raw_data, tmp_path) without return types