mne.viz.plot_evoked_topomap error

  • MNE version: 1.1.1
  • operating system: Windows 10
  • Python version: 3.7.13

Hello, I was following the tutorial about Group Analysis of ERP Data (Group Analysis of ERP Data — Data Science for Psychology and Neuroscience — in Python) with my own data.
Everything works perfectly, except when I arrive to the “Scalp topographic map” part. I try to do a topomap plot of my evoked object (gA of a difference between my 2 conditions), exactly like the tutorial, but a weird error is occurring. It looks like mne.viz.plot_evoked_topomap() is bugged.

My code (without data dir and the other parts of the tutorial which work fine) :


# Load data files 
evokeds = {}
conditions = ['congruent', 'incongruent']
for idx, c in enumerate(conditions):
    evokeds[c] = [mne.read_evokeds(d)[idx] for d in data_files]

roi = ['Pz']

# Differences
diff_waves = []
for i in range(len(data_files)):
    diff_waves.append(mne.combine_evoked([evokeds['congruent'][i], evokeds['incongruent'][i]],
                                          weights=[1, -1]
                                         )
contrast = 'Congruent-Incongruent'
# Scalp topographic map
mne.viz.plot_evoked_topomap(mne.grand_average(diff_waves), 
                            times=0.300, average=0.100, 
                            title=contrast,
                            size=3
                           )
plt.show()

The error :

Traceback (most recent call last):

  File "C:\Users\remil\AppData\Local\Temp\ipykernel_13276\2413048152.py", line 4, in <module>
    size=3

  File "C:\Users\remil\anaconda3\envs\py37\lib\site-packages\mne\viz\topomap.py", line 1815, in plot_evoked_topomap
    mask=mask_[:, average_idx] if mask is not None else None, **kwargs)

  File "C:\Users\remil\anaconda3\envs\py37\lib\site-packages\mne\viz\topomap.py", line 996, in _plot_topomap
    pos, res, image_interp, extrapolate, outlines, border)

  File "C:\Users\remil\anaconda3\envs\py37\lib\site-packages\mne\viz\topomap.py", line 845, in _setup_interp
    clip_origin, clip_radius, border)

  File "C:\Users\remil\anaconda3\envs\py37\lib\site-packages\mne\viz\topomap.py", line 628, in __init__
    pos, extrapolate, origin, radii)

  File "C:\Users\remil\anaconda3\envs\py37\lib\site-packages\mne\viz\topomap.py", line 509, in _get_extra_points
    colinear = ((slopes == slopes[0]).all() or np.isinf(slopes).all())

IndexError: index 0 is out of bounds for axis 0 with size 0

I tried to add (extrapolate = ‘local’ or ‘box’) in the function but didnt work, although ‘box’ gave another error message but originating from the same code line in _get_extra_points.

The same error happens if I use plot_topomap() rather than mne.viz.plot_evoked_topomap() :

ga_evoked = mne.grand_average(diff_waves)
ga_evoked.plot_topomap(times=0.300, average=0.100, 
                title=contrast,
                size=3
                )
plt.show()

Any idea ?

I cannot reproduce this problem with the sample data. This works:

import mne
root = mne.datasets.sample.data_path() / 'MEG' / 'sample'
evk_file = root / 'sample_audvis-ave.fif'
evokeds_list = mne.read_evokeds(evk_file, verbose=False)
evokeds = {e.comment: [e] for e in evokeds_list}
diff_waves = []
for i in [0]:  # only one subj in sample data
    diff_wav = mne.combine_evoked(
        [evokeds['Left Auditory'][i], evokeds['Right Auditory'][i]],
        weights=[1, -1])
    diff_waves.append(diff_wav)
ga = mne.grand_average(diff_waves)
mne.viz.plot_evoked_topomap(ga, times=0.3, average=0.1, size=3)

It differs from your example in a couple ways:

  1. only one subject, so each entry in dict evokeds a list of length 1. Likewise diff_waves only contains one evoked.
  2. I don’t set a title in the call to plot_evoked_topomap because the title parameter was recently deprecated.

I don’t think those changes account for the fact that this succeeds while your code fails. Can you provide a complete, minimal code sample that shows your problem? “Minimal” means don’t include things like plot titles or size (that aren’t necessary to reproduce the problem) or lines like roi = ['Pz'] which aren’t used later in the script. “Complete” means providing the data too, and the code that loads the data. Ideally you can find a way to reproduce this with the sample data; if not then please provide links to download (preferably small) data files of your own that do reproduce the problem.

First, thank you for your answer.

  • In the tutorial they also have many subjects, this is why we have mne.grand_average(diff_waves) which is creating one evoked object of the grand-average across subjects.
  • I tried without title but the same error happens.

Ok, as soon as I have a bit of time, I will provide a complete & minimal code sample !

My code sample also uses mne.grand_average() (even though it’s just an average of one subject) so I don’t think that is the source of the error.

Okay so here is a link to evoked files for 4 subjects : link expired
And this is the minimal complete code generating the error :


import mne
import glob

data_dir = ("C:/Users/remil/PhD/Python/EEGanalyses/results/evokeds/ern/")
data_files = glob.glob(data_dir + '/ern_*-ave.fif' )

conditions = ['congruent', 'incongruent']
contrast = 'Congruent-Incongruent'

evokeds = {}
for idx, c in enumerate(conditions):
    evokeds[c] = [mne.read_evokeds(d)[idx] for d in data_files]

diff_waves = []
for i in range(len(data_files)):
    diff_waves.append(mne.combine_evoked([evokeds['congruent'][i], evokeds['incongruent'][i]],
                                          weights=[1, -1]
                                         )
                     )

# Scalp topographic map
ga = mne.grand_average(diff_waves)
mne.viz.plot_evoked_topomap(ga, 
                            times=0.300, average=0.100, 
                            title=contrast,
                            size=3
                           )
plt.show()

You have only 1 channel in each of your evokeds. You cannot plot a topomap when you have only one channel.

2 Likes

Oops indeed, I feel stupid now.

Thank you very much for your quick answers !