Skip to content

Bug in sensors naming when using mne.viz.plot_topomap #12700

Open

Description

@Fayed-Rsl

Description of the problem

Hello,

I discovered a bug in the sensor name when using mne.viz.plot_topomap.
The values on the topomap remain correct but not the names; which can lead to confusion if we want to draw conclusion based on quick visualisation of sensor names.

Steps to reproduce

import mne
import numpy as np 
# activate interactive plot if not already
# %matplotlib qt 

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = (
    sample_data_folder / "MEG" / "sample" / "sample_audvis_filt-0-40_raw.fif"
)

# load the dataset
raw = mne.io.read_raw_fif(sample_data_raw_file)
raw.pick_types(meg='grad') # pick only gradiometers
raw.load_data()

# plot the sensors with their names using raw.plot_sensors
raw.plot_sensors(show_names=True)

# beta band
fmin = 13
fmax = 30
freqs_beta = {f'{fmin}-{fmax} Hz': (fmin, fmax)} # freq up to beta (13, 30) 

# compute psd and plot in beta band
raw_psd = raw.compute_psd(fmin=fmin, fmax=fmax)
raw_psd.plot_topomap(bands=freqs_beta, show_names=True)

# compute PSD and plot it
psds, freqs = mne.time_frequency.psd_array_welch(x=raw._data, sfreq=raw.info['sfreq'],
                                                 fmin=fmin, fmax=fmax, n_fft=2048, n_jobs=-1)

# just to check that the values are actually all the same 
assert np.all(raw_psd._data == psds), 'Raw PSD != psds'

# average the PSD over the frequency axis
psd_mean = np.mean(psds, axis=1)

# Plot the topomap of the Gradiometer power
mne.viz.plot_topomap(psd_mean, raw.info, show=True, res=300, sensors=True, names=raw.ch_names)

Link to data

No response

Expected results

raw.plot_sensors(show_names=True) should provide the following plot
image

raw_psd.plot_topomap(bands=freqs_beta, show_names=True)
image

So far this looks correct to me and I would expect mne.viz.plot_topomap to produce similar result as raw_psd.plot_topomap.

Actual results

But when doing mne.viz.plot_topomap(psd_mean, raw.info, show=True, res=300, sensors=True, names=raw.ch_names), I didn't expected to have this sensor names scheme.
Unfortunately there is no colorbar option using mne.viz.topomap to my knowledge so the color-scheme is slightly different but I checked that the values where the same earlier)
image

Additional information

Let me know if there is something that I am missing here.
Thanks for your support.

Activity

  1. cbrnr commented on Jul 5, 2024

    @cbrnr
    Contributor

    I'm already a bit puzzled by the first plot (raw.plot_sensors(show_names=True)), because (1) most labels seem to show at least two overlapping labels at the same position, and (2) the labels are different from the labels in the PSD plots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions