code: def test_tfr_with_inverse_operator(method):
      """Test time freq with MNE inverse computation."""
      tmin, tmax, event_id = -0.2, 0.5, 1
  
      # Setup for reading the raw data
      raw = read_raw_fif(fname_data)
      events = find_events(raw, stim_channel="STI 014")
      inv = read_inverse_operator(fname_inv)
      inv = prepare_inverse_operator(
          inv, nave=1, lambda2=1.0 / 9.0, method=method
      )
  
      raw.info["bads"] += ["MEG 2443", "EEG 053"]  # bads + 2 more
  
      # picks MEG gradiometers
      picks = pick_types(
          raw.info,
          meg=True,
          eeg=False,
          eog=True,
          stim=False,
          exclude="bads",
      )
  
      # Load condition 1
      event_id = 1
      events3 = events[
          :3
      ]  # take 3 events to keep the computation time low
      epochs = Epochs(
          raw,
          events3,
          event_id,
          tmin,
          tmax,
          picks=picks,
          baseline=(None, 0),
          reject=dict(grad=4000e-13, eog=150e-6),
          preload=True,
      )
  
      # Compute a source estimate per frequency band
      bands = dict(alpha=[10, 10])
      label = read_label(fname_label)
  
      # XXX someday we should refactor this so that you don't have to pass
      # method -- maybe `prepare_inverse_operator` should add a `method`
      # to it and when `prepared=True` the value passed in can be ignored
      # (or better, default method=None means "dSPM if unprepared" and if they
      # actually pass a value, we check against `inv['method']`)
      stcs = source_band_induced_power(
          epochs,
          inv,
          bands,
          method=method,
          n_cycles=2,
          use_fft=False,
          pca=True,
          label=label,
          prepared=True,
      )
  
      stc = stcs["alpha"]
      assert len(stcs) == len(list(bands.keys()))
      assert np.all(stc.data > 0)
      assert_allclose(stc.times, epochs.times, atol=1e-6)
  
      stcs_no_pca = source_band_induced_power(
          epochs,
          inv,
          bands,
          method=method,
          n_cycles=2,
          use_fft=False,
          pca=False,
          label=label,
          prepared=True,
      )
  
      assert_allclose(stcs["alpha"].data, stcs_no_pca["alpha"].data)
  
      # Compute a source estimate per frequency band
      epochs = Epochs(
          raw,
          events[:10],
          event_id,
          tmin,
          tmax,
          picks=picks,
          baseline=(None, 0),
          reject=dict(grad=4000e-13, eog=150e-6),
          preload=True,
      )
  
      freqs = np.arange(7, 30, 2)  # define frequencies of interest
      power, phase_lock = source_induced_power(
          epochs,
          inv,
          freqs,
          label,
          baseline=(-0.1, 0),
          baseline_mode="percent",
          n_cycles=2,
          n_jobs=None,
          method=method,
          prepared=True,
      )
      assert power.shape == phase_lock.shape
      assert np.all(phase_lock > 0)
      assert np.all(phase_lock <= 1)
      assert 5 < np.max(power) < 7
      # fairly precise spot check that our values match what we had on 2023/09/28
      if method != "eLORETA":
          # check phase-lock using arbitrary index value since pl max is 1
          assert_allclose(phase_lock[1, 0, 0], 0.576, rtol=1e-3)
          # check power
          max_inds = np.unravel_index(np.argmax(power), power.shape)
          assert_allclose(max_inds, [0, 11, 135])
          assert_allclose(power[max_inds], 6.05, rtol=1e-3)
  
file_path: mne-python/mne/minimum_norm/tests/test_time_frequency.py
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose
  from mne import Epochs, find_events, pick_types
  from mne._fiff.constants import FIFF
  from mne.datasets import testing
  from mne.io import read_raw_fif
  from mne.label import BiHemiLabel, read_label
  from mne.minimum_norm import INVERSE_METHODS, apply_inverse_epochs, prepare_inverse_operator, read_inverse_operator
  from mne.minimum_norm.time_frequency import compute_source_psd, compute_source_psd_epochs, source_band_induced_power, source_induced_power
  from mne.time_frequency.multitaper import psd_array_multitaper
label_desc: Use image node_id 1 for calling a global function with example usage: test_tfr_with_inverse_operator(method) without return types