8
8
9
9
import nibabel as nib
10
10
11
+ from mayavi import mlab
12
+ from mayavi .tools .mlab_scene_model import MlabSceneModel
13
+ from mayavi .core .ui .api import SceneEditor
14
+ from mayavi .core .ui .mayavi_scene import MayaviScene
15
+
11
16
from . import io
12
17
from . import utils
13
18
from .io import Surface , _get_subjects_dir
18
23
logging .basicConfig () # suppress "No handlers found for logger" error
19
24
logger = logging .getLogger ('surfer' )
20
25
21
- try :
22
- from traits .api import (HasTraits , Range , Int , Float ,
23
- Bool , Enum , on_trait_change , Instance )
24
- except ImportError :
25
- from enthought .traits .api import (HasTraits , Range , Int , Float ,
26
- Bool , Enum , on_trait_change , Instance )
26
+ from traits .api import (HasTraits , Range , Int , Float ,
27
+ Bool , Enum , on_trait_change , Instance )
27
28
28
29
lh_viewdict = {'lateral' : {'v' : (180. , 90. ), 'r' : 90. },
29
30
'medial' : {'v' : (0. , 90. ), 'r' : - 90. },
@@ -159,11 +160,6 @@ def _prepare_data(data):
159
160
160
161
def _force_render (figures , backend ):
161
162
"""Ensure plots are updated before properties are used"""
162
- try :
163
- from mayavi import mlab
164
- assert mlab
165
- except :
166
- from enthought .mayavi import mlab
167
163
if not isinstance (figures , list ):
168
164
figures = [[figures ]]
169
165
for ff in figures :
@@ -188,11 +184,6 @@ def _make_viewer(figure, n_row, n_col, title, scene_size, offscreen):
188
184
is returned to the command line. With the multi-view, TraitsUI
189
185
unfortunately has no such support, so we only use it if needed.
190
186
"""
191
- try :
192
- from mayavi import mlab
193
- assert mlab
194
- except :
195
- from enthought .mayavi import mlab
196
187
if figure is None :
197
188
# spawn scenes
198
189
h , w = scene_size
@@ -228,24 +219,11 @@ def _make_viewer(figure, n_row, n_col, title, scene_size, offscreen):
228
219
229
220
class _MlabGenerator (HasTraits ):
230
221
"""TraitsUI mlab figure generator"""
231
- try :
232
- from traitsui .api import View
233
- except ImportError :
234
- try :
235
- from traits .ui .api import View
236
- except ImportError :
237
- from enthought .traits .ui .api import View
238
-
222
+ from traitsui .api import View
239
223
view = Instance (View )
240
224
241
225
def __init__ (self , n_row , n_col , width , height , title , ** traits ):
242
226
HasTraits .__init__ (self , ** traits )
243
- try :
244
- from mayavi .tools .mlab_scene_model import MlabSceneModel
245
- assert MlabSceneModel
246
- except :
247
- from enthought .mayavi .tools .mlab_scene_model import MlabSceneModel
248
-
249
227
self .mlab_names = []
250
228
self .n_row = n_row
251
229
self .n_col = n_col
@@ -272,22 +250,7 @@ def _get_figs_view(self):
272
250
return figures , self ._v
273
251
274
252
def _get_gen_view (self ):
275
- try :
276
- from mayavi .core .ui .api import SceneEditor
277
- from mayavi .core .ui .mayavi_scene import MayaviScene
278
- assert SceneEditor
279
- assert MayaviScene
280
- except :
281
- from enthought .mayavi .core .ui .api import SceneEditor
282
- from enthought .mayavi .core .ui .mayavi_scene import MayaviScene
283
- try :
284
- from traitsui .api import (View , Item , VGroup , HGroup )
285
- except ImportError :
286
- try :
287
- from traits .ui .api import (View , Item , VGroup , HGroup )
288
- except ImportError :
289
- from enthought .traits .ui .api import (View , Item ,
290
- VGroup , HGroup )
253
+ from traitsui .api import (View , Item , VGroup , HGroup )
291
254
ind = 0
292
255
va = []
293
256
for ri in xrange (self .n_row ):
@@ -447,12 +410,6 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
447
410
# HELPERS
448
411
def _toggle_render (self , state , views = None ):
449
412
"""Turn rendering on (True) or off (False)"""
450
- try :
451
- from mayavi import mlab
452
- assert mlab
453
- except ImportError :
454
- from enthought .mayavi import mlab
455
-
456
413
figs = []
457
414
[figs .extend (f ) for f in self ._figures ]
458
415
if views is None :
@@ -1440,11 +1397,6 @@ def set_distance(self, distance=None):
1440
1397
distance : float
1441
1398
The distance used.
1442
1399
"""
1443
- try :
1444
- from mayavi import mlab
1445
- assert mlab
1446
- except :
1447
- from enthought .mayavi import mlab
1448
1400
if distance is None :
1449
1401
distance = []
1450
1402
for ff in self ._figures :
@@ -1679,12 +1631,6 @@ def hide_colorbar(self, row=-1, col=-1):
1679
1631
1680
1632
def close (self ):
1681
1633
"""Close all figures and cleanup data structure."""
1682
- try :
1683
- from mayavi import mlab
1684
- assert mlab
1685
- except ImportError :
1686
- from enthought .mayavi import mlab
1687
-
1688
1634
for ri , ff in enumerate (self ._figures ):
1689
1635
for ci , f in enumerate (ff ):
1690
1636
if f is not None :
@@ -1726,12 +1672,6 @@ def save_single_image(self, filename, row=-1, col=-1):
1726
1672
a Mayavi figure to plot instead of TraitsUI) if you intend to
1727
1673
script plotting commands.
1728
1674
"""
1729
- try :
1730
- from mayavi import mlab
1731
- assert mlab
1732
- except ImportError :
1733
- from enthought .mayavi import mlab
1734
-
1735
1675
brain = self .brain_matrix [row , col ]
1736
1676
ftype = filename [filename .rfind ('.' ) + 1 :]
1737
1677
good_ftypes = ['png' , 'jpg' , 'bmp' , 'tiff' , 'ps' ,
@@ -1833,11 +1773,6 @@ def screenshot_single(self, mode='rgb', antialiased=False, row=-1, col=-1):
1833
1773
a Mayavi figure to plot instead of TraitsUI) if you intend to
1834
1774
script plotting commands.
1835
1775
"""
1836
- try :
1837
- from mayavi import mlab
1838
- assert mlab
1839
- except ImportError :
1840
- from enthought .mayavi import mlab
1841
1776
brain = self .brain_matrix [row , col ]
1842
1777
return mlab .screenshot (brain ._f , mode , antialiased )
1843
1778
@@ -1965,12 +1900,6 @@ def save_montage(self, filename, order=['lat', 'ven', 'med'],
1965
1900
out : array
1966
1901
The montage image, useable with matplotlib.imshow().
1967
1902
"""
1968
- try :
1969
- from mayavi import mlab
1970
- assert mlab
1971
- except ImportError :
1972
- from enthought .mayavi import mlab
1973
-
1974
1903
assert orientation in ['h' , 'v' ]
1975
1904
if colorbar == 'auto' :
1976
1905
colorbar = [len (order ) // 2 ]
@@ -2067,11 +1996,6 @@ class _Hemisphere(object):
2067
1996
"""Object for visualizing one hemisphere with mlab"""
2068
1997
def __init__ (self , subject_id , hemi , surf , figure , geo , curv , title ,
2069
1998
config_opts , subjects_dir , bg_color , offset , backend ):
2070
- try :
2071
- from mayavi import mlab
2072
- assert mlab
2073
- except ImportError :
2074
- from enthought .mayavi import mlab
2075
1999
if not hemi in ['lh' , 'rh' ]:
2076
2000
raise ValueError ('hemi must be either "lh" or "rh"' )
2077
2001
# Set the identifying info
@@ -2109,12 +2033,6 @@ def __init__(self, subject_id, hemi, surf, figure, geo, curv, title,
2109
2033
2110
2034
def show_view (self , view = None , roll = None , distance = None ):
2111
2035
"""Orient camera to display view"""
2112
- try :
2113
- from mayavi import mlab
2114
- assert mlab
2115
- except ImportError :
2116
- from enthought .mayavi import mlab
2117
-
2118
2036
if isinstance (view , basestring ):
2119
2037
try :
2120
2038
vd = self ._xfm_view (view , 'd' )
@@ -2229,11 +2147,6 @@ def add_data(self, array, mlab_plot, vertices, smooth_mat, min, max,
2229
2147
else :
2230
2148
raise ValueError ("data has to be 1D or 2D" )
2231
2149
2232
- try :
2233
- from mayavi import mlab
2234
- assert mlab
2235
- except ImportError :
2236
- from enthought .mayavi import mlab
2237
2150
# Set up the visualization pipeline
2238
2151
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2239
2152
self ._geo .y ,
@@ -2271,12 +2184,6 @@ def add_data(self, array, mlab_plot, vertices, smooth_mat, min, max,
2271
2184
2272
2185
def add_annotation (self , annot , ids , cmap ):
2273
2186
"""Add an annotation file"""
2274
- try :
2275
- from mayavi import mlab
2276
- assert mlab
2277
- except ImportError :
2278
- from enthought .mayavi import mlab
2279
-
2280
2187
# Create an mlab surface to visualize the annot
2281
2188
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2282
2189
self ._geo .y ,
@@ -2295,12 +2202,6 @@ def add_annotation(self, annot, ids, cmap):
2295
2202
2296
2203
def add_label (self , label , label_name , color , alpha ):
2297
2204
"""Add an ROI label to the image"""
2298
- try :
2299
- from mayavi import mlab
2300
- assert mlab
2301
- except ImportError :
2302
- from enthought .mayavi import mlab
2303
-
2304
2205
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2305
2206
self ._geo .y ,
2306
2207
self ._geo .z ,
@@ -2315,12 +2216,6 @@ def add_label(self, label, label_name, color, alpha):
2315
2216
2316
2217
def add_morphometry (self , morph_data , colormap , measure , min , max ):
2317
2218
"""Add a morphometry overlay to the image"""
2318
- try :
2319
- from mayavi import mlab
2320
- assert mlab
2321
- except ImportError :
2322
- from enthought .mayavi import mlab
2323
-
2324
2219
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2325
2220
self ._geo .y ,
2326
2221
self ._geo .z ,
@@ -2342,12 +2237,6 @@ def add_morphometry(self, morph_data, colormap, measure, min, max):
2342
2237
2343
2238
def add_foci (self , foci_coords , scale_factor , color , alpha , name ):
2344
2239
"""Add spherical foci, possibly mapping to displayed surf"""
2345
- try :
2346
- from mayavi import mlab
2347
- assert mlab
2348
- except ImportError :
2349
- from enthought .mayavi import mlab
2350
-
2351
2240
# Create the visualization
2352
2241
points = mlab .points3d (foci_coords [:, 0 ],
2353
2242
foci_coords [:, 1 ],
@@ -2361,12 +2250,6 @@ def add_foci(self, foci_coords, scale_factor, color, alpha, name):
2361
2250
def add_contour_overlay (self , scalar_data , min = None , max = None ,
2362
2251
n_contours = 7 , line_width = 1.5 ):
2363
2252
"""Add a topographic contour overlay of the positive data"""
2364
- try :
2365
- from mayavi import mlab
2366
- assert mlab
2367
- except ImportError :
2368
- from enthought .mayavi import mlab
2369
-
2370
2253
# Set up the pipeline
2371
2254
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x , self ._geo .y ,
2372
2255
self ._geo .z ,
@@ -2390,12 +2273,6 @@ def add_contour_overlay(self, scalar_data, min=None, max=None,
2390
2273
2391
2274
def add_text (self , x , y , text , name , color = None , opacity = 1.0 ):
2392
2275
""" Add a text to the visualization"""
2393
- try :
2394
- from mayavi import mlab
2395
- assert mlab
2396
- except ImportError :
2397
- from enthought .mayavi import mlab
2398
-
2399
2276
return mlab .text (x , y , text , name = name , color = color ,
2400
2277
opacity = opacity , figure = self ._f )
2401
2278
@@ -2498,11 +2375,6 @@ class OverlayDisplay():
2498
2375
"""Encapsulation of overlay viz plotting"""
2499
2376
2500
2377
def __init__ (self , ol , figure ):
2501
- try :
2502
- from mayavi import mlab
2503
- assert mlab
2504
- except ImportError :
2505
- from enthought .mayavi import mlab
2506
2378
args = [ol .geo .x , ol .geo .y , ol .geo .z , ol .geo .faces ]
2507
2379
kwargs = dict (scalars = ol .mlab_data , figure = figure )
2508
2380
if ol .pos_lims is not None :
@@ -2558,14 +2430,7 @@ class TimeViewer(HasTraits):
2558
2430
brain(s) to control
2559
2431
"""
2560
2432
# Nested import of traisui for setup.py without X server
2561
- try :
2562
- from traitsui .api import (View , Item , VSplit , HSplit , Group )
2563
- except ImportError :
2564
- try :
2565
- from traits .ui .api import (View , Item , VSplit , HSplit , Group )
2566
- except ImportError :
2567
- from enthought .traits .ui .api import (View , Item , VSplit ,
2568
- HSplit , Group )
2433
+ from traitsui .api import (View , Item , VSplit , HSplit , Group )
2569
2434
min_time = Int (0 )
2570
2435
max_time = Int (1E9 )
2571
2436
current_time = Range (low = "min_time" , high = "max_time" , value = 0 )
0 commit comments