ar.fit(epochs['Auditory/Left']) epochs_clean = ar.transform(epochs['Auditory/Left']) evoked_clean = epochs_clean.average() evoked = epochs['Auditory/Left'].average() ############################################################################### # Now, we will manually mark the bad channels just for plotting. evoked.info['bads'] = ['MEG 2443'] evoked_clean.info['bads'] = ['MEG 2443'] ############################################################################### # Let us plot the results. import matplotlib.pyplot as plt # noqa set_matplotlib_defaults(plt) fig, axes = plt.subplots(2, 1, figsize=(6, 6)) for ax in axes: ax.tick_params(axis='x', which='both', bottom='off', top='off') ax.tick_params(axis='y', which='both', left='off', right='off') ylim = dict(grad=(-170, 200)) evoked.pick_types(meg='grad', exclude=[]) evoked.plot(exclude=[], axes=axes[0], ylim=ylim, show=False) axes[0].set_title('Before autoreject') evoked_clean.pick_types(meg='grad', exclude=[]) evoked_clean.plot(exclude=[], axes=axes[1], ylim=ylim) axes[1].set_title('After autoreject') plt.tight_layout()
# may be saved by fitting :class:`autoreject.AutoReject` on a # representative subsample of the data. ar = AutoReject(picks=picks, random_state=42, n_jobs=1, verbose=True) epochs_ar, reject_log = ar.fit_transform(this_epoch, return_log=True) # %% # We can visualize the cross validation curve over two variables import numpy as np # noqa import matplotlib.pyplot as plt # noqa import matplotlib.patches as patches # noqa from autoreject import set_matplotlib_defaults # noqa set_matplotlib_defaults(plt, style='seaborn-white') loss = ar.loss_['eeg'].mean(axis=-1) # losses are stored by channel type. plt.matshow(loss.T * 1e6, cmap=plt.get_cmap('viridis')) plt.xticks(range(len(ar.consensus)), ['%.1f' % c for c in ar.consensus]) plt.yticks(range(len(ar.n_interpolate)), ar.n_interpolate) # Draw rectangle at location of best parameters ax = plt.gca() idx, jdx = np.unravel_index(loss.argmin(), loss.shape) rect = patches.Rectangle((idx - 0.5, jdx - 0.5), 1, 1, linewidth=2, edgecolor='r', facecolor='none') ax.add_patch(rect) ax.xaxis.set_ticks_position('bottom') plt.xlabel(r'Consensus percentage $\kappa$') plt.ylabel(r'Max sensors interpolated $\rho$')
ar = LocalAutoRejectCV(thresh_func=thresh_func, verbose='tqdm', picks=picks) ar.fit(this_epoch) epochs_ar = ar.transform(this_epoch) ############################################################################### # We can visualize the cross validation curve over two variables import numpy as np # noqa import matplotlib.pyplot as plt # noqa import matplotlib.patches as patches # noqa from autoreject import set_matplotlib_defaults # noqa set_matplotlib_defaults(plt, style='seaborn-white') loss = ar.loss_['eeg'].mean(axis=-1) # losses are stored by channel type. plt.matshow(loss.T * 1e6, cmap=plt.get_cmap('viridis')) plt.xticks(range(len(ar.consensus_percs)), ar.consensus_percs) plt.yticks(range(len(ar.n_interpolates)), ar.n_interpolates) # Draw rectangle at location of best parameters ax = plt.gca() idx, jdx = np.unravel_index(loss.argmin(), loss.shape) rect = patches.Rectangle((idx - 0.5, jdx - 0.5), 1, 1, linewidth=2, edgecolor='r', facecolor='none') ax.add_patch(rect) ax.xaxis.set_ticks_position('bottom') plt.xlabel(r'Consensus percentage $\kappa$') plt.ylabel(r'Max sensors interpolated $\rho$')
# #for idx, evoked in enumerate(evokeds): # for cond in [1,3]: # comm = evoked[cond].comment # evoked[cond].plot_joint(title='Subject %s %s' % (idx + 1, comm)) event_id = {'stim/face':101, 'stim/house':102, 'imag/face':201, 'imag/house':202 } exclude = [7, 11] all_epochs=list() chan_range= ['PO8','PO7'] # def figure params set_matplotlib_defaults(plt) #plt.tight_layout() fig1, ax1 = plt.subplots(nrows=2, ncols=2) fig2, ax2 = plt.subplots(nrows=2, ncols=2) fig3, ax3 = plt.subplots(nrows=2, ncols=2) fig4, ax4 = plt.subplots(nrows=2, ncols=2) fig5, ax5 = plt.subplots(nrows=2, ncols=2) fig6, ax6 = plt.subplots(nrows=2, ncols=2) nplot_x=0 nplot_y =0 count=0 nsuj=0 coord=[(0,0), (0,1), (1,0), (1,1)]