Created
March 28, 2023 14:23
-
-
Save dtxe/d76c127c6234fc0364637e66e2a67a33 to your computer and use it in GitHub Desktop.
MNE interpolate new scalp channels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mne | |
mneraw = mne.read_raw_edf('file.edf') | |
electrodes = ['Fpz', 'Cz'] | |
# if electrodes to plot are not available, try to interpolate them | |
electrodes_not_in_list = [e for e in electrodes if e not in mneraw.ch_names] | |
if len(electrodes_not_in_list) > 0: | |
try: | |
mneraw = mne.add_reference_channels(mneraw, ref_channels=electrodes_not_in_list, copy=False) | |
scalpmontage = mne.channels.make_standard_montage('standard_1020') | |
mneraw = mneraw.set_montage(None) # remove montage | |
mneraw = mneraw.set_montage(scalpmontage, on_missing='warn') # re-add montage for Fpz electrode | |
# for e in electrodes_not_in_list: | |
mneraw.info['bads'].extend(electrodes_not_in_list) | |
mneraw = mneraw.interpolate_bads(reset_bads=True) | |
except Exception as ex: | |
logging.info('Could not add ' + repr(electrodes_not_in_list) + ' and interpolate: ' + repr(ex)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment