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 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 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(addon): SlicerPanel.addon = addon bpy.context.scene.show_full_slice = False create_joint_brain_obj() # print('init slicer') # bpy.context.scene.is_sliced_ind = -1 # bpy.context.scene.last_cursor_location = [0.0, 0.0, 0.0] bpy.types.Scene.last_cursor_location = bpy.props.FloatVectorProperty( default=(0.0, 0.0, 0.0), size=3) bpy.types.Scene.is_sliced_ind = bpy.props.IntProperty(default=-1) bpy.context.scene.last_cursor_location = (0.0, 0.0, 0.0) bpy.context.scene.is_sliced_ind = -1 bpy.context.scene.slicer_cut_type = 'coronal' ct_trans_fname = op.join(mu.get_user_fol(), 'ct', 'ct_trans.npz') t2_trans_fname = op.join(mu.get_user_fol(), 't2_trans.npz') if op.isfile(ct_trans_fname) or op.isfile(t2_trans_fname): items_ind = 1 items = [('mri', 'MRI', '', items_ind)] if op.isfile(t2_trans_fname): SlicerPanel.t2_exist = True items_ind += 1 items.append(('t2', 'T2', '', items_ind)) if op.isfile(ct_trans_fname): items_ind += 1 SlicerPanel.ct_exist = True items.append(('ct', 'CT', '', items_ind)) if op.isfile(op.join(mu.get_user_fol(), 'ct', 't1_ct.mgz')): items_ind += 1 SlicerPanel.t1_ct_exist = True items.append(('t1_ct', 'T1&CT', '', items_ind)) bpy.types.Scene.slices_modality = bpy.props.EnumProperty( items=items, update=slices_modality_update) pial_vol_mask_fname = op.join(mu.get_user_fol(), 'freeview', 'pial_vol_mask.npy') dural_vol_mask_fname = op.join(mu.get_user_fol(), 'freeview', 'dural_vol_mask.npy') bpy.context.scene.pial_vol_mask_exist = op.isfile(pial_vol_mask_fname) bpy.context.scene.dural_vol_mask_exist = op.isfile(dural_vol_mask_fname) bpy.context.scene.slices_show_pial = False bpy.context.scene.slices_show_dural = False bpy.context.scene.slices_modality_mix = 0 bpy.context.scene.slices_zoom = 1 bpy.context.scene.new_electrode_num = 1 bpy.context.scene.slices_zoom_around_voxel = False bpy.context.scene.slices_zoom_voxels_num = 30 bpy.context.scene.slices_zoom_interpolate = False bpy.context.scene.slices_plot_cross = True bpy.context.scene.slices_mark_voxel = True bpy.context.scene.slices_modality = 'mri' empty_brain_path = op.join(mu.get_mmvt_code_root(), 'resources', 'empty_subject.blend', 'Material') for slice_str in ['coronal', 'sagital', 'axial']: cur_mat_name = '{}_plane_mat'.format(slice_str) if bpy.data.materials.get(cur_mat_name) is None: print('Importing {} from empty_brain file'.format(cur_mat_name)) bpy.ops.wm.append(filename=cur_mat_name, directory=empty_brain_path) # bpy.context.scene['slice_plane_flipped'] = {'coronal': False, 'axial': False, 'sagital': False} SlicerPanel.init = True register()