示例#1
0
def arbitrary_colours(_, atlas_name):
    """
    Non-meaningful colour selection.
    """
    from palettable.colorbrewer.qualitative import Paired_12
    cmap = Paired_12.get_mpl_colormap()
    regions = atlas.get_atlas_labels(atlas_name)

    x = np.linspace(0, 1, len(regions))
    data = {r: cmap(x[i])[:3] for i, r in enumerate(regions)}
    print data

    return 0, 1, data
示例#2
0
def groups(filename, atlas_name):
    """
    Returns a dictionary of colours for the brain surfaces. Input values are
    assumed to be ordinal values of clusters or groups of regions, starting
    with zero.
    """
    regions = atlas.get_atlas_labels(atlas_name)
    data = [x.rstrip().split(',') for x in open(filename).readlines()]
    data = [(x, int(y)) for x, y in data if x in regions]
    n = max(y for x, y in data)

    import seaborn
    cmap = seaborn.color_palette(n_colors=n+1)
    data = {x: cmap[y] for x, y in data}

    return 0, n, data
示例#3
0
def make_fig(filename, hemi, surf, atlas_name, colour_func, output_dir, missing=(0.5, 0.5, 0.5)):
    """
    Make a brain figure.

    filename : path to the csv that contains the brain region names and the
    associated values.

    hemi : 'lh' or 'rh'.

    surf : 'inflated' or 'pial'

    atlas_name : 'Destrieux' or 'DSK'.

    colour_func : function object that creates a colour dictionary based on the
    data inside the csv.

    output_dir : name of output directory (put inside 'outputs').
    """
    if colour_func is not None:
        min, max, cd = colour_func(filename, atlas_name)
    else:
        cd = {}
    regions = atlas.get_atlas_labels(atlas_name)

    for region in regions:
        if region in cd:
            c = cd[region]
            load.load_surface(hemi, surf, atlas_name, region, c)
        else:
            if missing is not None:
                c = missing
                print "Warning: '%s' region missing (%s atlas)." % (region, atlas_name)
                load.load_surface(hemi, surf, atlas_name, region, c)

    # reposition the camera
    angles = [[180, -90, -70], [180, 90, 70], [180, 0, 0], [0, 180, 0]]

    fpath = paths.pj(paths.OUTPUTS_DIR, output_dir)
    if not os.path.exists(fpath):
        os.makedirs(fpath)

    for a, e, r in angles:
        f = paths.pj(fpath, "%i_%i_%i.png" % (a, e, r))
        mlab.view(a, e, roll=r)
        mlab.savefig(f, magnification=3)
示例#4
0
def minuslog10pvals(filename, atlas_name):
    """
    Returns a dictionary of colours for the brain surfaces. Input values are
    assumed to be p-values and colours are based on -log10 of those values.
    """
    cmap = plt.cm.get_cmap('afmhot_r')
    regions = atlas.get_atlas_labels(atlas_name)

    f = lambda x: (
        x.rstrip().split(',')[0],
        -np.log10(float(x.rstrip().split(',')[1]))
    )
    data = [f(x) for x in open(filename).readlines()]
    extra_regions = [x for x, y in data if x not in regions]
    print 'Warning: Extra regions:', extra_regions
    data = [x for x in data if x[0] in regions]
    vmin, vmax = min(x[1] for x in data), max(x[1] for x in data)
    data = {r: cmap(v / vmax)[:3] for r, v in data}

    print data
    return vmin, vmax, data