Beginner Question: epoching with subset of channels after average re-reference

Hi all,

I just started using MNE to analyze some EEG data I collected for a study I
am conducting. So far, I've been enjoying learning about the package. The
tutorials online are great. However, I seem to be stuck on something I can
only imagine is straightforward. First, an overview of what I am trying to
accomplish:

I use a 64-electrode cap.

Ultimately, I want to (1) re-reference to the average of all electrodes,
(2) apply some basic filters (3) look ERPs of 4 channels for various target
types.

I get stuck getting epochs (3). When trying to select one channel to epoch,
I get the warning message telling me that I should not apply a projector to
1/64 of channels...

How do I get around this given that I want to both re-reference to the
average of *all *electrodes and only do analysis on some subset of
channels.

I imagine that it is clear that I am confused, so any conceptual tips with
respect to the implementation of this package will be helpful.

I've attached the script I have been using. The last line of that script is
where I get stuck (as the comments will show).

Any help will be greatly appreciated.

Thank you,

*Ghislain d'Entremont*
BSc, Neuroscience, Honors
Dalhousie University
tel: 902-802-5671 (text)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160708/f22e4d70/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Analysis.py
Type: text/x-python-script
Size: 2407 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160708/f22e4d70/attachment.bin

Hi Ghislain,

Do you actually need to epoch just a subset of channels? What I usually do
is apply my pre-processing (including epoching) to the whole montage, and I
don't worry about pulling out specific channels until I get to data
analysis (e.g. when I want to plot just the channel that I care about, or
run statistics just on a couple channels, or whatever).

An additional benefit of keeping all the data for as long as I can is that
if I later decide to do some post-hoc, exploratory analysis on some other
channels, I already have that data, instead of having to re-run my
preprocessing on those other channels.

Best,
Steve

Hi Ghislaine,

As long as you stick to linear operations, you can apply the average
reference until the very end. If you want to look at PSDs, you may want to
apply the grand average projection first.

Below is a script that plot the evoked before and after average ref.

For future reference it's generally easier to express your problem with one
of the available dataset.

Hope that helps,

JR

import mne
from mne.datasets import sample
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
events_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
raw = mne.io.read_raw_fif(raw_fname, preload=True)
picks = mne.pick_types(raw.info, eeg=True, meg=False)
events = mne.read_events(events_fname)
event_id = {'AudL': 1, 'AudR': 2, 'VisL': 3, 'VisR': 4}
epochs = mne.Epochs(raw, events, event_id, -0.050, 0.400,
                    picks=picks, verbose=False, proj=False)

# Evoked potentials are linear so you can apply the projection late
evoked = epochs.average()
evoked.plot(show=False, titles='No Average Reference')
evoked.add_eeg_average_proj().apply_proj().plot(proj=True, titles='Average
Reference')

# PSD are non linear, so you may want to apply the projection early
raw = mne.io.read_raw_fif(raw_fname, preload=True, proj=False)  # proj True
by default
raw.pick_types(meg=False, eeg=True)
raw.add_eeg_average_proj().apply_proj().notch_filter(60)
raw.plot_psd()

Dear Ghislain,

you are running into something that is a little opaque in the workings of MNE: applying projectors.
When you set an average reference (either while loading the data with add_eeg_ref=True or later with a call to mne.io.set_eeg_reference(raw)) the reference isn?t directly applied. Instead, a ?projector? is added to the dataset to be applied at a later time. The reason for this is that it makes it easy to later look at the data with and without the projection. When you create the Epochs object, MNE tried to apply the projector. But at this stage you?ve selected only one channel, meaning MNE tries to compute an average reference using only this one channel, which doesn?t make any sense and raises a warning.

What you want to do is call raw.apply_proj() *before* you select any channels, so that the average reference is applied using all channels. Then, you can tell the Epochs object to only extract epochs for certain channels. It goes like this:

import mne
raw = mne.io.read_whatever_data_format_you_have(preload=True)
raw, _ = mne.io.set_eeg_reference(raw)
raw.apply_proj() # actually do the average reference
raw = raw.filter(some filter settings)

# selecting the indices of the channels you want
picks = [raw.ch_names.index(ch) for ch in [?Cz?, ?Pz?, ?C3?, ?C4?]]

# creating the epochs for only the selected channels
epochs = mne.Epochs(raw, picks=picks, other_parameters_you_want)

hope that helps!
Marijn.

p.s. Before applying an average reference, *always* make sure you?ve noted any bad channels in raw.info[?bads?] ! You don?t want to include any noisy or otherwise broken channels in the computation of your average reference.

Dear MNE users,
I also had a question related to the EEG processing.
Which reference eletrode is originally used in the EEG included in sample data?

Thank you in advance.

Junpeng
??? ???
?Live as you are dying, and never stop trying?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160709/0582d4a8/attachment.html

hi,

MNE uses by default average reference.

have a look at this tutorial

http://martinos.org/mne/dev/auto_tutorials/plot_eeg_erp.html

HTH
Alex

Thanks, Alex,

I have learned the tutorials.
But do you know what is the original reference of the EEG sample data?
I noticed that
the scalp map using average reference is different from that using original one.

Best wishes,
Junpeng

sorry no idea

A

During Neuromag EEG acquisition usually there is a reference electrode
placed on the nose. You could check the digitization field in the
measurement information info['dig'] or look at any EEG channel
info['chs'][eeg_idx]['loc'], IIRC the first three numbers are the digitized
electrode location XYZ and the next three are the digitized reference
location XYZ in head coordinates.

HTH,
Eric

Nose reference
Hth
D