@@ -294,17 +294,22 @@ class Brain(object):
294
294
in different viewing panes.
295
295
surf : geometry name
296
296
freesurfer surface mesh name (ie 'white', 'inflated', etc.)
297
- curv : boolean
298
- if true, loads curv file and displays binary curvature
299
- (default: True)
300
297
title : str
301
298
title for the window
302
- cortex : str or tuple
303
- specifies how binarized curvature values are rendered.
304
- either the name of a preset PySurfer cortex colorscheme (one of
305
- 'classic', 'bone', 'low_contrast', or 'high_contrast'), or the
306
- name of mayavi colormap, or a tuple with values (colormap, min,
307
- max, reverse, alpha) to fully specify the curvature colors.
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.
311
+ alpha : float in [0, 1]
312
+ Alpha level to control opacity.
308
313
size : float or pair of floats
309
314
the size of the window, in pixels. can be one number to specify
310
315
a square window, or the (width, height) of a rectangular window.
@@ -335,11 +340,11 @@ class Brain(object):
335
340
List of the underlying brain instances.
336
341
337
342
"""
338
- def __init__ (self , subject_id , hemi , surf , curv = True , title = None ,
339
- cortex = "classic" , size = 800 , background = "black" ,
343
+ def __init__ (self , subject_id , hemi , surf , title = None ,
344
+ cortex = "classic" , alpha = 1.0 , size = 800 , background = "black" ,
340
345
foreground = "white" , figure = None , subjects_dir = None ,
341
346
views = ['lat' ], offset = True , show_toolbar = False ,
342
- offscreen = False , config_opts = None ):
347
+ offscreen = False , config_opts = None , curv = None ):
343
348
344
349
# Keep backwards compatability
345
350
if config_opts is not None :
@@ -356,6 +361,18 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
356
361
width = config_opts .get ("width" , size )
357
362
height = config_opts .get ("height" , size )
358
363
size = (width , height )
364
+ # Keep backwards compatability
365
+ if curv is not None :
366
+ msg = ("The `curv` keyword has been deprecated and will "
367
+ "be removed in future versions. You should update your "
368
+ "code and use the `cortex` keyword to specify how the "
369
+ "brain surface is rendered. Setting `cortex` to `None` "
370
+ "will reproduce the previous behavior when `curv` was "
371
+ "set to `False`. To emulate the previous behavior for "
372
+ "cases where `curv` was set to `True`, simply omit it." )
373
+ warn (msg )
374
+ if not curv :
375
+ cortex = None
359
376
360
377
col_dict = dict (lh = 1 , rh = 1 , both = 1 , split = 2 )
361
378
n_col = col_dict [hemi ]
@@ -385,12 +402,13 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
385
402
geo_hemis = ['rh' ]
386
403
else :
387
404
raise ValueError ('bad hemi value' )
405
+ geo_kwargs , geo_reverse , geo_curv = self ._get_geo_params (cortex , alpha )
388
406
for h in geo_hemis :
389
407
# Initialize a Surface object as the geometry
390
408
geo = Surface (subject_id , h , surf , subjects_dir , offset )
391
409
# Load in the geometry and (maybe) curvature
392
410
geo .load_geometry ()
393
- if curv :
411
+ if geo_curv :
394
412
geo .load_curvature ()
395
413
self .geo [h ] = geo
396
414
@@ -414,9 +432,9 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
414
432
self ._toggle_render (False )
415
433
416
434
# fill figures with brains
417
- kwargs = dict (surf = surf , curv = curv , title = None ,
418
- cortex = cortex , subjects_dir = subjects_dir ,
419
- bg_color = self ._bg_color , offset = offset )
435
+ kwargs = dict (surf = surf , geo_curv = geo_curv , geo_kwargs = geo_kwargs ,
436
+ geo_reverse = geo_reverse , subjects_dir = subjects_dir ,
437
+ bg_color = self ._bg_color )
420
438
brains = []
421
439
brain_matrix = []
422
440
for ri , view in enumerate (views ):
@@ -492,6 +510,77 @@ def _set_window_properties(self, size, background, foreground):
492
510
fg_color_rgb = colorConverter .to_rgb (foreground )
493
511
self ._fg_color = fg_color_rgb
494
512
513
+ def _get_geo_params (self , cortex , alpha = 1.0 ):
514
+ """Return keyword arguments and other parameters for surface
515
+ rendering.
516
+
517
+ Parameters
518
+ ----------
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.
522
+ alpha : float in [0, 1]
523
+ Alpha level to control opacity.
524
+
525
+ Returns
526
+ -------
527
+ kwargs : dict
528
+ Dictionary with keyword arguments to be used for surface
529
+ rendering. For colormaps, keys are ['colormap', 'vmin',
530
+ 'vmax', 'alpha'] to specify the name, minimum, maximum,
531
+ and alpha transparency of the colormap respectively. For
532
+ colors, keys are ['color', 'alpha'] to specify the name
533
+ and alpha transparency of the color respectively.
534
+ reverse : boolean
535
+ Boolean indicating whether a colormap should be
536
+ reversed. Set to False if a color (rather than a colormap)
537
+ is specified.
538
+ curv : boolean
539
+ Boolean indicating whether curv file is loaded and binary
540
+ curvature is displayed.
541
+
542
+ """
543
+ colormap_map = dict (classic = (dict (colormap = "Greys" ,
544
+ vmin = - 1 , vmax = 2 ,
545
+ opacity = alpha ), False , True ),
546
+ high_contrast = (dict (colormap = "Greys" ,
547
+ vmin = - .1 , vmax = 1.3 ,
548
+ opacity = alpha ), False , True ),
549
+ low_contrast = (dict (colormap = "Greys" ,
550
+ vmin = - 5 , vmax = 5 ,
551
+ opacity = alpha ), False , True ),
552
+ bone = (dict (colormap = "bone" ,
553
+ vmin = - .2 , vmax = 2 ,
554
+ opacity = alpha ), True , True ))
555
+ if cortex in colormap_map :
556
+ geo_params = colormap_map [cortex ]
557
+ elif cortex in lut_manager .lut_mode_list ():
558
+ geo_params = dict (colormap = cortex , vmin = - 1 , vmax = 2 ,
559
+ opacity = alpha ), False , True
560
+ elif isinstance (cortex , dict ):
561
+ geo_params = cortex , False , True
562
+ if not geo_params [0 ].has_key ('opacity' ):
563
+ geo_params [0 ]['opacity' ] = alpha
564
+ # check for None before checking len:
565
+ elif cortex is None :
566
+ geo_params = dict (color = (0.5 , 0.5 , 0.5 ),
567
+ opacity = alpha ), False , False
568
+ # Test for 4-tuple specifying colormap parameters. Need to
569
+ # avoid 4 letter strings and 4-tuples not specifying a
570
+ # colormap name in the first position (color can be specified
571
+ # as RGBA tuple, but the A value will be dropped by to_rgb()):
572
+ elif (not isinstance (cortex , basestring )) and (len (cortex ) == 4 ) and (
573
+ isinstance (cortex [0 ], basestring )):
574
+ geo_params = dict (colormap = cortex [0 ], vmin = cortex [1 ],
575
+ vmax = cortex [2 ], opacity = alpha ), cortex [3 ], True
576
+ else :
577
+ try :
578
+ color = colorConverter .to_rgb (cortex )
579
+ geo_params = dict (color = color , opacity = alpha ), False , False
580
+ except ValueError :
581
+ geo_params = cortex , False , True
582
+ return geo_params
583
+
495
584
def get_data_properties (self ):
496
585
""" Get properties of the data shown
497
586
@@ -2341,8 +2430,8 @@ def animate(self, views, n_steps=180., fname=None, use_cache=False,
2341
2430
2342
2431
class _Hemisphere (object ):
2343
2432
"""Object for visualizing one hemisphere with mlab"""
2344
- def __init__ (self , subject_id , hemi , surf , figure , geo , curv , title ,
2345
- cortex , subjects_dir , bg_color , offset , backend ):
2433
+ def __init__ (self , subject_id , hemi , surf , figure , geo , geo_curv ,
2434
+ geo_kwargs , geo_reverse , subjects_dir , bg_color , backend ):
2346
2435
if hemi not in ['lh' , 'rh' ]:
2347
2436
raise ValueError ('hemi must be either "lh" or "rh"' )
2348
2437
# Set the identifying info
@@ -2357,16 +2446,12 @@ def __init__(self, subject_id, hemi, surf, figure, geo, curv, title,
2357
2446
2358
2447
# mlab pipeline mesh and surface for geomtery
2359
2448
self ._geo = geo
2360
- if curv :
2449
+ if geo_curv :
2361
2450
curv_data = self ._geo .bin_curv
2362
2451
meshargs = dict (scalars = curv_data )
2363
- colormap , vmin , vmax , reverse , alpha = self ._get_geo_colors (cortex )
2364
- kwargs = dict (colormap = colormap , vmin = vmin , vmax = vmax ,
2365
- opacity = alpha )
2366
2452
else :
2367
2453
curv_data = None
2368
2454
meshargs = dict ()
2369
- kwargs = dict (color = (.5 , .5 , .5 ))
2370
2455
meshargs ['figure' ] = self ._f
2371
2456
x , y , z , f = self ._geo .x , self ._geo .y , self ._geo .z , self ._geo .faces
2372
2457
self ._geo_mesh = mlab .pipeline .triangular_mesh_source (x , y , z , f ,
@@ -2376,8 +2461,8 @@ def __init__(self, subject_id, hemi, surf, figure, geo, curv, title,
2376
2461
self ._geo_mesh .data .cell_data .normals = None
2377
2462
self ._geo_surf = mlab .pipeline .surface (self ._geo_mesh ,
2378
2463
figure = self ._f , reset_zoom = True ,
2379
- ** kwargs )
2380
- if curv and reverse :
2464
+ ** geo_kwargs )
2465
+ if geo_curv and geo_reverse :
2381
2466
curv_bar = mlab .scalarbar (self ._geo_surf )
2382
2467
curv_bar .reverse_lut = True
2383
2468
curv_bar .visible = False
@@ -2654,46 +2739,6 @@ def _orient_lights(self):
2654
2739
for light in self ._f .scene .light_manager .lights :
2655
2740
light .azimuth *= - 1
2656
2741
2657
- def _get_geo_colors (self , cortex ):
2658
- """Return an mlab colormap name, vmin, vmax, and alpha for binary
2659
- curvature.
2660
-
2661
- Parameters
2662
- ----------
2663
- cortex : {classic, high_contrast, low_contrast, bone, tuple}
2664
- The name of one of the preset cortex styles, or a tuple
2665
- with five entries as described in the return vales.
2666
-
2667
- Returns
2668
- -------
2669
- colormap : string
2670
- mlab colormap name
2671
- vmin : float
2672
- curv colormap minimum
2673
- vmax : float
2674
- curv colormap maximum
2675
- reverse : boolean
2676
- boolean indicating whether the colormap should be reversed
2677
- alpha : float in [0, 1]
2678
- alpha level to control opacity
2679
-
2680
- """
2681
- colormap_map = dict (classic = ("Greys" , - 1 , 2 , False , 1.0 ),
2682
- high_contrast = ("Greys" , - .1 , 1.3 , False , 1.0 ),
2683
- low_contrast = ("Greys" , - 5 , 5 , False , 1.0 ),
2684
- bone = ("bone" , - .2 , 2 , True , 1.0 ))
2685
-
2686
- if cortex in colormap_map :
2687
- color_data = colormap_map [cortex ]
2688
- elif cortex in lut_manager .lut_mode_list ():
2689
- color_data = cortex , - 1 , 2 , False , 1.0
2690
- else :
2691
- if len (cortex ) == 4 :
2692
- color_data = tuple (cortex ) + (1.0 , )
2693
- else :
2694
- color_data = cortex
2695
- return color_data
2696
-
2697
2742
def _format_cbar_text (self , cbar ):
2698
2743
bg_color = self ._bg_color
2699
2744
if bg_color is None or sum (bg_color ) < 2 :
0 commit comments