API reference¶
The reference below is generated from the public Python API. Functions and classes inherit docstrings directly from the source code to keep behavior descriptions synchronized.
Core parcellator¶
volume
¶
VolumetricParcellator
¶
Base volumetric parcellator.
The parcellator assumes an integer-valued atlas where each non-background voxel stores the parcel identifier. Parcellation is performed by sampling a scalar map image and aggregating values inside each region. Resampling to the atlas grid is handled by default to keep atlas boundaries consistent across inputs.
Source code in src/parcellate/parcellation/volume.py
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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
regions
property
¶
Tuple of regions defined in the atlas.
__init__(atlas_img, labels=None, lut=None, *, mask=None, mask_threshold=0.0, atlas_threshold=0.0, background_label=0, resampling_target='data', stat_functions=None, stat_tier=None)
¶
Initialize a volumetric parcellator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas_img
|
Nifti1Image | str | Path
|
The atlas image defining the parcellation. |
required |
labels
|
Mapping[int, str] | Sequence[str] | None
|
Region labels mapping or sequence, by default None |
None
|
lut
|
DataFrame | str | Path | None
|
Lookup table for region labels, by default None. Must include columns "index" and "label" following the BIDS standard. |
None
|
mask
|
Nifti1Image | str | Path | None
|
Optional mask to apply to the atlas, by default None |
None
|
mask_threshold
|
float
|
Threshold for the mask image. Voxels with mask values strictly greater
than this threshold are included; all others are excluded. Default is
|
0.0
|
atlas_threshold
|
float
|
Threshold for probabilistic (4D) atlas volumes. Voxels with probability
strictly greater than this value are included in each region's mask.
Default is |
0.0
|
background_label
|
int
|
Label value to treat as background, by default 0 |
0
|
resampling_target
|
Literal['data', 'labels', None]
|
Resampling target for input maps, by default "data" |
'data'
|
stat_functions
|
Mapping[str, StatFunction] | None
|
Mapping of statistic names to functions, by default None.
When provided, takes precedence over |
None
|
stat_tier
|
str | None
|
Named statistics tier to use when |
None
|
Source code in src/parcellate/parcellation/volume.py
fit(scalar_img)
¶
Fit the parcellator to a scalar image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar_img
|
Nifti1Image | str | Path
|
Scalar image to fit to. |
required |
Source code in src/parcellate/parcellation/volume.py
transform(scalar_img)
¶
Apply the parcellation to the fitted scalar image.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing parcellation statistics for each region. |
Source code in src/parcellate/parcellation/volume.py
Metrics¶
base
¶
volume
¶
A battery of volumetric parcellation statistics.
volume(parcel_values, scalar_img)
¶
Compute the actual tissue volume within a mask using modulated images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parcel_values
|
ndarray
|
The modulated tissue segment values within the ROI. |
required |
scalar_img
|
Nifti1Image
|
The modulated tissue segment (e.g., mwp1.nii). |
required |
Source code in src/parcellate/metrics/volume.py
voxel_count(parcel_values)
¶
Compute the count of non-zero voxels in a parcel.
This function counts the number of voxels in a parcel that have non-zero and non-NaN values. This is useful for modulated tissue maps (e.g., CAT12's mwp* files) where zero values indicate no tissue present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parcel_values
|
ndarray
|
An array of scalar values for voxels within the parcel. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of non-zero, non-NaN voxels in the parcel. |
Source code in src/parcellate/metrics/volume.py
z_filtered_mean(values, z_thresh=3.0)
¶
Compute the mean of values after applying a z-score filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to filter and compute the mean from. |
required |
z_thresh
|
float
|
The z-score threshold for filtering, by default 3.0. |
3.0
|
Returns:
| Type | Description |
|---|---|
float
|
The mean of the filtered values. |
Source code in src/parcellate/metrics/volume.py
z_filtered_std(values, z_thresh=3.0)
¶
Compute the standard deviation of values after applying a z-score filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to filter and compute the standard deviation from. |
required |
z_thresh
|
float
|
The z-score threshold for filtering, by default 3.0. |
3.0
|
Returns:
| Type | Description |
|---|---|
float
|
The standard deviation of the filtered values. |
Source code in src/parcellate/metrics/volume.py
iqr_filtered_mean(values, factor=1.5)
¶
Compute the mean of values after applying an interquartile range (IQR) filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to filter and compute the mean from. |
required |
factor
|
float
|
The IQR factor for filtering, by default 1.5. |
1.5
|
Returns:
| Type | Description |
|---|---|
float
|
The mean of the filtered values. |
Source code in src/parcellate/metrics/volume.py
iqr_filtered_std(values, factor=1.5)
¶
Compute the standard deviation of values after applying an interquartile range (IQR) filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to filter and compute the standard deviation from. |
required |
factor
|
float
|
The IQR factor for filtering, by default 1.5. |
1.5
|
Returns:
| Type | Description |
|---|---|
float
|
The standard deviation of the filtered values. |
Source code in src/parcellate/metrics/volume.py
robust_mean(values)
¶
Compute the robust mean of values using median and MAD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to compute the robust mean from. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The robust mean of the values. |
Source code in src/parcellate/metrics/volume.py
robust_std(values)
¶
Compute the robust standard deviation of values using median and MAD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to compute the robust standard deviation from. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The robust standard deviation of the values. |
Source code in src/parcellate/metrics/volume.py
mad_median(values)
¶
Compute the median absolute deviation (MAD) of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to compute the MAD from. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The MAD of the values. |
Source code in src/parcellate/metrics/volume.py
volsum(values)
¶
Compute the sum of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
The array of values to compute the sum from. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The sum of the values. |
Source code in src/parcellate/metrics/volume.py
cv(values)
¶
Classical coefficient of variation (CV = SD / mean).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Coefficient of variation. Higher values indicate more relative variability. |
Notes
Sensitive to mean approaching zero. For metrics that can be zero or negative, consider using robust_cv instead.
Typical values for neuroimaging: - Cortical thickness: CV ~ 0.10 - FA: CV ~ 0.15 - MD: CV ~ 0.20
Source code in src/parcellate/metrics/volume.py
robust_cv(values)
¶
Robust coefficient of variation (IQR / median).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Robust coefficient of variation. Less sensitive to outliers than classical CV. |
Notes
Recommended when outliers are present or suspected. More stable than classical CV for distributions with heavy tails.
Source code in src/parcellate/metrics/volume.py
quartile_dispersion(values)
¶
Quartile coefficient of dispersion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Quartile dispersion coefficient: (Q3 - Q1) / (Q3 + Q1) |
Notes
Scale-free measure of dispersion. Bounded between 0 and 1. Less affected by extreme values than CV.
Source code in src/parcellate/metrics/volume.py
skewness(values)
¶
Skewness (third standardized moment).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Skewness value. 0 = symmetric, >0 = right tail, <0 = left tail. |
Notes
Problematic if |skewness| > 0.5.
Neuroimaging context: - Cortical thickness often shows negative skew (-0.2 to -0.8) due to partial volume effects - FA often shows positive skew (0.3 to 1.2) due to crossing fibers
Source code in src/parcellate/metrics/volume.py
excess_kurtosis(values)
¶
Excess kurtosis (fourth standardized moment minus 3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Excess kurtosis. 0 = normal, >0 = heavy tails, <0 = light tails. |
Notes
Problematic if |kurtosis| > 1.0.
Positive kurtosis indicates outlier-prone distributions. Common in diffusion metrics due to partial volume effects with CSF.
Source code in src/parcellate/metrics/volume.py
abs_skewness(values)
¶
Absolute value of skewness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Absolute skewness. Useful for categorizing without caring about direction. |
Source code in src/parcellate/metrics/volume.py
abs_excess_kurtosis(values)
¶
Absolute value of excess kurtosis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Absolute excess kurtosis. |
Source code in src/parcellate/metrics/volume.py
bimodality_coefficient(values)
¶
Bimodality coefficient (Pfister et al. 2013).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Bimodality coefficient. Values > 0.555 suggest bimodal/multimodal distribution. |
Notes
Calculated as: BC = (skew² + 1) / (kurtosis + 3(n-1)²/((n-2)(n-3)))
Critical for cortical thickness ROIs that span gyri and sulci, which often show bimodal distributions.
References
Pfister R, Schwarz KA, Janczyk M, Dale R, Freeman JB (2013). Good things peak in pairs: a note on the bimodality coefficient. Front Psychol 4:700.
Source code in src/parcellate/metrics/volume.py
prop_outliers_2sd(values)
¶
Proportion of values beyond ±2 standard deviations from mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Proportion of outliers (0 to 1). Expected ~0.046 for normal distribution. |
Notes
Problematic if > 0.10 (10%).
Source code in src/parcellate/metrics/volume.py
prop_outliers_3sd(values)
¶
Proportion of values beyond ±3 standard deviations from mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Proportion of outliers (0 to 1). Expected ~0.003 for normal distribution. |
Notes
Problematic if > 0.02 (2%). High values suggest segmentation errors or image quality issues.
Source code in src/parcellate/metrics/volume.py
prop_outliers_iqr(values)
¶
Proportion of Tukey fence outliers (beyond Q1 - 1.5IQR or Q3 + 1.5IQR).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Proportion of outliers (0 to 1). Expected ~0.007 for normal distribution. |
Notes
More robust than SD-based outlier detection. This is the standard boxplot definition of outliers. Problematic if > 0.05 (5%).
Source code in src/parcellate/metrics/volume.py
left_tail_mass(values)
¶
Proportion of values in left tail (below mean - 2*SD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Left tail mass. Expected ~0.023 for normal distribution. |
Source code in src/parcellate/metrics/volume.py
right_tail_mass(values)
¶
Proportion of values in right tail (above mean + 2*SD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Right tail mass. Expected ~0.023 for normal distribution. |
Source code in src/parcellate/metrics/volume.py
tail_asymmetry(values)
¶
Difference between right and left tail masses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Tail asymmetry. >0 = heavier right tail, <0 = heavier left tail. |
Notes
Expected ~0 for symmetric distributions. Problematic if |asymmetry| > 0.02. Helps identify which tail is causing distributional problems.
Source code in src/parcellate/metrics/volume.py
excess_tail_mass(values)
¶
Total excess tail mass beyond what's expected for normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Excess tail mass. >0 indicates heavy tails. |
Notes
For normal distribution, total tail mass (beyond ±2SD) = 4.6%. Excess tail mass = observed - expected. Problematic if > 0.02 (2% excess).
Source code in src/parcellate/metrics/volume.py
dagostino_k2(values)
¶
D'Agostino-Pearson K² statistic for normality test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values (requires n ≥ 20) |
required |
Returns:
| Type | Description |
|---|---|
float
|
K² test statistic (chi-squared distributed with 2 df) |
Notes
Returns NaN if n < 20. Higher values indicate stronger deviation from normality.
See also
dagostino_p : Corresponding p-value
Source code in src/parcellate/metrics/volume.py
dagostino_p(values)
¶
D'Agostino-Pearson p-value for normality test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values (requires n ≥ 20) |
required |
Returns:
| Type | Description |
|---|---|
float
|
p-value. Values < 0.05 reject null hypothesis of normality. |
Notes
Returns NaN if n < 20. Combines tests of skewness and kurtosis. More computationally efficient than Shapiro-Wilk for large samples.
Source code in src/parcellate/metrics/volume.py
log_dagostino_k2(values)
¶
Log-transformed D'Agostino K² statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values (requires n ≥ 20) |
required |
Returns:
| Type | Description |
|---|---|
float
|
log(K²). Useful for visualization when K² spans many orders of magnitude. |
Source code in src/parcellate/metrics/volume.py
shapiro_w(values)
¶
Shapiro-Wilk W statistic for normality test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values (requires 3 ≤ n ≤ 5000) |
required |
Returns:
| Type | Description |
|---|---|
float
|
W statistic (ranges 0 to 1). Values close to 1 indicate normality. |
Notes
Returns NaN if n < 3 or n > 5000 or if test fails. Most powerful normality test but computationally expensive for large samples. Problematic if W < 0.95.
See also
shapiro_p : Corresponding p-value
Source code in src/parcellate/metrics/volume.py
shapiro_p(values)
¶
Shapiro-Wilk p-value for normality test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values (requires 3 ≤ n ≤ 5000) |
required |
Returns:
| Type | Description |
|---|---|
float
|
p-value. Values < 0.05 reject null hypothesis of normality. |
Notes
Returns NaN if n < 3 or n > 5000 or if test fails.
Source code in src/parcellate/metrics/volume.py
qq_correlation(values)
¶
Correlation coefficient from Q-Q plot (sample vs. theoretical normal quantiles).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
R value from Q-Q plot (ranges -1 to 1). Values close to 1 indicate normality. |
Notes
Quantifies the linearity of the Q-Q plot. Problematic if R² < 0.95.
See also
qq_r_squared : R² version (more commonly reported)
Source code in src/parcellate/metrics/volume.py
qq_r_squared(values)
¶
R² from Q-Q plot regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
R² (ranges 0 to 1). Values close to 1 indicate good fit to normal distribution. |
Notes
Problematic if R² < 0.95. Single-number summary of Q-Q plot linearity.
Source code in src/parcellate/metrics/volume.py
histogram_entropy(values, bins='auto')
¶
Shannon entropy of histogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
bins
|
int or str
|
Number of histogram bins or binning strategy. Default 'auto'. |
'auto'
|
Returns:
| Type | Description |
|---|---|
float
|
Entropy in bits. Higher values indicate more uniform/spread out distributions. |
Notes
Useful for comparing distributional complexity across ROIs. Not directly interpretable for normality assessment.
Source code in src/parcellate/metrics/volume.py
percentile_5(values)
¶
percentile_10(values)
¶
percentile_25(values)
¶
percentile_50(values)
¶
percentile_75(values)
¶
percentile_90(values)
¶
percentile_95(values)
¶
is_strongly_skewed(values, threshold=0.5)
¶
Whether distribution is strongly skewed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
threshold
|
float
|
Absolute skewness threshold. Default 0.5. |
0.5
|
Returns:
| Type | Description |
|---|---|
bool
|
True if |skewness| > threshold |
Source code in src/parcellate/metrics/volume.py
is_heavy_tailed(values, threshold=1.0)
¶
Whether distribution has heavy tails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
threshold
|
float
|
Absolute excess kurtosis threshold. Default 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if |excess_kurtosis| > threshold |
Source code in src/parcellate/metrics/volume.py
is_bimodal(values, threshold=0.555)
¶
Whether distribution appears bimodal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
threshold
|
float
|
Bimodality coefficient threshold. Default 0.555. |
0.555
|
Returns:
| Type | Description |
|---|---|
bool
|
True if bimodality_coefficient > threshold |
Source code in src/parcellate/metrics/volume.py
has_outliers(values, threshold=0.01)
¶
Whether distribution has excessive outliers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
threshold
|
float
|
Proportion threshold for 3SD outliers. Default 0.01 (1%). |
0.01
|
Returns:
| Type | Description |
|---|---|
bool
|
True if proportion of 3SD outliers > threshold |
Source code in src/parcellate/metrics/volume.py
fails_normality(values)
¶
Whether distribution fails normality tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if Shapiro-Wilk p < 0.05 (if available), else D'Agostino p < 0.05 |
Notes
Prioritizes Shapiro-Wilk (more powerful) when n ≤ 5000. Falls back to D'Agostino-Pearson for larger samples.
Source code in src/parcellate/metrics/volume.py
coverage(values)
¶
Proportion of non-NaN values in the parcel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Within-ROI voxel/vertex values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Coverage proportion (0 to 1). Higher values indicate more complete data. |
Source code in src/parcellate/metrics/volume.py
Utilities¶
image
¶
Utility functions for image handling