surfer.Brain

class surfer.Brain(subject_id, hemi, surf, title=None, cortex='classic', alpha=1.0, size=800, background='black', foreground=None, figure=None, subjects_dir=None, views=['lat'], offset=True, show_toolbar=False, offscreen='auto', interaction='trackball', units='mm')[source]

Class for visualizing a brain using multiple views in mlab

Parameters:
subject_id : str

subject name in Freesurfer subjects dir

hemi : str

hemisphere id (ie ‘lh’, ‘rh’, ‘both’, or ‘split’). In the case of ‘both’, both hemispheres are shown in the same window. In the case of ‘split’ hemispheres are displayed side-by-side in different viewing panes.

surf : str

freesurfer surface mesh name (ie ‘white’, ‘inflated’, etc.)

title : str

title for the window

cortex : str, tuple, dict, or None

Specifies how the cortical surface is rendered. Options:

  1. The name of one of the preset cortex styles: 'classic' (default), 'high_contrast', 'low_contrast', or 'bone'.
  2. A color-like argument to render the cortex as a single color, e.g. 'red' or (0.1, 0.4, 1.). Setting this to None is equivalent to (0.5, 0.5, 0.5).
  3. The name of a colormap used to render binarized curvature values, e.g., Grays.
  4. A list of colors used to render binarized curvature values. Only the first and last colors are used. E.g., [‘red’, ‘blue’] or [(1, 0, 0), (0, 0, 1)].
  5. A container with four entries for colormap (string specifiying the name of a colormap), vmin (float specifying the minimum value for the colormap), vmax (float specifying the maximum value for the colormap), and reverse (bool specifying whether the colormap should be reversed. E.g., ('Greys', -1, 2, False).
  6. A dict of keyword arguments that is passed on to the call to surface.
alpha : float in [0, 1]

Alpha level to control opacity of the cortical surface.

size : float or pair of floats

the size of the window, in pixels. can be one number to specify a square window, or the (width, height) of a rectangular window.

background : matplotlib color

Color of the background.

foreground : matplotlib color

Color of the foreground (will be used for colorbars and text). None (default) will use black or white depending on the value of background.

figure : list of mayavi.core.scene.Scene | None | int

If None (default), a new window will be created with the appropriate views. For single view plots, the figure can be specified as int to retrieve the corresponding Mayavi window.

subjects_dir : str | None

If not None, this directory will be used as the subjects directory instead of the value set using the SUBJECTS_DIR environment variable.

views : list | str

views to use

offset : bool

If True, aligs origin with medial wall. Useful for viewing inflated surface where hemispheres typically overlap (Default: True)

show_toolbar : bool

If True, toolbars will be shown for each view.

offscreen : bool | str

If True, rendering will be done offscreen (not shown). Useful mostly for generating images or screenshots, but can be buggy. Use at your own risk. Can be “auto” (default) to use mlab.options.offscreen.

interaction : str

Can be “trackball” (default) or “terrain”, i.e. a turntable-style camera.

units : str

Can be ‘m’ or ‘mm’ (default).

Attributes:
annot : list

List of annotations.

brains : list

List of the underlying brain instances.

contour : list

List of the contours.

foci : foci

The foci.

labels : dict

The labels.

overlays : dict

The overlays.

texts : dict

The text objects.

Methods

add_annotation(annot[, borders, alpha, …]) Add an annotation file.
add_contour_overlay(source[, min, max, …]) Add a topographic contour overlay of the positive data.
add_data(array[, min, max, thresh, …]) Display data from a numpy array on the surface.
add_foci(coords[, coords_as_verts, …]) Add spherical foci, possibly mapping to displayed surf.
add_label(label[, color, alpha, …]) Add an ROI label to the image.
add_morphometry(measure[, grayscale, hemi, …]) Add a morphometry overlay to the image.
add_overlay(source[, min, max, sign, name, hemi]) Add an overlay to the overlay dict from a file or array.
add_text(x, y, text, name[, color, opacity, …]) Add a text to the visualization
animate(views[, n_steps, fname, use_cache, …]) Animate a rotation.
close() Close all figures and cleanup data structure.
get_data_properties() Get properties of the data shown
hide_colorbar([row, col]) Hide colorbar(s) for given plot
index_for_time(time[, rounding]) Find the data time index closest to a specific time point.
remove_data([hemi]) Remove data shown with Brain.add_data().
remove_foci([name]) Remove foci added with Brain.add_foci().
remove_labels([labels, hemi]) Remove one or more previously added labels from the image.
reset_view() Orient camera to display original view
save_image(filename[, mode, antialiased]) Save view from all panels to disk
save_image_sequence(time_idx, fname_pattern) Save a temporal image sequence
save_imageset(prefix, views[, filetype, …]) Convenience wrapper for save_image
save_montage(filename[, order, orientation, …]) Create a montage from a given order of images
save_movie(fname[, time_dilation, tmin, …]) Save a movie (for data with a time axis)
save_single_image(filename[, row, col]) Save view from one panel to disk
scale_data_colormap(fmin, fmid, fmax, …[, …]) Scale the data colormap.
screenshot([mode, antialiased]) Generate a screenshot of current view.
screenshot_single([mode, antialiased, row, col]) Generate a screenshot of current view from a single panel.
set_data_smoothing_steps(smoothing_steps[, …]) Set the number of smoothing steps
set_data_time_index(time_idx[, interpolation]) Set the data time index to show
set_distance([distance]) Set view distances for all brain plots to the same value
set_surf(surf) Change the surface geometry
set_time(time) Set the data time index to the time point closest to time
show_colorbar([row, col]) Show colorbar(s) for given plot
show_view([view, roll, distance, row, col]) Orient camera to display view
toggle_toolbars([show]) Toggle toolbar display
update_text(text, name[, row, col]) Update text label
__hash__($self, /)

Return hash(self).

add_annotation(annot, borders=True, alpha=1, hemi=None, remove_existing=True)[source]

Add an annotation file.

Parameters:
annot : str | tuple

Either path to annotation file or annotation name. Alternatively, the annotation can be specified as a (labels, ctab) tuple per hemisphere, i.e. annot=(labels, ctab) for a single hemisphere or annot=((lh_labels, lh_ctab), (rh_labels, rh_ctab)) for both hemispheres. labels and ctab should be arrays as returned by nibabel.freesurfer.io.read_annot().

borders : bool | int

Show only label borders. If int, specify the number of steps (away from the true border) along the cortical mesh to include as part of the border definition.

alpha : float in [0, 1]

Alpha level to control opacity.

hemi : str | None

If None, it is assumed to belong to the hemipshere being shown. If two hemispheres are being shown, data must exist for both hemispheres.

remove_existing : bool

If True (default), remove old annotations.

add_contour_overlay(source, min=None, max=None, n_contours=7, line_width=1.5, colormap='YlOrRd_r', hemi=None, remove_existing=True, colorbar=True)[source]

Add a topographic contour overlay of the positive data.

Note: This visualization will look best when using the “low_contrast” cortical curvature colorscheme.

Parameters:
source : str or array

path to the overlay file or numpy array

min : float

threshold for overlay display

max : float

saturation point for overlay display

n_contours : int

number of contours to use in the display

line_width : float

width of contour lines

colormap : string, list of colors, or array

name of matplotlib colormap to use, a list of matplotlib colors, or a custom look up table (an n x 4 array coded with RBGA values between 0 and 255).

hemi : str | None

If None, it is assumed to belong to the hemipshere being shown. If two hemispheres are being shown, an error will be thrown.

remove_existing : bool

If there is an existing contour overlay, remove it before plotting.

colorbar : bool

If True, show the colorbar for the scalar value.

add_data(array, min=None, max=None, thresh=None, colormap='auto', alpha=1, vertices=None, smoothing_steps=20, time=None, time_label='time index=%d', colorbar=True, hemi=None, remove_existing=False, time_label_size=14, initial_time=None, scale_factor=None, vector_alpha=None, mid=None, center=None, transparent=False, verbose=None)[source]

Display data from a numpy array on the surface.

This provides a similar interface to surfer.Brain.add_overlay(), but it displays it with a single colormap. It offers more flexibility over the colormap, and provides a way to display four-dimensional data (i.e., a timecourse) or five-dimensional data (i.e., a vector-valued timecourse).

Note

min sets the low end of the colormap, and is separate from thresh (this is a different convention from surfer.Brain.add_overlay()).

Parameters:
array : numpy array, shape (n_vertices[, 3][, n_times])

Data array. For the data to be understood as vector-valued (3 values per vertex corresponding to X/Y/Z surface RAS), then array must be have all 3 dimensions. If vectors with no time dimension are desired, consider using a singleton (e.g., np.newaxis) to create a “time” dimension and pass time_label=None.

min : float

min value in colormap (uses real min if None)

mid : float

intermediate value in colormap (middle between min and max if None)

max : float

max value in colormap (uses real max if None)

thresh : None or float

if not None, values below thresh will not be visible

center : float or None

if not None, center of a divergent colormap, changes the meaning of min, max and mid, see scale_data_colormap() for further info.

transparent : bool

if True: use a linear transparency between fmin and fmid and make values below fmin fully transparent (symmetrically for divergent colormaps)

colormap : string, list of colors, or array

name of matplotlib colormap to use, a list of matplotlib colors, or a custom look up table (an n x 4 array coded with RBGA values between 0 and 255), the default “auto” chooses a default divergent colormap, if “center” is given (currently “icefire”), otherwise a default sequential colormap (currently “rocket”).

alpha : float in [0, 1]

alpha level to control opacity of the overlay.

vertices : numpy array

vertices for which the data is defined (needed if len(data) < nvtx)

smoothing_steps : int or None

number of smoothing steps (smoothing is used if len(data) < nvtx) Default : 20

time : numpy array

time points in the data array (if data is 2D or 3D)

time_label : str | callable | None

format of the time label (a format string, a function that maps floating point time values to strings, or None for no label)

colorbar : bool

whether to add a colorbar to the figure

hemi : str | None

If None, it is assumed to belong to the hemisphere being shown. If two hemispheres are being shown, an error will be thrown.

remove_existing : bool

Remove surface added by previous “add_data” call. Useful for conserving memory when displaying different data in a loop.

time_label_size : int

Font size of the time label (default 14)

initial_time : float | None

Time initially shown in the plot. None to use the first time sample (default).

scale_factor : float | None (default)

The scale factor to use when displaying glyphs for vector-valued data.

vector_alpha : float | None

alpha level to control opacity of the arrows. Only used for vector-valued data. If None (default), alpha is used.

verbose : bool, str, int, or None

If not None, override default verbose level (see surfer.verbose).

Notes

If the data is defined for a subset of vertices (specified by the “vertices” parameter), a smoothing method is used to interpolate the data onto the high resolution surface. If the data is defined for subsampled version of the surface, smoothing_steps can be set to None, in which case only as many smoothing steps are applied until the whole surface is filled with non-zeros.

Due to a Mayavi (or VTK) alpha rendering bug, vector_alpha is clamped to be strictly < 1.

add_foci(coords, coords_as_verts=False, map_surface=None, scale_factor=1, color='white', alpha=1, name=None, hemi=None)[source]

Add spherical foci, possibly mapping to displayed surf.

The foci spheres can be displayed at the coordinates given, or mapped through a surface geometry. In other words, coordinates from a volume-based analysis in MNI space can be displayed on an inflated average surface by finding the closest vertex on the white surface and mapping to that vertex on the inflated mesh.

Parameters:
coords : numpy array

x, y, z coordinates in stereotaxic space (default) or array of vertex ids (with coord_as_verts=True)

coords_as_verts : bool

whether the coords parameter should be interpreted as vertex ids

map_surface : Freesurfer surf or None

surface to map coordinates through, or None to use raw coords

scale_factor : float

Controls the size of the foci spheres (relative to 1cm).

color : matplotlib color code

HTML name, RBG tuple, or hex code

alpha : float in [0, 1]

opacity of focus gylphs

name : str

internal name to use

hemi : str | None

If None, it is assumed to belong to the hemipshere being shown. If two hemispheres are being shown, an error will be thrown.

add_label(label, color=None, alpha=1, scalar_thresh=None, borders=False, hemi=None, subdir=None)[source]

Add an ROI label to the image.

Parameters:
label : str | instance of Label

label filepath or name. Can also be an instance of an object with attributes “hemi”, “vertices”, “name”, and optionally “color” and “values” (if scalar_thresh is not None).

color : matplotlib-style color | None

anything matplotlib accepts: string, RGB, hex, etc. (default “crimson”)

alpha : float in [0, 1]

alpha level to control opacity

scalar_thresh : None or number

threshold the label ids using this value in the label file’s scalar field (i.e. label only vertices with scalar >= thresh)

borders : bool | int

Show only label borders. If int, specify the number of steps (away from the true border) along the cortical mesh to include as part of the border definition.

hemi : str | None

If None, it is assumed to belong to the hemipshere being shown. If two hemispheres are being shown, an error will be thrown.

subdir : None | str

If a label is specified as name, subdir can be used to indicate that the label file is in a sub-directory of the subject’s label directory rather than in the label directory itself (e.g. for $SUBJECTS_DIR/$SUBJECT/label/aparc/lh.cuneus.label brain.add_label('cuneus', subdir='aparc')).

Notes

To remove previously added labels, run Brain.remove_labels().

add_morphometry(measure, grayscale=False, hemi=None, remove_existing=True, colormap=None, min=None, max=None, colorbar=True)[source]

Add a morphometry overlay to the image.

Parameters:
measure : {‘area’ | ‘curv’ | ‘jacobian_white’ | ‘sulc’ | ‘thickness’}

which measure to load

grayscale : bool

whether to load the overlay with a grayscale colormap

hemi : str | None

If None, it is assumed to belong to the hemipshere being shown. If two hemispheres are being shown, data must exist for both hemispheres.

remove_existing : bool

If True (default), remove old annotations.

colormap : str

Mayavi colormap name, or None to use a sensible default.

min, max : floats

Endpoints for the colormap; if not provided the robust range of the data is used.

colorbar : bool

If True, show a colorbar corresponding to the overlay data.

add_overlay(source, min=2, max='robust_max', sign='abs', name=None, hemi=None)[source]

Add an overlay to the overlay dict from a file or array.

Parameters:
source : str or numpy array

path to the overlay file or numpy array with data

min : float

threshold for overlay display

max : float

saturation point for overlay display

sign : {‘abs’ | ‘pos’ | ‘neg’}

whether positive, negative, or both values should be displayed

name : str

name for the overlay in the internal dictionary

hemi : str | None

If None, it is assumed to belong to the hemipshere being shown. If two hemispheres are being shown, an error will be thrown.

add_text(x, y, text, name, color=None, opacity=1.0, row=-1, col=-1, font_size=None, justification=None)[source]

Add a text to the visualization

Parameters:
x : Float

x coordinate

y : Float

y coordinate

text : str

Text to add

name : str

Name of the text (text label can be updated using update_text())

color : Tuple

Color of the text. Default is the foreground color set during initialization (default is black or white depending on the background color).

opacity : Float

Opacity of the text. Default: 1.0

row : int

Row index of which brain to use

col : int

Column index of which brain to use

animate(views, n_steps=180.0, fname=None, use_cache=False, row=-1, col=-1)[source]

Animate a rotation.

Currently only rotations through the axial plane are allowed.

Parameters:
views: sequence

views to animate through

n_steps: float

number of steps to take in between

fname: string

If not None, it saves the animation as a movie. fname should end in ‘.avi’ as only the AVI format is supported

use_cache: bool

Use previously generated images in ./.tmp/

row : int

Row index of the brain to use

col : int

Column index of the brain to use

close()[source]

Close all figures and cleanup data structure.

data_dict

For backwards compatibility

data_time_index

Retrieve the currently displayed data time index

Returns:
time_idx : int

Current time index.

Notes

Raises a RuntimeError if the Brain instance has not data overlay.

get_data_properties()[source]

Get properties of the data shown

Returns:
props : dict

Dictionary with data properties

props[“fmin”] : minimum colormap props[“fmid”] : midpoint colormap props[“fmax”] : maximum colormap props[“transparent”] : lower part of colormap transparent? props[“time”] : time points props[“time_idx”] : current time index props[“smoothing_steps”] : number of smoothing steps

hide_colorbar(row=-1, col=-1)[source]

Hide colorbar(s) for given plot

Parameters:
row : int

Row index of which brain to use

col : int

Column index of which brain to use

index_for_time(time, rounding='closest')[source]

Find the data time index closest to a specific time point.

Parameters:
time : scalar

Time.

rounding : ‘closest’ | ‘up’ | ‘down’

How to round if the exact time point is not an index.

Returns:
index : int

Data time index closest to time.

labels_dict

For backwards compatibility

remove_data(hemi=None)[source]

Remove data shown with Brain.add_data().

Parameters:
hemi : str | None

Hemisphere from which to remove data (default is all shown hemispheres).

remove_foci(name=None)[source]

Remove foci added with Brain.add_foci().

Parameters:
name : str | list of str | None

Names of the foci to remove (if None, remove all).

Notes

Only foci added with a unique names can be removed.

remove_labels(labels=None, hemi=None)[source]

Remove one or more previously added labels from the image.

Parameters:
labels : None | str | list of str

Labels to remove. Can be a string naming a single label, or None to remove all labels. Possible names can be found in the Brain.labels attribute.

hemi : None

Deprecated parameter, do not use.

reset_view()[source]

Orient camera to display original view

save_image(filename, mode='rgb', antialiased=False)[source]

Save view from all panels to disk

Only mayavi image types are supported: (png jpg bmp tiff ps eps pdf rib oogl iv vrml obj

Parameters:
filename: string

path to new image file

mode : string

Either ‘rgb’ (default) to render solid background, or ‘rgba’ to include alpha channel for transparent background.

antialiased : bool

Antialias the image (see mayavi.mlab.screenshot() for details; see default False).

Notes

Due to limitations in TraitsUI, if multiple views or hemi=’split’ is used, there is no guarantee painting of the windows will complete before control is returned to the command line. Thus we strongly recommend using only one figure window (which uses a Mayavi figure to plot instead of TraitsUI) if you intend to script plotting commands.

save_image_sequence(time_idx, fname_pattern, use_abs_idx=True, row=-1, col=-1, montage='single', border_size=15, colorbar='auto', interpolation='quadratic')[source]

Save a temporal image sequence

The files saved are named fname_pattern % pos where pos is a relative or absolute index (controlled by use_abs_idx).

Parameters:
time_idx : array_like

Time indices to save. Non-integer values will be displayed using interpolation between samples.

fname_pattern : str

Filename pattern, e.g. ‘movie-frame_%0.4d.png’.

use_abs_idx : bool

If True the indices given by time_idx are used in the filename if False the index in the filename starts at zero and is incremented by one for each image (Default: True).

row : int

Row index of the brain to use.

col : int

Column index of the brain to use.

montage : ‘current’ | ‘single’ | list

Views to include in the images: ‘current’ uses the currently displayed image; ‘single’ (default) uses a single view, specified by the row and col parameters; a 1 or 2 dimensional list can be used to specify a complete montage. Examples: ['lat', 'med'] lateral and ventral views ordered horizontally; [['fro'], ['ven']] frontal and ventral views ordered vertically.

border_size : int

Size of image border (more or less space between images).

colorbar : ‘auto’ | int | list of int | None

For ‘auto’, the colorbar is shown in the middle view (default). For int or list of int, the colorbar is shown in the specified views. For None, no colorbar is shown.

interpolation : str

Interpolation method (scipy.interpolate.interp1d parameter, one of ‘linear’ | ‘nearest’ | ‘zero’ | ‘slinear’ | ‘quadratic’ | ‘cubic’, default ‘quadratic’). Interpolation is only used for non-integer indexes.

Returns:
images_written : list

All filenames written.

save_imageset(prefix, views, filetype='png', colorbar='auto', row=-1, col=-1)[source]

Convenience wrapper for save_image

Files created are prefix+’_$view’+filetype

Parameters:
prefix: string | None

filename prefix for image to be created. If None, a list of arrays representing images is returned (not saved to disk).

views: list

desired views for images

filetype: string

image type

colorbar: ‘auto’ | int | list of int | None

For ‘auto’, the colorbar is shown in the middle view (default). For int or list of int, the colorbar is shown in the specified views. For None, no colorbar is shown.

row : int

row index of the brain to use

col : int

column index of the brain to use

Returns:
images_written: list

all filenames written

save_montage(filename, order=['lat', 'ven', 'med'], orientation='h', border_size=15, colorbar='auto', row=-1, col=-1)[source]

Create a montage from a given order of images

Parameters:
filename: string | None

path to final image. If None, the image will not be saved.

order: list

list of views: order of views to build montage (default ['lat', 'ven', 'med']; nested list of views to specify views in a 2-dimensional grid (e.g, [['lat', 'ven'], ['med', 'fro']])

orientation: {‘h’ | ‘v’}

montage image orientation (horizontal of vertical alignment; only applies if order is a flat list)

border_size: int

Size of image border (more or less space between images)

colorbar: ‘auto’ | int | list of int | None

For ‘auto’, the colorbar is shown in the middle view (default). For int or list of int, the colorbar is shown in the specified views. For None, no colorbar is shown.

row : int

row index of the brain to use

col : int

column index of the brain to use

Returns:
out : array

The montage image, usable with matplotlib.pyplot.imshow().

save_movie(fname, time_dilation=4.0, tmin=None, tmax=None, framerate=24, interpolation='quadratic', codec=None, bitrate=None, **kwargs)[source]

Save a movie (for data with a time axis)

The movie is created through the imageio module. The format is determined by the extension, and additional options can be specified through keyword arguments that depend on the format. For available formats and corresponding parameters see the imageio documentation: http://imageio.readthedocs.io/en/latest/formats.html#multiple-images

Warning

This method assumes that time is specified in seconds when adding data. If time is specified in milliseconds this will result in movies 1000 times longer than expected.

Parameters:
fname : str

Path at which to save the movie. The extension determines the format (e.g., ‘*.mov’, ‘*.gif’, …; see the imageio documenttion for available formats).

time_dilation : float

Factor by which to stretch time (default 4). For example, an epoch from -100 to 600 ms lasts 700 ms. With time_dilation=4 this would result in a 2.8 s long movie.

tmin : float

First time point to include (default: all data).

tmax : float

Last time point to include (default: all data).

framerate : float

Framerate of the movie (frames per second, default 24).

interpolation : str

Interpolation method (scipy.interpolate.interp1d parameter, one of ‘linear’ | ‘nearest’ | ‘zero’ | ‘slinear’ | ‘quadratic’ | ‘cubic’, default ‘quadratic’).

**kwargs :

Specify additional options for imageio.

Notes

Requires imageio package, which can be installed together with PySurfer with:

$ pip install -U pysurfer[save_movie]
save_single_image(filename, row=-1, col=-1)[source]

Save view from one panel to disk

Only mayavi image types are supported: (png jpg bmp tiff ps eps pdf rib oogl iv vrml obj

Parameters:
filename: string

path to new image file

row : int

row index of the brain to use

col : int

column index of the brain to use

Due to limitations in TraitsUI, if multiple views or hemi=’split’
is used, there is no guarantee painting of the windows will
complete before control is returned to the command line. Thus
we strongly recommend using only one figure window (which uses
a Mayavi figure to plot instead of TraitsUI) if you intend to
script plotting commands.
scale_data_colormap(fmin, fmid, fmax, transparent, center=None, alpha=1.0, verbose=None)[source]

Scale the data colormap.

The colormap may be sequential or divergent. When the colormap is divergent indicate this by providing a value for ‘center’. The meanings of fmin, fmid and fmax are different for sequential and divergent colormaps. For sequential colormaps the colormap is characterised by:

[fmin, fmid, fmax]

where fmin and fmax define the edges of the colormap and fmid will be the value mapped to the center of the originally chosen colormap. For divergent colormaps the colormap is characterised by:

[center-fmax, center-fmid, center-fmin, center,
 center+fmin, center+fmid, center+fmax]

i.e., values between center-fmin and center+fmin will not be shown while center-fmid will map to the middle of the first half of the original colormap and center-fmid to the middle of the second half.

Parameters:
fmin : float

minimum value for colormap

fmid : float

value corresponding to color midpoint

fmax : float

maximum value for colormap

transparent : boolean

if True: use a linear transparency between fmin and fmid and make values below fmin fully transparent (symmetrically for divergent colormaps)

center : float

if not None, gives the data value that should be mapped to the center of the (divergent) colormap

alpha : float

sets the overall opacity of colors, maintains transparent regions

verbose : bool, str, int, or None

If not None, override default verbose level (see surfer.verbose).

screenshot(mode='rgb', antialiased=False)[source]

Generate a screenshot of current view.

Wraps to mayavi.mlab.screenshot() for ease of use.

Parameters:
mode : string

Either ‘rgb’ or ‘rgba’ for values to return.

antialiased : bool

Antialias the image (see mayavi.mlab.screenshot() for details; default False).

Returns:
screenshot : array

Image pixel values.

Notes

Due to limitations in TraitsUI, if multiple views or hemi='split' is used, there is no guarantee painting of the windows will complete before control is returned to the command line. Thus we strongly recommend using only one figure window (which uses a Mayavi figure to plot instead of TraitsUI) if you intend to script plotting commands.

screenshot_single(mode='rgb', antialiased=False, row=-1, col=-1)[source]

Generate a screenshot of current view from a single panel.

Wraps to mayavi.mlab.screenshot() for ease of use.

Parameters:
mode: string

Either ‘rgb’ or ‘rgba’ for values to return

antialiased: bool

Antialias the image (see mayavi.mlab.screenshot() for details).

row : int

row index of the brain to use

col : int

column index of the brain to use

Returns:
screenshot: array

Image pixel values

Notes

Due to limitations in TraitsUI, if multiple views or hemi=’split’ is used, there is no guarantee painting of the windows will complete before control is returned to the command line. Thus we strongly recommend using only one figure window (which uses a Mayavi figure to plot instead of TraitsUI) if you intend to script plotting commands.

set_data_smoothing_steps(smoothing_steps, verbose=None)[source]

Set the number of smoothing steps

Parameters:
smoothing_steps : int

Number of smoothing steps

verbose : bool, str, int, or None

If not None, override default verbose level (see surfer.verbose).

set_data_time_index(time_idx, interpolation='quadratic')[source]

Set the data time index to show

Parameters:
time_idx : int | float

Time index. Non-integer values will be displayed using interpolation between samples.

interpolation : str

Interpolation method (scipy.interpolate.interp1d parameter, one of ‘linear’ | ‘nearest’ | ‘zero’ | ‘slinear’ | ‘quadratic’ | ‘cubic’, default ‘quadratic’). Interpolation is only used for non-integer indexes.

set_distance(distance=None)[source]

Set view distances for all brain plots to the same value

Parameters:
distance : float | None

Distance to use. If None, brains are set to the farthest “best fit” distance across all current views; note that the underlying “best fit” function can be buggy.

Returns:
distance : float

The distance used.

set_surf(surf)[source]

Change the surface geometry

Parameters:
surf : str

freesurfer surface mesh name (ie ‘white’, ‘inflated’, etc.)

set_time(time)[source]

Set the data time index to the time point closest to time

Parameters:
time : scalar

Time.

show_colorbar(row=-1, col=-1)[source]

Show colorbar(s) for given plot

Parameters:
row : int

Row index of which brain to use

col : int

Column index of which brain to use

show_view(view=None, roll=None, distance=None, row=-1, col=-1)[source]

Orient camera to display view

Parameters:
view : str | dict

brain surface to view (one of ‘lateral’, ‘medial’, ‘rostral’, ‘caudal’, ‘dorsal’, ‘ventral’, ‘frontal’, ‘parietal’) or kwargs to pass to mayavi.mlab.view().

roll : float

camera roll

distance : float | ‘auto’ | None

distance from the origin

row : int

Row index of which brain to use

col : int

Column index of which brain to use

Returns:
view : tuple

tuple returned from mlab.view

roll : float

camera roll returned from mlab.roll

toggle_toolbars(show=None)[source]

Toggle toolbar display

Parameters:
show : bool | None

If None, the state is toggled. If True, the toolbar will be shown, if False, hidden.

update_text(text, name, row=-1, col=-1)[source]

Update text label

Parameters:
text : str

New text for label

name : str

Name of text label