mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

AverageTFR.plot_topo color scale bug #11247

Open drammock opened 2 years ago

drammock commented 2 years ago

MWE adapted from #10920

import numpy as np
import mne

data_path = mne.datasets.sample.data_path()
subjects_dir = data_path / 'subjects'
raw_fname = data_path / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

# Read the raw data
raw = mne.io.read_raw_fif(raw_fname)
raw.info['bads'] = ['MEG 2443']  # bad MEG channel

# Set up the epoching
events = mne.find_events(raw)

# pick data channel types
raw.pick(['meg', 'eeg', 'eog'])

# create epochs, leave room for cutting out edge artifact
epochs = mne.Epochs(raw, events, event_id=dict(left_aud=1),
                    tmin=-0.5, tmax=0.5, baseline=(None, 0),
                    preload=True, proj=False,
                    reject=dict(grad=4000e-13, mag=4e-12,
                                eeg=1e-4, eog=150e-6))

# done with eog now
del raw
epochs.pick(['meg', 'eeg'])

# set average reference
epochs.set_eeg_reference('average', projection=True)

# focus on alpha and beta oscillations
freqs = np.logspace(*np.log10([8, 35]), num=6)

# select subset of trials for speed
epochs = epochs[:10]

# time-frequency decomposition
average_tfr = mne.time_frequency.tfr_morlet(
    epochs, freqs=freqs, n_cycles=freqs / 2, return_itc=False,
    average=True)

average_tfr.plot_topo()

plotting average_tfr.plot_topo(picks=slice(0, 2)) or slice(0, 5) or even slice(0, 40) yields (partial) topo plots where at least some of the sensors have visible activity. I'm assuming some sort of bad color normalization (across sensors) is the cause, but that's a wild guess.

mmagnuski commented 1 year ago

Part of the scaling problem may be due to very high response (10-fold judging from the colormap) on one MEG channel (MEG2313):

average_tfr.plot_topo(baseline=(None, 0), mode='percent')

image image

Setting the vmax to something much lower than max value makes it better:

average_tfr.plot_topo(baseline=(None, 0), mode='percent',
                      vmin=-2.5, vmax=2.5)

image

maybe the automatic vmax choice in mne could be not max but something like 95th percentile of the data to be more robust?