12
12
13
13
from mayavi import mlab
14
14
from mayavi .tools .mlab_scene_model import MlabSceneModel
15
+ from mayavi .core import lut_manager
15
16
from mayavi .core .ui .api import SceneEditor
16
17
from mayavi .core .ui .mayavi_scene import MayaviScene
17
18
from traits .api import (HasTraits , Range , Int , Float ,
18
19
Bool , Enum , on_trait_change , Instance )
19
20
20
21
from . import utils , io
21
- from .config import config
22
22
from .utils import (Surface , verbose , create_color_lut , _get_subjects_dir ,
23
23
string_types , assert_ffmpeg_is_available , ffmpeg )
24
24
@@ -296,8 +296,18 @@ class Brain(object):
296
296
(default: True)
297
297
title : str
298
298
title for the window
299
- config_opts : dict
300
- options to override visual options in config file
299
+ cortex : str or tuple
300
+ specifies how binarized curvature values are rendered.
301
+ either the name of a preset PySurfer cortex colorscheme (one of
302
+ 'classic', 'bone', 'low_contrast', or 'high_contrast'), or the
303
+ name of mayavi colormap, or a tuple with values (colormap, min,
304
+ max, reverse) to fully specify the curvature colors.
305
+ width, height : floats
306
+ width and height (in pixels) of the display window
307
+ size : float
308
+ specify a square display window, overriding the width and height
309
+ background, foreground : matplotlib colors
310
+ color of the background and foreground of the display window
301
311
figure : list of instances of mayavi.core.scene.Scene | None
302
312
If None, a new window will be created with the appropriate
303
313
views.
@@ -318,10 +328,28 @@ class Brain(object):
318
328
----------
319
329
brains : list
320
330
List of the underlying brain instances.
331
+
321
332
"""
322
333
def __init__ (self , subject_id , hemi , surf , curv = True , title = None ,
323
- config_opts = {}, figure = None , subjects_dir = None ,
324
- views = ['lat' ], show_toolbar = False , offscreen = False ):
334
+ cortex = "classic" , width = 800 , height = 800 , size = None ,
335
+ background = "black" , foreground = "white" , figure = None ,
336
+ subjects_dir = None , views = ['lat' ],
337
+ show_toolbar = False , offscreen = False , config_opts = None ):
338
+
339
+ # Keep backwards compatability
340
+ if config_opts is not None :
341
+ msg = ("The `config_opts` dict has been deprecated and will "
342
+ "be removed in future versions. You should update your "
343
+ "code and pass these options directly to the `Brain` "
344
+ "constructor." )
345
+ warn (msg )
346
+ cortex = config_opts .get ("cortex" , cortex )
347
+ width = config_opts .get ("width" , width )
348
+ height = config_opts .get ("height" , height )
349
+ size = config_opts .get ("size" , size )
350
+ background = config_opts .get ("background" , background )
351
+ foreground = config_opts .get ("foreground" , foreground )
352
+
325
353
col_dict = dict (lh = 1 , rh = 1 , both = 1 , split = 2 )
326
354
n_col = col_dict [hemi ]
327
355
if hemi not in col_dict .keys ():
@@ -360,7 +388,8 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
360
388
self .geo [h ] = geo
361
389
362
390
# deal with making figures
363
- self ._set_window_properties (config_opts )
391
+ self ._set_window_properties (width , height , size ,
392
+ background , foreground )
364
393
figures , _v = _make_viewer (figure , n_row , n_col , title ,
365
394
self ._scene_size , offscreen )
366
395
self ._figures = figures
@@ -371,6 +400,7 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
371
400
if f .scene is not None :
372
401
f .scene .background = self ._bg_color
373
402
f .scene .foreground = self ._fg_color
403
+
374
404
# force rendering so scene.lights exists
375
405
_force_render (self ._figures , self ._window_backend )
376
406
self .toggle_toolbars (show_toolbar )
@@ -379,7 +409,7 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
379
409
380
410
# fill figures with brains
381
411
kwargs = dict (surf = surf , curv = curv , title = None ,
382
- config_opts = config_opts , subjects_dir = subjects_dir ,
412
+ cortex = cortex , subjects_dir = subjects_dir ,
383
413
bg_color = self ._bg_color , offset = offset )
384
414
brains = []
385
415
brain_matrix = []
@@ -441,39 +471,19 @@ def _toggle_render(self, state, views=None):
441
471
_force_render (self ._figures , self ._window_backend )
442
472
return views
443
473
444
- def _set_window_properties (self , config_opts ):
445
- """Set window properties using config_opts"""
474
+ def _set_window_properties (self , width , height , size ,
475
+ background , foreground ):
476
+ """Set window properties that are used elsewhere."""
446
477
# old option "size" sets both width and height
447
- if "size" in config_opts :
448
- width = config_opts ["size" ]
449
- height = width
450
-
451
- if "width" in config_opts :
452
- width = config_opts ["width" ]
453
- else :
454
- width = config .getfloat ("visual" , "width" )
455
- if 'height' in config_opts :
456
- height = config_opts ['height' ]
457
- else :
458
- height = config .getfloat ("visual" , "height" )
459
- self ._scene_size = (height , width )
478
+ if size is not None :
479
+ width , height = size , size
480
+ self ._scene_size = height , width
460
481
461
- try :
462
- bg_color_name = config_opts ['background' ]
463
- except KeyError :
464
- bg_color_name = config .get ("visual" , "background" )
465
- if bg_color_name is not None :
466
- bg_color_code = colorConverter .to_rgb (bg_color_name )
467
- else :
468
- bg_color_code = None
469
- self ._bg_color = bg_color_code
482
+ bg_color_rgb = colorConverter .to_rgb (background )
483
+ self ._bg_color = bg_color_rgb
470
484
471
- try :
472
- fg_color_name = config_opts ['foreground' ]
473
- except KeyError :
474
- fg_color_name = config .get ("visual" , "foreground" )
475
- fg_color_code = colorConverter .to_rgb (fg_color_name )
476
- self ._fg_color = fg_color_code
485
+ fg_color_rgb = colorConverter .to_rgb (foreground )
486
+ self ._fg_color = fg_color_rgb
477
487
478
488
def get_data_properties (self ):
479
489
""" Get properties of the data shown
@@ -693,45 +703,24 @@ def _get_display_range(self, scalar_data, min, max, sign):
693
703
else :
694
704
range_data = np .abs (scalar_data )
695
705
696
- # Get the min and max from among various places
697
- if min is None :
698
- try :
699
- min = config .getfloat ("overlay" , "min_thresh" )
700
- except ValueError :
701
- min_str = config .get ("overlay" , "min_thresh" )
702
- if min_str == "robust_min" :
703
- min = stats .scoreatpercentile (range_data , 2 )
704
- elif min_str == "actual_min" :
705
- min = range_data .min ()
706
- else :
707
- min = 2.0
708
- warn ("The 'min_thresh' value in your config value must be "
709
- "a float, 'robust_min', or 'actual_min', but it is "
710
- "%s. I'm setting the overlay min to the config "
711
- "default of 2" % min )
706
+ # Get a numeric value for the scalar minimum
707
+ if min == "robust_min" :
708
+ min = stats .scoreatpercentile (range_data , 2 )
709
+ elif min == "actual_min" :
710
+ min = range_data .min ()
712
711
713
- if max is None :
714
- try :
715
- max = config .getfloat ("overlay" , "max_thresh" )
716
- except ValueError :
717
- max_str = config .get ("overlay" , "max_thresh" )
718
- if max_str == "robust_max" :
719
- max = stats .scoreatpercentile (scalar_data , 98 )
720
- elif max_str == "actual_max" :
721
- max = range_data .max ()
722
- else :
723
- max = stats .scoreatpercentile (range_data , 98 )
724
- warn ("The 'max_thresh' value in your config value must be "
725
- "a float, 'robust_min', or 'actual_min', but it is "
726
- "%s. I'm setting the overlay min to the config "
727
- "default of robust_max" % max )
712
+ # Get a numeric value for the scalar maximum
713
+ if max == "robust_max" :
714
+ max = stats .scoreatpercentile (scalar_data , 98 )
715
+ elif max == "actual_max" :
716
+ max = range_data .max ()
728
717
729
718
return min , max
730
719
731
720
###########################################################################
732
721
# ADDING DATA PLOTS
733
- def add_overlay (self , source , min = None , max = None , sign = "abs" , name = None ,
734
- hemi = None ):
722
+ def add_overlay (self , source , min = 2 , max = "robust_max" , sign = "abs" ,
723
+ name = None , hemi = None ):
735
724
"""Add an overlay to the overlay dict from a file or array.
736
725
737
726
Parameters
@@ -2260,7 +2249,7 @@ def animate(self, views, n_steps=180., fname=None, use_cache=False,
2260
2249
class _Hemisphere (object ):
2261
2250
"""Object for visualizing one hemisphere with mlab"""
2262
2251
def __init__ (self , subject_id , hemi , surf , figure , geo , curv , title ,
2263
- config_opts , subjects_dir , bg_color , offset , backend ):
2252
+ cortex , subjects_dir , bg_color , offset , backend ):
2264
2253
if hemi not in ['lh' , 'rh' ]:
2265
2254
raise ValueError ('hemi must be either "lh" or "rh"' )
2266
2255
# Set the identifying info
@@ -2278,7 +2267,7 @@ def __init__(self, subject_id, hemi, surf, figure, geo, curv, title,
2278
2267
if curv :
2279
2268
curv_data = self ._geo .bin_curv
2280
2269
meshargs = dict (scalars = curv_data )
2281
- colormap , vmin , vmax , reverse = self ._get_geo_colors (config_opts )
2270
+ colormap , vmin , vmax , reverse = self ._get_geo_colors (cortex )
2282
2271
kwargs = dict (colormap = colormap , vmin = vmin , vmax = vmax )
2283
2272
else :
2284
2273
curv_data = None
@@ -2568,13 +2557,14 @@ def _orient_lights(self):
2568
2557
for light in self ._f .scene .light_manager .lights :
2569
2558
light .azimuth *= - 1
2570
2559
2571
- def _get_geo_colors (self , config_opts ):
2560
+ def _get_geo_colors (self , cortex ):
2572
2561
"""Return an mlab colormap name, vmin, and vmax for binary curvature.
2573
2562
2574
2563
Parameters
2575
2564
----------
2576
- config_opts : dict
2577
- dictionary of config file "visual" options
2565
+ cortex : {classic, high_contrast, low_contrast, bone, tuple}
2566
+ The name of one of the preset cortex styles, or a tuple
2567
+ with four entries as described in the return vales.
2578
2568
2579
2569
Returns
2580
2570
-------
@@ -2593,19 +2583,12 @@ def _get_geo_colors(self, config_opts):
2593
2583
low_contrast = ("Greys" , - 5 , 5 , False ),
2594
2584
bone = ("bone" , - .2 , 2 , True ))
2595
2585
2596
- try :
2597
- cortex_color = config_opts ['cortex' ]
2598
- except KeyError :
2599
- cortex_color = config .get ("visual" , "cortex" )
2600
- try :
2601
- color_data = colormap_map [cortex_color ]
2602
- except KeyError :
2603
- warn (""
2604
- "The 'cortex' setting in your config file must be one of "
2605
- "'classic', 'high_contrast', 'low_contrast', or 'bone', "
2606
- "but your value is '%s'. I'm setting the cortex colormap "
2607
- "to the 'classic' setting." % cortex_color )
2608
- color_data = colormap_map ['classic' ]
2586
+ if cortex in colormap_map :
2587
+ color_data = colormap_map [cortex ]
2588
+ elif cortex in lut_manager .lut_mode_list ():
2589
+ color_data = cortex , - 1 , 2 , False
2590
+ else :
2591
+ color_data = cortex
2609
2592
2610
2593
return color_data
2611
2594
0 commit comments