autoreject / autoreject

Automated rejection and repair of bad trials/sensors in M/EEG
https://autoreject.github.io
BSD 3-Clause "New" or "Revised" License
138 stars 58 forks source link

pre-marking bad channels in autoreject #311

Open jasmainak opened 1 year ago

jasmainak commented 1 year ago

cross posting from the forum:

https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369/4

# set parameters for autoreject
n_interpolates = np.array((1, 2, 3, 5, 7, 9))
consensus_percs = np.linspace(0.2, 0.7, 11)

# init autoreject object, picks are grads or mags respectively
rej = AutoReject(n_interpolates, consensus_percs, picks=picks,
                    thresh_method='bayesian_optimization')

# run the autoreject (local) algorithm
rej.fit(epochs)

# extract the log file
rej_log = rej.get_reject_log(epochs)

# plot
xlabels = reject_log.ch_names
image = reject_log.labels
image[image == 2] = 0.5  # move interp to 0.5
legend_label = {0: 'good', 0.5: 'interpolated', 1: 'bad'}
cmap = colors.ListedColormap(['white', 'blue', 'red'])
img = axes.imshow(image.T, cmap=cmap, vmin=0, vmax=1, interpolation='none')
plt.setp(axes, yticks=range(0, len(xlabels)), yticklabels=xlabels)
plt.setp(axes.get_yticklabels(), fontsize=2)
#add red box around rejected epochs
for idx in np.where(reject_log.bad_epochs)[0]:
    axes.add_patch(patches.Rectangle((idx - 0.5, -0.5), 1, len(xlabels),
                 linewidth=1, edgecolor='r', facecolor='none'))

I would have to dig into it at a calmer moment ... in the meanwhile, I wouldn't mind if someone beat me to it