CAR reference as a projector doesn't set custom_ref_applied and remains in projs
See original GitHub issueThe .set_eeg_reference
methods have a projection
argument that can be set to True to set the CAR reference as a projector. I guess in most cases it should be set to False, and the CAR referencing should be directly applied to the data; but if you set it to True, it creates some issues in later processing.
Someone else from my lab encountered two today:
The flag custom_ref_applied
is not set to True when the projector is applied.
from pathlib import Path
import mne
import numpy as np
directory = Path(mne.datasets.sample.data_path())/'MEG'/'sample'
fname = directory/'sample_audvis_filt-0-40_raw.fif'
#%% CAR
raw = mne.io.read_raw_fif(fname, preload=True)
raw.del_proj() # 3 PCA, 1 CAR all inactive.
raw.set_eeg_reference('average', projection=False)
data = raw.get_data(picks='eeg')
raw.info['custom_ref_applied']
# Out: 1 (FIFFV_MNE_CUSTOM_REF_ON)
#%% CAR proj
raw = mne.io.read_raw_fif(fname, preload=True)
raw.del_proj() # 3 PCA, 1 CAR all inactive.
raw.set_eeg_reference('average', projection=True)
data_unapplied = raw.get_data(picks='eeg')
raw.apply_proj()
data_applied = raw.get_data(picks='eeg')
raw.info['custom_ref_applied']
# Out: 0 (FIFFV_MNE_CUSTOM_REF_OFF)
#%% Test
assert np.isclose(data, data_applied).all()
assert not np.isclose(data, data_unapplied).all()
Once .apply_proj
is called, the only way to remove the projector is to delete all channels affected… i.e. all eeg
channels in which case neither the projector or the flag custom_ref_applied
make sense. IMO, it should be set to True when a CAR projector is applied.
The CAR projector remains in the list of projectors (and becomes active)
This makes probably sense for other types of projectors, but I feel like it’s a mistake for the CAR projectors. The changes have been made to the eeg
data; and the only way to remove it is again to delete all eeg
channels.
Now, consider this (sorry I didn’t make an example for that one yet, I’ll add one tomorrow):
- I have 2 different EEG recordings from the same participant, same session ->
raw1
andraw2
. - On both, I use
raw.set_eeg_reference('average', projection=True)
. - Now, I create similar epochs on both (assume same type of recordings, same events) ->
epochs1
andepochs2
. - In
epochs.info['projs']
, the CAR projector (active) is displayed. - Now, if I use
mne.concatenate_epochs
to concatenate both in a single epochs instance; an error is raised because projectors between both differ.
This probably makes sense for SSP, PCA projectors; but for a common average reference on EEG channels, it doesn’t (at least to me).
For now, to quickly solve the problem encountered with data at hand (without changing .set_eeg_reference
proj to False), I proposed to do epochs.info['projs'] = []
, but obviously I’d like to avoid this.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top GitHub Comments
you mean "if you know what you are doing something bad but you don’t care. " 😃
really for me doing this is not clean. For me MNE complains for good reasons.
Usually I use and and see other people use it for concatenating epochs from the same subject, usually from even the same recording.
It removes entries from
raw.info['bads']
so it would make sense to me that the CAR proj would be updated to include the “new” good channel as wellTo me “custom ref applied” means “a non-projector-based reference has been applied” / “do not use or (re)apply an average EEG reference projector”.
Historically, MNE originally only ever had support for CAR-as-projector, there was no other reference scheme available – and there was no
custom_ref_applied
at all. People started asking for other referencing methods, so we added them along with this new parameter, basically to have mean the above.Rather than trying to change what
custom_ref_applied
means, I’d rather put effort toward making it mostly obsolete via something much better and complete like https://github.com/mne-tools/mne-python/issues/8962#issuecomment-788792586. I think we came to a consensus on what needed to be done there, we “just” need someone motivated to work on it, as it’s non-trivial…