Skip to content

Commit 10dcd36

Browse files
committed
RF/DOC: improved documenation, updated pysurfer script, added example
1 parent 85d5df6 commit 10dcd36

File tree

3 files changed

+84
-24
lines changed

3 files changed

+84
-24
lines changed

bin/pysurfer

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ if __name__ == '__main__':
7373
from surfer import Brain
7474

7575
# Load up the figure and underlying brain object
76-
b = Brain(args.subject_id, args.hemi, args.surf, args.curv,
77-
args.title, views=args.views, size=args.size,
78-
background=args.background, cortex=args.cortex)
76+
b = Brain(args.subject_id, args.hemi, args.surf, title=args.title,
77+
cortex=args.cortex, alpha=args.alpha, size=args.size,
78+
background=args.background, foreground=args.foreground,
79+
views=args.views)
7980

8081
# Maybe load some morphometry
8182
if args.morphometry is not None:

examples/plot_transparent_brain.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
=======================
3+
Plot Transparent Brain
4+
=======================
5+
6+
Plot a transparent brain to visualize foci below the surface.
7+
8+
"""
9+
import os
10+
import os.path as op
11+
from surfer import Brain
12+
13+
print(__doc__)
14+
15+
subject_id = "fsaverage"
16+
subjects_dir = os.environ["SUBJECTS_DIR"]
17+
18+
"""To render a transparent brain, we are specifying an alpha <
19+
1.0. This allows us to visualize foci that are not on the cortical
20+
surface. When the brain see-through, rendering of binary curvature is
21+
distracting, so we specify a color, rather than a color map as the
22+
argument for cortex:
23+
24+
"""
25+
brain = Brain(subject_id, "lh", "pial", cortex='ivory', alpha=0.5)
26+
27+
"""Here's a set of stereotaxic foci in the MNI coordinate system that
28+
are not on the cortical surface which we want to display.
29+
30+
"""
31+
32+
coords = [[-20, 10, 10],
33+
[-25, 22, 15],
34+
[-18, 8, 20]]
35+
36+
"""Now we plot the foci in the brain. Because the foci are not on the
37+
cortical surface, they are only visible when alpha is set to < 1.0 in
38+
the call to Brain.
39+
40+
"""
41+
brain.add_foci(coords, color="red")

surfer/viz.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,24 @@ class Brain(object):
296296
freesurfer surface mesh name (ie 'white', 'inflated', etc.)
297297
title : str
298298
title for the window
299-
cortex : str, tuple, or dict
300-
Specifies if/how binarized curvature values are rendered. If
301-
binarized curvature values should be rendered it can be
302-
either the name of a preset PySurfer cortex colorscheme (one
303-
of 'classic' (default), 'bone', 'low_contrast', or
304-
'high_contrast'), the name of a mayavi colormap, a 4-tuple with
305-
values (colormap, min, max, reverse), or a dictionary with
306-
corresponding keys to fully specify the curvature colors. If a
307-
color is specified instead, the brain is rendered in that
308-
color without displaying the binarized curvature values. A
309-
setting of `None` produces a gray brain without binarized
310-
curvature.
299+
cortex : str, tuple, dict, or None
300+
Specifies how the cortical surface is rendered. Accepts
301+
specification of a colormap (in which case binarized curvature
302+
values are rendered) or a color (in which case the cortical
303+
surface is rendered without binarized curvature values). Can
304+
be set to: (1) the name of one of the preset cortex styles
305+
('classic' [default], 'high_contrast', 'low_contrast', or
306+
'bone'), (2) the name of a colormap, (3) a tuple with four
307+
entries for (colormap, vmin, vmax, reverse) indicating the
308+
name of the colormap, the min and max values respectively and
309+
whether or not the colormap should be reversed, (4) a valid
310+
color specification (such as a 3-tuple with RGB values or a
311+
valid color name), or (5) a dictionary of keyword arguments
312+
that is passed on to the call to surface. If set to `None`,
313+
color is set to (0.5, 0.5, 0.5) rendering a gray brain without
314+
binarized curvature.
311315
alpha : float in [0, 1]
312-
Alpha level to control opacity.
316+
Alpha level to control opacity of the cortical surface.
313317
size : float or pair of floats
314318
the size of the window, in pixels. can be one number to specify
315319
a square window, or the (width, height) of a rectangular window.
@@ -352,7 +356,7 @@ def __init__(self, subject_id, hemi, surf, title=None,
352356
"be removed in future versions. You should update your "
353357
"code and pass these options directly to the `Brain` "
354358
"constructor.")
355-
warn(msg)
359+
warn(msg, DeprecationWarning)
356360
cortex = config_opts.get("cortex", cortex)
357361
background = config_opts.get("background", background)
358362
foreground = config_opts.get("foreground", foreground)
@@ -370,7 +374,7 @@ def __init__(self, subject_id, hemi, surf, title=None,
370374
"will reproduce the previous behavior when `curv` was "
371375
"set to `False`. To emulate the previous behavior for "
372376
"cases where `curv` was set to `True`, simply omit it.")
373-
warn(msg)
377+
warn(msg, DeprecationWarning)
374378
if not curv:
375379
cortex = None
376380

@@ -516,11 +520,20 @@ def _get_geo_params(self, cortex, alpha=1.0):
516520
517521
Parameters
518522
----------
519-
cortex : {classic, high_contrast, low_contrast, bone, tuple}
520-
The name of one of the preset cortex styles, or a tuple
521-
with four entries as described in the return vales.
523+
cortex : {str, tuple, dict, None}
524+
Can be set to: (1) the name of one of the preset cortex
525+
styles ('classic', 'high_contrast', 'low_contrast', or
526+
'bone'), (2) the name of a colormap, (3) a tuple with
527+
four entries for (colormap, vmin, vmax, reverse)
528+
indicating the name of the colormap, the min and max
529+
values respectively and whether or not the colormap should
530+
be reversed, (4) a valid color specification (such as a
531+
3-tuple with RGB values or a valid color name), or (5) a
532+
dictionary of keyword arguments that is passed on to the
533+
call to surface. If set to None, color is set to (0.5,
534+
0.5, 0.5).
522535
alpha : float in [0, 1]
523-
Alpha level to control opacity.
536+
Alpha level to control opacity of the cortical surface.
524537
525538
Returns
526539
-------
@@ -553,9 +566,14 @@ def _get_geo_params(self, cortex, alpha=1.0):
553566
vmin=-.2, vmax=2,
554567
opacity=alpha), True, True))
555568
if isinstance(cortex, dict):
569+
if not cortex.has_key('opacity'):
570+
cortex['opacity'] = alpha
571+
if cortex.has_key('colormap'):
572+
if not cortex.has_key('vmin'):
573+
cortex['vmin'] = -1
574+
if not cortex.has_key('vmax'):
575+
cortex['vmax'] = 2
556576
geo_params = cortex, False, True
557-
if not geo_params[0].has_key('opacity'):
558-
geo_params[0]['opacity'] = alpha
559577
elif cortex in colormap_map:
560578
geo_params = colormap_map[cortex]
561579
elif cortex in lut_manager.lut_mode_list():

0 commit comments

Comments
 (0)