code: def test_restrict_forward_to_stc(tmp_path):
      """Test restriction of source space to source SourceEstimate."""
      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)
  
      vertno = [
          fwd["src"][0]["vertno"][0:15],
          fwd["src"][1]["vertno"][0:5],
      ]
      stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
      stc = SourceEstimate(
          stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq
      )
  
      fwd_out = restrict_forward_to_stc(fwd, stc)
      assert isinstance(fwd_out, Forward)
  
      assert_equal(fwd_out["sol"]["ncol"], 20)
      assert_equal(fwd_out["src"][0]["nuse"], 15)
      assert_equal(fwd_out["src"][1]["nuse"], 5)
      assert_equal(
          fwd_out["src"][0]["vertno"], fwd["src"][0]["vertno"][0:15]
      )
      assert_equal(
          fwd_out["src"][1]["vertno"], fwd["src"][1]["vertno"][0:5]
      )
  
      fwd = read_forward_solution(fname_meeg)
      fwd = convert_forward_solution(
          fwd, surf_ori=True, force_fixed=False
      )
      fwd = pick_types_forward(fwd, meg=True)
  
      vertno = [
          fwd["src"][0]["vertno"][0:15],
          fwd["src"][1]["vertno"][0:5],
      ]
      stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
      stc = SourceEstimate(
          stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq
      )
  
      fwd_out = restrict_forward_to_stc(fwd, stc)
  
      assert_equal(fwd_out["sol"]["ncol"], 60)
      assert_equal(fwd_out["src"][0]["nuse"], 15)
      assert_equal(fwd_out["src"][1]["nuse"], 5)
      assert_equal(
          fwd_out["src"][0]["vertno"], fwd["src"][0]["vertno"][0:15]
      )
      assert_equal(
          fwd_out["src"][1]["vertno"], fwd["src"][1]["vertno"][0:5]
      )
  
      # Test saving the restricted forward object. This only works if all fields
      # are properly accounted for.
      fname_copy = tmp_path / "copy-fwd.fif"
      with pytest.warns(RuntimeWarning, match="stored on disk"):
          write_forward_solution(fname_copy, fwd_out, overwrite=True)
      fwd_out_read = read_forward_solution(fname_copy)
      fwd_out_read = convert_forward_solution(
          fwd_out_read, surf_ori=True, force_fixed=False
      )
      assert_forward_allclose(fwd_out, fwd_out_read)
  
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 5 for calling a global function with example usage: test_restrict_forward_to_stc(tmp_path) without return types