def source_estimate(name, save_dir, lowpass, method, overwrite): inverse_operator = io.read_inverse_operator(name, save_dir, lowpass) to_reconstruct = io.read_evokeds(name, save_dir, lowpass) evokeds = io.read_evokeds(name, save_dir, lowpass) stcs = dict() for to_reconstruct_index, evoked in enumerate(evokeds): stc_name = name + filter_string(lowpass) + '_' + evoked.comment + \ '_' + method + '-lh.stc' stc_path = join(save_dir, stc_name) if overwrite or not isfile(stc_path): trial_type = evoked.comment stcs[trial_type] = mne.minimum_norm.apply_inverse( to_reconstruct[to_reconstruct_index], inverse_operator, method=method) else: print('source estimates for: '+ stc_path + \ ' already exists') for stc in stcs: stc_name = name + filter_string(lowpass) + '_' + stc + '_' + method stc_path = join(save_dir, stc_name) if overwrite or not isfile(stc_path + '-lh.stc'): stcs[stc].save(stc_path)
def plot_evokeds(name, save_dir, lowpass, subject, save_plots, figures_path): evokeds = io.read_evokeds(name, save_dir, lowpass) order = [ 'standard_1', 'standard_2', 'standard_3', 'standard_4', 'standard_5', 'omission_4', 'omission_5', 'omission_6', 'non_stimulation' ] colours = [ 'white', 'blue', 'green', 'purple', 'yellow', 'red', 'orange', 'pink', 'grey' ] # sort evokeds plot_evokeds = [] plot_standards = [] plot_omissions = [] for evoked_type in order: for evoked in evokeds: if evoked.comment == evoked_type: plot_evokeds.append(evoked) if evoked.comment == evoked_type and \ (evoked.comment[0] == 's' or evoked.comment[0] == 'n'): plot_standards.append(evoked) if evoked.comment == evoked_type and \ (evoked.comment[0] == 'o' or evoked.comment[0] == 'n'): plot_omissions.append(evoked) plt.close('all') evoked_figure = mne.viz.plot_evoked_topo(plot_evokeds, color=colours, show=False) evoked_figure.comment = 'all_evokeds_' standards_figure = mne.viz.plot_evoked_topo(plot_standards, color=colours[:5] + colours[8:9], show=False) standards_figure.comment = 'standards_evokeds_' omissions_figure = mne.viz.plot_evoked_topo(plot_omissions, color=colours[5:9], show=False) omissions_figure.comment = 'omissions_evokeds_' figures = [evoked_figure, standards_figure, omissions_figure] if save_plots: for figure in figures: save_path = join(figures_path, subject, 'evokeds', figure.comment + name + \ filter_string(lowpass) + '.jpg') figure.savefig(save_path, dpi=600) print 'figure: ' + save_path + ' has been saved' else: print 'Not saving plots; set "save_plots" to "True" to save'
def plot_butterfly_evokeds(name, save_dir, lowpass, subject, save_plots, figures_path): evokeds = io.read_evokeds(name, save_dir, lowpass) for evoked in evokeds: figure = evoked.plot(show=False) if save_plots: save_path = join(figures_path, subject, 'evokeds', 'butterfly_' + evoked.comment + '_' + name + \ filter_string(lowpass) + '.jpg') figure.savefig(save_path, dpi=600) print 'figure: ' + save_path + ' has been saved' else: print 'Not saving plots; set "save_plots" to "True" to save'
# MORPH TO FSAVERAGE #========================================================================== if operations_to_apply['morph_to_fsaverage']: stcs = operations.morph_data_to_fsaverage(name, save_dir, subjects_dir, subject, lowpass, method=method, overwrite=overwrite) #========================================================================== # GRAND AVERAGE EVOKEDS (within-subject part) #========================================================================== if operations_to_apply['grand_averages_evokeds']: evoked_data = io.read_evokeds(name, save_dir, lowpass) for evoked in evoked_data: trial_type = evoked.comment evoked_data_all[trial_type].append(evoked) #========================================================================== # GRAND AVERAGE MORPHED DATA (within-subject part) #========================================================================== if operations_to_apply['average_morphed_data'] or \ operations_to_apply['statistics_source_space']: morphed_data = io.read_source_estimates(name, save_dir, lowpass, method=method, morphed=True) for trial_type in morphed_data: