def init(addon, first=True): ScriptsPanel.addon = addon user_fol = mu.get_user_fol() scripts_files = glob.glob(op.join(mu.get_mmvt_code_root(), 'src', 'examples', 'scripts', '*.py')) scripts_files_names = [mu.namebase(f) for f in scripts_files] scripts_files += [f for f in glob.glob(op.join(mu.get_parent_fol(user_fol), 'scripts', '*.py')) if mu.namebase(f) not in scripts_files_names] if len(scripts_files) == 0: return None sys.path.append(op.join(mu.get_mmvt_code_root(), 'src', 'examples', 'scripts')) sys.path.append(op.join(mu.get_parent_fol(user_fol), 'scripts')) scripts_files = sorted([f for f in scripts_files if check_script(mu.namebase(f))])[::-1] ScriptsPanel.scripts_names = files_names = [mu.namebase(fname).replace('_', ' ') for fname in scripts_files] scripts_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.scripts_files = bpy.props.EnumProperty( items=scripts_items, update=scripts_items_update, description='List of script in the folder:\n..\mmvt_root\mmvtcode\src\examples\scripts\n\nCurrent script') bpy.context.scene.scripts_files = files_names[0] bpy.context.scene.scripts_overwrite = True try: bpy.context.scene.report_use_script = bpy.context.scene.reports_files in ScriptsPanel.scripts_names except: pass # bpy.context.scene.scripts_threshold = 2 # bpy.context.scene.scripts_cb_min = 2 # bpy.context.scene.scripts_cb_max = 6 if first: register() ScriptsPanel.init = True
def init(addon_prefs): set_play_to(get_max_time_steps()) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) mmvt_utils.set_show_textured_solid() code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) os.chdir(code_fol)
def init(addon_prefs): set_play_to(get_max_time_steps()) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) mmvt_utils.set_show_textured_solid() mmvt_utils.hide_relationship_lines() code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) os.chdir(code_fol)
def init(addon): ReportsPanel.addon = addon if not PDFKIT_EXIST: print('reports_panel: no pdfkit') return None if not wkhtmltopdf_exist(): print('reports_panel: no wkhtmltopdf') return None user_fol = mu.get_user_fol() reports_files = glob.glob( op.join(mu.get_parent_fol(user_fol), 'reports', '*.html')) if len(reports_files) == 0: print('reports_panel: no reports') return None files_names = [ mu.namebase(fname).replace('_', ' ') for fname in reports_files ] reports_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.reports_files = bpy.props.EnumProperty( items=reports_items, description="reports files", update=reports_files_update) bpy.context.scene.reports_files = files_names[0] bpy.context.scene.report_use_script = files_names[0] in _addon( ).get_scripts_names() register() ReportsPanel.init = True
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 init_electrodes_labeling(addon): ela_code_fol = op.join(mu.get_parent_fol(mu.get_mmvt_code_root()), 'electrodes_rois') ElecsPanel.ela_code_exist = op.isfile( op.join(ela_code_fol, 'find_rois', 'find_rois.py')) ElecsPanel.labling_files = labling_files = find_elecrode_labeling_files() if len(labling_files) > 0: files_names = [ mu.namebase(fname) for fname in labling_files if mu.load(fname) ] labeling_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.electrodes_labeling_files = bpy.props.EnumProperty( items=labeling_items, description='Labeling files', update=electrodes_labeling_files_update) bpy.context.scene.electrodes_labeling_files = files_names[0] # ElecsPanel.electrodes_locs = mu.load(labling_files[0]) # ElecsPanel.lookup = create_lookup_table(ElecsPanel.electrodes_locs, ElecsPanel.electrodes) ElecsPanel.faces_verts = addon.get_faces_verts() atlases = mu.get_annot_files() if len(atlases) > 0: ElecsPanel.atlases_exist = True atlases_items = [(c, c, '', ind) for ind, c in enumerate(atlases)] bpy.types.Scene.ela_atlas = bpy.props.EnumProperty( items=atlases_items, description='atlases') bpy.context.scene.ela_atlas = atlases[0] bpy.context.scene.ela_bipolar = bpy.context.scene.bipolar return len(labling_files) > 0
def init_logo(): import bpy.utils.previews pcoll = bpy.utils.previews.new() hnn_icons_dir = op.join(mu.get_parent_fol(mu.get_user_fol()), 'icons') # load a preview thumbnail of a file and store in the previews collection pcoll.load("hnn_icon", os.path.join(hnn_icons_dir, "hnn.png"), 'IMAGE') preview_collections["main"] = pcoll
def run_ela_alg(): mmvt_code_fol = mu.get_mmvt_code_root() ela_code_fol = op.join(mu.get_parent_fol(mmvt_code_fol), 'electrodes_rois') if not op.isdir(ela_code_fol) or not op.isfile(op.join(ela_code_fol, 'find_rois', 'find_rois.py')): print("Can't find ELA folder!") return import importlib import sys if ela_code_fol not in sys.path: sys.path.append(ela_code_fol) from find_rois import find_rois importlib.reload(find_rois) args = find_rois.get_args(['-s', mu.get_user(), '-a', bpy.context.scene.ela_atlas, '-b', str(bpy.context.scene.ela_bipolar)]) find_rois.run_for_all_subjects(args) import shutil ela_output_fname_template = op.join( ela_code_fol, 'electrodes', '{}_{}_electrodes_cigar_r_*_l_*{}.pkl'.format( mu.get_user(), bpy.context.scene.ela_atlas, '_bipolar' if bpy.context.scene.ela_bipolar else '' )) ela_output_fnames = glob.glob(ela_output_fname_template) if len(ela_output_fnames) > 0: for ela_output_fname in ela_output_fnames: shutil.copyfile(ela_output_fname, op.join( mu.get_user_fol(), 'electrodes', mu.namebase_with_ext(ela_output_fname))) else: print('couldn\'t find any ELA output! ({})'.format(ela_output_fname_template)) init(_addon(), False)
def wkhtmltopdf_exist(): wkhtmltopdf_bin_path = op.join(mu.get_parent_fol(mu.get_user_fol()), 'reports') wkhtmltopdf_bin_name = 'wkhtmltopdf.exe' if mu.is_windows( ) else 'wkhtmltopdf' if not op.isfile(op.join(wkhtmltopdf_bin_path, wkhtmltopdf_bin_name)): print("Reports panel: Can't find wkhtmltopdf!" + \ 'Please download wkhtmltopdf ({}) and put it in {}'.format( 'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf', wkhtmltopdf_bin_path)) return False os.environ["PATH"] += os.pathsep + wkhtmltopdf_bin_path if mu.is_windows(): wkhtmltopdf = subprocess.Popen( ['where', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip() else: wkhtmltopdf = subprocess.Popen( ['which', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip() try: with open(wkhtmltopdf) as f: return True except IOError: print('Reports panel: No wkhtmltopdf executable found! ' + \ '(https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf)') return False
def load_connections_file(): d, vertices, vertices_lookup = None, None, None conn_file_name = bpy.context.scene.connectivity_files.replace(' ', '_') connectivity_file = op.join(mu.get_user_fol(), 'connectivity', '{}.npz'.format(conn_file_name)) vertices_file = op.join(mu.get_user_fol(), 'connectivity', '{}_vertices.pkl'.format( conn_file_name.replace('_static', ''))) if op.isfile(connectivity_file): print('loading connectivity: {}'.format(connectivity_file)) d = mu.Bag(np.load(connectivity_file)) d.labels = [l.astype(str) for l in d.labels] d.hemis = [l.astype(str) for l in d.hemis] d.con_names = np.array([l.astype(str) for l in d.con_names], dtype=np.str) d.conditions = [l.astype(str) for l in d.conditions] if d.con_values.ndim == 2: d.con_values = d.con_values[:, :, np.newaxis] conditions_items = [(cond, cond, '', cond_ind) for cond_ind, cond in enumerate(d.conditions)] if len(d.conditions) > 1: diff_cond = '{}-{} difference'.format(d.conditions[0], d.conditions[1]) conditions_items.append((diff_cond, diff_cond, '', len(d.conditions))) bpy.types.Scene.conditions = bpy.props.EnumProperty(items=conditions_items, description="Conditions") # bpy.context.scene.connections_max, bpy.context.scene.connections_min = d['data_max'], d['data_min'] else: print('No connections file! {}'.format(connectivity_file)) if op.isfile(vertices_file): vertices, vertices_lookup = mu.load(vertices_file) else: name_parts = mu.namebase(vertices_file).split('_') vertices_files = glob.glob( op.join(mu.get_parent_fol(vertices_file), '{}*_{}.pkl'.format(name_parts[0], name_parts[-1]))) if len(vertices_files) == 1: vertices, vertices_lookup = mu.load(vertices_files[0]) else: print('No vertices file! ({})'.format(vertices_file)) ConnectionsPanel.d, ConnectionsPanel.vertices, ConnectionsPanel.vertices_lookup = d, vertices, vertices_lookup
def read_report_html(): fol = op.join(mu.get_parent_fol(mu.get_user_fol()), 'reports') report_fname = op.join( fol, '{}.html'.format(bpy.context.scene.reports_files.replace(' ', '_'))) with open(report_fname, 'r') as f: report_text = f.read() return report_text
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 execute(self, context): _addon().clear_colors() fmri_file_template = load_surf_files(self.filepath[:-2]) if fmri_file_template != '': _addon().plot_fmri_file(fmri_file_template) if mu.get_parent_fol(self.filepath) != op.join( mu.get_user_fol(), 'fmri'): clean_nii_temp_files(fmri_file_template) return {'RUNNING_MODAL'}
def main(addon_prefs=None): show_electrodes(False) show_connections(False) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) os.chdir(code_fol) try: # _listener_in_queue, _listener__out_queue = start_listener() current_module = sys.modules[__name__] appearance_panel.init(current_module) show_hide_panel.init(current_module) selection_panel.init(current_module) coloring_panel.init(current_module) electrodes_panel.init(current_module) play_panel.init(current_module) filter_panel.init(current_module) freeview_panel.init(current_module, addon_prefs) render_panel.init(current_module) fMRI_panel.init(current_module) search_panel.init(current_module) transparency_panel.init(current_module) where_am_i_panel.init(current_module) data_panel.init(current_module) stim_panel.init(current_module) dti_panel.init(current_module) connections_panel.init(current_module) # listener_panel.init(current_module) vertex_data_panel.init(current_module) except: print('The classes are already registered!') print(traceback.format_exc()) show_activity()
def init(addon): if not bpy.data.objects.get('full_colorbar', None): print("No full_colorbar object, Can't load the colorbar panel") return ColorbarPanel.addon = addon colorbar_files_fol = mu.make_dir( op.join(mu.get_parent_fol(mu.get_user_fol()), 'color_maps')) colorbar_files_code_fol = op.join(mu.get_resources_dir(), 'color_maps') colorbar_files_template = op.join(colorbar_files_fol, '*.npy') colorbar_files_code_template = op.join(colorbar_files_code_fol, '*.npy') # colorbar_files_template = op.join(mu.file_fol(), 'color_maps', '*.npy') colorbar_files = glob.glob(colorbar_files_template) colorbar_code_files = glob.glob(colorbar_files_code_template) extra_files = list( set([mu.namebase_with_ext(f) for f in colorbar_code_files]) - set([mu.namebase_with_ext(f) for f in colorbar_files])) for extra_file in extra_files: print('Coping missing cb file: {}'.format( mu.namebase_with_ext(extra_file))) shutil.copyfile( op.join(colorbar_files_code_fol, extra_file), op.join(colorbar_files_fol, mu.namebase_with_ext(extra_file))) if len(colorbar_files) == 0: print("No colorbar files ({}), Can't load the colorbar panel".format( colorbar_files_template)) return None colorbar_files = glob.glob(colorbar_files_template) files_names = [mu.namebase(fname) for fname in colorbar_files] # .replace('_', '-') ColorbarPanel.maps_names = files_names colorbar_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.colorbar_files = bpy.props.EnumProperty( items=colorbar_items, update=colormap_update, description='Selects the colorbar color palette.\n\nCurrent palette') if not colorbar_values_are_locked(): bpy.context.scene.colorbar_files = files_names[0] else: load_colormap() for space in mu.get_3d_spaces(): if space.lock_object and space.lock_object.name == 'full_colorbar': space.show_only_render = True register() ColorbarPanel.init = True bpy.context.scene.show_cb_in_render = False mu.select_hierarchy('colorbar_camera', False, False) if not ColorbarPanel.colorbar_updated and not colorbar_values_are_locked(): ColorbarPanel.should_not_lock_values = True # bpy.context.scene.colorbar_min = -1 # bpy.context.scene.colorbar_max = 1 # bpy.context.scene.colorbar_title = ' MEG' bpy.context.scene.colorbar_y = 0.18 bpy.context.scene.colorbar_text_y = -1.53 bpy.context.scene.colorbar_prec = 2 ColorbarPanel.should_not_lock_values = False
def modal(self, context, event): if event.type == 'TIMER' and ChooseNiftiiFile.running: if mu.both_hemi_files_exist(self.fmri_npy_template_fname): _addon().plot_fmri_file(self.fmri_file_template) if mu.get_parent_fol(self.filepath) != op.join( mu.get_user_fol(), 'fmri'): clean_nii_temp_files(self.fmri_file_template) ChooseNiftiiFile.running = False bpy.context.scene.nii_label_output = '' self.cancel(context) return {'PASS_THROUGH'}
def draw(self, context): layout = self.layout user_fol = mu.get_user_fol() aparc_name = bpy.context.scene.atlas faces_verts_exist = mu.hemi_files_exists(op.join(user_fol, 'faces_verts_{hemi}.npy')) fmri_files = glob.glob(op.join(user_fol, 'fmri', '*_lh.npy')) # mu.hemi_files_exists(op.join(user_fol, 'fmri_{hemi}.npy')) # fmri_clusters_files_exist = mu.hemi_files_exists(op.join(user_fol, 'fmri', 'fmri_clusters_{hemi}.npy')) meg_files_exist = mu.hemi_files_exists(op.join(user_fol, 'activity_map_{hemi}', 't0.npy')) meg_labels_files_exist = op.isfile(op.join(user_fol, 'labels_vertices_{}.pkl'.format(aparc_name))) and \ mu.hemi_files_exists(op.join(user_fol, 'meg_labels_coloring_{hemi}.npz')) electrodes_files_exist = op.isfile(op.join(mu.get_user_fol(), 'electrodes', 'electrodes_data_{}.npz'.format( 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff'))) or \ op.isfile(op.join(mu.get_user_fol(), 'electrodes', 'electrodes_data_{}_data.npy'.format( 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff'))) electrodes_stim_files_exist = len(glob.glob(op.join( mu.get_user_fol(), 'electrodes', 'stim_electrodes_*.npz'))) > 0 electrodes_labels_files_exist = len(glob.glob(op.join( mu.get_user_fol(), 'electrodes', '*_labels_*.npz'))) > 0 and \ len(glob.glob(op.join(mu.get_user_fol(), 'electrodes', '*_subcortical_*.npz'))) > 0 manually_color_files_exist = len(glob.glob(op.join(user_fol, 'coloring', '*.csv'))) > 0 manually_groups_file_exist = op.isfile(op.join(mu.get_parent_fol(user_fol), '{}_groups.csv'.format(bpy.context.scene.atlas))) volumetric_coloring_files_exist = len(glob.glob(op.join(user_fol, 'coloring', 'volumetric', '*.csv'))) layout.prop(context.scene, 'coloring_threshold', text="Threshold") layout.prop(context.scene, 'coloring_both_pial_and_inflated', text="Both pial & inflated") if faces_verts_exist: if meg_files_exist: layout.operator(ColorMeg.bl_idname, text="Plot MEG ", icon='POTATO') if op.isfile(op.join(mu.get_user_fol(), 'subcortical_meg_activity.npz')): layout.prop(context.scene, 'coloring_meg_subcorticals', text="Plot also subcorticals") # if meg_labels_files_exist: # layout.operator(ColorMegLabels.bl_idname, text="Plot MEG Labels ", icon='POTATO') if len(fmri_files) > 0: layout.prop(context.scene, "fmri_files", text="") layout.operator(ColorFmri.bl_idname, text="Plot fMRI ", icon='POTATO') if manually_color_files_exist: layout.prop(context.scene, "coloring_files", text="") layout.operator(ColorManually.bl_idname, text="Color Manually", icon='POTATO') if manually_groups_file_exist: layout.prop(context.scene, 'labels_groups', text="") layout.operator(ColorGroupsManually.bl_idname, text="Color Groups", icon='POTATO') if volumetric_coloring_files_exist: layout.prop(context.scene, "vol_coloring_files", text="") layout.operator(ColorVol.bl_idname, text="Color Volumes", icon='POTATO') if not bpy.data.objects.get('eeg_helmet', None) is None: layout.operator(ColorEEGHelmet.bl_idname, text="Plot EEG Helmet", icon='POTATO') if electrodes_files_exist: layout.operator(ColorElectrodes.bl_idname, text="Plot Electrodes", icon='POTATO') if electrodes_labels_files_exist: layout.prop(context.scene, "electrodes_sources_files", text="") layout.operator(ColorElectrodesLabels.bl_idname, text="Plot Electrodes Sources", icon='POTATO') if electrodes_stim_files_exist: layout.operator(ColorElectrodesStim.bl_idname, text="Plot Electrodes Stimulation", icon='POTATO') layout.operator(ClearColors.bl_idname, text="Clear", icon='PANEL_CLOSE')
def init(addon_prefs): global settings run_faulthandler() print('filepath: {}'.format(bpy.data.filepath)) set_play_to(get_max_time_steps()) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # bpy.data.screens['Neuro'].areas[1].spaces[0].region_3d.view_rotation = [1, 0, 0, 0] make_all_fcurve_visible() # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) mmvt_utils.set_show_textured_solid() mmvt_utils.hide_relationship_lines() code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) settings = mmvt_utils.read_config_ini() os.chdir(code_fol) bpy.context.scene.mmvt_initialized = True
def draw(self, context): layout = self.layout user_fol = mu.get_user_fol() aparc_name = bpy.context.scene.atlas faces_verts_exist = mu.hemi_files_exists(op.join(user_fol, 'faces_verts_{hemi}.npy')) fmri_files = glob.glob(op.join(user_fol, 'fmri', '*_lh.npy')) # mu.hemi_files_exists(op.join(user_fol, 'fmri_{hemi}.npy')) # fmri_clusters_files_exist = mu.hemi_files_exists(op.join(user_fol, 'fmri', 'fmri_clusters_{hemi}.npy')) meg_files_exist = mu.hemi_files_exists(op.join(user_fol, 'activity_map_{hemi}', 't0.npy')) meg_labels_files_exist = op.isfile(op.join(user_fol, 'labels_vertices_{}.pkl'.format(aparc_name))) and \ mu.hemi_files_exists(op.join(user_fol, 'meg_labels_coloring_{hemi}.npz')) electrodes_files_exist = op.isfile(op.join(mu.get_user_fol(), 'electrodes', 'electrodes_data_{}.npz'.format( 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff'))) or \ op.isfile(op.join(mu.get_user_fol(), 'electrodes', 'electrodes_data_{}_data.npy'.format( 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff'))) electrodes_stim_files_exist = len(glob.glob(op.join( mu.get_user_fol(), 'electrodes', 'stim_electrodes_*.npz'))) > 0 electrodes_labels_files_exist = len(glob.glob(op.join( mu.get_user_fol(), 'electrodes', '*_labels_*.npz'))) > 0 and \ len(glob.glob(op.join(mu.get_user_fol(), 'electrodes', '*_subcortical_*.npz'))) > 0 manually_color_files_exist = len(glob.glob(op.join(user_fol, 'coloring', '*.csv'))) > 0 manually_groups_file_exist = op.isfile(op.join(mu.get_parent_fol(user_fol), '{}_groups.csv'.format(bpy.context.scene.atlas))) volumetric_coloring_files_exist = len(glob.glob(op.join(user_fol, 'coloring', 'volumetric', '*.csv'))) layout.prop(context.scene, 'coloring_threshold', text="Threshold") if faces_verts_exist: if meg_files_exist: layout.operator(ColorMeg.bl_idname, text="Plot MEG ", icon='POTATO') # if meg_labels_files_exist: # layout.operator(ColorMegLabels.bl_idname, text="Plot MEG Labels ", icon='POTATO') if len(fmri_files) > 0: layout.prop(context.scene, "fmri_files", text="") layout.operator(ColorFmri.bl_idname, text="Plot fMRI ", icon='POTATO') if manually_color_files_exist: layout.prop(context.scene, "coloring_files", text="") layout.operator(ColorManually.bl_idname, text="Color Manually", icon='POTATO') if manually_groups_file_exist: layout.prop(context.scene, 'labels_groups', text="") layout.operator(ColorGroupsManually.bl_idname, text="Color Groups", icon='POTATO') if volumetric_coloring_files_exist: layout.prop(context.scene, "vol_coloring_files", text="") layout.operator(ColorVol.bl_idname, text="Color Volumes", icon='POTATO') if electrodes_files_exist: layout.operator(ColorElectrodes.bl_idname, text="Plot Electrodes", icon='POTATO') if electrodes_labels_files_exist: layout.prop(context.scene, "electrodes_sources_files", text="") layout.operator(ColorElectrodesLabels.bl_idname, text="Plot Electrodes Sources", icon='POTATO') if electrodes_stim_files_exist: layout.operator(ColorElectrodesStim.bl_idname, text="Plot Electrodes Stimulation", icon='POTATO') layout.operator(ClearColors.bl_idname, text="Clear", icon='PANEL_CLOSE')
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
def init(addon): if not bpy.data.objects.get('full_colorbar', None): print("No full_colorbar object, Can't load the colorbar panel") return ColorbarPanel.addon = addon colorbar_files_template = op.join(mu.get_parent_fol(mu.get_user_fol()), 'color_maps', '*.npy') # colorbar_files_template = op.join(mu.file_fol(), 'color_maps', '*.npy') colorbar_files = glob.glob(colorbar_files_template) if len(colorbar_files) == 0: print("No colorbar files ({}), Can't load the colorbar panel".format( colorbar_files_template)) return None files_names = [mu.namebase(fname) for fname in colorbar_files] # .replace('_', '-') ColorbarPanel.maps_names = files_names colorbar_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.colorbar_files = bpy.props.EnumProperty( items=colorbar_items, description="colormaps files", update=colormap_update) if not colorbar_values_are_locked(): bpy.context.scene.colorbar_files = files_names[0] else: load_colormap() for space in mu.get_3d_spaces(): if space.lock_object and space.lock_object.name == 'full_colorbar': space.show_only_render = True register() ColorbarPanel.init = True bpy.context.scene.show_cb_in_render = False mu.select_hierarchy('colorbar_camera', False, False) if not ColorbarPanel.colorbar_updated and not colorbar_values_are_locked(): ColorbarPanel.should_not_lock_values = True # bpy.context.scene.colorbar_min = -1 # bpy.context.scene.colorbar_max = 1 # bpy.context.scene.colorbar_title = ' MEG' bpy.context.scene.colorbar_y = 0.18 bpy.context.scene.colorbar_text_y = -1.53 bpy.context.scene.colorbar_prec = 2 ColorbarPanel.should_not_lock_values = False
def read_groups_labels(colors): groups_fname = op.join(mu.get_parent_fol(mu.get_user_fol()), '{}_groups.csv'.format(bpy.context.scene.atlas)) if not op.isfile(groups_fname): return {} groups = defaultdict(list) # OrderedDict() # defaultdict(list) color_ind = 0 for line in mu.csv_file_reader(groups_fname): group_name = line[0] group_color = line[1] labels = line[2:] if group_name[0] == '#': continue groups[group_name] = [] for label in labels: # group_color = cu.name_to_rgb(colors[color_ind]) groups[group_name].append(dict(name=label, color=cu.name_to_rgb(group_color))) color_ind += 1 order_groups = OrderedDict() groups_names = sorted(list(groups.keys())) for group_name in groups_names: order_groups[group_name] = groups[group_name] return order_groups
def execute(self, context): _addon().clear_colors() fmri_file_template = load_surf_files(self.filepath[:-2]) _addon().plot_fmri_file(fmri_file_template) if mu.get_parent_fol(self.filepath) != op.join( mu.get_user_fol(), 'fmri'): clean_nii_temp_files(fmri_file_template) # self.fmri_file_template, hemi, other_hemi = load_surf_files(self.filepath[:-2]) # if hemi == '': # bpy.context.scene.nii_label_prompt = "Can't determine the hemi!" # return {'RUNNING_MODAL'} # self.fmri_npy_template_fname = op.join(mu.get_user_fol(), 'fmri', 'fmri_{}.npy'.format( # mu.namebase(self.fmri_file_template))) # print('Waiting for both hemi files to be created ({})'.format(self.fmri_npy_template_fname)) # if self.fmri_file_template != '': # bpy.context.scene.nii_label_output = 'Loading nii file...' # ChooseNiftiiFile.running = True # context.window_manager.modal_handler_add(self) # self._timer = context.window_manager.event_timer_add(0.1, context.window) # else: # bpy.context.scene.nii_label_prompt = 'Please select the nii file for the {} hemi'.format( # 'right' if hemi == 'lh' else 'left') return {'RUNNING_MODAL'}