def import_evokes(evokes_fname): import importlib import mne mu.add_mmvt_code_root_to_path() from src.preproc import meg importlib.reload(meg) opt_trans_files = glob.glob( op.join(mu.get_parent_fol(evokes_fname), '*.fif')) trans_files = meg.filter_trans_files(opt_trans_files) trans_file = mu.select_one_file(trans_files, template='*.fif', files_desc='MRI-Head transformation') args = mu.get_remote_subject_info_args() evokes = mne.read_evokeds(evokes_fname) events_keys = [ev.comment for ev in evokes] meg.read_sensors_layout(mu.get_user(), args, info=evokes[0].info, trans_file=trans_file) meg.save_evokes_to_mmvt(evokes, events_keys, mu.get_user()) _addon().import_meg_sensors() _addon().add_data_to_meg_sensors() # _addon().load_all_panels() _addon().show_meg_sensors()
def dipole_fit(): mu.add_mmvt_code_root_to_path() from src.preproc import meg importlib.reload(meg) subject = mu.get_user() args = meg.read_cmd_args( dict(subject=subject, mri_subject=subject, atlas=mu.get_atlas())) meg.init(subject, args) dipoles_times = [(bpy.context.scene.meg_dipole_fit_tmin, bpy.context.scene.meg_dipole_fit_tmax)] dipoloes_title = mask_roi = MEGPanel.current_cluster['intersects'][0][ 'name'] meg.dipoles_fit(dipoles_times, dipoloes_title, None, mu.get_real_fname('meg_noise_cov_fname'), mu.get_real_fname('meg_evoked_fname'), mu.get_real_fname('head_to_mri_trans_mat_fname'), 5., bpy.context.scene.meg_dipole_fit_use_meg, bpy.context.scene.meg_dipole_fit_use_eeg, mask_roi=mask_roi, do_plot=False, n_jobs=4)
def load_surf_files(nii_fname, run_fmri_preproc=True, user_fol='', debug=True): fmri_file_template = '' if user_fol == '': user_fol = mu.get_user_fol() nii_fol = mu.get_fname_folder(nii_fname) if debug: print('load_surf_files: nii_fol: {}'.format(nii_fol)) hemi, fmri_hemis = mu.get_hemi_from_full_fname(nii_fname) if debug: print('load_surf_files: hemi, fmri_hemis: {}, {}'.format( hemi, fmri_hemis)) if hemi == '': hemi = mu.find_hemi_using_vertices_num(nii_fname) if hemi == '': return '' # fmri_hemis = mu.get_both_hemis_files(nii_fname) local_fname = build_local_fname(nii_fname, user_fol) if debug: print('load_surf_files: local_fname: {}'.format(local_fname)) mu.make_dir(op.join(user_fol, 'fmri')) if nii_fol != op.join(user_fol, 'fmri'): mu.make_link(nii_fname, local_fname, True) other_hemi = mu.other_hemi(hemi) if debug: print('load_surf_files: other_hemi: {}'.format(other_hemi)) other_hemi_fname = fmri_hemis[other_hemi] if other_hemi_fname == '': other_hemi_fname = local_fname.replace(hemi, other_hemi) if debug: print('load_surf_files: other_hemi_fname: {}'.format(other_hemi_fname)) # todo: if the other hemi file doens't exist, just create an empty one output_fname_template = '' if op.isfile(other_hemi_fname): local_other_hemi_fname = build_local_fname(other_hemi_fname, user_fol) if nii_fol != op.join(user_fol, 'fmri'): mu.make_link(other_hemi_fname, local_other_hemi_fname, True) fmri_file_template = mu.get_template_hemi_label_name( mu.namebase_with_ext(local_fname)) if run_fmri_preproc: mu.add_mmvt_code_root_to_path() from src.preproc import fMRI importlib.reload(fMRI) vertices_num = mu.get_vertices_num() ret, npy_output_fname_template = fMRI.load_surf_files( mu.get_user(), fmri_hemis, vertices_num=vertices_num) output_fname_template = op.join( mu.get_parent_fol(npy_output_fname_template), mu.namebase_with_ext(npy_output_fname_template)[len('fmri_'):]) else: mu.run_mmvt_func( 'src.preproc.fMRI', 'load_surf_files', flags='--fmri_file_template "{}"'.format(fmri_file_template)) # todo: find what should be the output_fname_template else: print( "Couldn't find the other hemi file! ({})".format(other_hemi_fname)) return output_fname_template #, hemi, other_hemi
def calc_clusters(): import importlib mu.add_mmvt_code_root_to_path() from src.preproc import fMRI importlib.reload(fMRI) surf_template_fname = 'fmri_{}.?h.npy'.format(_addon().coloring.get_select_fMRI_contrast()) print(mu.get_user(), surf_template_fname, bpy.context.scene.fmri_clustering_threshold, bpy.context.scene.atlas) fMRI.find_clusters(mu.get_user(), surf_template_fname, bpy.context.scene.fmri_clustering_threshold, bpy.context.scene.subject_annot_files)
def load_fmri_volume(nii_fname): import importlib mu.add_mmvt_code_root_to_path() from src.preproc import fMRI importlib.reload(fMRI) fmri_file_template = mu.namebase(nii_fname) subject = mu.get_user() flag, fmri_contrast_file_template = fMRI.project_volume_to_surface( subject, fmri_file_template, remote_fmri_dir=mu.get_parent_fol(nii_fname)) if not flag: print('load_fmri_volume: Error in fMRI.project_volume_to_surface!') return False flag = fMRI.calc_fmri_min_max(subject, fmri_contrast_file_template) if not flag: print('load_fmri_volume: Error in fMRI.calc_fmri_min_max!') return False # _addon().coloring.init(_addon(), register=False) fMRI_file_name = fmri_contrast_file_template.replace('fmri_', '') _addon().coloring.plot_fmri_file(fMRI_file_name) return True