示例#1
0
def plot_labels(labels_names,
                colors,
                atlas,
                atlas_labels_rh=[],
                atlas_labels_lh=[],
                do_plot=True):
    if len(atlas_labels_rh) == 0 and len(
            atlas_labels_lh) == 0:  # or atlas == bpy.context.scene.atlas:
        atlas_labels_rh = mu.read_labels_from_annots(atlas, hemi='rh')
        atlas_labels_lh = mu.read_labels_from_annots(atlas, hemi='lh')
    atlas_labels = atlas_labels_rh + atlas_labels_lh
    if len(atlas_labels) == 0:
        print("Couldn't find the atlas! ({})".format(atlas))
        return
    annot_verts_ok = check_annot_verts(atlas_labels_lh, atlas_labels_rh, atlas)
    if not annot_verts_ok:
        return
    org_delim, org_pos, label, label_hemi = mu.get_hemi_delim_and_pos(
        atlas_labels[0].name)
    labels_names_fix = []
    for label_name in labels_names:
        delim, pos, label, label_hemi = mu.get_hemi_delim_and_pos(label_name)
        label = mu.get_label_hemi_invariant_name(label_name)
        label_fix = mu.build_label_name(org_delim, org_pos, label, label_hemi)
        labels_names_fix.append(label_fix)
    labels = [l for l in atlas_labels if l.name in labels_names_fix]
    if len(labels) < len(labels_names):
        dump_fname = op.join(mu.get_user_fol(), 'logs',
                             '{}_labels.txt'.format(atlas))
        print("Can't find all the labels ({}) in the {} atlas!".format(
            labels_names, atlas))
        print("Take a look here for the {} labels names: {}".format(
            atlas, dump_fname))
        with open(dump_fname, 'w') as output_file:
            output_file.write(
                "Can't find all the labels ({}) in the {} atlas!\n".format(
                    labels_names, atlas))
            output_file.write(
                "Take a look here for the {} labels names:\n".format(atlas))
            for label in atlas_labels:
                output_file.write('{}\n'.format(label.name))
        import webbrowser
        webbrowser.open_new(dump_fname)
        return
    labels.sort(key=lambda x: labels_names_fix.index(x.name))
    # todo: check if bpy.context.scene.color_rois_homogeneously
    for label, color in zip(labels, colors):
        print('color {}: {}'.format(label, color))
        # plot_label(label, color)
        LabelsPanel.labels_plotted.append((label, color))
    if do_plot:
        _plot_labels()
示例#2
0
def build_new_label_name():
    closest_label_output = bpy.context.scene.closest_label_output
    if closest_label_output == '':
        new_label_name = 'Unknown'
    else:
        delim, pos, label, label_hemi = mu.get_hemi_delim_and_pos(closest_label_output)
        label = '{}-{}mm'.format(label, bpy.context.scene.new_label_r)
        new_label_name = mu.build_label_name(delim, pos, label, label_hemi)
    bpy.context.scene.new_label_name = new_label_name
示例#3
0
 def execute(self, context):
     stc_fname = self.filepath
     user_fol = mu.get_user_fol()
     stc_fol = mu.get_fname_folder(stc_fname)
     if stc_fol != op.join(user_fol, 'meg'):
         other_hemi_stc_fname = op.join(stc_fol, '{}.stc'.format(mu.get_other_hemi_label_name(mu.namebase(stc_fname))))
         shutil.copy(stc_fname, op.join(user_fol, 'meg', mu.namesbase_with_ext(stc_fname)))
         shutil.copy(other_hemi_stc_fname, op.join(user_fol, 'meg', mu.namesbase_with_ext(other_hemi_stc_fname)))
         _addon().init_meg_activity_map()
     _, _, label, hemi = mu.get_hemi_delim_and_pos(mu.namebase(stc_fname))
     bpy.context.scene.meg_files = label
     return {'FINISHED'}