Indexing error in Evoked.plot_topomap() when trying to mask channels
See original GitHub issueSo either this is a documentation problem or a code bug: I supply times
and mask
with a shape of (n_times, n_chans)
to Evoked.plot_topomap()
, and it crashes with an IndexError
.
# %%
from pathlib import Path
import numpy as np
import mne
sample_data_dir = Path(mne.datasets.sample.data_path())
fname = sample_data_dir / 'MEG' / 'sample' / 'sample_audvis-ave.fif'
condition = 'Left Auditory'
evoked = mne.read_evokeds(fname=fname, condition=condition)
evoked.pick('mag')
evoked.apply_baseline((None, 0))
times = (0.090, 0.110)
mask = np.empty(
[len(evoked.ch_names), len(times)]
)
mask.fill(False)
mask[20, :] = True
fig = evoked.plot_topomap(times=times, time_unit='s', mask=mask)
Traceback (most recent call last):
File "/private/tmp/mwe_topo.py", line 22, in <module>
fig = evoked.plot_topomap(times=times, time_unit='s', mask=mask)
File "/Users/hoechenberger/Development/mne-python/mne/evoked.py", line 478, in plot_topomap
return plot_evoked_topomap(
File "/Users/hoechenberger/Development/mne-python/mne/viz/topomap.py", line 1697, in plot_evoked_topomap
mask_ = mask[np.ix_(picks, time_idx)]
IndexError: index 174 is out of bounds for axis 1 with size 2
I expected a topoplot at the two time points, showing only the first 20 channels.
Issue Analytics
- State:
- Created 2 years ago
- Comments:25 (25 by maintainers)
Top Results From Across the Web
Mne.viz.plot_topomap mask settings - Support & Discussions - MNE ...
I have opened an issue, see Indexing error in Evoked.plot_topomap() when trying to mask channels · Issue #9611 · mne-tools/mne-python · GitHub.
Read more >mne.Evoked — MNE 1.2.2 documentation - MNE-Python
LEGACY: New code should use .compute_psd().plot_topomap(). ... This will also set the mask to be polygonal based on the convex hull of the ......
Read more >evoked.plot_topomap multiple masks · Issue #2530 - GitHub
I want to highlight two sets of channels in two different colors. All reactions.
Read more >Group Analysis of ERP Data
import mne mne.set_log_level('error') # reduce extraneous MNE output import ... Here when we read_evokeds() you will likewise get a list of Evoked objects....
Read more >Visualizing Evoked data - Jupyter Notebooks Gallery
Like many MNE-Python plotting functions, :meth: evoked.plot() <mne. ... has a picks parameter that can select channels to plot by name, index, or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@drammock Thanks, I completely missed point 1 in this discussion. Yes, to plot topomap based on only some of the sensors you need to drop the remaining ones and use
extrapolate='local'
. @mscheltienne.astype()
would needcopy=False
, so that the mask is not copied if it has the correct dtype.The code snippet posted by @drammock could be a part of a short example on masking channels with
evoked.plot()
andplot_topomap()
. It could also be added to this example/tutorial on topomap plotting: https://mne.tools/stable/auto_examples/visualization/evoked_topomap.html#sphx-glr-auto-examples-visualization-evoked-topomap-py.sorry to be super-late chiming in on this issue. Here is my impression:
mask
is only to affect the drawing of sensor markers on the plot. It is not intended to affect the field interpolation. (I think if you want to see field interpolation based on a subset of sensors it should work to drop all other sensors first before plotting?)evoked.plot_topomap()
should be updated to emphasize thatmask
must match the shape ofevoked.data
(n_channels, n_displayed_times)
then I agree with @mmagnuski that we’d want to hear an example use case where this would make sense. Note that you can still make it work: