code: def test_apply_dics_timeseries(_load_forward, idx):
      """Test DICS applied to timeseries data."""
      fwd_free, fwd_surf, fwd_fixed, fwd_vol = _load_forward
      (
          epochs,
          evoked,
          csd,
          source_vertno,
          label,
          vertices,
          source_ind,
      ) = _simulate_data(fwd_fixed, idx)
      reg = 5  # Lots of regularization for our toy dataset
  
      with pytest.raises(ValueError, match="several sensor types"):
          make_dics(evoked.info, fwd_surf, csd)
      evoked.pick(picks="grad")
  
      multiple_filters = make_dics(
          evoked.info, fwd_surf, csd, label=label, reg=reg
      )
  
      # Sanity checks on the resulting STC after applying DICS on evoked
      stcs = apply_dics(evoked, multiple_filters)
      assert isinstance(stcs, list)
      assert len(stcs) == len(multiple_filters["weights"])
      assert_array_equal(
          stcs[0].vertices[0], multiple_filters["vertices"][0]
      )
      assert_array_equal(
          stcs[0].vertices[1], multiple_filters["vertices"][1]
      )
      assert_allclose(stcs[0].times, evoked.times)
  
      # Applying filters for multiple frequencies on epoch data should fail
      with pytest.raises(
          ValueError, match="computed for a single frequency"
      ):
          apply_dics_epochs(epochs, multiple_filters)
  
      # From now on, only apply filters with a single frequency (20 Hz).
      csd20 = csd.pick_frequency(20)
      filters = make_dics(
          evoked.info,
          fwd_surf,
          csd20,
          label=label,
          reg=reg,
          inversion="single",
      )
  
      # Sanity checks on the resulting STC after applying DICS on epochs.
      # Also test here that no warnings are thrown - implemented to check whether
      # src should not be None warning occurs
      stcs = apply_dics_epochs(epochs, filters)
  
      assert isinstance(stcs, list)
      assert len(stcs) == 1
      assert_array_equal(stcs[0].vertices[0], filters["vertices"][0])
      assert_array_equal(stcs[0].vertices[1], filters["vertices"][1])
      assert_allclose(stcs[0].times, epochs.times)
  
      # Did we find the source?
      stc = (stcs[0] ** 2).mean()
      dist = _fwd_dist(stc, fwd_surf, vertices, source_ind, tidx=0)
      assert dist == 0
  
      # Apply filters to evoked
      stc = apply_dics(evoked, filters)
      stc = (stc**2).mean()
      dist = _fwd_dist(stc, fwd_surf, vertices, source_ind, tidx=0)
      assert dist == 0
  
      # Test if wrong channel selection is detected in application of filter
      evoked_ch = cp.deepcopy(evoked)
      evoked_ch.pick(evoked_ch.ch_names[:-1])
      with pytest.raises(
          ValueError, match="MEG 2633 which is not present"
      ):
          apply_dics(evoked_ch, filters)
  
      # Test whether projections are applied, by adding a custom projection
      filters_noproj = make_dics(
          evoked.info, fwd_surf, csd20, label=label
      )
      stc_noproj = apply_dics(evoked, filters_noproj)
      evoked_proj = evoked.copy()
      p = compute_proj_evoked(evoked_proj, n_grad=1, n_mag=0, n_eeg=0)
      proj_matrix = make_projector(p, evoked_proj.ch_names)[0]
      evoked_proj.add_proj(p)
      filters_proj = make_dics(
          evoked_proj.info, fwd_surf, csd20, label=label
      )
      assert_array_equal(filters_proj["proj"], proj_matrix)
      stc_proj = apply_dics(evoked_proj, filters_proj)
      assert np.any(np.not_equal(stc_noproj.data, stc_proj.data))
  
      # Test detecting incompatible projections
      filters_proj["proj"] = filters_proj["proj"][:-1, :-1]
      with pytest.raises(
          ValueError, match="operands could not be broadcast"
      ):
          apply_dics(evoked_proj, filters_proj)
  
      # Test returning a generator
      stcs = apply_dics_epochs(epochs, filters, return_generator=False)
      stcs_gen = apply_dics_epochs(
          epochs, filters, return_generator=True
      )
      assert_array_equal(stcs[0].data, next(stcs_gen).data)
  
      # Test computing timecourses on a volume source space
      filters_vol = make_dics(
          evoked.info, fwd_vol, csd20, reg=reg, inversion="single"
      )
      stc = apply_dics(evoked, filters_vol)
      stc = (stc**2).mean()
      assert stc.data.shape[1] == 1
      vol_source_ind = _nearest_vol_ind(
          fwd_vol, fwd_surf, vertices, source_ind
      )
      dist = _fwd_dist(
          stc,
          fwd_vol,
          fwd_vol["src"][0]["vertno"],
          vol_source_ind,
          tidx=0,
      )
      vol_tols = {100: 0.008, 200: 0.015}
      vol_tol = vol_tols.get(idx, 0.0)
      assert dist <= vol_tol
  
      # check whether a filters object without src_type throws expected warning
      del filters_vol[
          "src_type"
      ]  # emulate 0.16 behaviour to cause warning
      with pytest.warns(
          RuntimeWarning, match="filter does not contain src_typ"
      ):
          apply_dics_epochs(epochs, filters_vol)
  
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 11 for calling a global function with example usage: test_apply_dics_timeseries(_load_forward, idx) without return types