Python API Reference

These are the classes and functions in pycortex.

Most commonly used modules


Makes flattened views of volumetric data on the cortical surface.

add_curvature(fig, dataview[, extents, ...]) Add curvature layer to figure
add_data(fig, braindata[, height, thick, ...]) Add data to quickflat plot
add_rois(fig, dataview[, extents, height, ...]) Add ROIs layer to a figure
add_sulci(fig, dataview[, extents, height, ...]) Add sulci layer to figure
add_hatch(fig, hatch_data[, extents, ...]) Add hatching to figure at locations specified in hatch_data
add_colorbar(fig, cimg[, colorbar_ticks, ...]) Add a colorbar to a flatmap plot
add_custom(fig, dataview, svgfile, layer[, ...]) Add a custom data layer
add_cutout(fig, name, dataview[, layers, ...]) Apply a cutout mask to extant layers in flatmap figure
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.
get_flatmask(subject[, height, recache])
get_flatcache(subject, xfmname[, pixelwise, ...])


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.


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(red, green, blue[, subject, ...]) 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


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.


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


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


Contains functions for interfacing with freesurfer

get_paths(subject, hemi[, type, ...]) Retrive paths for all surfaces for a subject processed by freesurfer
autorecon(subject[, type])
flatten(subject, hemi, patch[, ...]) Flattens a brain
import_subj(subject[, sname, ...]) Imports a subject from freesurfer
import_flat(subject, patch[, sname, ...]) Imports a flat brain from freesurfer
show_surf(subject, hemi, type[, patch, ...]) Show a surface from a Freesurfer subject directory
make_fiducial(subject[, freesurfer_subject_dir])
get_surf(subject, hemi, type[, patch, ...])
get_curv(subject, hemi[, type, ...])
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(left, right, shape) Maps data from epi volume onto surface using various projections
get_mapper(subject, xfmname[, type, recache])


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.


Surface(pts, polys) Represents a single cortical hemisphere surface.
Distortion(flat, ref, polys) Used to compute distortion metrics between fiducial and another (e.g.


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

init_subject(subject, filename) Run the first initial segmentation for a subject’s anatomy.
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.


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)


Contain utility functions

add_roi(data[, name, open_inkscape, add_path]) 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, xfmname, aseg_id, ...) 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)
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 bitmask for the given ROI
get_roi_masks(subject, xfmname[, roi_list, ...]) Return a numbered mask + dictionary of roi numbers
get_roi_verts(subject[, roi]) 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 a movie


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]
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


Affine transformation class

Transform(xfm, reference) A standard affine transform.