I want to re-reference my recording to the contralateral mastoids (All left-hemisphere channels to A2 and all right-hemisphere channels to A1). It seems like itās not possible to reference to a subset of channels using mne.set_eeg_reference().
Does anyone have an idea how I could re-reference to the contralateral mastoids?
I donāt know for sure that this will work, but you might be able to hack this by temporarily changing the channel type of the electrodes in one hemisphere, then using the ch_type parameter of set_eeg_reference to specify which hemisphere youāre referencing. So youād call set_eeg_reference twice, then change the channel types back to normal.
My proposal would be to create bipolar channels. All channels on the left hemisphere can be referenced to the right mastoid and vice versa. It seems like the cleanest solution to me, unless Iām overlooking any complications here Please let me know if you need advice on how to do it. And welcome to the forum, @Anna!
# %%
import numpy as np
import mne
ssvep_folder = mne.datasets.ssvep.data_path()
ssvep_data_raw_path = (ssvep_folder / 'sub-02' / 'ses-01' / 'eeg' /
'sub-02_ses-01_task-ssvep_eeg.vhdr')
raw = mne.io.read_raw_brainvision(ssvep_data_raw_path, preload=True)
raw.set_montage('easycap-M1')
# %%
raw.rename_channels({
'TP9': 'M1',
'TP10': 'M2'
})
fig = raw.plot_sensors(show_names=True, sphere='eeglab')
# Get names of the channels on the left and right hemisphere
# make_1020_channel_selections() only yields indices, but we want the
# channel names instead. We convert raw.ch_names to an array for easier indexing
# (retrieving multiple elements at once). Eventually, we convert the result
# back to a list, because set_bipolar_reference() cannot ingest an array.
# This is all a bit ugly but works.
channel_indices = mne.channels.make_1020_channel_selections(raw.info)
channel_names = {
'Left': list(np.array(raw.ch_names)[channel_indices['Left']]),
'Right': list(np.array(raw.ch_names)[channel_indices['Right']])
}
# We will use M1 and M2 as references and remove them from the montage
# during creation of the bipolar reference channels
del channel_names['Left'][channel_names['Left'].index('M1')]
del channel_names['Right'][channel_names['Right'].index('M2')]
# %%
# Create bipolar references
mne.set_bipolar_reference(
raw,
anode=channel_names['Left'],
cathode=['M2']*len(channel_names['Left']),
copy=False
)
mne.set_bipolar_reference(
raw,
anode=channel_names['Right'],
cathode=['M1']*len(channel_names['Right']),
copy=False
)
# %%
# We're done!
#
# We cannot use the EEGLAB head anymore, as our channels don't have
# standard names anymore.
fig = raw.plot_sensors(show_names=True)
Before re-referencing, with EEGLAB-style head:
After re-referencing; we unfortunately cannot use the EEGLAB-style head anymore, as channel names are not standard names anymore:
(Note that we could arrange for the channel names to remain unchanged, but in this example I wanted to explicitly demonstrate which reference was used for the left and right hemisphere, respectively)
Now that there are a few proposed solutions, Iād be interested in why you want to do that in the first place @Anna. Iāve never seen two different references in an analysis.
Itās the most common way to reference in sleep research to visually identify sleep stages. I think the idea behind it is to use a reference as far away as possible (F3, F4, C3, C4, O1 and O2 are often the only channels used) to see large differences, but Iām not a 100% sure.
Using the contralateral mastoids does indeed seem like a common thing in sleep EEG. Just google for āsleep eeg contralateral mastoidsā and a number of publications pop up.