Spatiotemporal permutation F-test on full sensor data#

Tests for differential evoked responses in at least one condition using a permutation clustering test. The FieldTrip neighbor templates will be used to determine the adjacency between sensors. This serves as a spatial prior to the clustering. Spatiotemporal clusters will then be visualized using custom matplotlib code.

Here, the unit of observation is epochs from a specific study subject. However, the same logic applies when the unit observation is a number of study subject each of whom contribute their own averaged data (i.e., an average of their epochs). This would then be considered an analysis at the “2nd level”.

See the FieldTrip tutorial for a caveat regarding the possible interpretation of “significant” clusters.

For more information on cluster-based permutation testing in MNE-Python, see also: Non-parametric 1 sample cluster statistic on single trial power

# Authors: Denis Engemann <denis.engemann@gmail.com>
#          Jona Sassenhagen <jona.sassenhagen@gmail.com>
#          Alex Rockhill <aprockhill@mailbox.org>
#          Stefan Appelhoff <stefan.appelhoff@mailbox.org>
#
# License: BSD-3-Clause
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import scipy.stats

import mne
from mne.stats import spatio_temporal_cluster_test, combine_adjacency
from mne.datasets import sample
from mne.channels import find_ch_adjacency
from mne.viz import plot_compare_evokeds
from mne.time_frequency import tfr_morlet

Set parameters#

data_path = sample.data_path()
meg_path = data_path / 'MEG' / 'sample'
raw_fname = meg_path / 'sample_audvis_filt-0-40_raw.fif'
event_fname = meg_path / 'sample_audvis_filt-0-40_raw-eve.fif'
event_id = {'Aud/L': 1, 'Aud/R': 2, 'Vis/L': 3, 'Vis/R': 4}
tmin = -0.2
tmax = 0.5

# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.filter(1, 30)
events = mne.read_events(event_fname)
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
        Average EEG reference (1 x 60)  idle
    Range : 6450 ... 48149 =     42.956 ...   320.665 secs
Ready.
Reading 0 ... 41699  =      0.000 ...   277.709 secs...
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 1 - 30 Hz

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 1.00
- Lower transition bandwidth: 1.00 Hz (-6 dB cutoff frequency: 0.50 Hz)
- Upper passband edge: 30.00 Hz
- Upper transition bandwidth: 7.50 Hz (-6 dB cutoff frequency: 33.75 Hz)
- Filter length: 497 samples (3.310 sec)

Read epochs for the channel of interest#

picks = mne.pick_types(raw.info, meg='mag', eog=True)

reject = dict(mag=4e-12, eog=150e-6)
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
                    baseline=None, reject=reject, preload=True)

epochs.drop_channels(['EOG 061'])
epochs.equalize_event_counts(event_id)

# Obtain the data as a 3D matrix and transpose it such that
# the dimensions are as expected for the cluster permutation test:
# n_epochs × n_times × n_channels
X = [epochs[event_name].get_data() for event_name in event_id]
X = [np.transpose(x, (0, 2, 1)) for x in X]
Not setting metadata
288 matching events found
No baseline correction applied
Created an SSP operator (subspace dimension = 3)
4 projection items activated
Using data from preloaded Raw for 288 events and 106 original time points ...
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on MAG : ['MEG 1711']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on MAG : ['MEG 1711']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
49 bad epochs dropped
Removing projector <Projection | Average EEG reference, active : True, n_channels : 60>
Dropped 19 epochs: 50, 51, 84, 93, 95, 96, 129, 146, 149, 150, 154, 156, 157, 189, 194, 200, 202, 210, 211

Find the FieldTrip neighbor definition to setup sensor adjacency#

adjacency, ch_names = find_ch_adjacency(epochs.info, ch_type='mag')

print(type(adjacency))  # it's a sparse matrix!

fig, ax = plt.subplots(figsize=(5, 4))
ax.imshow(adjacency.toarray(), cmap='gray', origin='lower',
          interpolation='nearest')
ax.set_xlabel('{} Magnetometers'.format(len(ch_names)))
ax.set_ylabel('{} Magnetometers'.format(len(ch_names)))
ax.set_title('Between-sensor adjacency')
fig.tight_layout()
Between-sensor adjacency
Reading adjacency matrix for neuromag306mag.
<class 'scipy.sparse._csr.csr_matrix'>

Compute permutation statistic#

How does it work? We use clustering to “bind” together features which are similar. Our features are the magnetic fields measured over our sensor array at different times. This reduces the multiple comparison problem. To compute the actual test-statistic, we first sum all F-values in all clusters. We end up with one statistic for each cluster. Then we generate a distribution from the data by shuffling our conditions between our samples and recomputing our clusters and the test statistics. We test for the significance of a given cluster by computing the probability of observing a cluster of that size 12.

# We are running an F test, so we look at the upper tail
# see also: https://stats.stackexchange.com/a/73993
tail = 1

# We want to set a critical test statistic (here: F), to determine when
# clusters are being formed. Using Scipy's percent point function of the F
# distribution, we can conveniently select a threshold that corresponds to
# some alpha level that we arbitrarily pick.
alpha_cluster_forming = 0.001

# For an F test we need the degrees of freedom for the numerator
# (number of conditions - 1) and the denominator (number of observations
# - number of conditions):
n_conditions = len(event_id)
n_observations = len(X[0])
dfn = n_conditions - 1
dfd = n_observations - n_conditions

# Note: we calculate 1 - alpha_cluster_forming to get the critical value
# on the right tail
f_thresh = scipy.stats.f.ppf(1 - alpha_cluster_forming, dfn=dfn, dfd=dfd)

# run the cluster based permutation analysis
cluster_stats = spatio_temporal_cluster_test(X, n_permutations=1000,
                                             threshold=f_thresh, tail=tail,
                                             n_jobs=1, buffer_size=None,
                                             adjacency=adjacency)
F_obs, clusters, p_values, _ = cluster_stats
stat_fun(H1): min=0.004107 max=196.094418
Running initial clustering
Found 22 clusters
Permuting 999 times...

  0%|          |  : 0/999 [00:00<?,       ?it/s]
  0%|          |  : 1/999 [00:00<00:34,   29.20it/s]
  0%|          |  : 3/999 [00:00<00:22,   44.33it/s]
  1%|          |  : 6/999 [00:00<00:16,   59.77it/s]
  1%|          |  : 9/999 [00:00<00:14,   67.54it/s]
  1%|1         |  : 12/999 [00:00<00:13,   72.22it/s]
  2%|1         |  : 15/999 [00:00<00:13,   75.33it/s]
  2%|1         |  : 18/999 [00:00<00:12,   77.52it/s]
  2%|2         |  : 21/999 [00:00<00:12,   79.18it/s]
  2%|2         |  : 24/999 [00:00<00:12,   80.41it/s]
  3%|2         |  : 27/999 [00:00<00:11,   81.44it/s]
  3%|3         |  : 30/999 [00:00<00:11,   82.27it/s]
  3%|3         |  : 32/999 [00:00<00:12,   79.76it/s]
  4%|3         |  : 35/999 [00:00<00:11,   80.67it/s]
  4%|3         |  : 38/999 [00:00<00:11,   81.46it/s]
  4%|4         |  : 41/999 [00:00<00:11,   82.14it/s]
  4%|4         |  : 43/999 [00:00<00:11,   80.09it/s]
  5%|4         |  : 46/999 [00:00<00:11,   80.80it/s]
  5%|4         |  : 49/999 [00:00<00:11,   81.44it/s]
  5%|5         |  : 52/999 [00:00<00:11,   82.03it/s]
  5%|5         |  : 54/999 [00:00<00:11,   80.24it/s]
  6%|5         |  : 57/999 [00:00<00:11,   80.88it/s]
  6%|6         |  : 60/999 [00:00<00:11,   81.45it/s]
  6%|6         |  : 63/999 [00:00<00:11,   81.97it/s]
  7%|6         |  : 66/999 [00:00<00:11,   82.44it/s]
  7%|6         |  : 69/999 [00:00<00:11,   82.87it/s]
  7%|7         |  : 72/999 [00:00<00:11,   83.26it/s]
  7%|7         |  : 74/999 [00:00<00:11,   81.66it/s]
  8%|7         |  : 77/999 [00:00<00:11,   82.12it/s]
  8%|8         |  : 80/999 [00:00<00:11,   82.55it/s]
  8%|8         |  : 83/999 [00:01<00:11,   82.93it/s]
  9%|8         |  : 86/999 [00:01<00:10,   83.28it/s]
  9%|8         |  : 89/999 [00:01<00:10,   83.62it/s]
  9%|9         |  : 92/999 [00:01<00:10,   83.93it/s]
  9%|9         |  : 94/999 [00:01<00:10,   82.43it/s]
 10%|9         |  : 97/999 [00:01<00:10,   82.81it/s]
 10%|#         |  : 100/999 [00:01<00:10,   83.16it/s]
 10%|#         |  : 103/999 [00:01<00:10,   83.46it/s]
 11%|#         |  : 105/999 [00:01<00:10,   82.04it/s]
 11%|#         |  : 108/999 [00:01<00:10,   82.41it/s]
 11%|#1        |  : 111/999 [00:01<00:10,   82.78it/s]
 11%|#1        |  : 114/999 [00:01<00:10,   83.12it/s]
 12%|#1        |  : 117/999 [00:01<00:10,   83.43it/s]
 12%|#2        |  : 120/999 [00:01<00:10,   83.73it/s]
 12%|#2        |  : 122/999 [00:01<00:10,   82.36it/s]
 13%|#2        |  : 125/999 [00:01<00:10,   82.72it/s]
 13%|#2        |  : 128/999 [00:01<00:10,   83.04it/s]
 13%|#3        |  : 131/999 [00:01<00:10,   83.26it/s]
 13%|#3        |  : 133/999 [00:01<00:10,   81.94it/s]
 14%|#3        |  : 136/999 [00:01<00:10,   82.30it/s]
 14%|#3        |  : 139/999 [00:01<00:10,   82.65it/s]
 14%|#4        |  : 142/999 [00:01<00:10,   82.98it/s]
 15%|#4        |  : 145/999 [00:01<00:10,   83.29it/s]
 15%|#4        |  : 147/999 [00:01<00:10,   82.00it/s]
 15%|#5        |  : 150/999 [00:01<00:10,   82.35it/s]
 15%|#5        |  : 153/999 [00:01<00:10,   82.69it/s]
 16%|#5        |  : 156/999 [00:01<00:10,   83.00it/s]
 16%|#5        |  : 159/999 [00:01<00:10,   83.29it/s]
 16%|#6        |  : 161/999 [00:01<00:10,   82.02it/s]
 16%|#6        |  : 164/999 [00:01<00:10,   82.38it/s]
 17%|#6        |  : 166/999 [00:02<00:10,   81.16it/s]
 17%|#6        |  : 169/999 [00:02<00:10,   81.55it/s]
 17%|#7        |  : 172/999 [00:02<00:10,   81.92it/s]
 17%|#7        |  : 174/999 [00:02<00:10,   80.73it/s]
 18%|#7        |  : 177/999 [00:02<00:10,   81.15it/s]
 18%|#8        |  : 180/999 [00:02<00:10,   81.54it/s]
 18%|#8        |  : 183/999 [00:02<00:09,   81.91it/s]
 19%|#8        |  : 186/999 [00:02<00:09,   82.26it/s]
 19%|#8        |  : 188/999 [00:02<00:10,   81.07it/s]
 19%|#9        |  : 191/999 [00:02<00:09,   81.45it/s]
 19%|#9        |  : 194/999 [00:02<00:09,   81.83it/s]
 20%|#9        |  : 197/999 [00:02<00:09,   82.18it/s]
 20%|##        |  : 200/999 [00:02<00:09,   82.51it/s]
 20%|##        |  : 202/999 [00:02<00:09,   81.30it/s]
 21%|##        |  : 205/999 [00:02<00:09,   81.67it/s]
 21%|##        |  : 208/999 [00:02<00:09,   82.03it/s]
 21%|##1       |  : 211/999 [00:02<00:09,   82.37it/s]
 21%|##1       |  : 213/999 [00:02<00:09,   81.18it/s]
 22%|##1       |  : 216/999 [00:02<00:09,   81.56it/s]
 22%|##1       |  : 219/999 [00:02<00:09,   81.92it/s]
 22%|##2       |  : 222/999 [00:02<00:09,   82.26it/s]
 23%|##2       |  : 225/999 [00:02<00:09,   82.57it/s]
 23%|##2       |  : 228/999 [00:02<00:09,   82.88it/s]
 23%|##3       |  : 230/999 [00:02<00:09,   81.68it/s]
 23%|##3       |  : 233/999 [00:02<00:09,   82.02it/s]
 24%|##3       |  : 236/999 [00:02<00:09,   82.36it/s]
 24%|##3       |  : 238/999 [00:02<00:09,   81.18it/s]
 24%|##4       |  : 241/999 [00:02<00:09,   81.56it/s]
 24%|##4       |  : 244/999 [00:02<00:09,   81.93it/s]
 25%|##4       |  : 247/999 [00:03<00:09,   82.26it/s]
 25%|##5       |  : 250/999 [00:03<00:09,   82.59it/s]
 25%|##5       |  : 252/999 [00:03<00:09,   81.41it/s]
 26%|##5       |  : 255/999 [00:03<00:09,   81.78it/s]
 26%|##5       |  : 258/999 [00:03<00:09,   82.13it/s]
 26%|##6       |  : 261/999 [00:03<00:08,   82.46it/s]
 26%|##6       |  : 263/999 [00:03<00:09,   81.28it/s]
 27%|##6       |  : 266/999 [00:03<00:08,   81.66it/s]
 27%|##6       |  : 269/999 [00:03<00:08,   82.02it/s]
 27%|##7       |  : 272/999 [00:03<00:08,   82.36it/s]
 28%|##7       |  : 275/999 [00:03<00:08,   82.68it/s]
 28%|##7       |  : 277/999 [00:03<00:08,   81.49it/s]
 28%|##8       |  : 280/999 [00:03<00:08,   81.86it/s]
 28%|##8       |  : 283/999 [00:03<00:08,   82.20it/s]
 29%|##8       |  : 286/999 [00:03<00:08,   82.54it/s]
 29%|##8       |  : 289/999 [00:03<00:08,   82.85it/s]
 29%|##9       |  : 292/999 [00:03<00:08,   83.14it/s]
 30%|##9       |  : 295/999 [00:03<00:08,   83.42it/s]
 30%|##9       |  : 298/999 [00:03<00:08,   83.68it/s]
 30%|###       |  : 301/999 [00:03<00:08,   83.94it/s]
 30%|###       |  : 304/999 [00:03<00:08,   84.17it/s]
 31%|###       |  : 306/999 [00:03<00:08,   82.91it/s]
 31%|###       |  : 309/999 [00:03<00:08,   83.18it/s]
 31%|###1      |  : 312/999 [00:03<00:08,   83.46it/s]
 32%|###1      |  : 315/999 [00:03<00:08,   83.72it/s]
 32%|###1      |  : 318/999 [00:03<00:08,   83.98it/s]
 32%|###2      |  : 321/999 [00:03<00:08,   84.22it/s]
 32%|###2      |  : 323/999 [00:03<00:08,   82.96it/s]
 33%|###2      |  : 326/999 [00:03<00:08,   83.23it/s]
 33%|###2      |  : 329/999 [00:03<00:08,   83.50it/s]
 33%|###3      |  : 332/999 [00:04<00:07,   83.77it/s]
 34%|###3      |  : 335/999 [00:04<00:07,   84.02it/s]
 34%|###3      |  : 338/999 [00:04<00:07,   84.26it/s]
 34%|###4      |  : 341/999 [00:04<00:07,   84.47it/s]
 34%|###4      |  : 343/999 [00:04<00:07,   83.20it/s]
 35%|###4      |  : 347/999 [00:04<00:07,   84.95it/s]
 35%|###4      |  : 349/999 [00:04<00:07,   83.60it/s]
 35%|###5      |  : 352/999 [00:04<00:07,   83.85it/s]
 36%|###5      |  : 355/999 [00:04<00:07,   84.06it/s]
 36%|###5      |  : 358/999 [00:04<00:07,   84.30it/s]
 36%|###6      |  : 362/999 [00:04<00:07,   86.00it/s]
 37%|###6      |  : 365/999 [00:04<00:07,   86.12it/s]
 37%|###6      |  : 368/999 [00:04<00:07,   86.25it/s]
 37%|###7      |  : 371/999 [00:04<00:07,   86.37it/s]
 37%|###7      |  : 374/999 [00:04<00:07,   86.47it/s]
 38%|###7      |  : 376/999 [00:04<00:07,   85.11it/s]
 38%|###7      |  : 379/999 [00:04<00:07,   85.27it/s]
 38%|###8      |  : 382/999 [00:04<00:07,   85.45it/s]
 39%|###8      |  : 385/999 [00:04<00:07,   85.61it/s]
 39%|###8      |  : 388/999 [00:04<00:07,   85.76it/s]
 39%|###9      |  : 391/999 [00:04<00:07,   85.91it/s]
 39%|###9      |  : 393/999 [00:04<00:07,   84.57it/s]
 40%|###9      |  : 396/999 [00:04<00:07,   84.78it/s]
 40%|###9      |  : 399/999 [00:04<00:07,   84.98it/s]
 40%|####      |  : 402/999 [00:04<00:07,   85.16it/s]
 41%|####      |  : 405/999 [00:04<00:06,   85.34it/s]
 41%|####      |  : 408/999 [00:04<00:06,   85.49it/s]
 41%|####1     |  : 411/999 [00:04<00:06,   85.64it/s]
 41%|####1     |  : 414/999 [00:04<00:06,   85.79it/s]
 42%|####1     |  : 417/999 [00:05<00:06,   85.94it/s]
 42%|####2     |  : 420/999 [00:05<00:06,   86.09it/s]
 42%|####2     |  : 423/999 [00:05<00:06,   86.21it/s]
 43%|####2     |  : 425/999 [00:05<00:06,   84.85it/s]
 43%|####2     |  : 428/999 [00:05<00:06,   85.04it/s]
 43%|####3     |  : 431/999 [00:05<00:06,   85.23it/s]
 43%|####3     |  : 434/999 [00:05<00:06,   85.38it/s]
 44%|####3     |  : 437/999 [00:05<00:06,   85.55it/s]
 44%|####3     |  : 439/999 [00:05<00:06,   84.19it/s]
 44%|####4     |  : 442/999 [00:05<00:06,   84.42it/s]
 45%|####4     |  : 445/999 [00:05<00:06,   84.63it/s]
 45%|####4     |  : 448/999 [00:05<00:06,   84.83it/s]
 45%|####5     |  : 451/999 [00:05<00:06,   85.02it/s]
 45%|####5     |  : 454/999 [00:05<00:06,   85.20it/s]
 46%|####5     |  : 457/999 [00:05<00:06,   85.38it/s]
 46%|####6     |  : 460/999 [00:05<00:06,   85.54it/s]
 46%|####6     |  : 463/999 [00:05<00:06,   85.70it/s]
 47%|####6     |  : 466/999 [00:05<00:06,   85.86it/s]
 47%|####6     |  : 468/999 [00:05<00:06,   84.52it/s]
 47%|####7     |  : 471/999 [00:05<00:06,   84.73it/s]
 47%|####7     |  : 474/999 [00:05<00:06,   84.93it/s]
 48%|####7     |  : 477/999 [00:05<00:06,   85.11it/s]
 48%|####8     |  : 480/999 [00:05<00:06,   85.29it/s]
 48%|####8     |  : 483/999 [00:05<00:06,   85.45it/s]
 49%|####8     |  : 485/999 [00:05<00:06,   84.12it/s]
 49%|####8     |  : 489/999 [00:05<00:05,   85.83it/s]
 49%|####9     |  : 491/999 [00:05<00:06,   84.50it/s]
 49%|####9     |  : 494/999 [00:05<00:05,   84.71it/s]
 50%|####9     |  : 497/999 [00:05<00:05,   84.90it/s]
 50%|#####     |  : 500/999 [00:05<00:05,   85.09it/s]
 50%|#####     |  : 503/999 [00:06<00:05,   85.27it/s]
 51%|#####     |  : 505/999 [00:06<00:05,   83.97it/s]
 51%|#####     |  : 508/999 [00:06<00:05,   84.20it/s]
 51%|#####1    |  : 511/999 [00:06<00:05,   84.42it/s]
 51%|#####1    |  : 514/999 [00:06<00:05,   84.64it/s]
 52%|#####1    |  : 517/999 [00:06<00:05,   84.84it/s]
 52%|#####2    |  : 520/999 [00:06<00:05,   85.03it/s]
 52%|#####2    |  : 523/999 [00:06<00:05,   85.21it/s]
 53%|#####2    |  : 526/999 [00:06<00:05,   85.38it/s]
 53%|#####2    |  : 529/999 [00:06<00:05,   85.56it/s]
 53%|#####3    |  : 532/999 [00:06<00:05,   85.72it/s]
 54%|#####3    |  : 535/999 [00:06<00:05,   85.86it/s]
 54%|#####3    |  : 537/999 [00:06<00:05,   84.51it/s]
 54%|#####4    |  : 540/999 [00:06<00:05,   84.71it/s]
 54%|#####4    |  : 543/999 [00:06<00:05,   84.91it/s]
 55%|#####4    |  : 546/999 [00:06<00:05,   85.10it/s]
 55%|#####4    |  : 549/999 [00:06<00:05,   85.28it/s]
 55%|#####5    |  : 552/999 [00:06<00:05,   85.45it/s]
 56%|#####5    |  : 555/999 [00:06<00:05,   85.61it/s]
 56%|#####5    |  : 558/999 [00:06<00:05,   85.76it/s]
 56%|#####6    |  : 561/999 [00:06<00:05,   85.91it/s]
 56%|#####6    |  : 564/999 [00:06<00:05,   86.05it/s]
 57%|#####6    |  : 567/999 [00:06<00:05,   86.18it/s]
 57%|#####7    |  : 570/999 [00:06<00:04,   86.23it/s]
 57%|#####7    |  : 572/999 [00:06<00:05,   84.87it/s]
 58%|#####7    |  : 575/999 [00:06<00:04,   85.06it/s]
 58%|#####7    |  : 579/999 [00:06<00:04,   86.71it/s]
 58%|#####8    |  : 582/999 [00:06<00:04,   86.81it/s]
 59%|#####8    |  : 585/999 [00:06<00:04,   86.89it/s]
 59%|#####8    |  : 588/999 [00:07<00:04,   86.98it/s]
 59%|#####9    |  : 591/999 [00:07<00:04,   87.06it/s]
 59%|#####9    |  : 594/999 [00:07<00:04,   87.14it/s]
 60%|#####9    |  : 597/999 [00:07<00:04,   87.22it/s]
 60%|######    |  : 600/999 [00:07<00:04,   87.30it/s]
 60%|######    |  : 603/999 [00:07<00:04,   87.36it/s]
 61%|######    |  : 606/999 [00:07<00:04,   87.43it/s]
 61%|######    |  : 609/999 [00:07<00:04,   87.49it/s]
 61%|######1   |  : 612/999 [00:07<00:04,   87.54it/s]
 62%|######1   |  : 615/999 [00:07<00:04,   87.59it/s]
 62%|######1   |  : 618/999 [00:07<00:04,   87.63it/s]
 62%|######2   |  : 621/999 [00:07<00:04,   87.69it/s]
 62%|######2   |  : 624/999 [00:07<00:04,   87.74it/s]
 63%|######2   |  : 627/999 [00:07<00:04,   87.79it/s]
 63%|######3   |  : 630/999 [00:07<00:04,   87.84it/s]
 63%|######3   |  : 633/999 [00:07<00:04,   87.89it/s]
 64%|######3   |  : 636/999 [00:07<00:04,   87.92it/s]
 64%|######3   |  : 639/999 [00:07<00:04,   87.96it/s]
 64%|######4   |  : 642/999 [00:07<00:04,   87.99it/s]
 65%|######4   |  : 645/999 [00:07<00:04,   88.02it/s]
 65%|######4   |  : 648/999 [00:07<00:03,   88.06it/s]
 65%|######5   |  : 651/999 [00:07<00:03,   88.08it/s]
 65%|######5   |  : 654/999 [00:07<00:03,   88.11it/s]
 66%|######5   |  : 657/999 [00:07<00:03,   88.13it/s]
 66%|######6   |  : 661/999 [00:07<00:03,   89.64it/s]
 66%|######6   |  : 664/999 [00:07<00:03,   89.59it/s]
 67%|######6   |  : 667/999 [00:07<00:03,   89.55it/s]
 67%|######7   |  : 670/999 [00:07<00:03,   89.50it/s]
 67%|######7   |  : 673/999 [00:07<00:03,   89.46it/s]
 68%|######7   |  : 676/999 [00:07<00:03,   89.40it/s]
 68%|######7   |  : 678/999 [00:08<00:03,   87.89it/s]
 68%|######8   |  : 681/999 [00:08<00:03,   87.94it/s]
 68%|######8   |  : 684/999 [00:08<00:03,   87.98it/s]
 69%|######8   |  : 686/999 [00:08<00:03,   86.54it/s]
 69%|######8   |  : 689/999 [00:08<00:03,   86.64it/s]
 69%|######9   |  : 692/999 [00:08<00:03,   86.74it/s]
 70%|######9   |  : 695/999 [00:08<00:03,   86.84it/s]
 70%|######9   |  : 697/999 [00:08<00:03,   85.45it/s]
 70%|#######   |  : 700/999 [00:08<00:03,   85.61it/s]
 70%|#######   |  : 703/999 [00:08<00:03,   85.77it/s]
 71%|#######   |  : 706/999 [00:08<00:03,   85.91it/s]
 71%|#######   |  : 709/999 [00:08<00:03,   86.04it/s]
 71%|#######1  |  : 711/999 [00:08<00:03,   84.69it/s]
 71%|#######1  |  : 714/999 [00:08<00:03,   84.88it/s]
 72%|#######1  |  : 717/999 [00:08<00:03,   85.07it/s]
 72%|#######1  |  : 719/999 [00:08<00:03,   83.76it/s]
 72%|#######2  |  : 722/999 [00:08<00:03,   84.00it/s]
 73%|#######2  |  : 725/999 [00:08<00:03,   84.23it/s]
 73%|#######2  |  : 727/999 [00:08<00:03,   82.97it/s]
 73%|#######3  |  : 730/999 [00:08<00:03,   83.25it/s]
 73%|#######3  |  : 733/999 [00:08<00:03,   83.52it/s]
 74%|#######3  |  : 736/999 [00:08<00:03,   83.78it/s]
 74%|#######3  |  : 739/999 [00:08<00:03,   84.02it/s]
 74%|#######4  |  : 741/999 [00:08<00:03,   82.76it/s]
 74%|#######4  |  : 744/999 [00:08<00:03,   83.06it/s]
 75%|#######4  |  : 747/999 [00:08<00:03,   83.34it/s]
 75%|#######5  |  : 750/999 [00:08<00:02,   83.60it/s]
 75%|#######5  |  : 753/999 [00:08<00:02,   83.85it/s]
 76%|#######5  |  : 755/999 [00:08<00:02,   82.62it/s]
 76%|#######5  |  : 758/999 [00:09<00:02,   82.92it/s]
 76%|#######6  |  : 761/999 [00:09<00:02,   83.21it/s]
 76%|#######6  |  : 764/999 [00:09<00:02,   83.48it/s]
 77%|#######6  |  : 766/999 [00:09<00:02,   82.24it/s]
 77%|#######6  |  : 769/999 [00:09<00:02,   82.57it/s]
 77%|#######7  |  : 772/999 [00:09<00:02,   82.87it/s]
 78%|#######7  |  : 775/999 [00:09<00:02,   83.16it/s]
 78%|#######7  |  : 777/999 [00:09<00:02,   81.96it/s]
 78%|#######8  |  : 780/999 [00:09<00:02,   82.30it/s]
 78%|#######8  |  : 783/999 [00:09<00:02,   82.62it/s]
 79%|#######8  |  : 786/999 [00:09<00:02,   82.92it/s]
 79%|#######8  |  : 788/999 [00:09<00:02,   81.69it/s]
 79%|#######9  |  : 791/999 [00:09<00:02,   82.04it/s]
 79%|#######9  |  : 794/999 [00:09<00:02,   82.36it/s]
 80%|#######9  |  : 797/999 [00:09<00:02,   82.68it/s]
 80%|########  |  : 800/999 [00:09<00:02,   82.96it/s]
 80%|########  |  : 802/999 [00:09<00:02,   81.77it/s]
 81%|########  |  : 805/999 [00:09<00:02,   82.12it/s]
 81%|########  |  : 808/999 [00:09<00:02,   82.44it/s]
 81%|########1 |  : 811/999 [00:09<00:02,   82.75it/s]
 81%|########1 |  : 813/999 [00:09<00:02,   81.52it/s]
 82%|########1 |  : 816/999 [00:09<00:02,   81.88it/s]
 82%|########1 |  : 819/999 [00:09<00:02,   82.22it/s]
 82%|########2 |  : 822/999 [00:09<00:02,   82.55it/s]
 83%|########2 |  : 825/999 [00:09<00:02,   82.85it/s]
 83%|########2 |  : 828/999 [00:09<00:02,   83.15it/s]
 83%|########3 |  : 831/999 [00:09<00:02,   83.42it/s]
 83%|########3 |  : 834/999 [00:09<00:01,   83.68it/s]
 84%|########3 |  : 836/999 [00:09<00:01,   82.45it/s]
 84%|########3 |  : 839/999 [00:09<00:01,   82.76it/s]
 84%|########4 |  : 842/999 [00:10<00:01,   83.06it/s]
 85%|########4 |  : 845/999 [00:10<00:01,   83.35it/s]
 85%|########4 |  : 848/999 [00:10<00:01,   83.61it/s]
 85%|########5 |  : 851/999 [00:10<00:01,   83.87it/s]
 85%|########5 |  : 854/999 [00:10<00:01,   84.11it/s]
 86%|########5 |  : 856/999 [00:10<00:01,   82.86it/s]
 86%|########5 |  : 859/999 [00:10<00:01,   83.15it/s]
 86%|########6 |  : 862/999 [00:10<00:01,   83.42it/s]
 87%|########6 |  : 865/999 [00:10<00:01,   83.69it/s]
 87%|########6 |  : 868/999 [00:10<00:01,   83.94it/s]
 87%|########7 |  : 871/999 [00:10<00:01,   84.18it/s]
 87%|########7 |  : 874/999 [00:10<00:01,   84.41it/s]
 88%|########7 |  : 877/999 [00:10<00:01,   84.62it/s]
 88%|########8 |  : 880/999 [00:10<00:01,   84.82it/s]
 88%|########8 |  : 883/999 [00:10<00:01,   85.01it/s]
 89%|########8 |  : 886/999 [00:10<00:01,   85.20it/s]
 89%|########8 |  : 889/999 [00:10<00:01,   85.38it/s]
 89%|########9 |  : 892/999 [00:10<00:01,   85.54it/s]
 90%|########9 |  : 895/999 [00:10<00:01,   85.70it/s]
 90%|########9 |  : 898/999 [00:10<00:01,   85.85it/s]
 90%|######### |  : 901/999 [00:10<00:01,   85.99it/s]
 90%|######### |  : 904/999 [00:10<00:01,   86.11it/s]
 91%|######### |  : 908/999 [00:10<00:01,   87.72it/s]
 91%|#########1|  : 911/999 [00:10<00:01,   87.76it/s]
 91%|#########1|  : 914/999 [00:10<00:00,   87.79it/s]
 92%|#########1|  : 917/999 [00:10<00:00,   87.83it/s]
 92%|#########2|  : 920/999 [00:10<00:00,   87.87it/s]
 92%|#########2|  : 923/999 [00:10<00:00,   87.91it/s]
 93%|#########2|  : 926/999 [00:10<00:00,   87.95it/s]
 93%|#########2|  : 929/999 [00:11<00:00,   87.98it/s]
 93%|#########3|  : 932/999 [00:11<00:00,   88.02it/s]
 94%|#########3|  : 935/999 [00:11<00:00,   88.05it/s]
 94%|#########3|  : 938/999 [00:11<00:00,   88.05it/s]
 94%|#########4|  : 942/999 [00:11<00:00,   89.56it/s]
 95%|#########4|  : 945/999 [00:11<00:00,   89.51it/s]
 95%|#########4|  : 948/999 [00:11<00:00,   89.47it/s]
 95%|#########5|  : 951/999 [00:11<00:00,   89.44it/s]
 95%|#########5|  : 954/999 [00:11<00:00,   89.39it/s]
 96%|#########5|  : 957/999 [00:11<00:00,   89.35it/s]
 96%|#########6|  : 960/999 [00:11<00:00,   89.31it/s]
 96%|#########6|  : 963/999 [00:11<00:00,   89.27it/s]
 97%|#########6|  : 967/999 [00:11<00:00,   90.73it/s]
 97%|#########7|  : 970/999 [00:11<00:00,   90.62it/s]
 97%|#########7|  : 973/999 [00:11<00:00,   90.53it/s]
 98%|#########7|  : 976/999 [00:11<00:00,   90.43it/s]
 98%|#########7|  : 979/999 [00:11<00:00,   90.35it/s]
 98%|#########8|  : 982/999 [00:11<00:00,   90.26it/s]
 99%|#########8|  : 985/999 [00:11<00:00,   90.19it/s]
 99%|#########8|  : 988/999 [00:11<00:00,   90.11it/s]
 99%|#########9|  : 991/999 [00:11<00:00,   90.04it/s]
 99%|#########9|  : 994/999 [00:11<00:00,   89.97it/s]
100%|#########9|  : 997/999 [00:11<00:00,   89.91it/s]
100%|##########|  : 999/999 [00:11<00:00,   90.50it/s]
100%|##########|  : 999/999 [00:11<00:00,   84.91it/s]
Computing cluster p-values
Done.

Note

Note how we only specified an adjacency for sensors! However, because we used mne.stats.spatio_temporal_cluster_test(), an adjacency for time points was automatically taken into account. That is, at time point N, the time points N - 1 and N + 1 were considered as adjacent (this is also called “lattice adjacency”). This is only possbile because we ran the analysis on 2D data (times × channels) per observation … for 3D data per observation (e.g., times × frequencies × channels), we will need to use mne.stats.combine_adjacency(), as shown further below.

Note also that the same functions work with source estimates. The only differences are the origin of the data, the size, and the adjacency definition. It can be used for single trials or for groups of subjects.

Visualize clusters#

# We subselect clusters that we consider significant at an arbitrarily
# picked alpha level: "p_accept".
# NOTE: remember the caveats with respect to "significant" clusters that
# we mentioned in the introduction of this tutorial!
p_accept = 0.01
good_cluster_inds = np.where(p_values < p_accept)[0]

# configure variables for visualization
colors = {"Aud": "crimson", "Vis": 'steelblue'}
linestyles = {"L": '-', "R": '--'}

# organize data for plotting
evokeds = {cond: epochs[cond].average() for cond in event_id}

# loop over clusters
for i_clu, clu_idx in enumerate(good_cluster_inds):
    # unpack cluster information, get unique indices
    time_inds, space_inds = np.squeeze(clusters[clu_idx])
    ch_inds = np.unique(space_inds)
    time_inds = np.unique(time_inds)

    # get topography for F stat
    f_map = F_obs[time_inds, ...].mean(axis=0)

    # get signals at the sensors contributing to the cluster
    sig_times = epochs.times[time_inds]

    # create spatial mask
    mask = np.zeros((f_map.shape[0], 1), dtype=bool)
    mask[ch_inds, :] = True

    # initialize figure
    fig, ax_topo = plt.subplots(1, 1, figsize=(10, 3))

    # plot average test statistic and mark significant sensors
    f_evoked = mne.EvokedArray(f_map[:, np.newaxis], epochs.info, tmin=0)
    f_evoked.plot_topomap(times=0, mask=mask, axes=ax_topo, cmap='Reds',
                          vmin=np.min, vmax=np.max, show=False,
                          colorbar=False, mask_params=dict(markersize=10))
    image = ax_topo.images[0]

    # create additional axes (for ERF and colorbar)
    divider = make_axes_locatable(ax_topo)

    # add axes for colorbar
    ax_colorbar = divider.append_axes('right', size='5%', pad=0.05)
    plt.colorbar(image, cax=ax_colorbar)
    ax_topo.set_xlabel(
        'Averaged F-map ({:0.3f} - {:0.3f} s)'.format(*sig_times[[0, -1]]))

    # add new axis for time courses and plot time courses
    ax_signals = divider.append_axes('right', size='300%', pad=1.2)
    title = 'Cluster #{0}, {1} sensor'.format(i_clu + 1, len(ch_inds))
    if len(ch_inds) > 1:
        title += "s (mean)"
    plot_compare_evokeds(evokeds, title=title, picks=ch_inds, axes=ax_signals,
                         colors=colors, linestyles=linestyles, show=False,
                         split_legend=True, truncate_yaxis='auto')

    # plot temporal cluster extent
    ymin, ymax = ax_signals.get_ylim()
    ax_signals.fill_betweenx((ymin, ymax), sig_times[0], sig_times[-1],
                             color='orange', alpha=0.3)

    # clean up viz
    mne.viz.tight_layout(fig=fig)
    fig.subplots_adjust(bottom=.05)
    plt.show()
  • 0.000 s, Cluster #1, 4 sensors (mean) (GFP)
  • 0.000 s, Cluster #2, 86 sensors (mean) (GFP)
  • 0.000 s, Cluster #3, 7 sensors (mean) (GFP)
  • 0.000 s, Cluster #4, 9 sensors (mean) (GFP)
  • 0.000 s, Cluster #5, 33 sensors (mean) (GFP)
  • 0.000 s, Cluster #6, 5 sensors (mean) (GFP)
  • 0.000 s, Cluster #7, 3 sensors (mean) (GFP)
  • 0.000 s, Cluster #8, 9 sensors (mean) (GFP)
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"

Permutation statistic for time-frequencies#

Let’s do the same thing with the time-frequency decomposition of the data (see Frequency and time-frequency sensor analysis for a tutorial and Time-frequency on simulated data (Multitaper vs. Morlet vs. Stockwell) for a comparison of time-frequency methods) to show how cluster permutations can be done on higher-dimensional data.

decim = 4
freqs = np.arange(7, 30, 3)  # define frequencies of interest
n_cycles = freqs / freqs[0]

epochs_power = list()
for condition in [epochs[k] for k in ('Aud/L', 'Vis/L')]:
    this_tfr = tfr_morlet(condition, freqs, n_cycles=n_cycles,
                          decim=decim, average=False, return_itc=False)
    this_tfr.apply_baseline(mode='ratio', baseline=(None, 0))
    epochs_power.append(this_tfr.data)

# transpose again to (epochs, frequencies, times, channels)
X = [np.transpose(x, (0, 2, 3, 1)) for x in epochs_power]
Not setting metadata
Applying baseline correction (mode: ratio)
Not setting metadata
Applying baseline correction (mode: ratio)

Remember the note on the adjacency matrix from above: For 3D data, as here, we must use mne.stats.combine_adjacency() to extend the sensor-based adjacency to incorporate the time-frequency plane as well.

Here, the integer inputs are converted into a lattice and combined with the sensor adjacency matrix so that data at similar times and with similar frequencies and at close sensor locations are clustered together.

# our data at each observation is of shape frequencies × times × channels
tfr_adjacency = combine_adjacency(
    len(freqs), len(this_tfr.times), adjacency)

Now we can run the cluster permutation test, but first we have to set a threshold. This example decimates in time and uses few frequencies so we need to increase the threshold from the default value in order to have differentiated clusters (i.e., so that our algorithm doesn’t just find one large cluster). For a more principled method of setting this parameter, threshold-free cluster enhancement may be used. See Statistical inference for a discussion.

# This time we don't calculate a threshold based on the F distribution.
# We might as well select an arbitrary threshold for cluster forming
tfr_threshold = 15.0

# run cluster based permutation analysis
cluster_stats = spatio_temporal_cluster_test(
    X, n_permutations=1000, threshold=tfr_threshold, tail=1, n_jobs=1,
    buffer_size=None, adjacency=tfr_adjacency)
stat_fun(H1): min=0.000000 max=45.333033
Running initial clustering
Found 5 clusters
Permuting 999 times...

  0%|          |  : 0/999 [00:00<?,       ?it/s]
  0%|          |  : 2/999 [00:00<00:57,   17.33it/s]
  0%|          |  : 3/999 [00:00<01:02,   15.86it/s]
  0%|          |  : 4/999 [00:00<01:06,   14.95it/s]
  1%|          |  : 5/999 [00:00<00:59,   16.60it/s]
  1%|          |  : 7/999 [00:00<02:18,    7.17it/s]
  1%|          |  : 8/999 [00:00<02:04,    7.99it/s]
  1%|          |  : 9/999 [00:01<01:52,    8.78it/s]
  1%|1         |  : 10/999 [00:01<01:43,    9.57it/s]
  1%|1         |  : 11/999 [00:01<01:39,    9.91it/s]
  1%|1         |  : 12/999 [00:01<01:33,   10.60it/s]
  1%|1         |  : 13/999 [00:01<01:27,   11.33it/s]
  2%|1         |  : 16/999 [00:01<01:08,   14.34it/s]
  2%|1         |  : 19/999 [00:01<01:01,   15.83it/s]
  2%|2         |  : 22/999 [00:01<00:52,   18.50it/s]
  2%|2         |  : 23/999 [00:01<00:53,   18.14it/s]
  2%|2         |  : 24/999 [00:01<00:54,   17.82it/s]
  3%|2         |  : 25/999 [00:01<00:53,   18.13it/s]
  3%|2         |  : 26/999 [00:01<00:52,   18.54it/s]
  3%|2         |  : 29/999 [00:01<00:46,   21.07it/s]
  3%|3         |  : 32/999 [00:01<00:41,   23.55it/s]
  3%|3         |  : 33/999 [00:01<00:40,   23.64it/s]
  3%|3         |  : 34/999 [00:01<00:40,   23.86it/s]
  4%|3         |  : 35/999 [00:01<00:40,   23.94it/s]
  4%|3         |  : 36/999 [00:01<00:39,   24.16it/s]
  4%|3         |  : 37/999 [00:01<00:39,   24.23it/s]
  4%|3         |  : 38/999 [00:01<00:39,   24.44it/s]
  4%|4         |  : 40/999 [00:01<00:37,   25.80it/s]
  4%|4         |  : 42/999 [00:02<00:48,   19.63it/s]
  4%|4         |  : 44/999 [00:02<00:47,   19.97it/s]
  5%|4         |  : 45/999 [00:02<00:48,   19.52it/s]
  5%|4         |  : 46/999 [00:02<00:48,   19.80it/s]
  5%|4         |  : 48/999 [00:02<00:46,   20.27it/s]
  5%|5         |  : 51/999 [00:02<00:42,   22.24it/s]
  5%|5         |  : 54/999 [00:02<00:39,   24.19it/s]
  6%|5         |  : 57/999 [00:02<00:36,   26.13it/s]
  6%|5         |  : 58/999 [00:02<00:36,   26.11it/s]
  6%|5         |  : 59/999 [00:02<00:35,   26.22it/s]
  6%|6         |  : 61/999 [00:02<00:35,   26.31it/s]
  6%|6         |  : 62/999 [00:02<00:35,   26.29it/s]
  6%|6         |  : 63/999 [00:02<00:35,   26.39it/s]
  6%|6         |  : 64/999 [00:02<00:36,   25.44it/s]
  7%|6         |  : 65/999 [00:03<00:38,   24.55it/s]
  7%|6         |  : 66/999 [00:03<00:37,   24.71it/s]
  7%|6         |  : 69/999 [00:03<00:34,   26.72it/s]
  7%|7         |  : 70/999 [00:03<00:34,   26.69it/s]
  7%|7         |  : 71/999 [00:03<00:34,   26.78it/s]
  7%|7         |  : 72/999 [00:03<00:47,   19.48it/s]
  7%|7         |  : 73/999 [00:03<00:46,   19.73it/s]
  8%|7         |  : 75/999 [00:03<00:45,   20.14it/s]
  8%|7         |  : 76/999 [00:03<00:46,   19.81it/s]
  8%|7         |  : 77/999 [00:03<00:47,   19.43it/s]
  8%|7         |  : 78/999 [00:03<00:46,   19.63it/s]
  8%|7         |  : 79/999 [00:03<00:47,   19.32it/s]
  8%|8         |  : 80/999 [00:03<00:47,   19.51it/s]
  8%|8         |  : 81/999 [00:04<00:46,   19.77it/s]
  8%|8         |  : 82/999 [00:04<00:47,   19.37it/s]
  8%|8         |  : 83/999 [00:04<00:46,   19.57it/s]
  8%|8         |  : 84/999 [00:04<00:46,   19.76it/s]
  9%|8         |  : 85/999 [00:04<00:45,   20.03it/s]
  9%|8         |  : 86/999 [00:04<00:46,   19.67it/s]
  9%|8         |  : 87/999 [00:04<00:59,   15.32it/s]
  9%|8         |  : 88/999 [00:04<00:58,   15.64it/s]
  9%|9         |  : 90/999 [00:04<00:56,   16.20it/s]
  9%|9         |  : 93/999 [00:04<00:50,   17.85it/s]
  9%|9         |  : 94/999 [00:04<00:51,   17.60it/s]
 10%|9         |  : 95/999 [00:04<00:50,   17.85it/s]
 10%|9         |  : 98/999 [00:04<00:46,   19.54it/s]
 10%|9         |  : 99/999 [00:04<00:45,   19.72it/s]
 10%|#         |  : 100/999 [00:05<00:45,   19.97it/s]
 10%|#         |  : 101/999 [00:05<00:45,   19.53it/s]
 10%|#         |  : 102/999 [00:05<00:45,   19.72it/s]
 10%|#         |  : 103/999 [00:05<00:45,   19.90it/s]
 10%|#         |  : 104/999 [00:05<00:44,   20.16it/s]
 11%|#         |  : 107/999 [00:05<00:40,   22.03it/s]
 11%|#1        |  : 110/999 [00:05<00:37,   23.89it/s]
 11%|#1        |  : 113/999 [00:05<00:34,   25.74it/s]
 12%|#1        |  : 115/999 [00:05<00:34,   25.85it/s]
 12%|#1        |  : 117/999 [00:05<00:33,   26.69it/s]
 12%|#1        |  : 118/999 [00:05<00:32,   26.73it/s]
 12%|#2        |  : 121/999 [00:05<00:30,   28.59it/s]
 12%|#2        |  : 122/999 [00:05<00:30,   28.49it/s]
 12%|#2        |  : 123/999 [00:05<00:30,   28.52it/s]
 13%|#2        |  : 126/999 [00:05<00:38,   22.74it/s]
 13%|#2        |  : 128/999 [00:06<00:37,   22.99it/s]
 13%|#2        |  : 129/999 [00:06<00:37,   23.06it/s]
 13%|#3        |  : 130/999 [00:06<00:37,   23.22it/s]
 13%|#3        |  : 131/999 [00:06<00:37,   23.30it/s]
 13%|#3        |  : 132/999 [00:06<00:36,   23.46it/s]
 13%|#3        |  : 133/999 [00:06<00:36,   23.53it/s]
 13%|#3        |  : 134/999 [00:06<00:36,   23.70it/s]
 14%|#3        |  : 137/999 [00:06<00:33,   25.50it/s]
 14%|#3        |  : 138/999 [00:06<00:33,   25.51it/s]
 14%|#3        |  : 139/999 [00:06<00:33,   25.63it/s]
 14%|#4        |  : 142/999 [00:06<00:31,   27.49it/s]
 14%|#4        |  : 143/999 [00:06<00:32,   26.52it/s]
 14%|#4        |  : 144/999 [00:06<00:32,   26.55it/s]
 15%|#4        |  : 147/999 [00:06<00:29,   28.43it/s]
 15%|#4        |  : 148/999 [00:06<00:30,   27.49it/s]
 15%|#5        |  : 151/999 [00:06<00:29,   28.37it/s]
 15%|#5        |  : 152/999 [00:06<00:29,   28.28it/s]
 15%|#5        |  : 153/999 [00:06<00:29,   28.32it/s]
 16%|#5        |  : 156/999 [00:06<00:27,   30.19it/s]
 16%|#5        |  : 159/999 [00:06<00:26,   32.04it/s]
 16%|#6        |  : 161/999 [00:07<00:34,   24.38it/s]
 16%|#6        |  : 162/999 [00:07<00:35,   23.75it/s]
 16%|#6        |  : 163/999 [00:07<00:34,   23.90it/s]
 17%|#6        |  : 165/999 [00:07<00:34,   24.09it/s]
 17%|#6        |  : 166/999 [00:07<00:34,   24.14it/s]
 17%|#6        |  : 167/999 [00:07<00:34,   24.27it/s]
 17%|#6        |  : 168/999 [00:07<00:34,   24.32it/s]
 17%|#6        |  : 169/999 [00:07<00:33,   24.46it/s]
 17%|#7        |  : 170/999 [00:07<00:34,   23.76it/s]
 17%|#7        |  : 172/999 [00:07<00:34,   23.87it/s]
 17%|#7        |  : 173/999 [00:07<00:34,   24.02it/s]
 17%|#7        |  : 174/999 [00:07<00:34,   24.07it/s]
 18%|#7        |  : 175/999 [00:07<00:34,   24.21it/s]
 18%|#7        |  : 176/999 [00:07<00:33,   24.26it/s]
 18%|#7        |  : 177/999 [00:07<00:33,   24.41it/s]
 18%|#8        |  : 180/999 [00:07<00:31,   26.32it/s]
 18%|#8        |  : 181/999 [00:08<00:41,   19.69it/s]
 18%|#8        |  : 182/999 [00:08<00:41,   19.92it/s]
 18%|#8        |  : 184/999 [00:08<00:39,   20.78it/s]
 19%|#8        |  : 185/999 [00:08<00:38,   20.92it/s]
 19%|#8        |  : 186/999 [00:08<00:38,   21.06it/s]
 19%|#8        |  : 187/999 [00:08<00:38,   21.27it/s]
 19%|#8        |  : 189/999 [00:08<00:37,   21.61it/s]
 19%|#9        |  : 191/999 [00:08<00:35,   22.59it/s]
 19%|#9        |  : 194/999 [00:08<00:34,   23.63it/s]
 20%|#9        |  : 195/999 [00:08<00:33,   23.69it/s]
 20%|#9        |  : 196/999 [00:08<00:33,   23.85it/s]
 20%|#9        |  : 197/999 [00:08<00:34,   23.27it/s]
 20%|#9        |  : 198/999 [00:08<00:35,   22.64it/s]
 20%|#9        |  : 199/999 [00:08<00:35,   22.83it/s]
 20%|##        |  : 200/999 [00:09<00:34,   22.92it/s]
 20%|##        |  : 201/999 [00:09<00:34,   23.09it/s]
 20%|##        |  : 202/999 [00:09<00:35,   22.53it/s]
 20%|##        |  : 203/999 [00:09<00:46,   17.21it/s]
 20%|##        |  : 204/999 [00:09<00:45,   17.49it/s]
 21%|##        |  : 205/999 [00:09<00:44,   17.70it/s]
 21%|##        |  : 206/999 [00:09<00:44,   17.93it/s]
 21%|##        |  : 208/999 [00:09<00:41,   18.92it/s]
 21%|##1       |  : 210/999 [00:09<00:39,   19.84it/s]
 21%|##1       |  : 211/999 [00:09<00:39,   20.06it/s]
 21%|##1       |  : 213/999 [00:09<00:38,   20.39it/s]
 21%|##1       |  : 214/999 [00:09<00:39,   20.04it/s]
 22%|##1       |  : 215/999 [00:09<00:40,   19.56it/s]
 22%|##1       |  : 216/999 [00:10<00:39,   19.81it/s]
 22%|##1       |  : 217/999 [00:10<00:39,   19.91it/s]
 22%|##1       |  : 218/999 [00:10<00:38,   20.16it/s]
 22%|##2       |  : 221/999 [00:10<00:35,   22.01it/s]
 22%|##2       |  : 224/999 [00:10<00:32,   23.86it/s]
 23%|##2       |  : 226/999 [00:10<00:32,   24.08it/s]
 23%|##2       |  : 228/999 [00:10<00:30,   24.95it/s]
 23%|##2       |  : 229/999 [00:10<00:30,   25.05it/s]
 23%|##3       |  : 232/999 [00:10<00:28,   26.90it/s]
 23%|##3       |  : 233/999 [00:10<00:29,   25.98it/s]
 24%|##3       |  : 236/999 [00:10<00:36,   21.13it/s]
 24%|##3       |  : 238/999 [00:10<00:35,   21.44it/s]
 24%|##3       |  : 239/999 [00:10<00:35,   21.48it/s]
 24%|##4       |  : 240/999 [00:10<00:35,   21.67it/s]
 24%|##4       |  : 243/999 [00:11<00:33,   22.66it/s]
 24%|##4       |  : 244/999 [00:11<00:33,   22.21it/s]
 25%|##4       |  : 247/999 [00:11<00:32,   23.17it/s]
 25%|##4       |  : 249/999 [00:11<00:31,   24.01it/s]
 25%|##5       |  : 250/999 [00:11<00:32,   23.40it/s]
 25%|##5       |  : 251/999 [00:11<00:31,   23.55it/s]
 25%|##5       |  : 254/999 [00:11<00:29,   25.19it/s]
 26%|##5       |  : 255/999 [00:11<00:29,   25.20it/s]
 26%|##5       |  : 256/999 [00:11<00:29,   25.32it/s]
 26%|##5       |  : 258/999 [00:11<00:29,   25.45it/s]
 26%|##5       |  : 259/999 [00:11<00:29,   25.45it/s]
 26%|##6       |  : 260/999 [00:11<00:28,   25.57it/s]
 26%|##6       |  : 262/999 [00:11<00:28,   25.50it/s]
 26%|##6       |  : 263/999 [00:12<00:36,   20.07it/s]
 27%|##6       |  : 265/999 [00:12<00:36,   20.28it/s]
 27%|##6       |  : 266/999 [00:12<00:35,   20.42it/s]
 27%|##6       |  : 267/999 [00:12<00:35,   20.56it/s]
 27%|##6       |  : 268/999 [00:12<00:35,   20.76it/s]
 27%|##7       |  : 270/999 [00:12<00:34,   21.11it/s]
 27%|##7       |  : 273/999 [00:12<00:31,   22.72it/s]
 27%|##7       |  : 274/999 [00:12<00:32,   22.23it/s]
 28%|##7       |  : 276/999 [00:12<00:32,   22.49it/s]
 28%|##7       |  : 277/999 [00:12<00:32,   21.97it/s]
 28%|##7       |  : 278/999 [00:12<00:32,   22.16it/s]
 28%|##8       |  : 281/999 [00:12<00:30,   23.82it/s]
 28%|##8       |  : 282/999 [00:12<00:30,   23.87it/s]
 28%|##8       |  : 283/999 [00:12<00:29,   24.02it/s]
 28%|##8       |  : 284/999 [00:12<00:29,   24.07it/s]
 29%|##8       |  : 285/999 [00:12<00:29,   24.22it/s]
 29%|##8       |  : 287/999 [00:12<00:29,   24.32it/s]
 29%|##8       |  : 289/999 [00:13<00:36,   19.50it/s]
 29%|##9       |  : 290/999 [00:13<00:36,   19.18it/s]
 29%|##9       |  : 291/999 [00:13<00:36,   19.41it/s]
 29%|##9       |  : 292/999 [00:13<00:36,   19.57it/s]
 29%|##9       |  : 293/999 [00:13<00:35,   19.80it/s]
 30%|##9       |  : 295/999 [00:13<00:34,   20.19it/s]
 30%|##9       |  : 298/999 [00:13<00:32,   21.82it/s]
 30%|###       |  : 300/999 [00:13<00:31,   22.11it/s]
 30%|###       |  : 301/999 [00:13<00:31,   22.21it/s]
 30%|###       |  : 302/999 [00:13<00:31,   22.40it/s]
 30%|###       |  : 303/999 [00:13<00:31,   21.86it/s]
 30%|###       |  : 304/999 [00:13<00:31,   21.99it/s]
 31%|###       |  : 305/999 [00:13<00:31,   22.10it/s]
 31%|###       |  : 306/999 [00:13<00:31,   22.29it/s]
 31%|###       |  : 307/999 [00:13<00:31,   21.81it/s]
 31%|###       |  : 308/999 [00:14<00:40,   17.02it/s]
 31%|###       |  : 309/999 [00:14<00:39,   17.29it/s]
 31%|###1      |  : 311/999 [00:14<00:38,   17.76it/s]
 31%|###1      |  : 312/999 [00:14<00:38,   17.96it/s]
 31%|###1      |  : 313/999 [00:14<00:37,   18.23it/s]
 31%|###1      |  : 314/999 [00:14<00:37,   18.43it/s]
 32%|###1      |  : 315/999 [00:14<00:36,   18.70it/s]
 32%|###1      |  : 318/999 [00:14<00:33,   20.42it/s]
 32%|###2      |  : 320/999 [00:14<00:32,   20.79it/s]
 32%|###2      |  : 322/999 [00:14<00:32,   21.15it/s]
 32%|###2      |  : 323/999 [00:14<00:31,   21.28it/s]
 32%|###2      |  : 324/999 [00:14<00:31,   21.49it/s]
 33%|###2      |  : 326/999 [00:14<00:30,   21.83it/s]
 33%|###2      |  : 329/999 [00:14<00:29,   22.89it/s]
 33%|###3      |  : 330/999 [00:15<00:29,   22.40it/s]
 33%|###3      |  : 331/999 [00:15<00:37,   17.77it/s]
 33%|###3      |  : 332/999 [00:15<00:38,   17.54it/s]
 33%|###3      |  : 333/999 [00:15<00:37,   17.80it/s]
 33%|###3      |  : 334/999 [00:15<00:36,   17.99it/s]
 34%|###3      |  : 335/999 [00:15<00:36,   18.25it/s]
 34%|###3      |  : 336/999 [00:15<00:35,   18.45it/s]
 34%|###3      |  : 337/999 [00:15<00:35,   18.71it/s]
 34%|###3      |  : 339/999 [00:15<00:34,   19.16it/s]
 34%|###4      |  : 342/999 [00:15<00:31,   20.83it/s]
 34%|###4      |  : 343/999 [00:15<00:32,   20.47it/s]
 34%|###4      |  : 344/999 [00:15<00:32,   20.05it/s]
 35%|###4      |  : 345/999 [00:15<00:32,   20.28it/s]
 35%|###4      |  : 347/999 [00:16<00:30,   21.26it/s]
 35%|###4      |  : 349/999 [00:16<00:30,   21.61it/s]
 35%|###5      |  : 350/999 [00:16<00:29,   21.64it/s]
 35%|###5      |  : 351/999 [00:16<00:29,   21.85it/s]
 35%|###5      |  : 352/999 [00:16<00:30,   21.40it/s]
 35%|###5      |  : 353/999 [00:16<00:29,   21.54it/s]
 35%|###5      |  : 354/999 [00:16<00:29,   21.75it/s]
 36%|###5      |  : 356/999 [00:16<00:35,   17.99it/s]
 36%|###5      |  : 357/999 [00:16<00:36,   17.67it/s]
 36%|###5      |  : 358/999 [00:16<00:35,   17.94it/s]
 36%|###6      |  : 360/999 [00:16<00:33,   18.83it/s]
 36%|###6      |  : 361/999 [00:16<00:34,   18.51it/s]
 36%|###6      |  : 362/999 [00:16<00:33,   18.77it/s]
 36%|###6      |  : 363/999 [00:17<00:34,   18.52it/s]
 36%|###6      |  : 364/999 [00:17<00:33,   18.72it/s]
 37%|###6      |  : 365/999 [00:17<00:33,   18.99it/s]
 37%|###6      |  : 366/999 [00:17<00:32,   19.18it/s]
 37%|###6      |  : 367/999 [00:17<00:32,   19.45it/s]
 37%|###6      |  : 368/999 [00:17<00:32,   19.64it/s]
 37%|###6      |  : 369/999 [00:17<00:31,   19.91it/s]
 37%|###7      |  : 372/999 [00:17<00:28,   21.82it/s]
 37%|###7      |  : 373/999 [00:17<00:29,   21.26it/s]
 38%|###7      |  : 377/999 [00:17<00:26,   23.24it/s]
 38%|###7      |  : 379/999 [00:17<00:25,   24.24it/s]
 38%|###8      |  : 381/999 [00:17<00:25,   24.43it/s]
 38%|###8      |  : 383/999 [00:17<00:25,   24.62it/s]
 39%|###8      |  : 385/999 [00:17<00:24,   24.79it/s]
 39%|###8      |  : 386/999 [00:18<00:30,   19.96it/s]
 39%|###8      |  : 387/999 [00:18<00:31,   19.60it/s]
 39%|###8      |  : 388/999 [00:18<00:30,   19.83it/s]
 39%|###8      |  : 389/999 [00:18<00:30,   19.98it/s]
 39%|###9      |  : 390/999 [00:18<00:30,   20.21it/s]
 39%|###9      |  : 391/999 [00:18<00:29,   20.37it/s]
 39%|###9      |  : 392/999 [00:18<00:30,   19.94it/s]
 39%|###9      |  : 394/999 [00:18<00:28,   20.92it/s]
 40%|###9      |  : 395/999 [00:18<00:29,   20.48it/s]
 40%|###9      |  : 397/999 [00:18<00:28,   20.83it/s]
 40%|###9      |  : 398/999 [00:18<00:29,   20.38it/s]
 40%|###9      |  : 399/999 [00:18<00:29,   20.61it/s]
 40%|####      |  : 400/999 [00:18<00:28,   20.76it/s]
 40%|####      |  : 401/999 [00:18<00:28,   21.00it/s]
 40%|####      |  : 402/999 [00:18<00:28,   21.14it/s]
 40%|####      |  : 403/999 [00:18<00:27,   21.37it/s]
 41%|####      |  : 406/999 [00:18<00:25,   23.27it/s]
 41%|####      |  : 407/999 [00:19<00:33,   17.87it/s]
 41%|####      |  : 408/999 [00:19<00:32,   18.13it/s]
 41%|####      |  : 409/999 [00:19<00:32,   18.33it/s]
 41%|####1     |  : 410/999 [00:19<00:31,   18.60it/s]
 41%|####1     |  : 412/999 [00:19<00:30,   19.06it/s]
 42%|####1     |  : 415/999 [00:19<00:28,   20.76it/s]
 42%|####1     |  : 417/999 [00:19<00:27,   21.12it/s]
 42%|####1     |  : 418/999 [00:19<00:28,   20.66it/s]
 42%|####1     |  : 419/999 [00:19<00:27,   20.82it/s]
 42%|####2     |  : 420/999 [00:19<00:28,   20.35it/s]
 42%|####2     |  : 422/999 [00:19<00:27,   20.65it/s]
 42%|####2     |  : 423/999 [00:19<00:27,   20.80it/s]
 43%|####2     |  : 425/999 [00:19<00:27,   21.17it/s]
 43%|####2     |  : 426/999 [00:20<00:33,   17.29it/s]
 43%|####2     |  : 429/999 [00:20<00:31,   18.37it/s]
 43%|####3     |  : 431/999 [00:20<00:30,   18.78it/s]
 43%|####3     |  : 432/999 [00:20<00:30,   18.55it/s]
 44%|####3     |  : 435/999 [00:20<00:28,   19.59it/s]
 44%|####3     |  : 437/999 [00:20<00:28,   19.95it/s]
 44%|####3     |  : 438/999 [00:20<00:28,   19.67it/s]
 44%|####3     |  : 439/999 [00:20<00:28,   19.34it/s]
 44%|####4     |  : 440/999 [00:20<00:28,   19.56it/s]
 44%|####4     |  : 442/999 [00:20<00:27,   20.45it/s]
 44%|####4     |  : 443/999 [00:20<00:27,   20.00it/s]
 44%|####4     |  : 444/999 [00:20<00:27,   20.22it/s]
 45%|####4     |  : 446/999 [00:20<00:26,   20.58it/s]
 45%|####4     |  : 447/999 [00:21<00:26,   20.65it/s]
 45%|####4     |  : 448/999 [00:21<00:26,   20.86it/s]
 45%|####5     |  : 450/999 [00:21<00:32,   17.07it/s]
 45%|####5     |  : 451/999 [00:21<00:32,   16.88it/s]
 45%|####5     |  : 452/999 [00:21<00:31,   17.14it/s]
 45%|####5     |  : 454/999 [00:21<00:30,   17.99it/s]
 46%|####5     |  : 456/999 [00:21<00:29,   18.40it/s]
 46%|####5     |  : 457/999 [00:21<00:29,   18.14it/s]
 46%|####5     |  : 458/999 [00:21<00:29,   18.39it/s]
 46%|####5     |  : 459/999 [00:21<00:29,   18.57it/s]
 46%|####6     |  : 460/999 [00:21<00:28,   18.82it/s]
 46%|####6     |  : 462/999 [00:21<00:27,   19.25it/s]
 46%|####6     |  : 463/999 [00:21<00:27,   19.42it/s]
 46%|####6     |  : 464/999 [00:22<00:27,   19.67it/s]
 47%|####6     |  : 465/999 [00:22<00:26,   19.84it/s]
 47%|####6     |  : 466/999 [00:22<00:26,   20.08it/s]
 47%|####6     |  : 467/999 [00:22<00:26,   20.25it/s]
 47%|####6     |  : 468/999 [00:22<00:25,   20.49it/s]
 47%|####6     |  : 469/999 [00:22<00:26,   20.11it/s]
 47%|####7     |  : 470/999 [00:22<00:32,   16.35it/s]
 47%|####7     |  : 471/999 [00:22<00:32,   16.18it/s]
 47%|####7     |  : 472/999 [00:22<00:31,   16.48it/s]
 47%|####7     |  : 474/999 [00:22<00:30,   17.37it/s]
 48%|####7     |  : 477/999 [00:22<00:28,   18.53it/s]
 48%|####7     |  : 478/999 [00:22<00:28,   18.24it/s]
 48%|####7     |  : 479/999 [00:22<00:28,   18.49it/s]
 48%|####8     |  : 480/999 [00:22<00:28,   18.25it/s]
 48%|####8     |  : 483/999 [00:23<00:25,   19.94it/s]
 49%|####8     |  : 487/999 [00:23<00:22,   22.35it/s]
 49%|####8     |  : 488/999 [00:23<00:22,   22.45it/s]
 49%|####8     |  : 489/999 [00:23<00:22,   22.63it/s]
 49%|####9     |  : 491/999 [00:23<00:22,   22.91it/s]
 49%|####9     |  : 492/999 [00:23<00:22,   22.41it/s]
 49%|####9     |  : 494/999 [00:23<00:22,   22.69it/s]
 50%|####9     |  : 497/999 [00:23<00:20,   24.41it/s]
 50%|####9     |  : 498/999 [00:23<00:20,   24.45it/s]
 50%|####9     |  : 499/999 [00:23<00:20,   24.59it/s]
 50%|#####     |  : 500/999 [00:23<00:20,   24.62it/s]
 50%|#####     |  : 501/999 [00:23<00:20,   24.76it/s]
 50%|#####     |  : 502/999 [00:23<00:26,   19.00it/s]
 50%|#####     |  : 503/999 [00:24<00:26,   18.69it/s]
 50%|#####     |  : 504/999 [00:24<00:26,   18.94it/s]
 51%|#####     |  : 505/999 [00:24<00:25,   19.12it/s]
 51%|#####     |  : 506/999 [00:24<00:25,   19.37it/s]
 51%|#####     |  : 508/999 [00:24<00:24,   19.79it/s]
 51%|#####     |  : 509/999 [00:24<00:24,   19.96it/s]
 51%|#####1    |  : 510/999 [00:24<00:24,   20.20it/s]
 51%|#####1    |  : 511/999 [00:24<00:23,   20.36it/s]
 51%|#####1    |  : 512/999 [00:24<00:23,   20.60it/s]
 51%|#####1    |  : 513/999 [00:24<00:24,   20.22it/s]
 51%|#####1    |  : 514/999 [00:24<00:24,   19.87it/s]
 52%|#####1    |  : 515/999 [00:24<00:24,   19.46it/s]
 52%|#####1    |  : 516/999 [00:24<00:24,   19.67it/s]
 52%|#####1    |  : 517/999 [00:24<00:24,   19.34it/s]
 52%|#####1    |  : 518/999 [00:25<00:30,   15.75it/s]
 52%|#####1    |  : 519/999 [00:25<00:30,   15.66it/s]
 52%|#####2    |  : 522/999 [00:25<00:27,   17.28it/s]
 52%|#####2    |  : 524/999 [00:25<00:26,   18.23it/s]
 53%|#####2    |  : 526/999 [00:25<00:25,   18.63it/s]
 53%|#####2    |  : 528/999 [00:25<00:24,   19.06it/s]
 53%|#####3    |  : 530/999 [00:25<00:24,   19.41it/s]
 53%|#####3    |  : 531/999 [00:25<00:23,   19.58it/s]
 53%|#####3    |  : 532/999 [00:25<00:23,   19.82it/s]
 53%|#####3    |  : 534/999 [00:25<00:22,   20.71it/s]
 54%|#####3    |  : 535/999 [00:25<00:22,   20.85it/s]
 54%|#####3    |  : 536/999 [00:25<00:22,   21.00it/s]
 54%|#####3    |  : 537/999 [00:25<00:22,   20.59it/s]
 54%|#####3    |  : 538/999 [00:25<00:22,   20.83it/s]
 54%|#####4    |  : 540/999 [00:25<00:21,   21.76it/s]
 54%|#####4    |  : 541/999 [00:25<00:20,   21.94it/s]
 54%|#####4    |  : 544/999 [00:25<00:19,   23.80it/s]
 55%|#####4    |  : 545/999 [00:25<00:19,   23.86it/s]
 55%|#####4    |  : 546/999 [00:25<00:18,   24.03it/s]
 55%|#####4    |  : 548/999 [00:25<00:17,   25.07it/s]
 55%|#####5    |  : 551/999 [00:25<00:17,   26.09it/s]
 55%|#####5    |  : 553/999 [00:26<00:22,   20.06it/s]
 55%|#####5    |  : 554/999 [00:26<00:21,   20.25it/s]
 56%|#####5    |  : 555/999 [00:26<00:22,   19.94it/s]
 56%|#####5    |  : 556/999 [00:26<00:22,   19.55it/s]
 56%|#####5    |  : 557/999 [00:26<00:23,   19.21it/s]
 56%|#####5    |  : 558/999 [00:26<00:22,   19.41it/s]
 56%|#####6    |  : 560/999 [00:26<00:22,   19.75it/s]
 56%|#####6    |  : 561/999 [00:26<00:22,   19.46it/s]
 56%|#####6    |  : 563/999 [00:26<00:21,   19.86it/s]
 57%|#####6    |  : 565/999 [00:26<00:20,   20.72it/s]
 57%|#####6    |  : 566/999 [00:26<00:20,   20.88it/s]
 57%|#####6    |  : 568/999 [00:27<00:19,   21.83it/s]
 57%|#####7    |  : 570/999 [00:27<00:19,   22.14it/s]
 57%|#####7    |  : 571/999 [00:27<00:24,   17.49it/s]
 57%|#####7    |  : 572/999 [00:27<00:24,   17.28it/s]
 57%|#####7    |  : 573/999 [00:27<00:24,   17.50it/s]
 57%|#####7    |  : 574/999 [00:27<00:24,   17.70it/s]
 58%|#####7    |  : 575/999 [00:27<00:23,   17.94it/s]
 58%|#####7    |  : 576/999 [00:27<00:23,   18.14it/s]
 58%|#####7    |  : 577/999 [00:27<00:22,   18.40it/s]
 58%|#####8    |  : 580/999 [00:27<00:20,   20.06it/s]
 58%|#####8    |  : 583/999 [00:27<00:19,   21.73it/s]
 58%|#####8    |  : 584/999 [00:27<00:19,   21.27it/s]
 59%|#####8    |  : 585/999 [00:27<00:19,   20.81it/s]
 59%|#####8    |  : 586/999 [00:28<00:19,   21.02it/s]
 59%|#####8    |  : 587/999 [00:28<00:19,   20.64it/s]
 59%|#####8    |  : 589/999 [00:28<00:19,   21.01it/s]
 59%|#####9    |  : 590/999 [00:28<00:19,   20.55it/s]
 59%|#####9    |  : 591/999 [00:28<00:19,   20.74it/s]
 59%|#####9    |  : 592/999 [00:28<00:19,   20.37it/s]
 59%|#####9    |  : 594/999 [00:28<00:23,   17.17it/s]
 60%|#####9    |  : 596/999 [00:28<00:22,   17.63it/s]
 60%|#####9    |  : 599/999 [00:28<00:21,   18.69it/s]
 60%|######    |  : 601/999 [00:28<00:20,   19.49it/s]
 60%|######    |  : 602/999 [00:28<00:20,   19.68it/s]
 60%|######    |  : 603/999 [00:28<00:20,   19.77it/s]
 60%|######    |  : 604/999 [00:28<00:19,   20.00it/s]
 61%|######    |  : 605/999 [00:29<00:19,   20.15it/s]
 61%|######    |  : 606/999 [00:29<00:19,   20.38it/s]
 61%|######    |  : 607/999 [00:29<00:19,   19.96it/s]
 61%|######    |  : 608/999 [00:29<00:19,   20.13it/s]
 61%|######1   |  : 611/999 [00:29<00:17,   21.87it/s]
 61%|######1   |  : 612/999 [00:29<00:17,   21.98it/s]
 61%|######1   |  : 613/999 [00:29<00:17,   22.18it/s]
 62%|######1   |  : 615/999 [00:29<00:17,   22.49it/s]
 62%|######1   |  : 617/999 [00:29<00:16,   23.45it/s]
 62%|######2   |  : 620/999 [00:29<00:15,   24.48it/s]
 62%|######2   |  : 621/999 [00:29<00:15,   24.52it/s]
 62%|######2   |  : 622/999 [00:29<00:15,   24.66it/s]
 62%|######2   |  : 623/999 [00:29<00:15,   23.92it/s]
 62%|######2   |  : 624/999 [00:29<00:15,   23.98it/s]
 63%|######2   |  : 625/999 [00:30<00:19,   19.15it/s]
 63%|######2   |  : 626/999 [00:30<00:19,   18.82it/s]
 63%|######2   |  : 627/999 [00:30<00:19,   19.07it/s]
 63%|######2   |  : 629/999 [00:30<00:18,   19.50it/s]
 63%|######3   |  : 631/999 [00:30<00:18,   19.90it/s]
 63%|######3   |  : 633/999 [00:30<00:18,   20.29it/s]
 63%|######3   |  : 634/999 [00:30<00:17,   20.44it/s]
 64%|######3   |  : 635/999 [00:30<00:17,   20.66it/s]
 64%|######3   |  : 636/999 [00:30<00:17,   20.80it/s]
 64%|######3   |  : 637/999 [00:30<00:17,   21.03it/s]
 64%|######3   |  : 639/999 [00:30<00:16,   21.39it/s]
 64%|######4   |  : 640/999 [00:30<00:16,   21.52it/s]
 64%|######4   |  : 641/999 [00:30<00:16,   21.73it/s]
 64%|######4   |  : 644/999 [00:30<00:15,   23.57it/s]
 65%|######4   |  : 646/999 [00:30<00:14,   23.80it/s]
 65%|######4   |  : 647/999 [00:30<00:14,   23.86it/s]
 65%|######4   |  : 648/999 [00:30<00:14,   24.02it/s]
 65%|######5   |  : 650/999 [00:31<00:17,   19.88it/s]
 65%|######5   |  : 651/999 [00:31<00:17,   19.52it/s]
 65%|######5   |  : 652/999 [00:31<00:17,   19.75it/s]
 65%|######5   |  : 653/999 [00:31<00:17,   19.34it/s]
 65%|######5   |  : 654/999 [00:31<00:17,   19.51it/s]
 66%|######5   |  : 656/999 [00:31<00:17,   19.93it/s]
 66%|######5   |  : 657/999 [00:31<00:17,   20.09it/s]
 66%|######5   |  : 658/999 [00:31<00:16,   20.33it/s]
 66%|######6   |  : 660/999 [00:31<00:16,   20.72it/s]
 66%|######6   |  : 661/999 [00:31<00:16,   20.86it/s]
 66%|######6   |  : 662/999 [00:31<00:15,   21.09it/s]
 66%|######6   |  : 663/999 [00:31<00:15,   21.23it/s]
 66%|######6   |  : 664/999 [00:31<00:15,   21.46it/s]
 67%|######6   |  : 666/999 [00:31<00:14,   22.39it/s]
 67%|######6   |  : 667/999 [00:31<00:14,   22.50it/s]
 67%|######6   |  : 669/999 [00:31<00:14,   22.81it/s]
 67%|######7   |  : 670/999 [00:32<00:18,   18.25it/s]
 67%|######7   |  : 672/999 [00:32<00:17,   18.64it/s]
 67%|######7   |  : 673/999 [00:32<00:17,   18.84it/s]
 67%|######7   |  : 674/999 [00:32<00:17,   19.03it/s]
 68%|######7   |  : 675/999 [00:32<00:16,   19.29it/s]
 68%|######7   |  : 676/999 [00:32<00:16,   19.48it/s]
 68%|######7   |  : 677/999 [00:32<00:16,   19.73it/s]
 68%|######7   |  : 679/999 [00:32<00:15,   20.64it/s]
 68%|######8   |  : 680/999 [00:32<00:15,   20.80it/s]
 68%|######8   |  : 683/999 [00:32<00:13,   22.65it/s]
 68%|######8   |  : 684/999 [00:32<00:13,   22.75it/s]
 69%|######8   |  : 685/999 [00:32<00:13,   22.94it/s]
 69%|######8   |  : 686/999 [00:32<00:13,   23.03it/s]
 69%|######8   |  : 687/999 [00:32<00:13,   23.23it/s]
 69%|######8   |  : 688/999 [00:32<00:13,   22.54it/s]
 69%|######8   |  : 689/999 [00:32<00:13,   22.67it/s]
 69%|######9   |  : 690/999 [00:32<00:13,   22.11it/s]
 69%|######9   |  : 692/999 [00:33<00:13,   22.45it/s]
 69%|######9   |  : 693/999 [00:33<00:17,   17.51it/s]
 69%|######9   |  : 694/999 [00:33<00:17,   17.27it/s]
 70%|######9   |  : 695/999 [00:33<00:17,   17.55it/s]
 70%|######9   |  : 697/999 [00:33<00:16,   18.06it/s]
 70%|######9   |  : 699/999 [00:33<00:16,   18.53it/s]
 70%|#######   |  : 701/999 [00:33<00:15,   19.44it/s]
 70%|#######   |  : 702/999 [00:33<00:15,   19.66it/s]
 70%|#######   |  : 703/999 [00:33<00:15,   19.35it/s]
 71%|#######   |  : 705/999 [00:33<00:14,   19.66it/s]
 71%|#######   |  : 706/999 [00:33<00:14,   19.83it/s]
 71%|#######   |  : 709/999 [00:33<00:13,   21.58it/s]
 71%|#######1  |  : 711/999 [00:33<00:12,   22.54it/s]
 71%|#######1  |  : 714/999 [00:34<00:12,   23.59it/s]
 72%|#######1  |  : 715/999 [00:34<00:12,   23.65it/s]
 72%|#######1  |  : 716/999 [00:34<00:11,   23.81it/s]
 72%|#######1  |  : 718/999 [00:34<00:11,   24.03it/s]
 72%|#######2  |  : 721/999 [00:34<00:11,   25.02it/s]
 72%|#######2  |  : 723/999 [00:34<00:13,   19.93it/s]
 72%|#######2  |  : 724/999 [00:34<00:13,   20.10it/s]
 73%|#######2  |  : 727/999 [00:34<00:12,   21.63it/s]
 73%|#######2  |  : 728/999 [00:34<00:12,   21.23it/s]
 73%|#######3  |  : 731/999 [00:34<00:12,   22.19it/s]
 73%|#######3  |  : 733/999 [00:34<00:11,   22.45it/s]
 73%|#######3  |  : 734/999 [00:34<00:11,   22.54it/s]
 74%|#######3  |  : 735/999 [00:35<00:11,   22.70it/s]
 74%|#######3  |  : 736/999 [00:35<00:11,   22.78it/s]
 74%|#######3  |  : 737/999 [00:35<00:11,   22.95it/s]
 74%|#######3  |  : 738/999 [00:35<00:11,   22.38it/s]
 74%|#######3  |  : 739/999 [00:35<00:11,   22.51it/s]
 74%|#######4  |  : 741/999 [00:35<00:11,   23.45it/s]
 74%|#######4  |  : 743/999 [00:35<00:10,   23.68it/s]
 75%|#######4  |  : 747/999 [00:35<00:09,   26.16it/s]
 75%|#######4  |  : 748/999 [00:35<00:09,   26.15it/s]
 75%|#######4  |  : 749/999 [00:35<00:09,   26.24it/s]
 75%|#######5  |  : 750/999 [00:35<00:09,   26.22it/s]
 75%|#######5  |  : 751/999 [00:35<00:09,   26.32it/s]
 75%|#######5  |  : 752/999 [00:35<00:09,   26.30it/s]
 75%|#######5  |  : 753/999 [00:35<00:11,   20.57it/s]
 75%|#######5  |  : 754/999 [00:35<00:12,   20.17it/s]
 76%|#######5  |  : 755/999 [00:36<00:11,   20.39it/s]
 76%|#######5  |  : 757/999 [00:36<00:11,   20.76it/s]
 76%|#######5  |  : 759/999 [00:36<00:11,   21.66it/s]
 76%|#######6  |  : 762/999 [00:36<00:10,   22.69it/s]
 77%|#######6  |  : 765/999 [00:36<00:09,   24.33it/s]
 77%|#######6  |  : 767/999 [00:36<00:09,   24.51it/s]
 77%|#######6  |  : 768/999 [00:36<00:09,   24.54it/s]
 77%|#######6  |  : 769/999 [00:36<00:09,   24.67it/s]
 77%|#######7  |  : 770/999 [00:36<00:09,   24.70it/s]
 77%|#######7  |  : 771/999 [00:36<00:09,   24.84it/s]
 77%|#######7  |  : 774/999 [00:36<00:08,   26.61it/s]
 78%|#######7  |  : 776/999 [00:36<00:08,   27.42it/s]
 78%|#######7  |  : 777/999 [00:36<00:08,   27.46it/s]
 78%|#######7  |  : 779/999 [00:36<00:08,   27.47it/s]
 78%|#######8  |  : 782/999 [00:36<00:07,   29.26it/s]
 78%|#######8  |  : 783/999 [00:36<00:07,   29.14it/s]
 78%|#######8  |  : 784/999 [00:36<00:07,   29.15it/s]
 79%|#######8  |  : 786/999 [00:36<00:07,   29.05it/s]
 79%|#######8  |  : 788/999 [00:37<00:09,   22.26it/s]
 79%|#######9  |  : 791/999 [00:37<00:09,   23.10it/s]
 79%|#######9  |  : 792/999 [00:37<00:08,   23.16it/s]
 79%|#######9  |  : 793/999 [00:37<00:08,   23.32it/s]
 79%|#######9  |  : 794/999 [00:37<00:08,   22.83it/s]
 80%|#######9  |  : 797/999 [00:37<00:08,   24.44it/s]
 80%|#######9  |  : 798/999 [00:37<00:08,   23.75it/s]
 80%|########  |  : 801/999 [00:37<00:08,   24.67it/s]
 80%|########  |  : 803/999 [00:37<00:07,   24.82it/s]
 80%|########  |  : 804/999 [00:37<00:08,   24.25it/s]
 81%|########  |  : 805/999 [00:37<00:08,   23.63it/s]
 81%|########  |  : 806/999 [00:37<00:08,   23.71it/s]
 81%|########  |  : 807/999 [00:37<00:08,   23.77it/s]
 81%|########1 |  : 810/999 [00:38<00:07,   24.72it/s]
 81%|########1 |  : 813/999 [00:38<00:07,   26.36it/s]
 81%|########1 |  : 814/999 [00:38<00:08,   21.08it/s]
 82%|########1 |  : 816/999 [00:38<00:08,   21.24it/s]
 82%|########1 |  : 817/999 [00:38<00:08,   21.35it/s]
 82%|########1 |  : 818/999 [00:38<00:08,   21.01it/s]
 82%|########2 |  : 821/999 [00:38<00:07,   22.51it/s]
 82%|########2 |  : 822/999 [00:38<00:07,   22.59it/s]
 82%|########2 |  : 823/999 [00:38<00:07,   22.75it/s]
 82%|########2 |  : 824/999 [00:38<00:07,   22.27it/s]
 83%|########2 |  : 827/999 [00:38<00:07,   23.23it/s]
 83%|########2 |  : 829/999 [00:38<00:07,   23.97it/s]
 83%|########3 |  : 832/999 [00:38<00:06,   24.86it/s]
 83%|########3 |  : 833/999 [00:38<00:06,   24.88it/s]
 83%|########3 |  : 834/999 [00:39<00:06,   25.00it/s]
 84%|########3 |  : 836/999 [00:39<00:06,   25.78it/s]
 84%|########3 |  : 837/999 [00:39<00:06,   24.99it/s]
 84%|########3 |  : 838/999 [00:39<00:06,   25.11it/s]
 84%|########4 |  : 840/999 [00:39<00:06,   25.25it/s]
 84%|########4 |  : 841/999 [00:39<00:06,   24.62it/s]
 84%|########4 |  : 843/999 [00:39<00:07,   19.83it/s]
 84%|########4 |  : 844/999 [00:39<00:07,   19.51it/s]
 85%|########4 |  : 845/999 [00:39<00:07,   19.72it/s]
 85%|########4 |  : 847/999 [00:39<00:07,   20.08it/s]
 85%|########4 |  : 848/999 [00:39<00:07,   20.22it/s]
 85%|########4 |  : 849/999 [00:39<00:07,   20.43it/s]
 85%|########5 |  : 850/999 [00:40<00:07,   20.11it/s]
 85%|########5 |  : 852/999 [00:40<00:07,   20.47it/s]
 85%|########5 |  : 854/999 [00:40<00:06,   21.36it/s]
 86%|########5 |  : 856/999 [00:40<00:06,   21.56it/s]
 86%|########5 |  : 857/999 [00:40<00:06,   21.10it/s]
 86%|########5 |  : 858/999 [00:40<00:06,   21.30it/s]
 86%|########6 |  : 861/999 [00:40<00:06,   22.93it/s]
 86%|########6 |  : 862/999 [00:40<00:05,   23.01it/s]
 86%|########6 |  : 863/999 [00:40<00:05,   23.17it/s]
 87%|########6 |  : 865/999 [00:40<00:05,   24.02it/s]
 87%|########6 |  : 866/999 [00:40<00:05,   24.15it/s]
 87%|########6 |  : 868/999 [00:40<00:06,   19.21it/s]
 87%|########7 |  : 870/999 [00:41<00:06,   19.59it/s]
 87%|########7 |  : 872/999 [00:41<00:06,   20.44it/s]
 87%|########7 |  : 874/999 [00:41<00:06,   20.71it/s]
 88%|########7 |  : 876/999 [00:41<00:05,   21.03it/s]
 88%|########7 |  : 879/999 [00:41<00:05,   22.54it/s]
 88%|########8 |  : 881/999 [00:41<00:05,   23.29it/s]
 88%|########8 |  : 882/999 [00:41<00:05,   22.75it/s]
 88%|########8 |  : 883/999 [00:41<00:05,   22.91it/s]
 89%|########8 |  : 885/999 [00:41<00:04,   23.15it/s]
 89%|########8 |  : 887/999 [00:41<00:04,   23.98it/s]
 89%|########8 |  : 889/999 [00:41<00:04,   24.17it/s]
 89%|########9 |  : 890/999 [00:41<00:04,   24.21it/s]
 89%|########9 |  : 891/999 [00:41<00:04,   24.35it/s]
 89%|########9 |  : 893/999 [00:41<00:04,   25.15it/s]
 90%|########9 |  : 895/999 [00:41<00:04,   25.28it/s]
 90%|########9 |  : 897/999 [00:41<00:04,   25.41it/s]
 90%|########9 |  : 898/999 [00:41<00:04,   24.78it/s]
 90%|########9 |  : 899/999 [00:41<00:04,   24.18it/s]
 90%|######### |  : 902/999 [00:42<00:04,   20.20it/s]
 90%|######### |  : 903/999 [00:42<00:04,   20.33it/s]
 90%|######### |  : 904/999 [00:42<00:04,   20.53it/s]
 91%|######### |  : 905/999 [00:42<00:04,   20.18it/s]
 91%|######### |  : 908/999 [00:42<00:04,   21.16it/s]
 91%|#########1|  : 911/999 [00:42<00:03,   22.66it/s]
 91%|#########1|  : 912/999 [00:42<00:03,   22.24it/s]
 92%|#########1|  : 915/999 [00:42<00:03,   23.76it/s]
 92%|#########1|  : 917/999 [00:42<00:03,   23.92it/s]
 92%|#########1|  : 918/999 [00:42<00:03,   23.42it/s]
 92%|#########1|  : 919/999 [00:42<00:03,   22.95it/s]
 92%|#########2|  : 921/999 [00:42<00:03,   23.72it/s]
 92%|#########2|  : 922/999 [00:43<00:03,   23.79it/s]
 92%|#########2|  : 924/999 [00:43<00:03,   24.67it/s]
 93%|#########2|  : 925/999 [00:43<00:03,   24.09it/s]
 93%|#########2|  : 926/999 [00:43<00:03,   19.15it/s]
 93%|#########2|  : 927/999 [00:43<00:03,   18.92it/s]
 93%|#########2|  : 928/999 [00:43<00:03,   18.64it/s]
 93%|#########2|  : 929/999 [00:43<00:03,   18.85it/s]
 93%|#########3|  : 930/999 [00:43<00:03,   19.02it/s]
 93%|#########3|  : 931/999 [00:43<00:03,   19.23it/s]
 93%|#########3|  : 932/999 [00:43<00:03,   19.40it/s]
 93%|#########3|  : 934/999 [00:43<00:03,   19.77it/s]
 94%|#########3|  : 935/999 [00:43<00:03,   19.99it/s]
 94%|#########3|  : 936/999 [00:44<00:03,   19.68it/s]
 94%|#########3|  : 939/999 [00:44<00:02,   21.33it/s]
 94%|#########4|  : 941/999 [00:44<00:02,   21.65it/s]
 94%|#########4|  : 943/999 [00:44<00:02,   21.95it/s]
 95%|#########4|  : 945/999 [00:44<00:02,   22.24it/s]
 95%|#########4|  : 947/999 [00:44<00:02,   22.52it/s]
 95%|#########4|  : 948/999 [00:44<00:02,   17.95it/s]
 95%|#########4|  : 949/999 [00:44<00:02,   17.78it/s]
 95%|#########5|  : 950/999 [00:44<00:02,   17.96it/s]
 95%|#########5|  : 951/999 [00:44<00:02,   18.20it/s]
 95%|#########5|  : 952/999 [00:44<00:02,   18.38it/s]
 95%|#########5|  : 953/999 [00:44<00:02,   18.63it/s]
 96%|#########5|  : 956/999 [00:44<00:02,   20.20it/s]
 96%|#########5|  : 958/999 [00:45<00:01,   21.10it/s]
 96%|#########6|  : 960/999 [00:45<00:01,   21.42it/s]
 96%|#########6|  : 962/999 [00:45<00:01,   21.73it/s]
 97%|#########6|  : 965/999 [00:45<00:01,   22.70it/s]
 97%|#########6|  : 968/999 [00:45<00:01,   24.27it/s]
 97%|#########6|  : 969/999 [00:45<00:01,   23.60it/s]
 97%|#########7|  : 971/999 [00:45<00:01,   23.72it/s]
 98%|#########7|  : 975/999 [00:45<00:00,   25.38it/s]
 98%|#########7|  : 976/999 [00:45<00:00,   24.80it/s]
 98%|#########7|  : 979/999 [00:45<00:00,   26.34it/s]
 98%|#########8|  : 981/999 [00:45<00:00,   26.41it/s]
 98%|#########8|  : 982/999 [00:46<00:00,   21.54it/s]
 99%|#########8|  : 985/999 [00:46<00:00,   22.41it/s]
 99%|#########8|  : 987/999 [00:46<00:00,   22.63it/s]
 99%|#########8|  : 988/999 [00:46<00:00,   22.71it/s]
 99%|#########8|  : 989/999 [00:46<00:00,   22.86it/s]
 99%|#########9|  : 992/999 [00:46<00:00,   24.32it/s]
 99%|#########9|  : 994/999 [00:46<00:00,   24.48it/s]
100%|#########9|  : 995/999 [00:46<00:00,   24.51it/s]
100%|#########9|  : 996/999 [00:46<00:00,   24.63it/s]
100%|##########|  : 999/999 [00:46<00:00,   26.35it/s]
100%|##########|  : 999/999 [00:46<00:00,   21.51it/s]
Computing cluster p-values
Done.

Finally, we can plot our results. It is difficult to visualize clusters in time-frequency-sensor space; plotting time-frequency spectrograms and plotting topomaps display time-frequency and sensor space respectively but they are difficult to combine. We will plot topomaps with the clustered sensors colored in white adjacent to spectrograms in order to provide a visualization of the results. This is a dimensionally limited view, however. Each sensor has its own significant time-frequencies, but, in order to display a single spectrogram, all the time-frequencies that are significant for any sensor in the cluster are plotted as significant. This is a difficulty inherent to visualizing high-dimensional data and should be taken into consideration when interpreting results.

F_obs, clusters, p_values, _ = cluster_stats
good_cluster_inds = np.where(p_values < p_accept)[0]

for i_clu, clu_idx in enumerate(good_cluster_inds):
    # unpack cluster information, get unique indices
    freq_inds, time_inds, space_inds = clusters[clu_idx]
    ch_inds = np.unique(space_inds)
    time_inds = np.unique(time_inds)
    freq_inds = np.unique(freq_inds)

    # get topography for F stat
    f_map = F_obs[freq_inds].mean(axis=0)
    f_map = f_map[time_inds].mean(axis=0)

    # get signals at the sensors contributing to the cluster
    sig_times = epochs.times[time_inds]

    # initialize figure
    fig, ax_topo = plt.subplots(1, 1, figsize=(10, 3))

    # create spatial mask
    mask = np.zeros((f_map.shape[0], 1), dtype=bool)
    mask[ch_inds, :] = True

    # plot average test statistic and mark significant sensors
    f_evoked = mne.EvokedArray(f_map[:, np.newaxis], epochs.info, tmin=0)
    f_evoked.plot_topomap(times=0, mask=mask, axes=ax_topo, cmap='Reds',
                          vmin=np.min, vmax=np.max, show=False,
                          colorbar=False, mask_params=dict(markersize=10))
    image = ax_topo.images[0]

    # create additional axes (for ERF and colorbar)
    divider = make_axes_locatable(ax_topo)

    # add axes for colorbar
    ax_colorbar = divider.append_axes('right', size='5%', pad=0.05)
    plt.colorbar(image, cax=ax_colorbar)
    ax_topo.set_xlabel(
        'Averaged F-map ({:0.3f} - {:0.3f} s)'.format(*sig_times[[0, -1]]))

    # remove the title that would otherwise say "0.000 s"
    ax_topo.set_title("")

    # add new axis for spectrogram
    ax_spec = divider.append_axes('right', size='300%', pad=1.2)
    title = 'Cluster #{0}, {1} spectrogram'.format(i_clu + 1, len(ch_inds))
    if len(ch_inds) > 1:
        title += " (max over channels)"
    F_obs_plot = F_obs[..., ch_inds].max(axis=-1)
    F_obs_plot_sig = np.zeros(F_obs_plot.shape) * np.nan
    F_obs_plot_sig[tuple(np.meshgrid(freq_inds, time_inds))] = \
        F_obs_plot[tuple(np.meshgrid(freq_inds, time_inds))]

    for f_image, cmap in zip([F_obs_plot, F_obs_plot_sig], ['gray', 'autumn']):
        c = ax_spec.imshow(f_image, cmap=cmap, aspect='auto', origin='lower',
                           extent=[epochs.times[0], epochs.times[-1],
                                   freqs[0], freqs[-1]])
    ax_spec.set_xlabel('Time (ms)')
    ax_spec.set_ylabel('Frequency (Hz)')
    ax_spec.set_title(title)

    # add another colorbar
    ax_colorbar2 = divider.append_axes('right', size='5%', pad=0.05)
    plt.colorbar(c, cax=ax_colorbar2)
    ax_colorbar2.set_ylabel('F-stat')

    # clean up viz
    mne.viz.tight_layout(fig=fig)
    fig.subplots_adjust(bottom=.05)
    plt.show()
  • Cluster #1, 5 spectrogram (max over channels)
  • Cluster #2, 6 spectrogram (max over channels)

Exercises#

  • What is the smallest p-value you can obtain, given the finite number of permutations? You can find the answers in the references 12.

References#

1(1,2)

Eric Maris and Robert Oostenveld. Nonparametric statistical testing of EEG- and MEG-data. Journal of Neuroscience Methods, 164(1):177–190, 2007. doi:10.1016/j.jneumeth.2007.03.024.

2(1,2)

Jona Sassenhagen and Dejan Draschkow. Cluster-based permutation tests of meg/eeg data do not establish significance of effect latency or location. Psychophysiology, 56(6):e13335, 2019. doi:10.1111/psyp.13335.

Total running time of the script: ( 1 minutes 12.752 seconds)

Estimated memory usage: 129 MB

Gallery generated by Sphinx-Gallery