code: def test_apply_forward():
      """Test projection of source space data to sensor space."""
      start = 0
      stop = 5
      n_times = stop - start - 1
      sfreq = 10.0
      t_start = 0.123
  
      fwd = read_forward_solution(fname_meeg)
      fwd = convert_forward_solution(
          fwd, surf_ori=True, force_fixed=True, use_cps=True
      )
      fwd = pick_types_forward(fwd, meg=True)
      assert isinstance(fwd, Forward)
  
      vertno = [fwd["src"][0]["vertno"], fwd["src"][1]["vertno"]]
      stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
      stc = SourceEstimate(
          stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq
      )
  
      gain_sum = np.sum(fwd["sol"]["data"], axis=1)
  
      # Evoked
      evoked = read_evokeds(fname_evoked, condition=0)
      evoked.pick(picks="meg")
      with pytest.warns(
          RuntimeWarning, match="only .* positive values"
      ):
          evoked = apply_forward(
              fwd, stc, evoked.info, start=start, stop=stop
          )
      data = evoked.data
      times = evoked.times
  
      # do some tests
      assert_array_almost_equal(evoked.info["sfreq"], sfreq)
      assert_array_almost_equal(
          np.sum(data, axis=1), n_times * gain_sum
      )
      assert_array_almost_equal(times[0], t_start)
      assert_array_almost_equal(
          times[-1], t_start + (n_times - 1) / sfreq
      )
  
      # vector
      stc_vec = VectorSourceEstimate(
          fwd["source_nn"][:, :, np.newaxis] * stc.data[:, np.newaxis],
          stc.vertices,
          stc.tmin,
          stc.tstep,
      )
      with pytest.warns(RuntimeWarning, match="very large"):
          evoked_2 = apply_forward(fwd, stc_vec, evoked.info)
      assert np.abs(evoked_2.data).mean() > 1e-5
      assert_allclose(evoked.data, evoked_2.data, atol=1e-10)
  
      # Raw
      with pytest.warns(
          RuntimeWarning, match="only .* positive values"
      ):
          raw_proj = apply_forward_raw(
              fwd, stc, evoked.info, start=start, stop=stop
          )
      data, times = raw_proj[:, :]
  
      # do some tests
      assert_array_almost_equal(raw_proj.info["sfreq"], sfreq)
      assert_array_almost_equal(
          np.sum(data, axis=1), n_times * gain_sum
      )
      atol = 1.0 / sfreq
      assert_allclose(raw_proj.first_samp / sfreq, t_start, atol=atol)
      assert_allclose(
          raw_proj.last_samp / sfreq,
          t_start + (n_times - 1) / sfreq,
          atol=atol,
      )
  
imports: import gc
  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 SourceEstimate, VectorSourceEstimate, apply_forward, apply_forward_raw, average_forward_solutions, convert_forward_solution, pick_types_forward, read_evokeds, read_forward_solution, write_forward_solution
  from mne._fiff.pick import pick_channels_forward
  from mne.channels import equalize_channels
  from mne.datasets import testing
  from mne.forward import Forward, compute_depth_prior, compute_orient_prior, is_fixed_orient, restrict_forward_to_label, restrict_forward_to_stc
  from mne.io import read_info
  from mne.label import read_label
  from mne.utils import requires_mne, run_subprocess
label_desc: Use image node_id 4 for calling a global function with example usage: test_apply_forward() without return types