code: def test_tfr_multitaper():
      """Test tfr_multitaper."""
      sfreq = 200.0
      ch_names = ["SIM0001", "SIM0002"]
      ch_types = ["grad", "grad"]
      info = create_info(
          ch_names=ch_names, sfreq=sfreq, ch_types=ch_types
      )
  
      n_times = int(sfreq)  # Second long epochs
      n_epochs = 3
      seed = 42
      rng = np.random.RandomState(seed)
      noise = 0.1 * rng.randn(n_epochs, len(ch_names), n_times)
      t = np.arange(n_times, dtype=np.float64) / sfreq
      signal = np.sin(np.pi * 2.0 * 50.0 * t)  # 50 Hz sinusoid signal
      signal[np.logical_or(t < 0.45, t > 0.55)] = 0.0  # Hard windowing
      on_time = np.logical_and(t >= 0.45, t <= 0.55)
      signal[on_time] *= np.hanning(on_time.sum())  # Ramping
      dat = noise + signal
  
      reject = dict(grad=4000.0)
      events = np.empty((n_epochs, 3), int)
      first_event_sample = 100
      event_id = dict(sin50hz=1)
      for k in range(n_epochs):
          events[k, :] = (
              first_event_sample + k * n_times,
              0,
              event_id["sin50hz"],
          )
  
      epochs = EpochsArray(
          data=dat,
          info=info,
          events=events,
          event_id=event_id,
          reject=reject,
      )
  
      freqs = np.arange(35, 70, 5, dtype=np.float64)
  
      power, itc = tfr_multitaper(
          epochs, freqs=freqs, n_cycles=freqs / 2.0, time_bandwidth=4.0
      )
      power2, itc2 = tfr_multitaper(
          epochs,
          freqs=freqs,
          n_cycles=freqs / 2.0,
          time_bandwidth=4.0,
          decim=slice(0, 2),
      )
      picks = np.arange(len(ch_names))
      power_picks, itc_picks = tfr_multitaper(
          epochs,
          freqs=freqs,
          n_cycles=freqs / 2.0,
          time_bandwidth=4.0,
          picks=picks,
      )
      power_epochs = tfr_multitaper(
          epochs,
          freqs=freqs,
          n_cycles=freqs / 2.0,
          time_bandwidth=4.0,
          return_itc=False,
          average=False,
      )
      power_averaged = power_epochs.average()
      power_evoked = tfr_multitaper(
          epochs.average(),
          freqs=freqs,
          n_cycles=freqs / 2.0,
          time_bandwidth=4.0,
          return_itc=False,
          average=False,
      ).average()
  
      print(power_evoked)  # test repr for EpochsTFR
  
      # Test channel picking
      power_epochs_picked = power_epochs.copy().drop_channels(
          ["SIM0002"]
      )
      assert_equal(power_epochs_picked.data.shape, (3, 1, 7, 200))
      assert_equal(power_epochs_picked.ch_names, ["SIM0001"])
  
      pytest.raises(
          ValueError,
          tfr_multitaper,
          epochs,
          freqs=freqs,
          n_cycles=freqs / 2.0,
          return_itc=True,
          average=False,
      )
  
      # test picks argument
      assert_allclose(power.data, power_picks.data)
      assert_allclose(power.data, power_averaged.data)
      assert_allclose(power.times, power_epochs.times)
      assert_allclose(power.times, power_averaged.times)
      assert_equal(power.nave, power_averaged.nave)
      assert_equal(power_epochs.data.shape, (3, 2, 7, 200))
      assert_allclose(itc.data, itc_picks.data)
      # one is squared magnitude of the average (evoked) and
      # the other is average of the squared magnitudes (epochs PSD)
      # so values shouldn't match, but shapes should
      assert_array_equal(power.data.shape, power_evoked.data.shape)
      pytest.raises(
          AssertionError, assert_allclose, power.data, power_evoked.data
      )
  
      tmax = t[np.argmax(itc.data[0, freqs == 50, :])]
      fmax = freqs[np.argmax(power.data[1, :, t == 0.5])]
      assert tmax > 0.3 and tmax < 0.7
      assert not np.any(itc.data < 0.0)
      assert fmax > 40 and fmax < 60
      assert power2.data.shape == (len(picks), len(freqs), 2)
      assert power2.data.shape == itc2.data.shape
  
      # Test decim parameter checks and compatibility between wavelets length
      # and instance length in the time dimension.
      pytest.raises(
          TypeError,
          tfr_multitaper,
          epochs,
          freqs=freqs,
          n_cycles=freqs / 2.0,
          time_bandwidth=4.0,
          decim=(1,),
      )
      pytest.raises(
          ValueError,
          tfr_multitaper,
          epochs,
          freqs=freqs,
          n_cycles=1000,
          time_bandwidth=4.0,
      )
  
      # Test invalid frequency arguments
      with pytest.raises(
          ValueError, match=" 'freqs' must be greater than 0"
      ):
          tfr_multitaper(epochs, freqs=np.arange(0, 3), n_cycles=7)
      with pytest.raises(
          ValueError, match=" 'freqs' must be greater than 0"
      ):
          tfr_multitaper(epochs, freqs=np.arange(-4, -1), n_cycles=7)
  
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 5 for calling a global function with example usage: test_tfr_multitaper() without return types