@@ -423,7 +423,7 @@ def __init__(self, subject_id, hemi, surf, title=None,
423
423
title = subject_id
424
424
self .subject_id = subject_id
425
425
426
- if not isinstance (views , list ):
426
+ if not isinstance (views , ( list , tuple ) ):
427
427
views = [views ]
428
428
n_row = len (views )
429
429
@@ -1095,23 +1095,20 @@ def add_data(self, array, min=None, max=None, thresh=None,
1095
1095
smooth_mat = None
1096
1096
1097
1097
magnitude = None
1098
- magnitude_max = None
1099
1098
if array .ndim == 3 :
1100
1099
if array .shape [1 ] != 3 :
1101
1100
raise ValueError ('If array has 3 dimensions, array.shape[1] '
1102
1101
'must equal 3, got %s' % (array .shape [1 ],))
1103
1102
magnitude = np .linalg .norm (array , axis = 1 )
1104
1103
if scale_factor is None :
1105
- distance = np .sum ([array [:, dim , :].ptp (axis = 0 ).max () ** 2
1106
- for dim in range (3 )])
1104
+ distance = 4 * np .linalg .norm (array , axis = 1 ).max ()
1107
1105
if distance == 0 :
1108
1106
scale_factor = 1
1109
1107
else :
1110
1108
scale_factor = (0.4 * distance /
1111
1109
(4 * array .shape [0 ] ** (0.33 )))
1112
1110
if self ._units == 'm' :
1113
1111
scale_factor = scale_factor / 1000.
1114
- magnitude_max = magnitude .max ()
1115
1112
elif array .ndim not in (1 , 2 ):
1116
1113
raise ValueError ('array has must have 1, 2, or 3 dimensions, '
1117
1114
'got (%s)' % (array .ndim ,))
@@ -1188,7 +1185,7 @@ def time_label(x):
1188
1185
if brain ['hemi' ] == hemi :
1189
1186
s , ct , bar , gl = brain ['brain' ].add_data (
1190
1187
array , min , mid , max , thresh , lut , colormap , alpha ,
1191
- colorbar , layer_id , smooth_mat , magnitude , magnitude_max ,
1188
+ colorbar , layer_id , smooth_mat , magnitude ,
1192
1189
scale_factor , vertices , vector_alpha , ** kwargs )
1193
1190
surfs .append (s )
1194
1191
bars .append (bar )
@@ -2115,13 +2112,11 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'):
2115
2112
if vectors is not None :
2116
2113
vectors = vectors [:, :, time_idx ]
2117
2114
2118
- vector_values = scalar_data .copy ()
2119
2115
if data ['smooth_mat' ] is not None :
2120
2116
scalar_data = data ['smooth_mat' ] * scalar_data
2121
2117
for brain in self .brains :
2122
2118
if brain .hemi == hemi :
2123
- brain .set_data (data ['layer_id' ], scalar_data ,
2124
- vectors , vector_values )
2119
+ brain .set_data (data ['layer_id' ], scalar_data , vectors )
2125
2120
del brain
2126
2121
data ["time_idx" ] = time_idx
2127
2122
@@ -3225,24 +3220,25 @@ def _remove_scalar_data(self, array_id):
3225
3220
self ._mesh_clones .pop (array_id ).remove ()
3226
3221
self ._mesh_dataset .point_data .remove_array (array_id )
3227
3222
3228
- def _add_vector_data (self , vectors , vector_values , fmin , fmid , fmax ,
3229
- scale_factor_norm , vertices , vector_alpha , lut ):
3223
+ def _add_vector_data (self , vectors , fmin , fmid , fmax ,
3224
+ scale_factor , vertices , vector_alpha , lut ):
3230
3225
vertices = slice (None ) if vertices is None else vertices
3231
3226
x , y , z = np .array (self ._geo_mesh .data .points .data )[vertices ].T
3232
3227
vector_alpha = min (vector_alpha , 0.9999999 )
3233
3228
with warnings .catch_warnings (record = True ): # HasTraits
3234
3229
quiver = mlab .quiver3d (
3235
3230
x , y , z , vectors [:, 0 ], vectors [:, 1 ], vectors [:, 2 ],
3236
- scalars = vector_values , colormap = 'hot' , vmin = fmin ,
3231
+ colormap = 'hot' , vmin = fmin , scale_mode = 'vector' ,
3237
3232
vmax = fmax , figure = self ._f , opacity = vector_alpha )
3238
3233
3239
3234
# Enable backface culling
3240
3235
quiver .actor .property .backface_culling = True
3241
3236
quiver .mlab_source .update ()
3242
3237
3243
- # Compute scaling for the glyphs
3244
- quiver .glyph .glyph .scale_factor = (scale_factor_norm *
3245
- vector_values .max ())
3238
+ # Set scaling for the glyphs
3239
+ quiver .glyph .glyph .scale_factor = scale_factor
3240
+ quiver .glyph .glyph .clamping = False
3241
+ quiver .glyph .glyph .range = (0. , 1. )
3246
3242
3247
3243
# Scale colormap used for the glyphs
3248
3244
l_m = quiver .parent .vector_lut_manager
@@ -3293,7 +3289,7 @@ def add_overlay(self, old, **kwargs):
3293
3289
3294
3290
@verbose
3295
3291
def add_data (self , array , fmin , fmid , fmax , thresh , lut , colormap , alpha ,
3296
- colorbar , layer_id , smooth_mat , magnitude , magnitude_max ,
3292
+ colorbar , layer_id , smooth_mat , magnitude ,
3297
3293
scale_factor , vertices , vector_alpha , ** kwargs ):
3298
3294
"""Add data to the brain"""
3299
3295
# Calculate initial data to plot
@@ -3308,24 +3304,20 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
3308
3304
array_plot = magnitude [:, 0 ]
3309
3305
else :
3310
3306
raise ValueError ("data has to be 1D, 2D, or 3D" )
3311
- vector_values = array_plot
3312
3307
if smooth_mat is not None :
3313
3308
array_plot = smooth_mat * array_plot
3314
3309
3315
3310
# Copy and byteswap to deal with Mayavi bug
3316
3311
array_plot = _prepare_data (array_plot )
3317
3312
3318
3313
array_id , pipe = self ._add_scalar_data (array_plot )
3319
- scale_factor_norm = None
3320
3314
if array .ndim == 3 :
3321
- scale_factor_norm = scale_factor / magnitude_max
3322
3315
vectors = array [:, :, 0 ].copy ()
3323
3316
glyphs = self ._add_vector_data (
3324
- vectors , vector_values , fmin , fmid , fmax ,
3325
- scale_factor_norm , vertices , vector_alpha , lut )
3317
+ vectors , fmin , fmid , fmax ,
3318
+ scale_factor , vertices , vector_alpha , lut )
3326
3319
else :
3327
3320
glyphs = None
3328
- del scale_factor
3329
3321
mesh = pipe .parent
3330
3322
if thresh is not None :
3331
3323
if array_plot .min () >= thresh :
@@ -3364,7 +3356,7 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
3364
3356
3365
3357
self .data [layer_id ] = dict (
3366
3358
array_id = array_id , mesh = mesh , glyphs = glyphs ,
3367
- scale_factor_norm = scale_factor_norm )
3359
+ scale_factor = scale_factor )
3368
3360
return surf , orig_ctable , bar , glyphs
3369
3361
3370
3362
def add_annotation (self , annot , ids , cmap , ** kwargs ):
@@ -3475,7 +3467,7 @@ def remove_data(self, layer_id):
3475
3467
self ._remove_scalar_data (data ['array_id' ])
3476
3468
self ._remove_vector_data (data ['glyphs' ])
3477
3469
3478
- def set_data (self , layer_id , values , vectors = None , vector_values = None ):
3470
+ def set_data (self , layer_id , values , vectors = None ):
3479
3471
"""Set displayed data values and vectors."""
3480
3472
data = self .data [layer_id ]
3481
3473
self ._mesh_dataset .point_data .get_array (
@@ -3492,12 +3484,12 @@ def set_data(self, layer_id, values, vectors=None, vector_values=None):
3492
3484
3493
3485
# Update glyphs
3494
3486
q .mlab_source .vectors = vectors
3495
- q .mlab_source .scalars = vector_values
3496
3487
q .mlab_source .update ()
3497
3488
3498
3489
# Update changed parameters, and glyph scaling
3499
- q .glyph .glyph .scale_factor = (data ['scale_factor_norm' ] *
3500
- values .max ())
3490
+ q .glyph .glyph .scale_factor = data ['scale_factor' ]
3491
+ q .glyph .glyph .range = (0. , 1. )
3492
+ q .glyph .glyph .clamping = False
3501
3493
l_m .load_lut_from_list (lut / 255. )
3502
3494
l_m .data_range = data_range
3503
3495
0 commit comments