mne-tools / mne-tools/mne-python
BUG: set_eeg_reference with single channel behavior
@larsoner is already working on this.
Since Jan 22, 2024.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
When processing a recent brainvision recording with FCz as the reference (which means it's not in the recording), I wanted to recover this channel in the data, use an average ref proj, and eventually source localize. So I wanted to do:
raw_eeg = mne.io.read_raw_brainvision(eeg_fname).load_data()
raw_eeg.rename_channels(eeg_renames) # numbers to standard 1020 names
mne.add_reference_channels(raw_eeg, "FCz", copy=False) # add all-zero channel
raw_eeg.set_montage("standard_1020") # set locations
raw_eeg.set_eeg_reference(["FCz"]) # set the reference information explicitly
raw_eeg.set_eeg_reference(projection=True) # switch to an average reference using projection
and have source loc etc. work. However, doing this we end up with two problems for source loc:
raw_eeg.info["custom_ref_applied"] == 1raw_eeg.info["chs"][ii]["loc"][3:6]is all zeros
Correct behavior here I think would be to have each EEG channel's ch["loc"][3:6] be FCz's ch["loc"][:3], and have custom_ref_applied be set to "off", i.e.:
with raw_eeg.info._unlock():
for ch in raw_eeg.info["chs"]:
ch["loc"][3:6] = raw_eeg.info["chs"][-1]["loc"][3:6]
raw_eeg.info["custom_ref_applied"] = 0
So concretely, I propose that in cases where set_eeg_reference is called with a single channel name and that channel name has a meaningful position (ch["loc"][:3]"), we set custom_ref_applied to False and set ch["loc"][3:6] for all EEG channels properly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.