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.1.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.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parcellate-0.4.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7872d1488d60a994edc4633c84cd3680ba0a94f96d35f475735c5e49aa9af271
MD5 a8e32ff62524c39c93c6eaf22f5dbc6d
BLAKE2b-256 61e2ba246ff2baa66ef07bc0ee2de66cb714b611888460c5515e6ba0eb4a0de1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parcellate-0.4.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6de6f380b2ea8fb0b4ad1c943a6378ff45f446563bca2314312e595e73922e6
MD5 3f2d41dd1b07d0ccd6e37042b72530ec
BLAKE2b-256 60d9cc4b76e172b0f24525714957a3fb91f377273e1de3823a8eaf326cc4caa5

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