def calc_con_colors(con_values, high_low_diff):
    M = con_values.shape[0]
    stat_data = utils.calc_stat_data(con_values, STAT_AVG, axis=con_values.ndim-1)
    # con_colors = utils.arr_to_colors(stat_data, 0, 1)[:, :3]
    # con_colors = utils.arr_to_colors_two_colors_maps(stat_data, 0, 1, 'RdPu', 'hot', 0.05, flip_cm_big=True)[:, :3]
    from src.mmvt_addon import colors_utils
    red = np.array(colors_utils.name_to_rgb('red')) / 255.0
    blue = np.array(colors_utils.name_to_rgb('blue')) / 255.0
    magenta = np.array(colors_utils.name_to_rgb('magenta')) / 255.0
    green = np.array(colors_utils.name_to_rgb('green')) / 255.0
    if con_values.ndim == 2:
        con_colors = np.zeros((M, 3))
        con_colors[(stat_data <= 0.05) & (high_low_diff >= 0)] = red
        con_colors[(stat_data <= 0.05) & (high_low_diff < 0)] = blue
        con_colors[(stat_data > 0.05) & (high_low_diff >= 0)] = magenta
        con_colors[(stat_data > 0.05) & (high_low_diff < 0)] = green
    elif con_values.ndim == 3:
        W = con_values.shape[1]
        con_colors = np.zeros((M, W, 3))
        for w in range(W):
            stat_w = stat_data[:, w]
            high_low_diff_w = high_low_diff[:, w]
            sig_high = (abs(stat_w) >= -np.log10(0.05)) & (high_low_diff_w >= 0)
            sig_low =  (abs(stat_w) >= -np.log10(0.05)) & (high_low_diff_w < 0)
            print(w, sig_high, sig_low)
            con_colors[sig_high, w] = red
            con_colors[sig_low, w] = blue
            con_colors[(abs(stat_w) < -np.log10(0.05)) & (high_low_diff_w >= 0), w] = (1, 1, 1)
            con_colors[(abs(stat_w) < -np.log10(0.05)) & (high_low_diff_w < 0), w] = (1, 1, 1)
    # con_colors = con_colors[:, :, :, np.newaxis]
    return con_colors
Beispiel #2
0
def get_rois_colors(subject, atlas, rois):
    not_white_rois = set(filter(lambda r:'white' not in r.lower(), rois))
    white_rois = rois - not_white_rois
    not_white_rois = sorted(list(not_white_rois))
    colors = cu.get_distinct_colors_and_names()
    lables_colors_rgbs_fname = op.join(MMVT_DIR, subject, 'coloring', 'labels_{}_coloring.csv'.format(atlas))
    lables_colors_names_fname = op.join(MMVT_DIR, subject, 'coloring', 'labels_{}_colors_names.csv'.format(atlas))
    labels_colors_exist = op.isfile(lables_colors_rgbs_fname) and op.isfile(lables_colors_names_fname)
    rois_colors_rgbs, rois_colors_names = OrderedDict(), OrderedDict()
    if not labels_colors_exist:
        print('No labels coloring file!')
    else:
        labels_colors_rgbs = np.genfromtxt(lables_colors_rgbs_fname, dtype=str, delimiter=',')
        labels_colors_names = np.genfromtxt(lables_colors_names_fname, dtype=str, delimiter=',')
    for roi in not_white_rois:
        if labels_colors_exist:
            roi_inds = np.where(labels_colors_rgbs[:, 0] == '{}-rh'.format(roi))[0]
            if len(roi_inds) > 0:
                color_rgb = labels_colors_rgbs[roi_inds][0, 1:].tolist()
                color_name = labels_colors_names[roi_inds][0, 1]
            else:
                color_rgb, color_name = next(colors)
        else:
            color_rgb, color_name = next(colors)
        rois_colors_rgbs[roi], rois_colors_names[roi] = color_rgb, color_name
    for white_roi in white_rois:
        rois_colors_rgbs[white_roi], rois_colors_names[white_roi] = cu.name_to_rgb('white').tolist(), 'white'
    return rois_colors_rgbs, rois_colors_names
Beispiel #3
0
def calc_con_colors(con_values, high_low_diff):
    M = con_values.shape[0]
    stat_data = utils.calc_stat_data(con_values,
                                     STAT_AVG,
                                     axis=con_values.ndim - 1)
    # con_colors = utils.arr_to_colors(stat_data, 0, 1)[:, :3]
    # con_colors = utils.arr_to_colors_two_colors_maps(stat_data, 0, 1, 'RdPu', 'hot', 0.05, flip_cm_big=True)[:, :3]
    from src.mmvt_addon import colors_utils
    red = np.array(colors_utils.name_to_rgb('red')) / 255.0
    blue = np.array(colors_utils.name_to_rgb('blue')) / 255.0
    magenta = np.array(colors_utils.name_to_rgb('magenta')) / 255.0
    green = np.array(colors_utils.name_to_rgb('green')) / 255.0
    if con_values.ndim == 2:
        con_colors = np.zeros((M, 3))
        con_colors[(stat_data <= 0.05) & (high_low_diff >= 0)] = red
        con_colors[(stat_data <= 0.05) & (high_low_diff < 0)] = blue
        con_colors[(stat_data > 0.05) & (high_low_diff >= 0)] = magenta
        con_colors[(stat_data > 0.05) & (high_low_diff < 0)] = green
    elif con_values.ndim == 3:
        W = con_values.shape[1]
        con_colors = np.zeros((M, W, 3))
        for w in range(W):
            stat_w = stat_data[:, w]
            high_low_diff_w = high_low_diff[:, w]
            sig_high = (abs(stat_w) >= -np.log10(0.05)) & (high_low_diff_w >=
                                                           0)
            sig_low = (abs(stat_w) >= -np.log10(0.05)) & (high_low_diff_w < 0)
            print(w, sig_high, sig_low)
            con_colors[sig_high, w] = red
            con_colors[sig_low, w] = blue
            con_colors[(abs(stat_w) < -np.log10(0.05)) &
                       (high_low_diff_w >= 0), w] = (1, 1, 1)
            con_colors[(abs(stat_w) < -np.log10(0.05)) & (high_low_diff_w < 0),
                       w] = (1, 1, 1)
    # con_colors = con_colors[:, :, :, np.newaxis]
    return con_colors
def write_electrode_colors(template, electrodes_colors):
    import csv
    fol = utils.make_dir(op.join(MMVT_DIR, template, 'coloring'))
    csv_fname = op.join(fol, 'morphed_electrodes.csv')
    # unique_colors = np.unique(utils.flat_list(([[k[1] for k in elecs] for elecs in electrodes_colors.values()])))
    # colors = utils.get_distinct_colors(len(unique_colors))
    from src.mmvt_addon import colors_utils as cu
    colors = [
        cu.name_to_rgb(c)
        for c in ['blue', 'green', 'purple', 'red', 'brown', 'yellow']
    ]
    print('Writing csv file to {}'.format(csv_fname))
    with open(csv_fname, 'w') as csv_file:
        wr = csv.writer(csv_file, quoting=csv.QUOTE_NONE)
        for subject in electrodes_colors.keys():
            # for elc_name, _ in template_electrodes[subject]:
            for elc_name, color_id in electrodes_colors[subject]:
                color = colors[color_id - 1]
                wr.writerow([elc_name, *color])