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 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 init(addon): user_fol = mu.get_user_fol() # clusters_labels_files = glob.glob(op.join(user_fol, 'fmri', 'clusters_labels_*.pkl')) # old code was saving those files as npy instead of pkl # clusters_labels_files.extend(glob.glob(op.join(user_fol, 'fmri', 'clusters_labels_*.npy'))) # fmri_blobs = glob.glob(op.join(user_fol, 'fmri', 'blobs_*_rh.npy')) fMRIPanel.addon = addon fMRIPanel.lookup, fMRIPanel.clusters_labels = {}, {} fMRIPanel.cluster_labels = {} files_names, clusters_labels_files = get_clusters_files(user_fol) fMRIPanel.fMRI_clusters_files_exist = len(files_names) > 0 # and len(fmri_blobs) > 0 if not fMRIPanel.fMRI_clusters_files_exist: return None # files_names = [mu.namebase(fname)[len('clusters_labels_'):] for fname in clusters_labels_files] fMRIPanel.clusters_labels_file_names = files_names clusters_labels_items = [(c, c, '', ind) for ind, c in enumerate(list(set(files_names)))] bpy.types.Scene.fmri_clusters_labels_files = bpy.props.EnumProperty( items=clusters_labels_items, description="fMRI files", update=fmri_clusters_labels_files_update) bpy.context.scene.fmri_clusters_labels_files = files_names[0] for file_name, clusters_labels_file in zip(files_names, clusters_labels_files): # Check if the constrast files exist if mu.hemi_files_exists(op.join(user_fol, 'fmri', 'fmri_{}_{}.npy'.format(file_name, '{hemi}'))): perc = mu.namebase(clusters_labels_file).split('_')[-1] key = '{}_{}'.format(file_name, perc) fMRIPanel.clusters_labels[key] = np.load(clusters_labels_file) # fMRIPanel.clusters_labels[key] = support_old_verions(fMRIPanel.clusters_labels[file_name]) fMRIPanel.lookup[key] = create_lookup_table(fMRIPanel.clusters_labels[key]) # bpy.context.scene.fmri_cluster_val_threshold = 2 # bpy.context.scene.fmri_cluster_size_threshold = 20 bpy.context.scene.search_closest_cluster_only_in_filtered = True bpy.context.scene.fmri_what_to_plot = 'blob' bpy.context.scene.fmri_how_to_sort = 'tval' update_clusters() fMRIPanel.blobs_activity, _ = calc_blobs_activity( fMRIPanel.constrast, fMRIPanel.clusters_labels_filtered, fMRIPanel.colors_in_hemis) bpy.context.scene.plot_fmri_cluster_per_click = False fMRIPanel.dont_show_clusters_info = True # addon.clear_cortex() register() fMRIPanel.init = True
def init(addon): from random import shuffle ColoringMakerPanel.addon = addon user_fol = mu.get_user_fol() ColoringMakerPanel.faces_verts = None labels_vertices_fname = op.join(user_fol, 'labels_vertices_{}.pkl'.format(bpy.context.scene.atlas)) if not op.isfile(labels_vertices_fname): print("!!! Can't find {}!".format('labels_vertices_{}.pkl'.format(bpy.context.scene.atlas))) return None labels_names, labels_vertices = mu.load(labels_vertices_fname) ColoringMakerPanel.labels_vertices = dict(labels_names=labels_names, labels_vertices=labels_vertices) meg_files_exist = mu.hemi_files_exists(op.join(user_fol, 'activity_map_{hemi}', 't0.npy')) if meg_files_exist: data_min, data_max = mu.load(op.join(mu.get_user_fol(), 'meg_activity_map_minmax.pkl')) ColoringMakerPanel.meg_activity_colors_ratio = 256 / (data_max - data_min) ColoringMakerPanel.meg_activity_data_min = data_min print('data meg: {}-{}'.format(data_min, data_max)) fmri_files = glob.glob(op.join(user_fol, 'fmri', 'fmri_*_lh.npy')) if len(fmri_files) > 0: files_names = [mu.namebase(fname)[5:-3] for fname in fmri_files] clusters_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.fmri_files = bpy.props.EnumProperty( items=clusters_items, description="fMRI files", update=fmri_files_update) bpy.context.scene.fmri_files = files_names[0] for hemi in mu.HEMIS: ColoringMakerPanel.fMRI[hemi] = np.load('{}_{}.npy'.format(fmri_files[0][:-7], hemi)) electrodes_source_files = glob.glob(op.join(user_fol, 'electrodes', '*_labels_*-rh.npz')) if len(electrodes_source_files) > 0: files_names = [mu.namebase(fname)[:-len('-rh')] for fname in electrodes_source_files] items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.electrodes_sources_files = bpy.props.EnumProperty( items=items, description="electrodes sources", update=electrodes_sources_files_update) bpy.context.scene.electrodes_sources_files = files_names[0] mu.make_dir(op.join(user_fol, 'coloring')) manually_color_files = glob.glob(op.join(user_fol, 'coloring', '*.csv')) if len(manually_color_files) > 0: files_names = [mu.namebase(fname) for fname in manually_color_files] coloring_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.coloring_files = bpy.props.EnumProperty(items=coloring_items, description="Coloring files") bpy.context.scene.coloring_files = files_names[0] vol_color_files = glob.glob(op.join(user_fol, 'coloring', 'volumetric', '*.csv')) if len(vol_color_files) > 0: files_names = [mu.namebase(fname) for fname in vol_color_files] coloring_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.vol_coloring_files = bpy.props.EnumProperty( items=coloring_items, description="Volumetric Coloring files") bpy.context.scene.vol_coloring_files = files_names[0] ColoringMakerPanel.colors = list(set(list(cu.NAMES_TO_HEX.keys())) - set(['black'])) shuffle(ColoringMakerPanel.colors) ColoringMakerPanel.labels_groups = read_groups_labels(ColoringMakerPanel.colors) if len(ColoringMakerPanel.labels_groups) > 0: groups_items = [(gr, gr, '', ind) for ind, gr in enumerate(list(ColoringMakerPanel.labels_groups.keys()))] bpy.types.Scene.labels_groups = bpy.props.EnumProperty( items=groups_items, description="Groups") ColoringMakerPanel.faces_verts = load_faces_verts() ColoringMakerPanel.cm = np.load(op.join(mu.file_fol(), 'color_maps', 'BuPu_YlOrRd.npy')) register()
def init(addon): from random import shuffle ColoringMakerPanel.addon = addon user_fol = mu.get_user_fol() ColoringMakerPanel.faces_verts = None labels_vertices_fname = op.join(user_fol, 'labels_vertices_{}.pkl'.format(bpy.context.scene.atlas)) if not op.isfile(labels_vertices_fname): print("!!! Can't find {}!".format('labels_vertices_{}.pkl'.format(bpy.context.scene.atlas))) return None labels_names, labels_vertices = mu.load(labels_vertices_fname) ColoringMakerPanel.labels_vertices = dict(labels_names=labels_names, labels_vertices=labels_vertices) ColoringMakerPanel.max_labels_vertices_num = {} meg_files_exist = mu.hemi_files_exists(op.join(user_fol, 'activity_map_{hemi}', 't0.npy')) meg_data_maxmin_fname = op.join(mu.get_user_fol(), 'meg_activity_map_minmax.pkl') if meg_files_exist and op.isfile(meg_data_maxmin_fname): data_min, data_max = mu.load(meg_data_maxmin_fname) ColoringMakerPanel.meg_activity_colors_ratio = 256 / (data_max - data_min) ColoringMakerPanel.meg_activity_data_min = data_min ColoringMakerPanel.meg_activity_data_max = data_max print('data meg: {}-{}'.format(data_min, data_max)) _addon().set_colorbar_max_min(data_max, data_min, True) _addon().set_colorbar_title('MEG') fmri_files = glob.glob(op.join(user_fol, 'fmri', 'fmri_*_lh.npy')) if len(fmri_files) > 0: files_names = [mu.namebase(fname)[5:-3] for fname in fmri_files] clusters_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.fmri_files = bpy.props.EnumProperty( items=clusters_items, description="fMRI files", update=fmri_files_update) bpy.context.scene.fmri_files = files_names[0] for hemi in mu.HEMIS: ColoringMakerPanel.fMRI[hemi] = np.load('{}_{}.npy'.format(fmri_files[0][:-7], hemi)) # Check separately for each contrast fmri_data_maxmin_fname = op.join(mu.get_user_fol(), 'fmri', 'fmri_activity_map_minmax.pkl') if op.isfile(fmri_data_maxmin_fname): data_min, data_max = mu.load(fmri_data_maxmin_fname) ColoringMakerPanel.fmri_activity_colors_ratio = 256 / (data_max - data_min) ColoringMakerPanel.fmri_activity_data_min = data_min ColoringMakerPanel.fmri_activity_data_max = data_max electrodes_source_files = glob.glob(op.join(user_fol, 'electrodes', '*_labels_*-rh.npz')) if len(electrodes_source_files) > 0: files_names = [mu.namebase(fname)[:-len('-rh')] for fname in electrodes_source_files] items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.electrodes_sources_files = bpy.props.EnumProperty( items=items, description="electrodes sources", update=electrodes_sources_files_update) bpy.context.scene.electrodes_sources_files = files_names[0] mu.make_dir(op.join(user_fol, 'coloring')) manually_color_files = glob.glob(op.join(user_fol, 'coloring', '*.csv')) if len(manually_color_files) > 0: files_names = [mu.namebase(fname) for fname in manually_color_files] coloring_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.coloring_files = bpy.props.EnumProperty(items=coloring_items, description="Coloring files") bpy.context.scene.coloring_files = files_names[0] vol_color_files = glob.glob(op.join(user_fol, 'coloring', 'volumetric', '*.csv')) if len(vol_color_files) > 0: files_names = [mu.namebase(fname) for fname in vol_color_files] coloring_items = [(c, c, '', ind) for ind, c in enumerate(files_names)] bpy.types.Scene.vol_coloring_files = bpy.props.EnumProperty( items=coloring_items, description="Volumetric Coloring files") bpy.context.scene.vol_coloring_files = files_names[0] ColoringMakerPanel.colors = list(set(list(cu.NAMES_TO_HEX.keys())) - set(['black'])) shuffle(ColoringMakerPanel.colors) ColoringMakerPanel.labels_groups = read_groups_labels(ColoringMakerPanel.colors) if len(ColoringMakerPanel.labels_groups) > 0: groups_items = [(gr, gr, '', ind) for ind, gr in enumerate(list(ColoringMakerPanel.labels_groups.keys()))] bpy.types.Scene.labels_groups = bpy.props.EnumProperty( items=groups_items, description="Groups") ColoringMakerPanel.faces_verts = load_faces_verts() bpy.context.scene.coloring_meg_subcorticals = False # ColoringMakerPanel.cm = np.load(op.join(mu.file_fol(), 'color_maps', 'BuPu_YlOrRd.npy')) register()