Skip to main content

Extract regional statistics from scalar brain maps using atlas-based parcellation.

Project description

parcellate

Build status codecov Documentation License

Extract regional statistics from scalar neuroimaging maps using atlas-based parcellation.

What It Does

parcellate is a Python library that extracts regional statistics from volumetric brain images using atlas-based parcellation. Given a scalar map (e.g., gray matter density, fractional anisotropy) and a labeled atlas, it computes summary statistics for each brain region and returns a tidy pandas.DataFrame.

Key Features:

  • 45 built-in statistics in three tiers (core / extended / diagnostic), including robust estimates, higher-order moments, and normality tests
  • Flexible atlases: discrete 3D integer-label atlases and 4D probabilistic atlases (e.g., XTRACT tracts)
  • Built-in masks: MNI152 grey-matter, white-matter, and brain masks via nilearn
  • Custom statistics: supply any callable as a statistic
  • Scikit-learn–style API: fit / transform pattern with smart resampling caching

Installation

pip install parcellate

Or from a local checkout:

git clone https://github.com/GalKepler/parcellate.git
cd parcellate
pip install -e .

Quick Start

from parcellate import VolumetricParcellator

parcellator = VolumetricParcellator(
    atlas_img="atlas.nii.gz",
    lut="atlas_lut.tsv",       # TSV with "index" and "label" columns
    mask="gm",                 # built-in MNI152 grey-matter mask
    stat_tier="extended",      # 21 statistics (default: all 45)
)

parcellator.fit("subject_map.nii.gz")
stats = parcellator.transform("subject_map.nii.gz")
print(stats.head())

Statistics Tiers

Select a tier with stat_tier to control the number of computed statistics:

Tier Count Use case
core 6 Fast exploration, large cohorts
extended 21 Production pipelines
diagnostic (default) 45 QC, distribution inspection

Core: mean, std, median, volume_mm3, voxel_count, sum

Extended adds: robust means (MAD, z-score, IQR filtered), dispersion (cv, robust_cv), shape (skewness, excess_kurtosis), percentiles (5th, 25th, 75th, 95th)

Diagnostic adds: normality tests (Shapiro-Wilk, D'Agostino K²), outlier proportions, tail mass, entropy, boolean QC flags

See the full Metrics reference for descriptions of all 45 statistics.

Custom Statistics

import numpy as np
from parcellate import VolumetricParcellator

parcellator = VolumetricParcellator(
    atlas_img="atlas.nii.gz",
    stat_functions={
        "iqr": lambda x: float(np.nanpercentile(x, 75) - np.nanpercentile(x, 25)),
        "q90": lambda x: float(np.nanpercentile(x, 90)),
    },
)

Output

transform() returns a pandas.DataFrame with one row per atlas region:

Column Description
index Integer region index from the atlas
label Region name from the lookup table
mean, std, … Computed statistics (depends on stat_tier)

Development

make install   # create venv + install pre-commit hooks
make test      # run tests with coverage
make check     # lock file, pre-commit, deptry

Documentation

Full documentation: https://GalKepler.github.io/parcellate/

License

MIT License — see the LICENSE file for details.

Citation

@software{parcellate,
  author = {Kepler, Gal},
  title = {parcellate: Atlas-based parcellation of neuroimaging data},
  url = {https://github.com/GalKepler/parcellate},
  year = {2024}
}

Acknowledgments

Repository initiated with fpgmaas/cookiecutter-uv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parcellate-0.4.2.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parcellate-0.4.2-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file parcellate-0.4.2.tar.gz.

File metadata

  • Download URL: parcellate-0.4.2.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for parcellate-0.4.2.tar.gz
Algorithm Hash digest
SHA256 07b68063073b65430a64f81d9732aca12b97348a37bd29b04ffae3e166ccfd5d
MD5 605d5c24ad139e606ed2863d838e1a2a
BLAKE2b-256 fd1d341d41670083b76364ad47dac35d2c665d5246c47d37d442e3b995602d93

See more details on using hashes here.

File details

Details for the file parcellate-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: parcellate-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for parcellate-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a396b968d504580a095fab4a7fce1690c8ba51dd7222ff9132e3b05ff45e0a3
MD5 3e4423d4919c670bb386d60f54a168b5
BLAKE2b-256 31c2380e5e650f4a6570415b43b95097faa521ca0f748094df70263b43769802

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page