Python API Reference

These are the classes and functions in pycortex.

Most commonly used modules

quickflat

make_figure(braindata[, recache, pixelwise, …])

Show a Volume or Vertex on a flatmap with matplotlib.

make_png(fname, braindata[, recache, …])

Create a PNG of the VertexData or VolumeData on a flatmap.

make_svg(fname, braindata[, with_labels, …])

Save an svg file of the desired flatmap.

webgl

Makes an interactive viewer for viewing data in a browser

show(data[, types, recache, cmap, layout, …])

Creates a webGL MRI viewer that is dynamically served by a tornado server running inside the current python process.

make_static(outpath, data[, types, recache, …])

Creates a static webGL MRI viewer in your filesystem so that it can easily be posted publically for sharing or just saved for later viewing.

dataset

Contains classes for representing brain data in either volumetric or vertex (surface-based) formats for visualization.

Volume(data, subject, xfmname[, mask, cmap, …])

Encapsulates a 3D volume or 4D volumetric movie.

Volume2D(dim1, dim2[, subject, xfmname, …])

Contains two 3D volumes for simultaneous visualization.

VolumeRGB(channel1, channel2, channel3[, …])

Contains RGB (or RGBA) colors for each voxel in a volumetric dataset.

Vertex(data, subject[, cmap, vmin, vmax, …])

Encapsulates a 1D vertex map or 2D vertex movie.

Vertex2D(dim1, dim2[, subject, description, …])

Contains two vertex maps for simultaneous visualization.

VertexRGB(red, green, blue[, subject, …])

Contains RGB (or RGBA) colors for each vertex in a surface dataset.

Dataset(**kwargs)

Wrapper for multiple data objects.

All the other modules

align

Contains functions for making alignments between functional data and the surface, or, finding where the brain is.

manual(subject, xfmname[, reference])

Open GUI for manually aligning a functional volume to the cortical surface for subject.

automatic(subject, xfmname, reference[, …])

Create an automatic alignment using the FLIRT boundary-based alignment (BBR) from FSL.

autotweak(subject, xfmname)

Tweak an alignment using the FLIRT boundary-based alignment (BBR) from FSL.

anat

Contains functions for making a whitematter mask

brainmask(outfile, subject)

whitematter(outfile, subject[, do_voxelize])

voxelize(outfile, subject[, surf, mp])

Voxelize the whitematter surface to generate the white matter mask

database

Contains a singleton object db of type Database which allows easy access to surface files, anatomical images, and transforms that are stored in the pycortex filestore.

Database()

Surface database

freesurfer

Contains functions for interfacing with freesurfer

get_paths(fs_subject, hemi[, type, …])

Retrive paths for all surfaces for a subject processed by freesurfer

autorecon(fs_subject[, type, parallel, n_cores])

Run Freesurfer’s autorecon-all command for a given freesurfer subject

flatten(fs_subject, hemi, patch[, …])

Perform flattening of a brain using freesurfer

import_subj(fs_subject[, cx_subject, …])

Imports a subject from freesurfer

import_flat(fs_subject, patch[, hemis, …])

Imports a flat brain from freesurfer

show_surf(subject, hemi, type[, patch, …])

Show a surface from a Freesurfer subject directory

make_fiducial(fs_subject[, …])

Make fiducial surface (halfway between white matter and pial surfaces)

parse_surf(filename)

parse_curv(filename)

parse_patch(filename)

get_surf(subject, hemi, type[, patch, …])

Read freesurfer surface file

get_curv(fs_subject, hemi[, type, …])

Load freesurfer curv file for a freesurfer subject

write_dot(fname, pts, polys[, name])

read_dot(fname, pts)

write_decimated(path, pts, polys)

SpringLayout(pts, polys[, dpts, pins, …])

stretch_mwall(pts, polys, mwall)

mapper

Mapper(left, right, shape, subject, xfmname)

Maps data from epi volume onto surface using various projections

get_mapper(subject, xfmname[, type, recache])

mni

Functions for finding MNI transforms for individual subjects and transforming functional data and surfaces to and from MNI space.

compute_mni_transform(subject, xfm[, template])

Compute transform from the space specified by xfm to MNI standard space.

transform_to_mni(volumedata, func_to_mni[, …])

Transform data in volumedata to MNI space, resample at the resolution of the atlas image.

transform_surface_to_mni(subject, surfname)

Transform the surface named surfname for subject called subject into MNI coordinates.

transform_mni_to_subject(subject, xfm, …)

Transform data in volarray from MNI space to functional space specified by xfm.

polyutils

Surface(pts, polys)

Represents a single cortical hemisphere surface.

Distortion(flat, ref, polys)

Used to compute distortion metrics between fiducial and another (e.g.

segment

Controls functions for segmentation of white/gray matter and other things in the brain.

init_subject(subject, filenames[, …])

Run the first initial segmentation for a subject’s anatomy (in Freesurfer).

fix_wm(subject)

Initializes an interface to make white matter edits to the surface.

fix_pia(subject)

Initializes an interface to make pial surface edits.

cut_surface(cx_subject, hemi[, name, …])

Initializes an interface to cut the segmented surface for flatmapping.

surfinfo

Contains functions for computing various surface properties. Mostly wrappers for functions in polyutils.Surface and polyutils.Distortion.

curvature(outfile, subject[, smooth])

Compute smoothed mean curvature of the fiducial surface for the given subject and save it to outfile.

distortion(outfile, subject[, dist_type, smooth])

Compute distortion of flatmap relative to fiducial surface and save it at outfile.

thickness(outfile, subject)

Compute cortical thickness as the distance between corresponding pial and white matter vertices for the given subject.

tissots_indicatrix(outfile, sub[, radius, …])

Compute a Tissot’s indicatrix for the given subject and save the result to a file.

flat_border(outfile, subject)

utils

Contain utility functions

add_roi(data[, name, open_inkscape, …])

Add new flatmap image to the ROI file for a subject.

anat2epispace(anatdata, subject, xfmname[, …])

Resamples data from anatomical space into epi space

get_aseg_mask(subject, aseg_name[, xfmname, …])

Return an epi space mask of the given ID from freesurfer’s automatic segmentation

get_cmap(name)

Gets a colormaps

get_cortical_mask(subject, xfmname[, type])

Gets the cortical mask for a particular transform

get_ctmmap(subject, **kwargs)

Parameters

get_ctmpack(subject[, types, method, level, …])

Creates ctm file for the specified input arguments.

get_dropout(subject, xfmname[, power])

Create a dropout Volume showing where EPI signal is very low.

get_hemi_masks(subject, xfmname[, type])

Returns a binary mask of the left and right hemisphere surface voxels for the given subject.

get_roi_mask(subject, xfmname[, roi, projection])

Return a mask for the given ROI(s)

get_roi_masks(subject, xfmname[, roi_list, …])

Return a dictionary of roi masks

get_roi_verts(subject[, roi, mask, overlay_file])

Return vertices for the given ROIs, or all ROIs if none are given.

get_vox_dist(subject, xfmname[, surface, …])

Get the distance (in mm) from each functional voxel to the closest point on the surface.

make_movie(stim, outfile[, fps, size])

Makes an .ogv movie

vertex_to_voxel(subject)

Parameters

volume

Contains functions for working with volume data

unmask(mask, data)

Unmask the data, assuming it’s been masked.

mosaic(data[, dim, show])

Turns volume data into a mosaic, useful for quickly viewing volumetric data with radiological convention (left side of figure is right side of subject).

epi2anatspace(volumedata[, order])

Resample an epi volume data into anatomical space using scipy.

anat2epispace(anatdata, subject, xfmname[, …])

Resamples data from anatomical space into epi space

epi2anatspace_fsl(volumedata)

Resamples epi-space [data] into the anatomical space for the given [subject] using the given transformation [xfm].

anat2epispace_fsl(data, subject, xfmname)

Resamples anat-space data into the epi space for the given [subject] and transformation [xfm]

show_slice(dataview, **kwargs)

show_mip(data, **kwargs)

Display a maximum intensity projection for the data, using three subplots

show_glass(dataview[, pad])

Create a classic “glass brain” view of the data, with the outline

xfm

Affine transformation class

Transform(xfm, reference)

A standard affine transform.