code: def _simulate_data(
      fwd, idx
  ):  # Somewhere on the frontal lobe by default
      """Simulate an oscillator on the cortex."""
      pytest.importorskip("nibabel")
      source_vertno = fwd["src"][0]["vertno"][idx]
  
      sfreq = 50.0  # Hz.
      times = np.arange(10 * sfreq) / sfreq  # 10 seconds of data
      signal = np.sin(20 * 2 * np.pi * times)  # 20 Hz oscillator
      signal[
          : len(times) // 2
      ] *= 2  # Make signal louder at the beginning
      signal *= 1e-9  # Scale to be in the ballpark of MEG data
  
      # Construct a SourceEstimate object that describes the signal at the
      # cortical level.
      stc = mne.SourceEstimate(
          signal[np.newaxis, :],
          vertices=[[source_vertno], []],
          tmin=0,
          tstep=1 / sfreq,
          subject="sample",
      )
  
      # Create an info object that holds information about the sensors
      info = mne.create_info(
          fwd["info"]["ch_names"], sfreq, ch_types="grad"
      )
      with info._unlock():
          info.update(
              fwd["info"]
          )  # Merge in sensor position information
      # heavily decimate sensors to make it much faster
      info = mne.pick_info(info, np.arange(info["nchan"])[::5])
      fwd = mne.pick_channels_forward(fwd, info["ch_names"])
  
      # Run the simulated signal through the forward model, obtaining
      # simulated sensor data.
      raw = mne.apply_forward_raw(fwd, stc, info)
  
      # Add a little noise
      random = np.random.RandomState(42)
      noise = random.randn(*raw._data.shape) * 1e-14
      raw._data += noise
  
      # Define a single epoch (weird baseline but shouldn't matter)
      epochs = mne.Epochs(
          raw,
          [[0, 0, 1]],
          event_id=1,
          tmin=0,
          tmax=raw.times[-1],
          baseline=(0.0, 0.0),
          preload=True,
      )
      evoked = epochs.average()
  
      # Compute the cross-spectral density matrix
      csd = csd_morlet(
          epochs, frequencies=[10, 20], n_cycles=[5, 10], decim=5
      )
  
      labels = mne.read_labels_from_annot(
          "sample", hemi="lh", subjects_dir=subjects_dir
      )
      label = [
          label
          for label in labels
          if np.isin(source_vertno, label.vertices)
      ]
      assert len(label) == 1
      label = label[0]
      vertices = np.intersect1d(label.vertices, fwd["src"][0]["vertno"])
      source_ind = vertices.tolist().index(source_vertno)
      assert vertices[source_ind] == source_vertno
      return (
          epochs,
          evoked,
          csd,
          source_vertno,
          label,
          vertices,
          source_ind,
      )
  
imports: import copy
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  import mne
  from mne import pick_types
  from mne._fiff.constants import FIFF
  from mne._fiff.pick import pick_info
  from mne.beamformer import Beamformer, apply_dics, apply_dics_csd, apply_dics_epochs, apply_dics_tfr_epochs, make_dics, read_beamformer
  from mne.beamformer._compute_beamformer import _prepare_beamformer_input
  from mne.beamformer._dics import _prepare_noise_csd
  from mne.beamformer.tests.test_lcmv import _assert_weight_norm
  from mne.datasets import testing
  from mne.io import read_info
  from mne.proj import compute_proj_evoked, make_projector
  from mne.surface import _compute_nearest
  from mne.time_frequency import CrossSpectralDensity, EpochsTFR, csd_morlet, csd_tfr
  from mne.time_frequency.csd import _sym_mat_to_vector
  from mne.transforms import apply_trans, invert_transform
  from mne.utils import catch_logging, object_diff
label_desc: Use image node_id 2 for calling a global function with example usage: _simulate_data(fwd, idx) and returns: epochs,  evoked,  csd,  source_vertno,  label,  vertices,  source_ind