mne-tools / mne-tools/mne-python

mne.viz.plot_topomap with bipolar montage

Open
#11,726 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

BUG
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Description of the problem

Could be considered bug or enhancement.

I'm re-referencing my EEG data to use bipolar montage (using set_bipolar_reference function in using mne.io.reference.py module) and am using the same channels multiple times as anodes with different cathodes (e.g. Fp1-AF3 and Fp1-AF7). The way mne currently works is to set the new virtual channel's information including sensor location the same as the anode's. As a result, both Fp1-AF3 and Fp1-AF7 virtual channels will have the same sensor locations. No error is actually being raised at this point.

The error will be raised when I tried calling mne.viz.plot_topomap and it'll yield the following message:

ValueError: The following electrodes have overlapping positions, which causes problems during visualization:

Two changes as a possible solution:

  1. Add update_loc boolean argument to set_bipolar_reference function to set the new virtual channel's sensor location as the midpoint of anode and cathode's sensor locations only for x and y coordinates. (In addition, how should we handle z coordinate for source reconstruction or other purposes?)
  2. Raise warning if multiple channels of the same type have the same sensor locations during set_bipolar_reference.
Steps to reproduce
import matplotlib as mpl
import matplotlib.pyplot as plt

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = (
    sample_data_folder / "MEG" / "sample" / "sample_audvis_filt-0-40_raw.fif"
)
raw = mne.io.read_raw_fif(sample_data_raw_file, preload=True)
info = mne.io.read_info(sample_data_raw_file)
raw.pick(mne.pick_types(info, meg=False, eeg=True, exclude=[]))
anode = ['EEG 004','EEG 005','EEG 004']
cathode = ['EEG 006','EEG 007','EEG 008']

mne.set_bipolar_reference(raw, anode=anode, cathode=cathode, copy=False, drop_refs=True)
raw.drop_channels(['EEG 001', 'EEG 002', 'EEG 003', 'EEG 009', 'EEG 010', 'EEG 011', 'EEG 012', 'EEG 013', 'EEG 014', 'EEG 015', 'EEG 016', 'EEG 017', 'EEG 018', 'EEG 019', 'EEG 020', 'EEG 021', 'EEG 022', 'EEG 023', 'EEG 024', 'EEG 025', 'EEG 026', 'EEG 027', 'EEG 028', 'EEG 029', 'EEG 030', 'EEG 031', 'EEG 032', 'EEG 033', 'EEG 034', 'EEG 035', 'EEG 036', 'EEG 037', 'EEG 038', 'EEG 039', 'EEG 040', 'EEG 041', 'EEG 042', 'EEG 043', 'EEG 044', 'EEG 045', 'EEG 046', 'EEG 047', 'EEG 048', 'EEG 049', 'EEG 050', 'EEG 051', 'EEG 052', 'EEG 053', 'EEG 054', 'EEG 055', 'EEG 056', 'EEG 057', 'EEG 058', 'EEG 059', 'EEG 060'])

mpl.use('QtAgg')

fig, axs = plt.subplots(figsize=(7.5, 4.5), nrows=2, ncols=2)

mne.viz.plot_topomap(raw, pos=raw.info, axes=axs[0,0], show=True)
Link to data

No response

Expected results

None

Actual results
ValueError: The following electrodes have overlapping positions, which causes problems during visualization:
EEG 004-EEG 006, EEG 004-EEG 008
Additional information

Platform: Windows-10-10.0.19045-SP0
Python: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:00:38) [MSC v.1934 64 bit (AMD64)]
Executable: C:\Users\mning\AppData\Local\mambaforge\envs\mne\python.exe
CPU: Intel64 Family 6 Model 142 Stepping 10, GenuineIntel: 8 cores
Memory: 7.8 GB

mne: 1.3.1
numpy: 1.23.5 {MKL 2022.1-Product with 4 threads}
scipy: 1.10.1
matplotlib: 3.7.1 {backend=QtAgg}

sklearn: 1.2.2
numba: 0.56.4
nibabel: 5.1.0
nilearn: 0.10.1
dipy: 1.7.0
openmeeg: 2.5.6
cupy: Not found
pandas: 2.0.1
pyvista: 0.39.0 {OpenGL 4.5.0 - Build 30.0.101.1122 via Intel(R) UHD Graphics 620}
pyvistaqt: 0.0.0
ipyvtklink: 0.2.2
vtk: 9.2.6
qtpy: 2.3.1 {PyQt5=5.15.6}
ipympl: Not found
pyqtgraph: 0.13.3
pooch: v1.7.0

mne_bids: Not found
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: 0.0.0
mne_connectivity: Not found
mne_icalabel: Not found

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mne.io.reference.py at set_bipolar_reference and trace how virtual-channel sensor locations are assigned. Reproduce the overlapping-position failure with mne.viz.plot_topomap using the example in the issue, then determine the intended handling of location coordinates and duplicate-position warnings. Done means the chosen behavior is implemented and the reported visualization failure is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.