def add_cb_to_electrode_probs():
    fol = '/homes/5/npeled/space1/mmvt/mg117/figures'
    fu.combine_brain_with_color_bar(op.join(fol, 'cortical.png'),
                                    cb_max=1,
                                    cb_min=0,
                                    cb_cm='YlOrRd',
                                    ticks=(0, 1))
def post_script(args):
    from src.utils import figures_utils as fu
    from src.utils import utils
    from src.mmvt_addon import clusters_utils as cu

    subject_fol = op.join(su.get_mmvt_dir(), args.subject)
    figures_fol = op.join(subject_fol, 'figures')
    clusters_file_names, _, _ = cu.get_clusters_files('fmri', subject_fol)
    clusters_names = [
        f for f in clusters_file_names if args.clusters_type in f
    ]
    print('clusters_names: {}'.format(clusters_names))
    fmri_files_minmax_fname = op.join(subject_fol, 'fmri',
                                      'fmri_files_minmax_cm.pkl')
    data_min, data_max, colors_map_name = utils.load(fmri_files_minmax_fname)
    for clusters_name, inflated, background_color in product(
            clusters_names, args.inflated, args.background_color):
        print('Combing figures for {}, inflated: {}, background color: {}'.
              format(clusters_name, inflated, background_color))
        perspectives_image_fname = fu.combine_four_brain_perspectives(
            figures_fol, inflated, args.dpi, background_color, clusters_name,
            args.inflated_ratio, True, args.overwrite)
        fu.combine_brain_with_color_bar(
            data_max, data_min, perspectives_image_fname, colors_map_name,
            args.overwrite, args.dpi, args.x_left_crop, args.x_right_crop,
            args.y_top_crop, args.y_buttom_crop, args.w_fac, args.h_fac,
            background_color)
Beispiel #3
0
def example1():
    figures_fol = '/cluster/neuromind/npeled/mmvt/fsaverage5c/figures/final2'
    colors_map = 'YlOrRd'
    data_max, data_min = 0.2, 0.3

    for fig_name in glob.glob(op.join(figures_fol, '*.png')):
        fu.combine_brain_with_color_bar(
            data_max, data_min, fig_name, colors_map, dpi=100,
            x_left_crop=350, x_right_crop=200)
def example5():
    figures_fol = '/home/npeled/mmvt/nmr00698/figures/'
    colors_map = 'BuPu_YlOrRd'
    data_max, data_min = 1, -1

    for fig_name in glob.glob(op.join(figures_fol, '*.png')):
        fu.combine_brain_with_color_bar(data_max,
                                        data_min,
                                        fig_name,
                                        colors_map,
                                        dpi=100)
Beispiel #5
0
def example4(subject='colin27', map_name='s32_spmT', figure_name='splitted_lateral_medial_pial_white.png'):
    data_min, data_max = utils.load(
        op.join(MMVT_DIR, subject, 'fmri', 'fmri_activity_map_minmax_{}.pkl'.format(map_name)))
    data_min = utils.ceil_floor(data_min)
    data_max = utils.ceil_floor(data_max)
    figure_fname = op.join(MMVT_DIR, subject, 'figures', figure_name)
    colors_map = 'BuPu_YlOrRd'
    background = 'white' if 'white' in figure_name else 'black'
    fu.combine_brain_with_color_bar(
        data_max, data_min, figure_fname, colors_map,
        x_left_crop=300, x_right_crop=300, y_top_crop=0, y_buttom_crop=0,
        w_fac=1.5, h_fac=1, facecolor=background)
def example1():
    figures_fol = '/cluster/neuromind/npeled/mmvt/fsaverage5c/figures/final2'
    colors_map = 'YlOrRd'
    data_max, data_min = 0.2, 0.3

    for fig_name in glob.glob(op.join(figures_fol, '*.png')):
        fu.combine_brain_with_color_bar(data_max,
                                        data_min,
                                        fig_name,
                                        colors_map,
                                        dpi=100,
                                        x_left_crop=350,
                                        x_right_crop=200)
def example7():
    images_names = glob.glob('/home/npeled/mmvt/nmr01216/figures/back/*.png')
    for fig_name in images_names:
        fu.combine_brain_with_color_bar(data_max,
                                        data_min,
                                        fig_name,
                                        args.cb_cm,
                                        dpi=100,
                                        overwrite=True,
                                        ticks=ticks,
                                        w_fac=1.2,
                                        h_fac=1.2,
                                        ddh=0.7,
                                        dy=0.13)
def example6():
    figures_fol = '/home/npeled/mmvt/nmr01216/figures'
    colors_map = 'RdOrYl'
    data_max, data_min = 2, 6
    background = '#393939'

    files = glob.glob(op.join(figures_fol, '*.png'))
    images_hemi_inv_list = set([
        utils.namebase(fname)[3:] for fname in files
        if utils.namebase(fname)[:2] in ['rh', 'lh']
    ])
    files = [[
        fname for fname in files if utils.namebase(fname)[3:] == img_hemi_inv
    ] for img_hemi_inv in images_hemi_inv_list]
    for files_coup in files:
        hemi = 'rh' if utils.namebase(files_coup[0]).startswith('rh') else 'lh'
        coup_template = files_coup[0].replace(hemi, '{hemi}')
        coup = {}
        for hemi in utils.HEMIS:
            coup[hemi] = coup_template.format(hemi=hemi)
        new_image_fname = op.join(utils.get_fname_folder(files_coup[0]),
                                  utils.namebase_with_ext(files_coup[0])[3:])

        fu.crop_image(coup['lh'], coup['lh'], dx=150, dy=0, dw=150, dh=0)
        fu.crop_image(coup['rh'], coup['rh'], dx=150, dy=0, dw=0, dh=0)
        fu.combine_two_images(coup['lh'],
                              coup['rh'],
                              new_image_fname,
                              facecolor=background)
        fu.combine_brain_with_color_bar(data_max,
                                        data_min,
                                        new_image_fname,
                                        colors_map,
                                        dpi=200,
                                        overwrite=True,
                                        w_fac=1.2,
                                        h_fac=1.2,
                                        ddh=0.7,
                                        dy=0.13,
                                        ddw=0.4,
                                        dx=-0.08)
        for hemi in utils.HEMIS:
            utils.remove_file(coup[hemi])
def example4(subject='colin27',
             map_name='s32_spmT',
             figure_name='splitted_lateral_medial_pial_white.png'):
    data_min, data_max = utils.load(
        op.join(MMVT_DIR, subject, 'fmri',
                'fmri_activity_map_minmax_{}.pkl'.format(map_name)))
    data_min = utils.ceil_floor(data_min)
    data_max = utils.ceil_floor(data_max)
    figure_fname = op.join(MMVT_DIR, subject, 'figures', figure_name)
    colors_map = 'BuPu_YlOrRd'
    background = 'white' if 'white' in figure_name else 'black'
    fu.combine_brain_with_color_bar(data_max,
                                    data_min,
                                    figure_fname,
                                    colors_map,
                                    x_left_crop=300,
                                    x_right_crop=300,
                                    y_top_crop=0,
                                    y_buttom_crop=0,
                                    w_fac=1.5,
                                    h_fac=1,
                                    facecolor=background)
Beispiel #10
0
def post_script(args):
    from src.utils import figures_utils as fu
    from src.mmvt_addon import fMRI_panel as fmri
    from src.utils import utils

    subject_fol = op.join(su.get_mmvt_dir(), args.subject)
    figures_fol = op.join(subject_fol, 'figures')
    clusters_file_names, _ = fmri.get_clusters_files(subject_fol)
    clusters_names = [f for f in clusters_file_names if args.clusters_type in f]
    print('clusters_names: {}'.format(clusters_names))
    fmri_files_minmax_fname = op.join(subject_fol, 'fmri', 'fmri_files_minmax_cm.pkl')
    data_min, data_max, colors_map_name = utils.load(fmri_files_minmax_fname)
    for clusters_name, inflated, background_color in product(clusters_names, args.inflated, args.background_color):
        print('Combing figures for {}, inflated: {}, background color: {}'.format(
            clusters_name, inflated, background_color))
        perspectives_image_fname = fu.combine_four_brain_perspectives(
            figures_fol, inflated, args.dpi, background_color,
            clusters_name, args.inflated_ratio, True, args.overwrite)
        fu.combine_brain_with_color_bar(
            data_max, data_min, perspectives_image_fname, colors_map_name, args.overwrite, args.dpi,
            args.x_left_crop, args.x_right_crop, args.y_top_crop, args.y_buttom_crop,
            args.w_fac, args.h_fac, background_color)
Beispiel #11
0
def post_blender_call(args):
    if not args.add_cb and not args.join_hemis:
        return

    from src.utils import figures_utils as fu
    from src.utils import utils
    from PIL import Image

    if args.call_mmvt_calls:
        su.waits_for_file(args.log_fname)
    with open(args.images_log_fname, 'r') as text_file:
        images_names = text_file.readlines()
    images_names = [l.strip() for l in images_names]
    data_max, data_min = list(map(float, args.cb_vals))
    ticks = list(map(float,
                     args.cb_ticks)) if args.cb_ticks is not None else None
    background = args.background_color  # '#393939'
    if args.join_hemis:
        images_hemi_inv_list = set([
            utils.namebase(fname)[3:] for fname in images_names
            if utils.namebase(fname)[:2] in ['rh', 'lh']
        ])
        files = [[
            fname for fname in images_names
            if utils.namebase(fname)[3:] == img_hemi_inv
        ] for img_hemi_inv in images_hemi_inv_list]
        fol = utils.get_fname_folder(files[0][0])
        cb_fname = op.join(fol, '{}_colorbar.jpg'.format(args.cb_cm))
        # if not op.isfile(cb_fname):
        fu.plot_color_bar(data_max,
                          data_min,
                          args.cb_cm,
                          do_save=True,
                          ticks=ticks,
                          fol=fol,
                          background_color=background,
                          cb_ticks_font_size=args.cb_ticks_font_size)
        cb_img = Image.open(cb_fname)
        for files_coup in files:
            hemi = 'rh' if utils.namebase(
                files_coup[0]).startswith('rh') else 'lh'
            coup_template = files_coup[0].replace(hemi, '{hemi}')
            coup = {
                hemi: coup_template.format(hemi=hemi)
                for hemi in utils.HEMIS
            }
            new_image_fname = op.join(
                fol,
                utils.namebase_with_ext(files_coup[0])[3:])
            if args.add_cb:
                if args.crop_figures:
                    fu.crop_image(coup['lh'],
                                  coup['lh'],
                                  dx=150,
                                  dy=0,
                                  dw=50,
                                  dh=70)
                    fu.crop_image(coup['rh'],
                                  coup['rh'],
                                  dx=150 + 50,
                                  dy=0,
                                  dw=0,
                                  dh=70)
                fu.combine_two_images(coup['lh'],
                                      coup['rh'],
                                      new_image_fname,
                                      facecolor=background,
                                      dpi=200,
                                      w_fac=1,
                                      h_fac=1)
                fu.combine_brain_with_color_bar(new_image_fname,
                                                cb_img,
                                                overwrite=True)
            else:
                if args.crop_figures:
                    fu.crop_image(coup['lh'],
                                  coup['lh'],
                                  dx=150,
                                  dy=0,
                                  dw=150,
                                  dh=0)
                    fu.crop_image(coup['rh'],
                                  coup['rh'],
                                  dx=150,
                                  dy=0,
                                  dw=150,
                                  dh=0)
                fu.combine_two_images(coup['lh'],
                                      coup['rh'],
                                      new_image_fname,
                                      facecolor=background)
            if args.remove_temp_figures:
                for hemi in utils.HEMIS:
                    utils.remove_file(coup[hemi])
    elif args.add_cb and not args.join_hemis:
        fol = utils.get_fname_folder(images_names[0])
        cb_fname = op.join(fol, '{}_colorbar.jpg'.format(args.cb_cm))
        if not op.isfile(cb_fname):
            fu.plot_color_bar(data_max,
                              data_min,
                              args.cb_cm,
                              do_save=True,
                              ticks=ticks,
                              fol=fol,
                              background_color=background)
        cb_img = Image.open(cb_fname)
        for fig_name in images_names:
            fu.combine_brain_with_color_bar(fig_name, cb_img, overwrite=True)