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', 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'
|
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
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 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 | |
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 | |