@@ -1163,6 +1163,7 @@ def remove_labels(self, labels=None, hemi=None):
1163
1163
ll .remove ()
1164
1164
1165
1165
def add_morphometry (self , measure , grayscale = False , hemi = None ,
1166
+ colormap = None , min = None , max = None , colorbar = True ,
1166
1167
remove_existing = True ):
1167
1168
"""Add a morphometry overlay to the image.
1168
1169
@@ -1176,6 +1177,8 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
1176
1177
If None, it is assumed to belong to the hemipshere being
1177
1178
shown. If two hemispheres are being shown, data must exist
1178
1179
for both hemispheres.
1180
+ colormap : str
1181
+ Mayavi colormap name, or None to use a sensible default.
1179
1182
remove_existing : bool
1180
1183
If True (default), remove old annotations.
1181
1184
"""
@@ -1195,16 +1198,23 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
1195
1198
# Get rid of any old overlays
1196
1199
for m in self .morphometry_list :
1197
1200
m ['surface' ].remove ()
1198
- m ['colorbar' ].visible = False
1201
+ if m ["colorbar" ] is not None :
1202
+ m ['colorbar' ].visible = False
1199
1203
self .morphometry_list = []
1200
1204
ml = self .morphometry_list
1205
+
1201
1206
for hemi , morph_file in zip (hemis , morph_files ):
1202
- # Preset colormaps
1203
- cmap_dict = dict (area = "pink" ,
1204
- curv = "RdBu" ,
1205
- jacobian_white = "pink" ,
1206
- sulc = "RdBu" ,
1207
- thickness = "pink" )
1207
+
1208
+ if colormap is None :
1209
+ # Preset colormaps
1210
+ if grayscale :
1211
+ colormap = "gray"
1212
+ else :
1213
+ colormap = dict (area = "pink" ,
1214
+ curv = "RdBu" ,
1215
+ jacobian_white = "pink" ,
1216
+ sulc = "RdBu" ,
1217
+ thickness = "pink" )[measure ]
1208
1218
1209
1219
# Read in the morphometric data
1210
1220
morph_data = nib .freesurfer .read_morph_data (morph_file )
@@ -1214,24 +1224,27 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
1214
1224
ctx_idx = self .geo [hemi ].labels ["cortex" ]
1215
1225
1216
1226
# Get the display range
1217
- if measure == "thickness" :
1218
- min , max = 1 , 4
1219
- else :
1220
- min , max = stats .describe (morph_data [ctx_idx ])[1 ]
1227
+ min_default , max_default = np .percentile (morph_data [ctx_idx ],
1228
+ [2 , 98 ])
1229
+ if min is None :
1230
+ min = min_default
1231
+ if max is None :
1232
+ max = max_default
1233
+
1234
+ # Use appropriate values for bivariate measures
1235
+ if measure in ["curv" , "sulc" ]:
1236
+ lim = np .max ([abs (min ), abs (max )])
1237
+ min , max = - lim , lim
1221
1238
1222
1239
# Set up the Mayavi pipeline
1223
1240
morph_data = _prepare_data (morph_data )
1224
1241
1225
- if grayscale :
1226
- colormap = "gray"
1227
- else :
1228
- colormap = cmap_dict [measure ]
1229
-
1230
1242
for brain in self ._brain_list :
1231
1243
if brain ['hemi' ] == hemi :
1232
1244
ml .append (brain ['brain' ].add_morphometry (morph_data ,
1233
1245
colormap , measure ,
1234
- min , max ))
1246
+ min , max ,
1247
+ colorbar ))
1235
1248
self .morphometry_list = ml
1236
1249
self ._toggle_render (True , views )
1237
1250
@@ -2469,7 +2482,8 @@ def add_label(self, label, label_name, color, alpha):
2469
2482
surf .module_manager .scalar_lut_manager .lut .table = cmap
2470
2483
return surf
2471
2484
2472
- def add_morphometry (self , morph_data , colormap , measure , min , max ):
2485
+ def add_morphometry (self , morph_data , colormap , measure ,
2486
+ min , max , colorbar ):
2473
2487
"""Add a morphometry overlay to the image"""
2474
2488
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2475
2489
self ._geo .y ,
@@ -2485,9 +2499,12 @@ def add_morphometry(self, morph_data, colormap, measure, min, max):
2485
2499
name = measure , figure = self ._f )
2486
2500
2487
2501
# Get the colorbar
2488
- bar = mlab .scalarbar (surf )
2489
- self ._format_cbar_text (bar )
2490
- bar .scalar_bar_representation .position2 = .8 , 0.09
2502
+ if colorbar :
2503
+ bar = mlab .scalarbar (surf )
2504
+ self ._format_cbar_text (bar )
2505
+ bar .scalar_bar_representation .position2 = .8 , 0.09
2506
+ else :
2507
+ bar = None
2491
2508
2492
2509
# Fil in the morphometry dict
2493
2510
return dict (surface = surf , colorbar = bar , measure = measure )
0 commit comments