code: def test_compute_tfr():
      """Test _compute_tfr function."""
      # Set parameters
      event_id = 1
      tmin = -0.2
      tmax = 0.498  # Allows exhaustive decimation testing
  
      # Setup for reading the raw data
      raw = read_raw_fif(raw_fname)
      events = read_events(event_fname)
  
      exclude = raw.info["bads"] + [
          "MEG 2443",
          "EEG 053",
      ]  # bads + 2 more
  
      # picks MEG gradiometers
      picks = pick_types(
          raw.info,
          meg="grad",
          eeg=False,
          stim=False,
          include=[],
          exclude=exclude,
      )
  
      picks = picks[:2]
      epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks)
      data = epochs.get_data()
      sfreq = epochs.info["sfreq"]
      freqs = np.arange(10, 20, 3).astype(float)
  
      # Check all combination of options
      for func, use_fft, zero_mean, output in product(
          (tfr_array_multitaper, tfr_array_morlet),
          (False, True),
          (False, True),
          (
              "complex",
              "power",
              "phase",
              "avg_power_itc",
              "avg_power",
              "itc",
          ),
      ):
          # Check runs
          out = func(
              data,
              sfreq=sfreq,
              freqs=freqs,
              use_fft=use_fft,
              zero_mean=zero_mean,
              n_cycles=2.0,
              output=output,
          )
          # Check shapes
          if func == tfr_array_multitaper and output in [
              "complex",
              "phase",
          ]:
              n_tapers = 3
              shape = np.r_[
                  data.shape[:2], n_tapers, len(freqs), data.shape[2]
              ]
          else:
              shape = np.r_[data.shape[:2], len(freqs), data.shape[2]]
          if ("avg" in output) or ("itc" in output):
              assert_array_equal(shape[1:], out.shape)
          else:
              assert_array_equal(shape, out.shape)
  
          # Check types
          if output in ("complex", "avg_power_itc"):
              assert_equal(np.complex128, out.dtype)
          else:
              assert_equal(np.float64, out.dtype)
          assert np.all(np.isfinite(out))
  
      # Check errors params
      for _data in (None, "foo", data[0]):
          pytest.raises(ValueError, _compute_tfr, _data, freqs, sfreq)
      for _freqs in (None, "foo", [[0]]):
          pytest.raises(ValueError, _compute_tfr, data, _freqs, sfreq)
      for _sfreq in (None, "foo"):
          pytest.raises(ValueError, _compute_tfr, data, freqs, _sfreq)
      for key in ("output", "method", "use_fft", "decim", "n_jobs"):
          for value in (None, "foo"):
              kwargs = {key: value}  # FIXME pep8
              pytest.raises(
                  ValueError, _compute_tfr, data, freqs, sfreq, **kwargs
              )
      with pytest.raises(ValueError, match="above Nyquist"):
          _compute_tfr(data, [sfreq], sfreq)
  
      # No time_bandwidth param in morlet
      pytest.raises(
          ValueError,
          _compute_tfr,
          data,
          freqs,
          sfreq,
          method="morlet",
          time_bandwidth=1,
      )
  
      # Inter-trial coherence tests
      out = _compute_tfr(data, freqs, sfreq, output="itc", n_cycles=2.0)
      assert np.sum(out >= 1) == 0
      assert np.sum(out <= 0) == 0
  
      # Check decim shapes
      # 2: multiple of len(times) even
      # 3: multiple odd
      # 8: not multiple, even
      # 9: not multiple, odd
      for decim in (2, 3, 8, 9, slice(0, 2), slice(1, 3), slice(2, 4)):
          _decim = (
              slice(None, None, decim)
              if isinstance(decim, int)
              else decim
          )
          n_time = len(np.arange(data.shape[2])[_decim])
          shape = np.r_[data.shape[:2], len(freqs), n_time]
  
          for method in ("multitaper", "morlet"):
              # Single trials
              out = _compute_tfr(
                  data,
                  freqs,
                  sfreq,
                  method=method,
                  decim=decim,
                  output="power",
                  n_cycles=2.0,
              )
              assert_array_equal(shape, out.shape)
              # Averages
              out = _compute_tfr(
                  data,
                  freqs,
                  sfreq,
                  method=method,
                  decim=decim,
                  output="avg_power",
                  n_cycles=2.0,
              )
              assert_array_equal(shape[1:], out.shape)
  
imports: import datetime
  import re
  from itertools import product
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from scipy.signal import morlet2
  import mne
  from mne import Epochs, EpochsArray, Info, Transform, create_info, pick_types, read_events
  from mne.io import read_raw_fif
  from mne.tests.test_epochs import assert_metadata_equal
  from mne.time_frequency import tfr_array_morlet, tfr_array_multitaper
  from mne.time_frequency.tfr import AverageTFR, EpochsTFR, _compute_tfr, _make_dpss, combine_tfr, cwt, fwhm, morlet, read_tfrs, tfr_morlet, tfr_multitaper, write_tfrs
  from mne.utils import catch_logging, grand_average
  from mne.viz.utils import _fake_click, _fake_keypress, _fake_scroll
label_desc: Use image node_id 14 for calling a global function with example usage: test_compute_tfr() without return types