Ejemplo n.º 1
0
def save_cycle():
    if bpy.context.scene.save_streaming:
        streaming_fol = datetime.strftime(datetime.now(), '%Y-%m-%d')
        output_fol = op.join(mu.get_user_fol(), 'electrodes', 'streaming', streaming_fol)
        output_fname = 'streaming_data_{}.npy'.format(datetime.strftime(datetime.now(), '%H-%M-%S'))
        mu.make_dir(output_fol)
        np.save(op.join(output_fol, output_fname), StreamingPanel.cycle_data)
Ejemplo n.º 2
0
 def init(addon):
     LoadResultsPanel.addon = addon
     mu.make_dir(op.join(mu.get_user_fol(), 'meg'))
     bpy.context.scene.nii_label_prompt = ''
     bpy.context.scene.nii_label_output = ''
     register()
     LoadResultsPanel.init = True
Ejemplo n.º 3
0
def init(addon):
    RenderingMakerPanel.addon = addon
    bpy.data.objects['Target'].rotation_euler.x = 0
    bpy.data.objects['Target'].rotation_euler.y = 0
    bpy.data.objects['Target'].rotation_euler.z = 0
    bpy.data.objects['Target'].location.x = 0
    bpy.data.objects['Target'].location.y = 0
    bpy.data.objects['Target'].location.z = 0
    mu.make_dir(op.join(mu.get_user_fol(), 'camera'))
    grab_camera(overwrite=False)
    update_camera_files()
    bpy.context.scene.in_camera_view = False
    bpy.context.scene.save_selected_view = False
    bpy.context.scene.view_distance = 17.36
    bpy.context.scene.render.resolution_percentage = 100
    bpy.context.scene.render.image_settings.file_format = 'JPEG'
    # bpy.context.scene.lighting = 1.0
    RenderingMakerPanel.queue = PriorityQueue()
    mu.make_dir(op.join(mu.get_user_fol(), 'logs'))
    logging.basicConfig(
        filename=op.join(mu.get_user_fol(), 'logs', 'reander_panel.log'),
        level=logging.DEBUG,
        format='%(asctime)-15s %(levelname)8s %(name)s %(message)s')
    RenderingMakerPanel.init = True
    register()
Ejemplo n.º 4
0
def run_faulthandler():
    import faulthandler
    logs = op.join(mmvt_utils.get_user_fol(), 'logs')
    mmvt_utils.make_dir(logs)
    fault_handler = open(
        op.join(logs,
                'faulthandler_{}.txt'.format(mmvt_utils.rand_letters(5))), 'w')
    faulthandler.enable(fault_handler)
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def run_faulthandler():
    try:
        import faulthandler
        logs = op.join(mmvt_utils.get_user_fol(), 'logs')
        mmvt_utils.make_dir(logs)
        fault_handler = open(op.join(logs, 'faulthandler_{}.txt'.format(mmvt_utils.rand_letters(5))), 'w')
        faulthandler.enable(fault_handler)
    except:
        print('Cannot create faulthandler log!')
        mmvt_utils.print_last_error_line()
Ejemplo n.º 7
0
def export_electrodes():
    import csv
    mu.make_dir(op.join(mu.get_user_fol(), 'electrodes'))
    csv_fname = op.join(mu.get_user_fol(), 'electrodes', '{}_RAS.csv'.format(mu.get_user()))
    electrodes = [e for e in bpy.data.objects[_addon().electrodes_panel_parent].children]
    with open(csv_fname, 'w') as csv_file:
        wr = csv.writer(csv_file, quoting=csv.QUOTE_ALL)
        wr.writerow(['Electrode Name','R','A','S'])
        for elc in electrodes:
            wr.writerow([elc.name, *['{:.2f}'.format(loc * 10) for loc in elc.location]])
Ejemplo n.º 8
0
def init(addon, do_register=True):
    ElecsPanel.init = False
    ElecsPanel.addon = addon
    ElecsPanel.parent = bpy.data.objects.get('Deep_electrodes')
    if ElecsPanel.parent is None or len(ElecsPanel.parent.children) == 0:
        print("Can't register electrodes panel, no Deep_electrodes object")
        return
    mu.make_dir(op.join(mu.get_user_fol(), 'electrodes'))
    init_sorted_groups()
    # show_hide_electrodes(True)
    ElecsPanel.groups_hemi = create_groups_hemi_lookup(
        ElecsPanel.sorted_groups)
    ElecsPanel.all_electrodes = [el.name for el in ElecsPanel.parent.children]
    ElecsPanel.groups = create_groups_lookup_table(ElecsPanel.all_electrodes)
    ElecsPanel.groups_first_electrode = find_first_electrode_per_group(
        ElecsPanel.all_electrodes)
    ElecsPanel.groups_electrodes = create_groups_electrodes_lookup(
        ElecsPanel.all_electrodes)
    init_leads_list()
    ret = init_electrodes_list()
    # if not ret:
    #     return
    ret = init_electrodes_labeling(addon)
    if ret:
        ElecsPanel.electrodes_labeling_file_exist = True
        _electrodes_labeling_files_update()
    else:
        ElecsPanel.electrodes_labeling_file_exist = False
        print('No electrodes labeling files.')

    # addon.clear_colors_from_parent_childrens('Deep_electrodes')
    # addon.clear_cortex()
    bpy.context.scene.show_only_lead = False
    bpy.context.scene.listen_to_keyboard = False
    bpy.context.scene.listener_is_running = False
    bpy.context.scene.show_lh_electrodes = True
    bpy.context.scene.show_rh_electrodes = True
    bpy.context.scene.show_ela = False
    bpy.context.scene.electrode_rotate = False
    bpy.context.scene.electrodes_more_settings = False
    bpy.context.scene.electrodes_create_curved_leads = False
    if not ElecsPanel.electrodes_locs or not ElecsPanel.lookup:
        if not ElecsPanel.electrodes_locs:
            print(
                "!!! Can't find electrodes labeling files in user/electrdes!")
        if not ElecsPanel.lookup:
            print('No electrodes lookup table!')
        print("!!! Can't plot electrodes' probabilties !!!")
    # if not ElecsPanel.groups or not ElecsPanel.groups_first_electrode or not ElecsPanel.sorted_groups or \
    #     not ElecsPanel.groups_hemi or not ElecsPanel.groups_electrodes:
    #         print('Error in electrodes panel init!')
    # else:
    if do_register:
        register()
    ElecsPanel.init = True
Ejemplo n.º 9
0
def init(addon):
    import shutil
    ElecsPanel.addon = addon
    ElecsPanel.parent = bpy.data.objects.get('Deep_electrodes')
    if ElecsPanel.parent is None or len(ElecsPanel.parent.children) == 0:
        print("Can't register electrodes panel, no Deep_electrodes object")
        return
    mu.make_dir(op.join(mu.get_user_fol(), 'electrodes'))
    sorted_groups_fname = op.join(mu.get_user_fol(), 'electrodes',
                                  'sorted_groups.pkl')
    if not op.isfile(sorted_groups_fname):
        # Try to get the file from the subject's root folder
        if op.isfile(op.join(mu.get_user_fol(), 'sorted_groups.pkl')):
            shutil.move(op.join(mu.get_user_fol(), 'sorted_groups.pkl'),
                        sorted_groups_fname)
        else:
            print("Can't register electrodes panel, no sorted groups file")
            return
    # show_hide_electrodes(True)
    ElecsPanel.sorted_groups = mu.load(sorted_groups_fname)
    ElecsPanel.groups_hemi = create_groups_hemi_lookup(
        ElecsPanel.sorted_groups)
    ElecsPanel.all_electrodes = [el.name for el in ElecsPanel.parent.children]
    ElecsPanel.groups = create_groups_lookup_table(ElecsPanel.all_electrodes)
    ElecsPanel.groups_first_electrode = find_first_electrode_per_group(
        ElecsPanel.all_electrodes)
    ElecsPanel.groups_electrodes = create_groups_electrodes_lookup(
        ElecsPanel.all_electrodes)
    init_leads_list()
    init_electrodes_list()
    ret = init_electrodes_labeling(addon)
    if not ret:
        print('No electrodes labeling files.')
        return
    # addon.clear_colors_from_parent_childrens('Deep_electrodes')
    # addon.clear_cortex()
    bpy.context.scene.show_only_lead = False
    bpy.context.scene.listen_to_keyboard = False
    bpy.context.scene.listener_is_running = False
    bpy.context.scene.show_lh_electrodes = True
    bpy.context.scene.show_rh_electrodes = True
    _electrodes_labeling_files_update()
    if not ElecsPanel.electrodes_locs or not ElecsPanel.lookup:
        if not ElecsPanel.electrodes_locs:
            print(
                "!!! Can't find electrodes labeling files in user/electrdes!")
        if not ElecsPanel.lookup:
            print('No electrodes lookup table!')
        print("!!! Can't plot electrodes' probabilties !!!")
    if not ElecsPanel.groups or not ElecsPanel.groups_first_electrode or not ElecsPanel.sorted_groups or \
        not ElecsPanel.groups_hemi or not ElecsPanel.groups_electrodes:
        print('Error in electrodes panel init!')
    else:
        register()
        ElecsPanel.init = True
Ejemplo n.º 10
0
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)
    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()
    register()
Ejemplo n.º 11
0
def save_cursor_position(pos=None):
    # _addon().create_slices(pos=pos) # Don't call here create_slices!!!
    pos = mathutils.Vector(pos) if not pos is None else bpy.context.scene.cursor_location
    root = mu.get_user_fol()
    point = pos * 10.0
    freeview_cmd = 'freeview --ras {} {} {} tkreg\n'.format(point[0], point[1], point[2]) # .encode()
    if FreeviewPanel.freeview_in_queue:
        FreeviewPanel.freeview_in_queue.put(freeview_cmd)
    freeview_fol = op.join(root, 'freeview')
    mu.make_dir(freeview_fol)
    # print('Cursor was saved in {}'.format(op.join(freeview_fol, 'edit.dat')))
    np.savetxt(op.join(freeview_fol, 'edit.dat'), point)
Ejemplo n.º 12
0
def save_cursor_position():
    root = mu.get_user_fol()
    point = bpy.context.scene.cursor_location * 10.0
    freeview_cmd = 'freeview --ras {} {} {} tkreg\n'.format(point[0], point[1], point[2]) # .encode()
    if FreeviewPanel.freeview_in_queue:
        FreeviewPanel.freeview_in_queue.put(freeview_cmd)
    freeview_fol = op.join(root, 'freeview')
    mu.make_dir(freeview_fol)
    np.savetxt(op.join(freeview_fol, 'edit.dat'), point)
    cursor_position = np.array(bpy.context.scene.cursor_location) * 10
    ret = mu.conn_to_listener.send_command(dict(cmd='slice_viewer_change_pos',data=dict(
        position=cursor_position)))
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
def save_cursor_position():
    root = mu.get_user_fol()
    point = bpy.context.scene.cursor_location * 10.0
    freeview_cmd = 'freeview --ras {} {} {} tkreg\n'.format(
        point[0], point[1], point[2])  # .encode()
    if FreeviewPanel.freeview_in_queue:
        FreeviewPanel.freeview_in_queue.put(freeview_cmd)
    freeview_fol = op.join(root, 'freeview')
    mu.make_dir(freeview_fol)
    np.savetxt(op.join(freeview_fol, 'edit.dat'), point)
    cursor_position = np.array(bpy.context.scene.cursor_location) * 10
    ret = mu.conn_to_listener.send_command(
        dict(cmd='slice_viewer_change_pos',
             data=dict(position=cursor_position)))
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
def init_labels_data_files():
    user_fol = mu.get_user_fol()
    mu.make_dir(op.join(user_fol, 'labels', 'labels_data'))
    LabelsPanel.labels_data_files = labels_data_files = \
        glob.glob(op.join(user_fol, 'labels', 'labels_data', '*.npz')) + \
        glob.glob(op.join(user_fol, 'labels', 'labels_data', '*.mat'))
    if len(labels_data_files) > 0:
        files_names = [
            mu.namebase(fname).replace('_', ' ') for fname in labels_data_files
        ]
        labels_items = [(c, c, '', ind) for ind, c in enumerate(files_names)]
        bpy.types.Scene.labels_data_files = bpy.props.EnumProperty(
            items=labels_items,
            description="label files",
            update=labels_data_files_update)
        bpy.context.scene.labels_data_files = files_names[0]
Ejemplo n.º 17
0
def init_pizco(mmvt):
    log_fname = op.join(mu.make_dir(op.join(mu.get_user_fol(), 'logs')),
                        'pizco.log')
    if op.isfile(log_fname):
        try:
            os.remove(log_fname)
        except:
            print('Can\'t remove {}'.format(log_fname))
    for k in range(10):
        try:
            bpy.context.scene.pizco_server_address = 'tcp://127.0.0.1:800{}'.format(
                str(k))
            MMVT_Server(mmvt, bpy.context.scene.pizco_server_address)
            pizco_exist = True
            try:
                with open(log_fname, 'w') as log:
                    log.write(bpy.context.scene.pizco_server_address)
            except:
                print('Can\'t write to {}'.format(log_fname))
            break
        except:
            # print('No pizco')
            # print(traceback.format_exc())
            pizco_exist = False
    if not pizco_exist:
        print('No pizco')
    return pizco_exist
Ejemplo n.º 18
0
def init_labels_data_files():
    user_fol = mu.get_user_fol()
    mu.make_dir(op.join(user_fol, 'labels', 'labels_data'))
    LabelsPanel.labels_data_files = labels_data_files = \
        glob.glob(op.join(user_fol, 'labels', 'labels_data', '*.npz')) + \
        glob.glob(op.join(user_fol, 'labels', 'labels_data', '*.mat'))
    try:
        if len(labels_data_files) > 0:
            files_names = [mu.namebase(fname).replace('_', ' ') for fname in labels_data_files]
            labels_items = [(c, c, '', ind) for ind, c in enumerate(files_names)]
            bpy.types.Scene.labels_data_files = bpy.props.EnumProperty(
                items=labels_items, update=labels_data_files_update,
                description='Selects labels file from the subject’s labels folder:'
                '\n../mmvt_root/mmvt_blend/colin27/labels/labels_data\n\nCurrent file')
            bpy.context.scene.labels_data_files = files_names[0]
    except:
        print('init_labels_data_files: Error!')
Ejemplo n.º 19
0
def init(addon):
    import shutil
    ElecsPanel.addon = addon
    ElecsPanel.parent = bpy.data.objects.get('Deep_electrodes')
    if ElecsPanel.parent is None or len(ElecsPanel.parent.children) == 0:
        print("!!!! Can't register electrodes panel, no Deep_electrodes object!!!!")
        return
    mu.make_dir(op.join(mu.get_user_fol(), 'electrodes'))
    sorted_groups_fname = op.join(mu.get_user_fol(), 'electrodes', 'sorted_groups.pkl')
    if not op.isfile(sorted_groups_fname):
        # Try to get the file from the subject's root folder
        if op.isfile(op.join(mu.get_user_fol(), 'sorted_groups.pkl')):
            shutil.move(op.join(mu.get_user_fol(), 'sorted_groups.pkl'), sorted_groups_fname)
        else:
            print("!!!! Can't register electrodes panel, no sorted groups file!!!!")
            return
    ElecsPanel.sorted_groups = mu.load(sorted_groups_fname)
    ElecsPanel.groups_hemi = create_groups_hemi_lookup(ElecsPanel.sorted_groups)
    ElecsPanel.all_electrodes = [el.name for el in ElecsPanel.parent.children]
    ElecsPanel.groups = create_groups_lookup_table(ElecsPanel.all_electrodes)
    ElecsPanel.groups_first_electrode = find_first_electrode_per_group(ElecsPanel.all_electrodes)
    ElecsPanel.groups_electrodes = create_groups_electrodes_lookup(ElecsPanel.all_electrodes)
    init_leads_list()
    init_electrodes_list()
    init_electrodes_labeling(addon)
    addon.clear_colors_from_parent_childrens('Deep_electrodes')
    addon.clear_cortex()
    bpy.context.scene.show_only_lead = False
    bpy.context.scene.listen_to_keyboard = False
    bpy.context.scene.listener_is_running = False
    bpy.context.scene.show_lh_electrodes = True
    bpy.context.scene.show_rh_electrodes = True
    _electrodes_labeling_files_update()
    if not ElecsPanel.electrodes_locs or not ElecsPanel.lookup:
        if not ElecsPanel.electrodes_locs:
            print("!!! Can't find electrodes labeling files in user/electrdes!")
        if not ElecsPanel.lookup:
            print('No electrodes lookup table!')
        print("!!! Can't plot electrodes' probabilties !!!")
    if not ElecsPanel.groups or not ElecsPanel.groups_first_electrode or not ElecsPanel.sorted_groups or \
        not ElecsPanel.groups_hemi or not ElecsPanel.groups_electrodes:
            print('Error in electrodes panel init!')
    else:
        register()
        ElecsPanel.init = True
Ejemplo n.º 20
0
def init(addon):
    RenderingMakerPanel.addon = addon
    bpy.data.objects['Target'].rotation_euler.x = 0
    bpy.data.objects['Target'].rotation_euler.y = 0
    bpy.data.objects['Target'].rotation_euler.z = 0
    bpy.data.objects['Target'].location.x = 0
    bpy.data.objects['Target'].location.y = 0
    bpy.data.objects['Target'].location.z = 0
    mu.make_dir(op.join(mu.get_user_fol(), 'camera'))
    grab_camera()
    update_camera_files()
    # bpy.context.scene.lighting = 1.0
    RenderingMakerPanel.queue = PriorityQueue()
    mu.make_dir(op.join(mu.get_user_fol(), 'logs'))
    logging.basicConfig(
        filename=op.join(mu.get_user_fol(), 'logs', 'reander_panel.log'),
        level=logging.DEBUG, format='%(asctime)-15s %(levelname)8s %(name)s %(message)s')
    register()
Ejemplo n.º 21
0
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()
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
def load_surf_files(nii_fname):
    fmri_file_template = ''
    user_fol = mu.get_user_fol()
    nii_fol = mu.get_fname_folder(nii_fname)
    fmri_hemis = mu.get_both_hemis_files(nii_fname)
    hemi = mu.get_hemi_from_full_fname(nii_fname)
    local_fname = build_local_fname(nii_fname, user_fol)
    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)
    other_hemi_fname = fmri_hemis[other_hemi]
    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.namesbase_with_ext(local_fname))
        cmd = '{} -m src.preproc.fMRI -s {} -f load_surf_files --fmri_file_template "{}"'.format(
            bpy.context.scene.python_cmd, mu.get_user(), fmri_file_template)
        mu.run_command_in_new_thread(cmd, False)
    return fmri_file_template, hemi
Ejemplo n.º 24
0
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
Ejemplo n.º 25
0
def load_surf_files(nii_fname, run_fmri_preproc=True, user_fol=''):
    fmri_file_template = ''
    if user_fol == '':
        user_fol = mu.get_user_fol()
    nii_fol = mu.get_fname_folder(nii_fname)
    # hemi = mu.get_hemi_from_fname(mu.namebase(nii_fname))
    # if hemi == '':
    hemi, fmri_hemis = mu.get_hemi_from_full_fname(nii_fname)
    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)
    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)
    other_hemi_fname = fmri_hemis[other_hemi]
    # todo: if the other hemi file doens't exist, just create an empty one
    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.run_mmvt_func(
                'src.preproc.fMRI',
                'load_surf_files',
                flags='--fmri_file_template "{}"'.format(fmri_file_template))
            # cmd = '{} -m  -s {} -f  --fmri_file_template "{}" --ignore_missing 1'.format(
            #     bpy.context.scene.python_cmd, mu.get_user(), fmri_file_template)
            # mu.run_command_in_new_thread(cmd, False, cwd=mu.get_mmvt_code_root())
    else:
        print(
            "Couldn't find the other hemi file! ({})".format(other_hemi_fname))
    return fmri_file_template, hemi, other_hemi
Ejemplo n.º 26
0
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()
Ejemplo n.º 27
0
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()