@@ -1163,7 +1163,8 @@ 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
- remove_existing = True ):
1166
+ remove_existing = True , colormap = None ,
1167
+ min = None , max = None , colorbar = True ):
1167
1168
"""Add a morphometry overlay to the image.
1168
1169
1169
1170
Parameters
@@ -1178,6 +1179,14 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
1178
1179
for both hemispheres.
1179
1180
remove_existing : bool
1180
1181
If True (default), remove old annotations.
1182
+ colormap : str
1183
+ Mayavi colormap name, or None to use a sensible default.
1184
+ min, max : floats
1185
+ Endpoints for the colormap; if not provided the robust range
1186
+ of the data is used.
1187
+ colorbar : bool
1188
+ If True, show a colorbar corresponding to the overlay data.
1189
+
1181
1190
"""
1182
1191
hemis = self ._check_hemis (hemi )
1183
1192
morph_files = []
@@ -1195,16 +1204,23 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
1195
1204
# Get rid of any old overlays
1196
1205
for m in self .morphometry_list :
1197
1206
m ['surface' ].remove ()
1198
- m ['colorbar' ].visible = False
1207
+ if m ["colorbar" ] is not None :
1208
+ m ['colorbar' ].visible = False
1199
1209
self .morphometry_list = []
1200
1210
ml = self .morphometry_list
1211
+
1201
1212
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" )
1213
+
1214
+ if colormap is None :
1215
+ # Preset colormaps
1216
+ if grayscale :
1217
+ colormap = "gray"
1218
+ else :
1219
+ colormap = dict (area = "pink" ,
1220
+ curv = "RdBu" ,
1221
+ jacobian_white = "pink" ,
1222
+ sulc = "RdBu" ,
1223
+ thickness = "pink" )[measure ]
1208
1224
1209
1225
# Read in the morphometric data
1210
1226
morph_data = nib .freesurfer .read_morph_data (morph_file )
@@ -1214,24 +1230,27 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
1214
1230
ctx_idx = self .geo [hemi ].labels ["cortex" ]
1215
1231
1216
1232
# 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 ]
1233
+ min_default , max_default = np .percentile (morph_data [ctx_idx ],
1234
+ [2 , 98 ])
1235
+ if min is None :
1236
+ min = min_default
1237
+ if max is None :
1238
+ max = max_default
1239
+
1240
+ # Use appropriate values for bivariate measures
1241
+ if measure in ["curv" , "sulc" ]:
1242
+ lim = np .max ([abs (min ), abs (max )])
1243
+ min , max = - lim , lim
1221
1244
1222
1245
# Set up the Mayavi pipeline
1223
1246
morph_data = _prepare_data (morph_data )
1224
1247
1225
- if grayscale :
1226
- colormap = "gray"
1227
- else :
1228
- colormap = cmap_dict [measure ]
1229
-
1230
1248
for brain in self ._brain_list :
1231
1249
if brain ['hemi' ] == hemi :
1232
1250
ml .append (brain ['brain' ].add_morphometry (morph_data ,
1233
1251
colormap , measure ,
1234
- min , max ))
1252
+ min , max ,
1253
+ colorbar ))
1235
1254
self .morphometry_list = ml
1236
1255
self ._toggle_render (True , views )
1237
1256
@@ -2469,7 +2488,8 @@ def add_label(self, label, label_name, color, alpha):
2469
2488
surf .module_manager .scalar_lut_manager .lut .table = cmap
2470
2489
return surf
2471
2490
2472
- def add_morphometry (self , morph_data , colormap , measure , min , max ):
2491
+ def add_morphometry (self , morph_data , colormap , measure ,
2492
+ min , max , colorbar ):
2473
2493
"""Add a morphometry overlay to the image"""
2474
2494
mesh = mlab .pipeline .triangular_mesh_source (self ._geo .x ,
2475
2495
self ._geo .y ,
@@ -2485,9 +2505,12 @@ def add_morphometry(self, morph_data, colormap, measure, min, max):
2485
2505
name = measure , figure = self ._f )
2486
2506
2487
2507
# Get the colorbar
2488
- bar = mlab .scalarbar (surf )
2489
- self ._format_cbar_text (bar )
2490
- bar .scalar_bar_representation .position2 = .8 , 0.09
2508
+ if colorbar :
2509
+ bar = mlab .scalarbar (surf )
2510
+ self ._format_cbar_text (bar )
2511
+ bar .scalar_bar_representation .position2 = .8 , 0.09
2512
+ else :
2513
+ bar = None
2491
2514
2492
2515
# Fil in the morphometry dict
2493
2516
return dict (surface = surf , colorbar = bar , measure = measure )
0 commit comments