code: def test_apply_inverse_tfr(return_generator):
      """Test applying an inverse to time-frequency data."""
      rng = np.random.default_rng(11)
      n_epochs = 4
      info = read_info(fname_raw)
      inverse_operator = read_inverse_operator(fname_full)
      freqs = np.arange(8, 10)
      sfreq = info["sfreq"]
      times = np.arange(sfreq) / sfreq  # make epochs 1s long
      data = rng.random(
          (n_epochs, len(info.ch_names), freqs.size, times.size)
      )
      data = (
          data + 1j * data
      )  # make complex to simulate amplitude + phase
      epochs_tfr = EpochsTFR(info, data, times=times, freqs=freqs)
      epochs_tfr.apply_baseline((0, 0.5))
      pick_ori = "vector"
  
      with pytest.raises(
          ValueError, match="Expected 2 inverse operators, " "got 3"
      ):
          apply_inverse_tfr_epochs(
              epochs_tfr, [inverse_operator] * 3, lambda2
          )
  
      # test epochs
      stcs = apply_inverse_tfr_epochs(
          epochs_tfr,
          inverse_operator,
          lambda2,
          "dSPM",
          pick_ori=pick_ori,
          return_generator=return_generator,
      )
  
      n_orient = 3 if pick_ori == "vector" else 1
      if return_generator:
          stcs = [[s for s in these_stcs] for these_stcs in stcs]
      assert_allclose(stcs[0][0].times, times)
      assert len(stcs) == freqs.size
      assert all([len(s) == len(epochs_tfr) for s in stcs])
      assert all(
          [
              s.data.shape
              == (inverse_operator["nsource"], n_orient, times.size)
              for these_stcs in stcs
              for s in these_stcs
          ]
      )
  
      evoked = EvokedArray(
          data.mean(axis=(0, 2)), info, epochs_tfr.tmin
      )
      stc = apply_inverse(
          evoked, inverse_operator, lambda2, "dSPM", pick_ori=pick_ori
      )
      tfr_stc_data = np.array(
          [[stc.data for stc in tfr_stcs] for tfr_stcs in stcs]
      )
      assert_allclose(stc.data, tfr_stc_data.mean(axis=(0, 1)))
  
imports: import copy
  import re
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from scipy import sparse
  import mne
  from mne import Covariance, EvokedArray, SourceEstimate, combine_evoked, compute_raw_covariance, convert_forward_solution, make_ad_hoc_cov, make_forward_solution, make_sphere_model, pick_channels_forward, pick_types, pick_types_forward, read_cov, read_evokeds, read_forward_solution
  from mne.datasets import testing
  from mne.epochs import Epochs, EpochsArray, make_fixed_length_epochs
  from mne.event import read_events
  from mne.forward import apply_forward, is_fixed_orient, restrict_forward_to_stc
  from mne.io import read_info, read_raw_fif
  from mne.label import label_sign_flip, read_label
  from mne.minimum_norm import INVERSE_METHODS, apply_inverse, apply_inverse_cov, apply_inverse_epochs, apply_inverse_raw, apply_inverse_tfr_epochs, compute_rank_inverse, make_inverse_operator, prepare_inverse_operator, read_inverse_operator, write_inverse_operator
  from mne.source_estimate import VolSourceEstimate, read_source_estimate
  from mne.source_space._source_space import _get_src_nn
  from mne.surface import _normal_orth
  from mne.time_frequency import EpochsTFR
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 31 for calling a global function with example usage: test_apply_inverse_tfr(return_generator) without return types