def main(tup, remote_subject_dir, args, flags): (subject, mri_subject), inverse_method = tup evoked, epochs = None, None conditions, stat = init(subject, args, mri_subject, remote_subject_dir) if utils.should_run(args, 'read_sensors_layout'): flags['read_sensors_layout'] = read_sensors_layout_args( mri_subject, args) flags, evoked, epochs = meg.calc_evokes_wrapper(subject, conditions, args, flags, mri_subject=mri_subject) flags = meg.calc_fwd_inv_wrapper(subject, args, conditions, flags, mri_subject) flags, stcs_conds, stcs_num = meg.calc_stc_per_condition_wrapper( subject, conditions, inverse_method, args, flags) flags = meg.calc_labels_avg_per_condition_wrapper(subject, conditions, args.atlas, inverse_method, stcs_conds, args, flags, stcs_num, None, epochs) if 'calc_stc_zvals' in args.function: flags['calc_stc_zvals'] = meg.calc_stc_zvals( subject, args.stc_name, args.baseline_stc_name, 'eeg', args.use_abs, args.from_index, args.to_index, args.stc_zvals_name, False, args.overwrite_stc) if utils.should_run(args, 'create_helmet_mesh'): flags['create_helmet_mesh'] = create_helmet_mesh( mri_subject, args.eeg_electrodes_excluded_from_mesh) if utils.should_run(args, 'save_evoked_to_blender'): flags['save_evoked_to_blender'] = save_evoked_to_blender( mri_subject, conditions, args, evoked) if utils.should_run(args, 'calc_minmax'): flags['calc_minmax'] = calc_minmax(mri_subject, args) if 'plot_evoked' in args.function: flags['plot_evoked'], _ = plot_evoked(args.evo_fname, args.evoked_key, args.pick_meg, args.pick_eeg, args.pick_eog, args.ssp_proj, args.spatial_colors, args.window_title, args.hline, args.channels_to_exclude) if 'snap_sensors_to_outer_skin' in args.function: flags['snap_sensors_to_outer_skin'] = snap_sensors_to_outer_skin( mri_subject) return flags
def main(tup, remote_subject_dir, args, flags): (subject, mri_subject), inverse_method = tup evoked, epochs = None, None conditions, stat = init(subject, args, mri_subject, remote_subject_dir) if utils.should_run(args, 'read_eeg_sensors_layout'): flags['read_eeg_sensors_layout'] = read_eeg_sensors_layout( subject, mri_subject, args) flags, evoked, epochs = meg.calc_evokes_wrapper(subject, conditions, args, flags, mri_subject=mri_subject) if utils.should_run(args, 'create_eeg_mesh'): flags['create_eeg_mesh'] = create_eeg_mesh( mri_subject, args.eeg_electrodes_excluded_from_mesh) if utils.should_run(args, 'save_evoked_to_blender'): flags['save_evoked_to_blender'] = save_evoked_to_blender( mri_subject, conditions, args, evoked) if utils.should_run(args, 'calc_minmax'): flags['calc_minmax'] = calc_minmax(mri_subject, args) if utils.should_run(args, 'make_forward_solution') or utils.should_run(args, 'calc_inverse_operator') or \ utils.should_run(args, 'calc_stc'): if not op.isfile(meg.COR): eeg_cor = op.join(meg.SUBJECT_MEG_FOLDER, '{}-cor-trans.fif'.format(subject)) if op.isfile(eeg_cor): meg.COR = eeg_cor flags = meg.calc_fwd_inv_wrapper(subject, args, conditions, flags, mri_subject) flags = meg.calc_stc_per_condition_wrapper( subject, conditions, inverse_method, args, flags) else: print( "Can't find head-MRI transformation matrix. Should be in {} or in {}" .format(meg.COR, eeg_cor)) return flags
def calc_per_session(subject, condition, ctf_raw_data, inverse_method, args, all_eog_inds, eog_channel, calc_stc_per_session, only_examine_ica, overwrite_raw, plot_evoked, filter_raw_data, raw_data_filter_freqs): session = ctf_raw_data[-4] cond = list(condition.keys())[0] freqs_str = '-{}-{}'.format( raw_data_filter_freqs[0], raw_data_filter_freqs[1]) if filter_raw_data else '' args.raw_fname = op.join(MEG_DIR, subject, '{}-session{}-raw.fif'.format(cond, session)) new_raw_no_filter_fname = op.join( MEG_DIR, subject, '{}-session{}-ica-raw.fif'.format(cond, session)) new_raw_fname = op.join( MEG_DIR, subject, '{}-session{}{}-ica-raw.fif'.format(cond, session, freqs_str)) args.epo_fname = op.join( MEG_DIR, subject, '{}-session{}{}-epo.fif'.format(cond, session, freqs_str)) args.evo_fname = op.join( MEG_DIR, subject, '{}-session{}{}-ave.fif'.format(cond, session, freqs_str)) args.inv_fname = op.join(MEG_DIR, subject, '{}-session{}-inv.fif'.format(cond, session)) args.fwd_fname = op.join(MEG_DIR, subject, '{}-session{}-fwd.fif'.format(cond, session)) args.noise_cov_fname = op.join( MEG_DIR, subject, '{}-session{}-noise-cov.fif'.format(cond, session)) args.stc_template = op.join( MEG_DIR, subject, '{cond}-session' + session + '-{method}' + freqs_str + '.stc') stc_hemi_template = meg.get_stc_hemi_template(args.stc_template) if check_if_all_done(new_raw_fname, cond, inverse_method, calc_stc_per_session, stc_hemi_template, args.labels_data_template, args): return ica_fname = op.join(MEG_DIR, subject, '{}-session{}-ica.fif'.format(cond, session)) if len(all_eog_inds) > 0: session_ind = np.where( all_eog_inds[:, 0] == utils.namebase_with_ext(ica_fname))[0][0] eog_inds = [int(all_eog_inds[session_ind, 1])] else: eog_inds = [] if only_examine_ica: meg.fit_ica(ica_fname=ica_fname, do_plot=True, examine_ica=True, n_jobs=args.n_jobs) return if not op.isfile(new_raw_fname) or overwrite_raw or not op.isfile( ica_fname): if not op.isfile(args.raw_fname): raw = mne.io.read_raw_ctf(op.join(MEG_DIR, subject, 'raw', ctf_raw_data), preload=True) raw.save(args.raw_fname) if not op.isfile(new_raw_no_filter_fname): raw = mne.io.read_raw_fif(args.raw_fname, preload=True) raw = meg.remove_artifacts(raw, remove_from_raw=True, overwrite_ica=args.overwrite_ica, save_raw=True, raw_fname=new_raw_fname, new_raw_fname=new_raw_no_filter_fname, ica_fname=ica_fname, do_plot=args.do_plot_ica, eog_inds=eog_inds, eog_channel=eog_channel, n_jobs=args.n_jobs) else: raw = mne.io.read_raw_fif(new_raw_no_filter_fname, preload=True) meg.calc_noise_cov(None, args.noise_t_min, args.noise_t_max, args.noise_cov_fname, args, raw) if filter_raw_data: raw.filter(raw_data_filter_freqs[0], raw_data_filter_freqs[1], h_trans_bandwidth='auto', filter_length='auto', phase='zero') print('Saving new raw file in {}'.format(new_raw_fname)) if overwrite_raw or not op.isfile(new_raw_fname): raw.save(new_raw_fname, overwrite=True) else: raw = mne.io.read_raw_fif(new_raw_fname, preload=True) evoked, epochs = None, None if not op.isfile(args.epo_fname) or not op.isfile(args.evo_fname): _, evoked, epochs = meg.calc_evokes_wrapper(subject, condition, args, raw=raw) if evoked is not None and plot_evoked: fig = evoked[0].plot_joint(times=[-0.5, 0.05, 0.150, 0.250, 0.6]) plt.show() if calc_stc_per_session: meg.calc_fwd_inv_wrapper(subject, args, condition) # stcs_conds = None if not utils.both_hemi_files_exist( stc_hemi_template.format( cond=cond, method=inverse_method, hemi='{hemi}')): _, stcs_conds, stcs_num = meg.calc_stc_per_condition_wrapper( subject, condition, inverse_method, args)