Beispiel #1
0
def make_svg(fname, braindata, with_labels=False, with_curvature=True, layers=['rois'],
             height=1024, overlay_file=None, **kwargs):
    """Save an svg file of the desired flatmap.

    This function creates an SVG file with vector graphic ROIs overlaid on a single png image.
    Ideally, this function would layer different images (curvature, data, dropout, etc), but
    that has been left to implement at a future date if anyone really wants it.

    Parameters
    ----------
    fname : string
        file name to save
    braindata : Dataview
        the data you would like to plot on a flatmap
    with_labels : bool
        Whether to display text labels on ROIs
    with_curvature : bool
        Whether to include background curvature
    layers : list
        List of layer names to show
    height : int
        Height of PNG in pixels
    overlay_file : str
    	Custom ROI overlays file to use

    """
    fp = io.BytesIO()
    from matplotlib.pylab import imsave

    ## Render PNG file & retrieve image data
    arr, extents = make_flatmap_image(braindata, height=height, **kwargs)

    if hasattr(braindata, 'cmap'):
        imsave(fp, arr, cmap=braindata.cmap, vmin=braindata.vmin, vmax=braindata.vmax)
    else:
        imsave(fp, arr)
    fp.seek(0)
    pngdata = binascii.b2a_base64(fp.read())
    image_data = [pngdata]

    if with_curvature:
        # no options. learn to love it.
        from cortex import db
        fpc = io.BytesIO()
        curv_vertices = db.get_surfinfo(braindata.subject)
        curv_arr, _ = make_flatmap_image(curv_vertices, height=height)
        mask = np.isnan(curv_arr)
        curv_arr = np.where(curv_arr > 0, 0.5, 0.25)
        curv_arr[mask] = np.nan

        imsave(fpc, curv_arr, cmap='Greys_r', vmin=0, vmax=1)
        fpc.seek(0)
        image_data = [binascii.b2a_base64(fpc.read()), pngdata]

    ## Create and save SVG file
    roipack = utils.db.get_overlay(braindata.subject, overlay_file)
    roipack.get_svg(fname, layers=layers, labels=with_labels, with_ims=image_data)
Beispiel #2
0
def make_svg(fname, braindata, with_labels=False, with_curvature=True, layers=['rois'],
             height=1024, **kwargs):
    """Save an svg file of the desired flatmap.

    This function creates an SVG file with vector graphic ROIs overlaid on a single png image.
    Ideally, this function would layer different images (curvature, data, dropout, etc), but
    that has been left to implement at a future date if anyone really wants it.

    Parameters
    ----------
    fname : string
        file name to save
    braindata : Dataview
        the data you would like to plot on a flatmap
    with_labels : bool
        Whether to display text labels on ROIs
    with_curvature : bool
        Whether to include background curvature
    layers : list
        List of layer names to show
    height : int
        Height of PNG in pixels

    """
    fp = io.BytesIO()
    from matplotlib.pylab import imsave

    ## Render PNG file & retrieve image data
    arr, extents = make_flatmap_image(braindata, height=height, **kwargs)

    if hasattr(braindata, 'cmap'):
        imsave(fp, arr, cmap=braindata.cmap, vmin=braindata.vmin, vmax=braindata.vmax)
    else:
        imsave(fp, arr)
    fp.seek(0)
    pngdata = binascii.b2a_base64(fp.read())
    image_data = [pngdata]

    if with_curvature:
        # no options. learn to love it.
        from cortex import db
        fpc = io.BytesIO()
        curv_vertices = db.get_surfinfo(braindata.subject)
        curv_arr, _ = make_flatmap_image(curv_vertices, height=height)
        mask = np.isnan(curv_arr)
        curv_arr = np.where(curv_arr > 0, 0.5, 0.25)
        curv_arr[mask] = np.nan

        imsave(fpc, curv_arr, cmap='Greys_r', vmin=0, vmax=1)
        fpc.seek(0)
        image_data = [binascii.b2a_base64(fpc.read()), pngdata]

    ## Create and save SVG file
    roipack = utils.get_roipack(braindata.subject)
    roipack.get_svg(fname, layers=layers, labels=with_labels, with_ims=image_data)