code: def test_psd_array_welch_average_kwarg(crop):
      """Test `average` kwarg of psd_array_welch()."""
      data, sfreq, _ = _make_psd_data()
      # prepare kwargs
      n_per_seg = 32
      kwargs = dict(
          fmin=0,
          fmax=np.inf,
          n_fft=64,
          n_per_seg=n_per_seg,
          n_overlap=0,
      )
      # optionally crop data by n_per_seg so that we are sure to test both an
      # odd number and an even number of estimates (for median bias)
      if crop:
          data = data[..., :-n_per_seg]
      # run with average=mean/median/None
      psds_mean, freqs_mean = psd_array_welch(
          data, sfreq, average="mean", **kwargs
      )
      psds_median, freqs_median = psd_array_welch(
          data, sfreq, average="median", **kwargs
      )
      psds_unagg, freqs_unagg = psd_array_welch(
          data, sfreq, average=None, **kwargs
      )
      # Frequencies should be equal across all "average" types, as we feed in
      # the exact same data.
      assert_array_equal(freqs_mean, freqs_median)
      assert_array_equal(freqs_mean, freqs_unagg)
      # For `average=None`, the last dimension contains the un-aggregated
      # segments.
      assert psds_mean.shape == psds_median.shape
      assert psds_mean.shape == psds_unagg.shape[:-1]
      assert_array_equal(psds_mean, psds_unagg.mean(axis=-1))
      # Compare with manual median calculation (_median_bias copied from SciPy)
      bias = _median_bias(psds_unagg.shape[-1])
      assert_allclose(
          psds_median, np.median(psds_unagg, axis=-1) / bias
      )
      # check shape of unagg
      n_chan, n_times = data.shape
      n_freq = len(freqs_unagg)
      n_segs = np.ceil(n_times / n_per_seg).astype(int)
      assert n_segs % 2 == (1 if crop else 0)
      assert psds_unagg.shape == (n_chan, n_freq, n_segs)
  
file_path: mne-python/mne/time_frequency/tests/test_psd.py
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal
  from scipy.signal import welch
  from mne.time_frequency import psd_array_multitaper, psd_array_welch
  from mne.time_frequency.multitaper import _psd_from_mt
  from mne.time_frequency.psd import _median_biases
  from mne.utils import catch_logging
label_desc: Use image node_id 7 for calling a global function with example usage: test_psd_array_welch_average_kwarg(crop) without return types