code: def test_tfr_multi_label():
      """Test multi-label functionality."""
      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="dSPM"
      )
  
      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
      epochs = Epochs(
          raw,
          events[:3],  # take 3 events to keep the computation time low
          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)
  
      n_times = len(epochs.times)
      n_freqs = len(freqs)
  
      # prepare labels
      label = read_label(fname_label)  # lh Aud
      label2 = read_label(fname_label2)  # rh Aud
      labels = [label, label2]
      bad_lab = label.copy()
      bad_lab.vertices = np.hstack(
          (label.vertices, [2121])
      )  # add 1 unique vert
      bad_lbls = [label, bad_lab]
      nverts_lh = len(
          np.intersect1d(inv["src"][0]["vertno"], label.vertices)
      )
      nverts_rh = len(
          np.intersect1d(inv["src"][1]["vertno"], label2.vertices)
      )
      assert nverts_lh + 1 == nverts_rh == 3
  
      # prepare instances of BiHemiLabel
      fname_lvis = (
          data_path / "MEG" / "sample" / "labels" / "Vis-lh.label"
      )
      fname_rvis = (
          data_path / "MEG" / "sample" / "labels" / "Vis-rh.label"
      )
      lvis = read_label(fname_lvis)
      rvis = read_label(fname_rvis)
      bihl = BiHemiLabel(lh=label, rh=label2)  # auditory labels
      bihl.name = "Aud"
      bihl2 = BiHemiLabel(lh=lvis, rh=rvis)  # visual labels
      bihl2.name = "Vis"
      bihls = [bihl, bihl2]
      bad_bihl = BiHemiLabel(
          lh=bad_lab, rh=rvis
      )  # 1 unique vert on lh, rh ok
      bad_bihls = [bihl, bad_bihl]
      print(
          "BiHemi label verts:",
          bihl.lh.vertices.shape,
          bihl.rh.vertices.shape,
      )
  
      # check error handling
      sip_kwargs = dict(
          baseline=(-0.1, 0),
          baseline_mode="mean",
          n_cycles=2,
          n_jobs=None,
          return_plv=False,
          method="dSPM",
          prepared=True,
      )
      # label input errors
      with pytest.raises(TypeError, match="Label or BiHemi"):
          source_induced_power(
              epochs, inv, freqs, label="bad_input", **sip_kwargs
          )
      with pytest.raises(TypeError, match="Label or BiHemi"):
          source_induced_power(
              epochs,
              inv,
              freqs,
              label=[label, "bad_input"],
              **sip_kwargs,
          )
  
      # error handling for multi-label and plv
      sip_kwargs_bad = sip_kwargs.copy()
      sip_kwargs_bad["return_plv"] = True
      with pytest.raises(
          RuntimeError, match="value cannot be calculated"
      ):
          source_induced_power(
              epochs, inv, freqs, labels, **sip_kwargs_bad
          )
  
      # check multi-label handling
      label_sets = dict(
          Label=(labels, bad_lbls), BiHemi=(bihls, bad_bihls)
      )
      for ltype, lab_set in label_sets.items():
          n_verts = (
              nverts_lh if ltype == "Label" else nverts_lh + nverts_rh
          )
          # check overlapping verts error handling
          with pytest.raises(
              RuntimeError, match="overlapping vertices"
          ):
              source_induced_power(
                  epochs, inv, freqs, lab_set[1], **sip_kwargs
              )
  
          # TODO someday, eliminate both levels of this nested for-loop and use
          # pytest.mark.parametrize, but not unless/until the data IO and the loading /
          # preparing of the inverse operator have been made into fixtures (the overhead
          # of those operations makes it a bad idea to parametrize now)
          for ori in (
              None,
              "normal",
          ):  # check loose and normal orientations
              sip_kwargs.update(pick_ori=ori)
              lbl = lab_set[0][0]
  
              # check label=Label vs label=[Label]
              no_list_pow = source_induced_power(
                  epochs, inv, freqs, label=lbl, **sip_kwargs
              )
              assert no_list_pow.shape == (n_verts, n_freqs, n_times)
  
              list_pow = source_induced_power(
                  epochs, inv, freqs, label=[lbl], **sip_kwargs
              )
              assert list_pow.shape == (1, n_freqs, n_times)
  
              nlp_ave = np.mean(no_list_pow, axis=0)
              assert_allclose(nlp_ave, list_pow[0], rtol=1e-3)
  
              # check label=[Label1, Label2]
              multi_lab_pow = source_induced_power(
                  epochs, inv, freqs, label=lab_set[0], **sip_kwargs
              )
              assert multi_lab_pow.shape == (2, n_freqs, n_times)
  
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 2 for calling a global function with example usage: test_tfr_multi_label() without return types