Referencing to contralateral mastoids

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