def run_script(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    mmvt.find_fmri_files_min_max()
    clusters_names = [
        f for f in mmvt.get_clusters_file_names() if args.clusters_type in f
    ]
    print('clusters_names: {}'.format(clusters_names))
    if len(args.lighting) == 1 and len(args.background_color) == 2:
        args.lighting = [args.lighting] * 2
    for clusters_file_name in clusters_names:
        for inflated, background_color in product(args.inflated,
                                                  args.background_color):
            lighting = args.lighting[
                0] if background_color == 'black' else args.lighting[1]
            mmvt.init_rendering(inflated, args.inflated_ratio,
                                args.transparency, args.light_layers_depth,
                                lighting, background_color,
                                args.rendering_in_the_background)
            mmvt.load_fmri_cluster(clusters_file_name)
            mmvt.plot_all_blobs()
            mmvt.render_lateral_medial_split_brain(clusters_file_name,
                                                   args.quality,
                                                   args.overwrite)
    su.save_blend_file(subject_fname)
    su.exit_blender()
예제 #2
0
def wrap_mmvt_calls(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    mmvt_calls(mmvt, args, subject_fname)
    su.exit_blender()
예제 #3
0
def render_movie(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    if args.rel_output_path:
        mmvt_dir = op.join(su.get_links_dir(), 'mmvt')
        if args.output_path == '':
            args.output_path = args.play_type
        args.output_path = op.join(mmvt_dir, args.subject, 'movies',
                                   args.output_path)
    su.make_dir(args.output_path)
    mmvt = su.init_mmvt_addon()
    mmvt.show_hide_hemi(args.hide_lh, 'lh')
    mmvt.show_hide_hemi(args.hide_rh, 'rh')
    mmvt.show_hide_sub_corticals(args.hide_subs)
    mmvt.set_render_quality(args.quality)
    mmvt.set_render_output_path(args.output_path)
    mmvt.set_render_smooth_figure(args.smooth_figure)
    mmvt.set_light_layers_depth(args.light_layers)
    mmvt.set_brain_transparency(args.brain_trans)
    mmvt.filter_nodes(args.filter_nodes)
    mark_electrodes(mmvt, args)
    camera_fname = su.load_camera(mmvt, mmvt_dir, args)
    if not op.isfile(op.join(args.output_path, 'data.pkl')):
        try:
            mmvt.capture_graph(args.play_type, args.output_path,
                               args.selection_type)
        except:
            print("Graph couldn't be captured!")
    su.save_blend_file(subject_fname)
    mmvt.render_movie(args.play_type, args.play_from, args.play_to,
                      camera_fname, args.play_dt, args.set_to_camera_mode)
    su.exit_blender()
예제 #4
0
def do_something(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    # Call mmvt functions
    su.save_blend_file(subject_fname)
    su.exit_blender()
def render_electrodes_probs(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    figures_dir = su.get_figures_dir(args)
    if args.rel_output_path:
        args.output_path = op.join(figures_dir, args.output_path)
    su.make_dir(args.output_path)

    # Set the labeling file
    labeling_fname = '{}_{}_electrodes_cigar_r_*_l_*{}*.pkl'.format(
        args.subject, args.real_atlas, '_bipolar' if args.bipolar else '')
    labels_fol = op.join(su.get_mmvt_dir(), args.subject, 'electrodes')
    labeling_files = glob.glob(op.join(labels_fol, labeling_fname))
    if len(labeling_files) == 0:
        print('No labeling files in {}!'.format(labels_fol))
        return
    if len(labeling_files) > 1:
        print(
            'More than one labeling files in {}, please choose one using the --labeling flag'
            .format(labels_fol))
        return
    else:
        labeling_file = labeling_files[0]

    mmvt = su.init_mmvt_addon()
    mmvt.show_hide_hemi(args.hide_lh, 'lh')
    mmvt.show_hide_hemi(args.hide_rh, 'rh')
    mmvt.show_hide_sub_corticals(args.hide_subs)
    mmvt.set_render_quality(args.quality)
    mmvt.set_render_output_path(args.output_path)
    mmvt.set_render_smooth_figure(args.smooth_figure)
    camera_fol = su.get_camera_dir(args)
    if op.isfile(op.join(camera_fol, '{}.pkl'.format(args.camera_name))):
        mmvt.load_camera()
    else:
        cont = input(
            'No camera file was detected in the output folder, continue?')
        if not su.is_true(cont):
            return

    mmvt.set_electrodes_labeling_file(labeling_file)
    mmvt.show_electrodes()
    mmvt.color_the_relevant_lables(True)
    mmvt.set_show_only_lead(args.show_only_current_lead)
    leads = mmvt.get_leads()
    for lead in leads:
        electrodes = mmvt.get_lead_electrodes(lead)
        for electrode in electrodes:
            print(electrode)
            mmvt.clear_cortex()
            mmvt.set_current_electrode(electrode, lead)
            mmvt.render_image(electrode)

    su.save_blend_file(subject_fname)
    su.exit_blender()
예제 #6
0
def wrap_mmvt_calls(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    mmvt.utils.write_to_stderr('{} Importing electrodes...'.format(
        args.subject))
    if args.overwrite:
        mmvt.utils.delete_hierarchy('Deep_electrodes')
    mmvt.import_electrodes(args.pos_file, mmvt.ELECTRODES_LAYER, args.bipolar,
                           args.radius)
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    mmvt.utils.write_to_stderr('{} Done!'.format(args.subject))
    su.exit_blender()
예제 #7
0
def wrap_mmvt_calls(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    if args.modality == 'meg':
        mmvt.import_meg_sensors(args.overwrite_sensors)
        if args.load_data:
            mmvt.add_data_to_meg_sensors(args.stat)
    elif args.modality == 'eeg':
        mmvt.import_eeg_sensors(args.overwrite_sensors)
        if args.load_data:
            mmvt.add_data_to_eeg_sensors()
    else:
        print('args.modality should be eeg or meg!')
    su.save_blend_file(subject_fname)
    su.exit_blender()
예제 #8
0
def run_script(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    mmvt.find_fmri_files_min_max()
    clusters_names = [f for f in mmvt.get_clusters_file_names() if args.clusters_type in f]
    print('clusters_names: {}'.format(clusters_names))
    if len(args.lighting) == 1 and len(args.background_color) == 2:
        args.lighting = [args.lighting] * 2
    for clusters_file_name in clusters_names:
        for inflated, background_color in product(args.inflated, args.background_color):
            lighting = args.lighting[0] if background_color == 'black' else args.lighting[1]
            mmvt.init_rendering(inflated, args.inflated_ratio, args.transparency, args.light_layers_depth,
                                lighting, background_color, args.rendering_in_the_background)
            mmvt.load_fmri_cluster(clusters_file_name)
            mmvt.plot_all_blobs()
            mmvt.render_lateral_medial_split_brain(clusters_file_name, args.quality, args.overwrite)
    su.save_blend_file(subject_fname)
    su.exit_blender()
예제 #9
0
def do_something(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt = su.init_mmvt_addon()
    mu = mmvt.utils
    # Call mmvt functions
    script_check_ret = mmvt.scripts.check_script(mu.namebase(args.script_name),
                                                 return_all=True)
    if script_check_ret is None:
        print('Can\'t call the script {}!'.format(args.script_name))
        return
    lib, (run_func, init_func, draw_func, params) = script_check_ret
    for param_tup in args.script_params:
        if len(param_tup.split(':')) != 2:
            continue
        param_name, param_val = param_tup.split(':')
        mu.set_prop(param_name, param_val)

    run_func(mmvt)
    su.exit_blender()
예제 #10
0
def init_mmvt_addon():  # subject_fname
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    su.init_mmvt_addon()
    print('Finish init MMVT!')
예제 #11
0
def render_image_blender(subject_fname):
    args = read_args(su.get_python_argv())
    if args.debug:
        su.debug()
    mmvt_dir = su.get_link_dir(su.get_links_dir(), 'mmvt')
    subject = su.get_subject_name(subject_fname)
    if args.output_path == '':
        args.output_path = op.join(mmvt_dir, args.subject, 'figures')
    su.make_dir(args.output_path)
    mmvt = su.init_mmvt_addon()
    mmvt.set_render_quality(args.quality)
    mmvt.set_render_output_path(args.output_path)
    mmvt.set_render_smooth_figure(args.smooth_figure)
    if not args.hide_lh is None:
        mmvt.show_hide_hemi(args.hide_lh, 'lh')
    if not args.hide_rh is None:
        mmvt.show_hide_hemi(args.hide_rh, 'rh')
    if not args.hide_subs is None:
        mmvt.show_hide_sub_corticals(args.hide_subs)
    if not args.show_elecs is None:
        mmvt.show_electrodes(args.show_elecs)
    if not args.show_only_lead is None:
        print('Showing only the current lead: {}'.format(args.show_only_lead))
        mmvt.set_show_only_lead(args.show_only_lead)
    if args.curr_elec not in ['', 'None']:
        print('Setting current electrode to {}'.format(args.curr_elec))
        mmvt.set_current_electrode(args.curr_elec)
    if not args.show_connections is None:
        mmvt.show_hide_connections(args.show_connections)
        mmvt.filter_nodes(args.filter_nodes)
    if args.inflated:
        mmvt.show_inflated()
        mmvt.set_inflated_ratio = args.inflated_ratio
    mmvt.set_background_color(args.background_color)
    mmvt.set_lighting(args.lighting)
    for image_name, camera in zip(args.image_name, args.camera):
        if camera == '':
            camera = op.join(mmvt_dir, subject, 'camera', 'camera.pkl')
        print('Camera fname: {}'.format(camera))
        if op.isfile(camera):
            mmvt.load_camera(camera)
        else:
            camera = op.join(mmvt_dir, subject, 'camera', 'camera.pkl')
            print('Camera was not found, loading default camera')
            mmvt.load_camera(camera)
            # if args.interactive:
            #     cont = input('No camera file was detected in the output folder, continue?')
            #     if not su.is_true(cont):
            #         continue
            # else:
            #     su.stdout_print('No camera file was detected in the output folder!!!')
            #     continue
        # su.save_blend_file(subject_fname)
        print('Rendering {}->{}'.format(image_name, args.output_path))
        mmvt.render_image(image_name,
                          args.output_path,
                          args.quality,
                          args.smooth_figure,
                          render_background=False,
                          overwrite=args.overwrite)
    su.stdout_print('*** finish rendering! ***')
    su.exit_blender()