def _plot_labels(labels_plotted_tuple=None, faces_verts=None, choose_rand_colors=False): if labels_plotted_tuple is None: labels_plotted_tuple = LabelsPanel.labels_plotted if faces_verts is None: faces_verts = _addon().coloring.get_faces_verts() hemi_verts_num = {hemi: faces_verts[hemi].shape[0] for hemi in mu.HEMIS} data = {hemi: np.zeros((hemi_verts_num[hemi], 4)) for hemi in mu.HEMIS} colors_num = len(labels_plotted_tuple) rand_colors = mu.get_distinct_colors( colors_num) if choose_rand_colors else [''] * colors_num for (label, color), rand_color in zip(labels_plotted_tuple, rand_colors): label.vertices = label.vertices[ label.vertices < hemi_verts_num[label.hemi]] if choose_rand_colors: color = rand_color data[label.hemi][label.vertices] = [1, *color] for hemi in mu.HEMIS: _addon().coloring.color_hemi_data( 'inflated_{}'.format(hemi), data[hemi], threshold=0.5, coloring_layer=bpy.context.scene.labels_layer, check_valid_verts=False) if bpy.context.scene.replot_contours: replot_contours() _addon().show_activity()
def plot_labels_probs(elc): _addon().init_activity_map_coloring('FMRI') if bpy.context.scene.electrodes_what_to_color == 'probs': if len(elc['cortical_rois']) > 0: hemi = mu.get_obj_hemi(elc['cortical_rois'][0]) if not hemi is None: labels_data = dict(data=elc['cortical_probs'], names=elc['cortical_rois']) if not _addon().colorbar_values_are_locked(): _addon().set_colorbar_title('Electrodes probabilities') _addon().set_colormap('YlOrRd') atlas = bpy.context.scene.electrodes_labeling_files.split( '_')[1:-6][0] _addon().labels_coloring_hemi(labels_data, ElecsPanel.faces_verts, hemi, 0, colors_min=0, colors_max=1, atlas=atlas) colors = mu.get_distinct_colors(len(elc['cortical_rois'])) if bpy.context.scene.electrodes_label_contours: _addon().color_contours(elc['cortical_rois'], specific_colors=colors) else: print("Can't get the rois hemi!") else: _addon().clear_cortex() _addon().clear_subcortical_regions() if len(elc['subcortical_rois']) > 0: cm = _addon().get_cm() colors = mu.calc_colors_from_cm(elc['subcortical_probs'], 0, 256, cm) for region, color in zip(elc['subcortical_rois'], colors): _addon().color_subcortical_region(region, color) elif bpy.context.scene.electrodes_what_to_color == 'verts': if len(elc['cortical_indices']) > 0: hemi = bpy.data.objects[elc['hemi']] if not hemi is None: _addon().init_activity_map_coloring('FMRI', subcorticals=True) vertices_num = np.max(elc['cortical_indices']) + 1 activity = np.ones((vertices_num, 4)) activity[:, 0] = 0 activity[elc['cortical_indices'], 0] = 1 activity[elc['cortical_indices'], 1:] = np.tile(cu.name_to_rgb('blue'), (len(elc['cortical_indices']), 1)) print('Plot {} vertices with blue'.format( len(elc['cortical_indices']))) _addon().activity_map_obj_coloring( hemi, activity, ElecsPanel.faces_verts[elc['hemi']], 0, True) else: print("Can't get the elec's hemi!") else: _addon().clear_cortex() print('No cortical vertices for {}'.format(elc['name']))