epochs = Epochs(raw_filter, events, event_id, tmin - w_size, tmax + w_size, proj=False, baseline=None, preload=True) epochs.drop_bad() y = le.fit_transform(epochs.events[:, 2]) # Roll covariance, csp and lda over time for t, w_time in enumerate(centered_w_times): # Center the min and max of the window w_tmin = w_time - w_size / 2. w_tmax = w_time + w_size / 2. # Crop data into time-window of interest X = epochs.copy().crop(w_tmin, w_tmax).get_data() # Save mean scores over folds for each frequency and time window tf_scores[freq, t] = np.mean(cross_val_score(estimator=clf, X=X, y=y, scoring='roc_auc', cv=cv, n_jobs=1), axis=0) ############################################################################### # Plot time-frequency results # Set up time frequency object av_tfr = AverageTFR(create_info(['freq'], sfreq), tf_scores[np.newaxis, :], centered_w_times, freqs[1:], 1) chance = np.mean(y) # set chance level to white in the plot av_tfr.plot([0], vmin=chance, title="Time-Frequency Decoding Scores", cmap=plt.cm.Reds)
# Roll covariance, csp and lda over time for t, w_time in enumerate(centered_w_times): # Center the min and max of the window w_tmin = w_time - w_size / 2. w_tmax = w_time + w_size / 2. # Crop data into time-window of interest X = epochs.copy().crop(w_tmin, w_tmax).get_data() # Save mean scores over folds for each frequency and time window scores[freq, t] = np.mean(cross_val_score(estimator=clf, X=X, y=y, cv=cv, n_jobs=1), axis=0) ############################################################################### # Plot results # Set up time frequency object av_tfr = AverageTFR(create_info(['freq'], sfreq), scores[np.newaxis, :], centered_w_times, freqs[1:], 1) chance = np.mean(y) # set chance level to white in the plot av_tfr.plot([0], vmin=chance, title="Time-Frequency Decoding Scores", cmap=plt.cm.Reds)
c.info['subject_info'] = 'P14' c.info['cond'] = conds[ix_c] calc_wpli_over_time(c) dats = list() for c in conds: dat = np.load( op.join(study_path, 'results', 'wpli', 'P14_{}_wpli.npz'.format(c))) dats.append(dat) info = dat['info'].item() for ix_c, c in enumerate(conds): tfr = AverageTFR(info, dats[ix_c]['con'][1, :, :, :], dat['times'], dat['freqs'], 1) tfr.plot(picks=[83], vmin=-1, vmax=1, cmap='viridis', title=c) # TF ROI if ref == 'avg': rois = { 'HP_r': np.array(raw.ch_names)[picks[:4]], 'HP_l': np.array(raw.ch_names)[picks[4:]] } # :4 elif ref == 'bip': rois = { 'HP_l': np.array(raw.ch_names)[picks[:2]], 'HP_r': np.array(raw.ch_names)[picks[2:]] } roi_fig, axes = plt.subplots(len(rois), len(conds), sharey=True, sharex=True) roi_pows = {'HP_l': list(), 'HP_r': list()}