Example #1
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()
Example #2
0
def import_electrodes(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.import_electrodes(args.pos_file, args.bipolar, args.radius)
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #3
0
def render_image(subject_fname):
    args = read_args(su.get_python_argv())
    if args.output_path == '':
        mmvt_dir = op.join(su.get_links_dir(), 'mmvt')
        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 op.isfile(op.join(args.output_path, 'camera.pkl')):
        mmvt.load_camera()
    else:
        cont = input('No camera file was detected in the output folder, continue?')
        if not su.is_true(cont):
            return
    # su.save_blend_file(subject_fname)
    mmvt.render_image(args.image_name, args.output_path, args.quality, args.smooth_figure, render_background=False)
    su.exit_blender()
Example #4
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()
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()
Example #6
0
def create_new_subject(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.import_brain()
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #7
0
def import_electrodes(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.import_electrodes(args.pos_file, args.bipolar, args.radius)
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #8
0
def import_meg_sensors(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.import_meg_sensors()
    mmvt.add_data_to_meg_sensors(args.stat)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #9
0
def create_new_subject(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.import_brain()
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #10
0
def import_connections(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.set_connection_type(args.type)
    mmvt.set_connections_threshold(args.threshold)
    mmvt.create_connections()
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #11
0
def import_meg(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.add_data_to_parent_brain_obj(args.stat)
    mmvt.add_data_to_brain()
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #12
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()
Example #13
0
def import_connections(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.set_connection_type(args.type)
    mmvt.set_connections_threshold(args.threshold)
    mmvt.create_connections()
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #14
0
def render_electrodes_probs(subject_fname):
    args = read_args(su.get_python_argv())
    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)
    if op.isfile(op.join(args.output_path, 'camera.pkl')):
        mmvt.load_camera()
    else:
        # Try to find the camera in the figures folder
        if op.isfile(op.join(figures_dir, 'camera.pkl')):
            mmvt.set_render_output_path(figures_dir)
            mmvt.load_camera()
            mmvt.set_render_output_path(args.output_path)
        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)
    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()
Example #15
0
def install_blender_reqs():
    import pip
    pip.main(['install', '--upgrade', 'pip'])
    libs = ['zmq', 'pizco', 'scipy', 'mne', 'joblib']
    for lib in libs:
        try:
            pip.main(['install', lib])
        except:
            print('Error in installing {}!'.format(lib))
    su.exit_blender()
def render_electrodes_probs(subject_fname):
    args = read_args(su.get_python_argv())
    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)
    if op.isfile(op.join(args.output_path, 'camera.pkl')):
        mmvt.load_camera()
    else:
        # Try to find the camera in the figures folder
        if op.isfile(op.join(figures_dir, 'camera.pkl')):
            mmvt.set_render_output_path(figures_dir)
            mmvt.load_camera()
            mmvt.set_render_output_path(args.output_path)
        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)
    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()
def wrap_mmvt_calls(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    mmvt.import_brain()
    mmvt.set_render_output_path = su.get_figures_dir(args)
    su.save_blend_file(subject_fname)
    with open(args.log_fname, 'w') as text_file:
        print(args, file=text_file)
    try:
        su.exit_blender()
    except:
        pass
Example #18
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()
Example #19
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()
Example #20
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()
Example #21
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()
Example #22
0
def render_image(subject_fname):
    args = read_args(su.get_python_argv())
    if args.output_path == '':
        mmvt_dir = op.join(su.get_links_dir(), 'mmvt')
        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)
    if op.isfile(op.join(args.output_path, 'camera.pkl')):
        mmvt.load_camera()
    else:
        cont = input(
            'No camera file was detected in the output folder, continue?')
        if not su.is_true(cont):
            return
    # su.save_blend_file(subject_fname)
    mmvt.render_image(args.image_name,
                      args.output_path,
                      args.quality,
                      args.smooth_figure,
                      render_background=False)
    su.exit_blender()
Example #23
0
def render_movie(subject_fname):
    args = read_args(su.get_python_argv())
    if args.rel_output_path:
        mmvt_dir = op.join(su.get_links_dir(), 'mmvt')
        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)
    if op.isfile(op.join(args.output_path, 'camera.pkl')):
        mmvt.load_camera()
    else:
        cont = input('No camera file was detected in the output folder, continue?')
        if not su.is_true(cont):
            return
    if not op.isfile(op.join(args.output_path, 'data.pkl')):
        mmvt.capture_graph(args.play_type, args.output_path, args.selection_type)
    su.save_blend_file(subject_fname)
    mmvt.render_movie(args.play_type, args.play_from, args.play_to, args.play_dt)
    su.exit_blender()
Example #24
0
def import_meg(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    try:
        mmvt.add_data_to_parent_brain_obj(args.stat)
    except:
        logging.error('Error in add_data_to_parent_brain_obj!')
        logging.error(traceback.format_exc())
    try:
        mmvt.add_data_to_brain()
    except:
        logging.error('Error in add_data_to_brain!')
        logging.error(traceback.format_exc())
    try:
        mmvt.set_render_output_path = su.get_figures_dir(args)
    except:
        logging.error('Error in set_render_output_path!')
        logging.error(traceback.format_exc())
    try:
        su.save_blend_file(subject_fname)
    except:
        logging.error('Error in save_blend_file!')
        logging.error(traceback.format_exc())
    su.exit_blender()
Example #25
0
def import_meg(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    try:
        mmvt.add_data_to_parent_brain_obj(args.stat)
    except:
        logging.error('Error in add_data_to_parent_brain_obj!')
        logging.error(traceback.format_exc())
    try:
        mmvt.add_data_to_brain()
    except:
        logging.error('Error in add_data_to_brain!')
        logging.error(traceback.format_exc())
    try:
        mmvt.set_render_output_path = su.get_figures_dir(args)
    except:
        logging.error('Error in set_render_output_path!')
        logging.error(traceback.format_exc())
    try:
        su.save_blend_file(subject_fname)
    except:
        logging.error('Error in save_blend_file!')
        logging.error(traceback.format_exc())
    su.exit_blender()
def add_fmri_dynamics_to_parent_obj(subject_fname):
    mmvt = su.init_mmvt_addon()
    mmvt.add_fmri_dynamics_to_parent_obj(add_fmri_subcorticals_data=True)
    su.save_blend_file(subject_fname)
    su.exit_blender()
Example #27
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()
Example #28
0
def do_something(subject_fname):
    args = read_args(su.get_python_argv())
    mmvt = su.init_mmvt_addon()
    # Call mmvt functions
    su.save_blend_file(subject_fname)
    su.exit_blender()