question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TF image (ERDS map) with significance mask

See original GitHub issue

I’m trying to plot a TF image (more specifically an ERDS map) with a significance mask. In other words, I would like to plot only significant t/f values, whereas not significant values should be white.

Here’s the example code I’m working with: https://martinos.org/mne/stable/auto_examples/time_frequency/plot_time_frequency_erds.html

I need the individual epochs to compute the significance, so I add the argument average=False to tfr_multitaper. I create a new object containing the average TFR with average_tfr = power.average().

I renamed power to tfr for consistency. Here is the modified code starting on line 103 (everything else above doesn’t change except for two additional imports:

from numpy.ma import masked
from mne.stats import permutation_cluster_1samp_test as pc_test

for event in event_ids:
    tfr = tfr_multitaper(epochs[event], freqs=freqs, n_cycles=n_cycles,
                         use_fft=True, return_itc=False, average=False,
                         decim=2)
    tfr.crop(tmin, tmax)

    fig, ax = plt.subplots(1, 4, figsize=(12, 4),
                           gridspec_kw={"width_ratios": [10, 10, 10, 1]})
    average_tfr = tfr.average()
    for i in range(3):
        t_obs, cl, ps, _ = pc_test(tfr.data[:, i, ...], n_permutations=100,
                                   threshold=5)
        shape = average_tfr.data[i].shape
        mask = np.full(shape, True)

        for c, p in zip(cl, ps):
            if p <= 0.05:
                mask[c] = False

        # average_tfr.data[i] = tfr_plot
        average_tfr.plot([i], baseline=[-1, 0], mode="percent", vmin=vmin,
                         vmax=vmax, cmap=(cmap, False), axes=ax[i],
                         colorbar=False, show=False)
        arr = ax[i].collections[0].get_array().reshape(shape)
        arr[mask] = masked
        ax[i].collections[0].set_array(arr.flatten())
        ax[i].set_title(epochs.ch_names[i], fontsize=10)
        ax[i].axvline(0, linewidth=1, color="black", linestyle=":")  # event
        if i > 0:
            ax[i].set_ylabel("")
            ax[i].set_yticklabels("")
    fig.colorbar(ax[0].collections[0], cax=ax[-1])
    fig.suptitle("ERDS ({})".format(event))
    fig.show()

This code is inspired by https://martinos.org/mne/stable/auto_tutorials/plot_stats_cluster_1samp_test_time_frequency.html. However, my modified example doesn’t look right. The masked regions do not fit the TFR at all, it seems like the non-significant patches are arbitrarily placed on the TFR image (I’ve used threshold=5 in the cluster permutation test):

figure_1 figure_2

Any idea what I’m missing here? Could this be related to the fact that I’m plotting the TFR image with baseline=[-1, 0], mode="percent", which might not be reflected in average_tfr.data? If so, how can I run a significance test on the correct data? Or is there something wrong with how I’m performing the cluster permutation test?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Mar 22, 2018

(…And by that I mean don’t use the phrase “significant clusters”, even though that’s how people tend to colloquially refer to them. The step_down_p stuff is fine for publication.)

1reaction
larsonercommented, Mar 22, 2018

Maybe this will improve when I handle positive and negative clusters separately as you suggest.

Also you can use e.g. step_down_p=0.05. It removes “significant clusters” (don’t ever say this in a publication) that could be pushing the null distribution larger than it should be.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compute and visualize ERDS maps - MNE-Python
This example calculates and displays ERDS maps of event-related EEG data. ERDS (sometimes also written as ERD/ERS) is short for ...
Read more >
tfa.image.cutout | TensorFlow Addons
Apply cutout to images. ... This operation applies a (mask_height x mask_width) mask of zeros to a location within images specified by the...
Read more >
Compute and visualize ERDS maps - | notebook.community
This example calculates and displays ERDS maps of event-related EEG data. ... Visualization of significant ERD/ERS patterns in multichannel EEG and ECoG ...
Read more >
Mapping Large-Scale Networks Associated with Action ... - NCBI
To visualize significant TF activations or de-activations, ... We used the significance maps from both analyses to mask the [go–wait] contrast.
Read more >
reK - River Thames Conditions - Environment Agency - GOV.UK
#in Bentley continental gt 2012, The snow fell, Drop your name meaning, ... Medium breeds of dogs pictures, Rouge volupte perle, Tiantongyuan map, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found