Referencing to contralateral mastoids

Hi,

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?

Thanks!!!

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.

1 Like

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 :sweat_smile: Please let me know if you need advice on how to do it. And welcome to the forum, @Anna!

2 Likes

ah, I wondered if that would work too. Thatā€™s probably a better approach than my suggestion.

1 Like

Or you could split your raw into 2 raws, one for each hemisphere, do the re-referencing, and then regroup the channels in a single raw. Good luck!

2 Likes

Hereā€™s a reproducible example I just cooked up.

# %%
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:
image

After re-referencing; we unfortunately cannot use the EEGLAB-style head anymore, as channel names are not standard names anymore:
image

(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)

2 Likes

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.

3 Likes

Thank you so much! That is super helpful!

1 Like

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.

2 Likes

But then, why not consider a common reference for all channels, e.g. the average between both mastoids?

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.

1 Like

Iā€™ve converted richardā€™s answer above into a new example for our docs:

3 Likes