question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CAR reference as a projector doesn't set custom_ref_applied and remains in projs

See original GitHub issue

The .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 and raw2.
  • 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 and epochs2.
  • 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:closed
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
agramfortcommented, Nov 24, 2021

It does sound like a good solution, enabling the possibility to concatenate epochs / compare recordings with different ref if you know what you are doing.

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.

0reactions
larsonercommented, Nov 25, 2021

However, then what is the use case envisioned for mne.concatenate_epochs (for EEG datasets)?

Usually I use and and see other people use it for concatenating epochs from the same subject, usually from even the same recording.

should .interpolate_bads update the CAR projector?

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 well

should custom_ref_applied be set to True when a CAR projector is applied? What would be the downside?

To 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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

fangfei 2x Custom Logo Wireless LED Projector Car Door ...
Buy fangfei 2x Custom Logo Wireless LED Projector Car Door Step Courtesy ... The projection light is white, you can set the color...
Read more >
How to Quickly Fix Common Projector Issues | K-12 Tech Repair
If you're desperately trying to fix projector problems in your school, try some of the following tips from the experts at K-12 Tech....
Read more >
The Best Projector Screen (for most people)
We spent 90 hours building, painting, testing, and comparing video projector screens to find the best image quality for the best value.
Read more >
Projector Setup Settings - Extended Menu - Epson
Settings on the Extended menu let you customize various projector setup features that control its operation.
Read more >
How to perfectly align a projector
The picture doesn't fill the screen. Projector-zoom-out. You have two ways to correct the problem of the projected image not filling your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found