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
@@ -231,21 +222,12 @@ class _MlabGenerator(HasTraits):
231
222
try :
232
223
from traitsui .api import View
233
224
except ImportError :
234
- try :
235
- from traits .ui .api import View
236
- except ImportError :
237
- from enthought .traits .ui .api import View
225
+ from traits .ui .api import View
238
226
239
227
view = Instance (View )
240
228
241
229
def __init__ (self , n_row , n_col , width , height , title , ** traits ):
242
230
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
231
self .mlab_names = []
250
232
self .n_row = n_row
251
233
self .n_col = n_col
@@ -272,22 +254,10 @@ def _get_figs_view(self):
272
254
return figures , self ._v
273
255
274
256
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
257
try :
284
258
from traitsui .api import (View , Item , VGroup , HGroup )
285
259
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 )
260
+ from traits .ui .api import (View , Item , VGroup , HGroup )
291
261
ind = 0
292
262
va = []
293
263
for ri in xrange (self .n_row ):
@@ -447,12 +417,6 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
447
417
# HELPERS
448
418
def _toggle_render (self , state , views = None ):
449
419
"""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
420
figs = []
457
421
[figs .extend (f ) for f in self ._figures ]
458
422
if views is None :
@@ -1440,11 +1404,6 @@ def set_distance(self, distance=None):
1440
1404
distance : float
1441
1405
The distance used.
1442
1406
"""
1443
- try :
1444
- from mayavi import mlab
1445
- assert mlab
1446
- except :
1447
- from enthought .mayavi import mlab
1448
1407
if distance is None :
1449
1408
distance = []
1450
1409
for ff in self ._figures :
@@ -1679,12 +1638,6 @@ def hide_colorbar(self, row=-1, col=-1):
1679
1638
1680
1639
def close (self ):
1681
1640
"""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
1641
for ri , ff in enumerate (self ._figures ):
1689
1642
for ci , f in enumerate (ff ):
1690
1643
if f is not None :
@@ -1726,12 +1679,6 @@ def save_single_image(self, filename, row=-1, col=-1):
1726
1679
a Mayavi figure to plot instead of TraitsUI) if you intend to
1727
1680
script plotting commands.
1728
1681
"""
1729
- try :
1730
- from mayavi import mlab
1731
- assert mlab
1732
- except ImportError :
1733
- from enthought .mayavi import mlab
1734
-
1735
1682
brain = self .brain_matrix [row , col ]
1736
1683
ftype = filename [filename .rfind ('.' ) + 1 :]
1737
1684
good_ftypes = ['png' , 'jpg' , 'bmp' , 'tiff' , 'ps' ,
@@ -1833,11 +1780,6 @@ def screenshot_single(self, mode='rgb', antialiased=False, row=-1, col=-1):
1833
1780
a Mayavi figure to plot instead of TraitsUI) if you intend to
1834
1781
script plotting commands.
1835
1782
"""
1836
- try :
1837
- from mayavi import mlab
1838
- assert mlab
1839
- except ImportError :
1840
- from enthought .mayavi import mlab
1841
1783
brain = self .brain_matrix [row , col ]
1842
1784
return mlab .screenshot (brain ._f , mode , antialiased )
1843
1785
@@ -1965,12 +1907,6 @@ def save_montage(self, filename, order=['lat', 'ven', 'med'],
1965
1907
out : array
1966
1908
The montage image, useable with matplotlib.imshow().
1967
1909
"""
1968
- try :
1969
- from mayavi import mlab
1970
- assert mlab
1971
- except ImportError :
1972
- from enthought .mayavi import mlab
1973
-
1974
1910
assert orientation in ['h' , 'v' ]
1975
1911
if colorbar == 'auto' :
1976
1912
colorbar = [len (order ) // 2 ]
@@ -2067,11 +2003,6 @@ class _Hemisphere(object):
2067
2003
"""Object for visualizing one hemisphere with mlab"""
2068
2004
def __init__ (self , subject_id , hemi , surf , figure , geo , curv , title ,
2069
2005
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
2006
if not hemi in ['lh' , 'rh' ]:
2076
2007
raise ValueError ('hemi must be either "lh" or "rh"' )
2077
2008
# Set the identifying info
@@ -2109,12 +2040,6 @@ def __init__(self, subject_id, hemi, surf, figure, geo, curv, title,
2109
2040
2110
2041
def show_view (self , view = None , roll = None , distance = None ):
2111
2042
"""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
2043
if isinstance (view , basestring ):
2119
2044
try :
2120
2045
vd = self ._xfm_view (view , 'd' )
@@ -2229,11 +2154,6 @@ def add_data(self, array, mlab_plot, vertices, smooth_mat, min, max,
2229
2154
else :
2230
2155
raise ValueError ("data has to be 1D or 2D" )
2231
2156
2232
- try :
2233
- from mayavi import mlab
2234
- assert mlab
2235
- except ImportError :
2236
- from enthought .mayavi import mlab
2237
2157
# Set up the visualization pipeline
2238
2158
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2239
2159
self ._geo .y ,
@@ -2271,12 +2191,6 @@ def add_data(self, array, mlab_plot, vertices, smooth_mat, min, max,
2271
2191
2272
2192
def add_annotation (self , annot , ids , cmap ):
2273
2193
"""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
2194
# Create an mlab surface to visualize the annot
2281
2195
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2282
2196
self ._geo .y ,
@@ -2295,12 +2209,6 @@ def add_annotation(self, annot, ids, cmap):
2295
2209
2296
2210
def add_label (self , label , label_name , color , alpha ):
2297
2211
"""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
2212
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2305
2213
self ._geo .y ,
2306
2214
self ._geo .z ,
@@ -2315,12 +2223,6 @@ def add_label(self, label, label_name, color, alpha):
2315
2223
2316
2224
def add_morphometry (self , morph_data , colormap , measure , min , max ):
2317
2225
"""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
2226
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2325
2227
self ._geo .y ,
2326
2228
self ._geo .z ,
@@ -2342,12 +2244,6 @@ def add_morphometry(self, morph_data, colormap, measure, min, max):
2342
2244
2343
2245
def add_foci (self , foci_coords , scale_factor , color , alpha , name ):
2344
2246
"""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
2247
# Create the visualization
2352
2248
points = mlab .points3d (foci_coords [:, 0 ],
2353
2249
foci_coords [:, 1 ],
@@ -2361,12 +2257,6 @@ def add_foci(self, foci_coords, scale_factor, color, alpha, name):
2361
2257
def add_contour_overlay (self , scalar_data , min = None , max = None ,
2362
2258
n_contours = 7 , line_width = 1.5 ):
2363
2259
"""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
2260
# Set up the pipeline
2371
2261
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x , self ._geo .y ,
2372
2262
self ._geo .z ,
@@ -2390,12 +2280,6 @@ def add_contour_overlay(self, scalar_data, min=None, max=None,
2390
2280
2391
2281
def add_text (self , x , y , text , name , color = None , opacity = 1.0 ):
2392
2282
""" 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
2283
return mlab .text (x , y , text , name = name , color = color ,
2400
2284
opacity = opacity , figure = self ._f )
2401
2285
@@ -2498,11 +2382,6 @@ class OverlayDisplay():
2498
2382
"""Encapsulation of overlay viz plotting"""
2499
2383
2500
2384
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
2385
args = [ol .geo .x , ol .geo .y , ol .geo .z , ol .geo .faces ]
2507
2386
kwargs = dict (scalars = ol .mlab_data , figure = figure )
2508
2387
if ol .pos_lims is not None :
@@ -2561,11 +2440,7 @@ class TimeViewer(HasTraits):
2561
2440
try :
2562
2441
from traitsui .api import (View , Item , VSplit , HSplit , Group )
2563
2442
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 )
2443
+ from traits .ui .api import (View , Item , VSplit , HSplit , Group )
2569
2444
min_time = Int (0 )
2570
2445
max_time = Int (1E9 )
2571
2446
current_time = Range (low = "min_time" , high = "max_time" , value = 0 )
0 commit comments