Loading in list of bad channels

Hi there,

I am looking to load in pre-set list of bad channels when reading in a CTF file of MEG data. Does anyone have any information on the proper way to format channel names? I have created a BadChannels file, but am encountering errors when trying to load in the Bad Channels. Thanks in advance for your help.

ultimately you want your bad channel names in a python list, so any format that can yield a list would be fine. Here are a couple possibilities:

# file bads.csv (one line, comma-separated)
foo, bar, baz

option 1: csv module

import csv
with open('bads.csv', 'r') as f:
    bads = list(csv.reader(f))[0]

option 2: numpy

# file bads.txt (one channel name per line)
foo
bar
baz
import numpy as np
bads = np.loadtxt('bads.txt', dtype=str).tolist()

option 3: python builtins.

bads = list()
with open('bads.txt', 'r') as f:
    bads.append(f.readline().strip())

You could also use, e.g., pandas.read_csv().

Hi Kaya,

In addition to what @drammock has listed. One other option - is just to save the text file in the CTF dataset, versus loading once in MNE python. The text file is inside the CTF folder and is called BadChannels and is loaded with the dataset:

In [1]: import mne

In [2]: !cat sub-21111_task-mmi3_run-1_meg.ds/BadChannels
   ...: 
MLP33
MLP54
MRC54

In [3]: raw=mne.io.read_raw_ctf('sub-21111_task-mmi3_run-1_meg.ds', verbose=False,system_cl
   ...: ock='ignore')

In [4]: raw.info['bads']
Out[4]: ['MLP33-1609', 'MLP54-1609', 'MRC54-1609']

-Jeff Stout

3 Likes

oh nice! I’ve not worked with CTF data so I didn’t know about that.