Python API Reference
subcortex_visualization.plotting.plot_subcortical_data(subcortex_data=None, atlas='aseg_subcortex', value_column='value', hemisphere='L', views=['medial', 'lateral'], line_thickness=1.5, line_color='black', plot_title=None, fill_title='values', cmap=None, NA_fill='#cccccc', fill_alpha=1.0, fill_by_significance=False, nonsig_fill_alpha=0.5, vmin=None, vmax=None, midpoint=None, show_legend=True, show_figure=True, fontsize=12, ax=None)
Visualize a given subcortical or cerebellar atlas template as a vector graphic, colored according to user-provided data values or, by default, a simple region-based color scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subcortex_data
|
DataFrame
|
DataFrame with columns ['region', 'value', 'hemisphere']. If None, regions will be simply colored based on their assigned index in the corresponding atlas (which is arbitrary). |
None
|
atlas
|
str
|
The atlas used for the subcortical regions. The default is 'aseg_subcortex'. |
'aseg_subcortex'
|
value_column
|
str
|
The name of the column in |
'value'
|
hemisphere
|
(L, R, both)
|
Which hemisphere(s) to display. Use 'L' for left, 'R' for right, or 'both' for bilateral plots. |
'L'
|
views
|
list of str
|
Which faces of the subcortical regions to display. Options include 'medial', 'lateral', 'superior', and 'inferior'. Not applicable to the SUIT cerebellar lobule atlas. |
['medial', 'lateral']
|
line_thickness
|
float or str
|
Thickness of the outline for each region, or a column name in |
1.5
|
line_color
|
str
|
Color of the outline around each subcortical region. |
'black'
|
plot_title
|
str
|
Title for the plot. |
"title"
|
fill_title
|
str
|
Label for the colorbar indicating the meaning of the fill values. |
"values"
|
cmap
|
str or Colormap
|
Colormap used to fill in the regions. Accepts a string name or a Colormap object. |
'viridis'
|
NA_fill
|
str
|
Color to use for regions with missing data (NaN values). |
"#cccccc"
|
fill_alpha
|
float
|
Opacity level for the filled regions, between 0 (transparent) and 1 (opaque). |
1.0
|
fill_by_significance
|
bool
|
If True, adjusts fill_alpha based on significance (e.g., p-values) in the data. Requires a 'p_value' column in |
False
|
nonsig_fill_alpha
|
float
|
If |
0.5
|
vmin
|
float
|
Minimum value for colormap normalization. If None, the minimum of the input values is used. |
None
|
vmax
|
float
|
Maximum value for colormap normalization. If None, the maximum of the input values is used. |
None
|
midpoint
|
float
|
If provided, uses a diverging colormap centered around this value. |
None
|
show_legend
|
bool
|
If True, displays a legend or colorbar indicating the mapping of values to colors. |
True
|
show_figure
|
bool
|
If True, displays the figure using |
True
|
fontsize
|
int
|
Font size for the figure text elements. |
12
|
ax
|
Axes
|
Axes object to plot on. If None, a new figure and axes are created. |
None
|
Returns:
| Type | Description |
|---|---|
Figure or None
|
The generated figure, if |
Notes
- The function loads SVG files and a lookup CSV bundled with the package, which can be found under
data/directory. - The input
subcortex_datashould align with regions defined in the lookup table.
Source code in subcortex_visualization/plotting.py
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 | |
subcortex_visualization.segmentation.parcel_segstats(input_vol, atlas_space='MNI152NLin6Asym', atlas='aseg_subcortex', func_name='Functional map', parc_stat=np.mean, ignore_background=True, background_value=0, interpolation=None)
Extract voxel values from an input volume based on a parcellation atlas and apply a reduction function to each parcel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_vol
|
Nifti1Image or str
|
The input 3D or 4D NIfTI image from which to extract voxel values. Can be a nibabel Nifti1Image object or a file path to a NIfTI image. |
required |
atlas_space
|
str
|
The standard space to use for the corresponding atlas. Options include 'MNI152NLin6Asym' (the default) and 'MNI152NLin2009cAsym'. |
'MNI152NLin6Asym'
|
atlas
|
str or list of str
|
Name(s) of the subcortical atlas/atlases to apply. Default is 'aseg_subcortex', which is the FreeSurfer subcortical segmentation atlas. If multiple atlases are provided, the function will iterate over them and concatenate results. |
'aseg_subcortex'
|
func_name
|
str
|
A name for the functional map being summarized, used for labeling purposes in the output DataFrame. Default is 'Functional map'. |
'Functional map'
|
parc_stat
|
function
|
A function like np.mean, np.std, etc. that takes an array of values and returns a single summary statistic (scalar). Default is np.mean. Can also be a list of functions, in which case the output DataFrame will have one row per parcel per summary statistic. |
mean
|
ignore_background
|
bool
|
If True, the background label (as defined by |
True
|
background_value
|
int
|
Integer label in the parcellation that represents background (non-parcel) voxels. |
0
|
interpolation
|
str or None
|
If the input volume and atlas have different affines or spatial dimensions, this parameter specifies the interpolation method for resampling the atlas to match the input volume. Options include 'nearest', 'linear', and 'cubic'. If None (default), no resampling is performed and an error will be raised if affines or dimensions do not match. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
results_df |
DataFrame
|
One row per parcel per summary statistic, with columns: 'stat', 'value', 'Atlas', 'Functional_Map', 'region', 'Hemisphere', 'Region_Index'. |
Notes
- Users should ensure that the input volume is in the same standard space as the atlas specified by
atlas_spaceto avoid issues with affine and spatial dimension mismatches. If resampling is necessary, users must specify an interpolation method.
Source code in subcortex_visualization/segmentation.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
subcortex_visualization.utils.get_atlas_regions(atlas_name)
Return the names of regions in a given subcortical or cerebellar atlas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas_name
|
str
|
Name of the subcortical/cerebellar atlas. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray or tuple of np.ndarray
|
For most atlases: a 1-D array of region names ordered by segmentation index. For 'SUIT_cerebellar_lobule': a tuple of (hemisphere_regions, vermis_regions). For 'Brainstem_Navigator': a tuple of (hemisphere_regions, midline_regions). |
Source code in subcortex_visualization/utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |