Skip to main content

Processing pipelines to extract brain microstructure from diffusion MRI

Project description

kwneuro

Actions Status Documentation Status

PyPI version PyPI platforms

GitHub Discussion

A Python-native toolkit for diffusion MRI analysis -- pip install and go from raw dMRI data to microstructure maps, fiber orientations, and tract segmentations without wrestling with multi-tool installations.

Early phase, under active development. The API may change between releases.

Why kwneuro?

Diffusion MRI analysis typically requires stitching together several packages (FSL, MRtrix3, DIPY, AMICO, ANTs, ...), each with its own installation story, file conventions, and coordinate quirks. kwneuro wraps the best of these tools behind a single, pip-installable Python interface so you can:

  • Get started fast -- no system-level dependencies to configure.
  • Swap models easily -- go from DTI to NODDI to CSD without rewriting your script.
  • Work lazily or eagerly -- data stays on disk until you call .load(), so you control memory usage.

kwneuro is not (yet) a replacement for the full power of FSL or MRtrix3. It is a lightweight layer for researchers who want standard dMRI analyses with minimal friction.

Installation

pip install kwneuro

Requires Python 3.10+.

Quick start

from kwneuro.dwi import Dwi
from kwneuro.io import FslBvalResource, FslBvecResource, NiftiVolumeResource

# Load DWI data into memory
dwi = Dwi(
    NiftiVolumeResource("sub-01_dwi.nii.gz"),
    FslBvalResource("sub-01_dwi.bval"),
    FslBvecResource("sub-01_dwi.bvec"),
).load()

# Denoise and extract a brain mask
dwi = dwi.denoise()
mask = dwi.extract_brain()

# Fit DTI and get FA / MD maps
dti = dwi.estimate_dti(mask=mask)
fa, md = dti.get_fa_md()

# Fit NODDI (needs multi-shell data)
noddi = dwi.estimate_noddi(mask=mask)

# Save everything to disk
dti.save("output/dti.nii.gz")
NiftiVolumeResource.save(fa, "output/fa.nii.gz")
noddi.save("output/noddi.nii.gz")

What's included

Capability What it does Powered by
Denoising Patch2Self self-supervised denoising DIPY
Brain extraction Deep-learning brain masking from mean b=0 HD-BET
DTI Tensor fitting, FA, MD, eigenvalue decomposition DIPY
NODDI Neurite density, orientation dispersion, free water fraction AMICO
CSD Fiber orientation distributions and peak extraction DIPY
Tract segmentation 72 white-matter bundles from CSD peaks TractSeg
Registration Pairwise registration (rigid, affine, SyN) ANTs
Template building Iterative unbiased population templates (single- or multi-metric) ANTs

Example notebooks

The notebooks/ directory contains Jupytext notebooks you can run end-to-end:

  • example-pipeline.py -- Single-subject walkthrough: loading, denoising, brain extraction, DTI, NODDI, CSD, and TractSeg.
  • example-group-template.py -- Multi-subject FA/MD template construction using iterative registration.

Contributing

Contributions are welcome! To set up a dev environment:

pip install -e ".[dev]"
pre-commit install

Run the tests and linter:

pytest
ruff check .

See the GitHub Discussions for questions and ideas, or open an issue for bugs and feature requests.

Acknowledgements

This work is supported by the National Institutes of Health under Award Number 1R21MH132982. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health.

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

kwneuro-0.3.0.tar.gz (60.1 kB view details)

Uploaded Source

Built Distribution

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

kwneuro-0.3.0-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file kwneuro-0.3.0.tar.gz.

File metadata

  • Download URL: kwneuro-0.3.0.tar.gz
  • Upload date:
  • Size: 60.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kwneuro-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1d0612edf4ae89d73e6ee354136ae18415ac7792406bc306719ad713797af83f
MD5 49dbfd3807f3c1de62b29fbb1da8a7fe
BLAKE2b-256 f74d6bce732190d11577ae2d8a2d50148664f9b60fedbe919d8c34da783d795a

See more details on using hashes here.

Provenance

The following attestation bundles were made for kwneuro-0.3.0.tar.gz:

Publisher: cd.yml on KitwareMedical/kwneuro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kwneuro-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: kwneuro-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kwneuro-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffee1b6ef120d1ca3e474ebcd8d08da320658b1271fe8147c20dcc409f8ae979
MD5 3c89d2ed6556a17d9ad3c0f4b16ab17c
BLAKE2b-256 05fd249e4be0c04f1cbcdfbae2c99d6f3d38399c054df912cd6805f38ab34c45

See more details on using hashes here.

Provenance

The following attestation bundles were made for kwneuro-0.3.0-py3-none-any.whl:

Publisher: cd.yml on KitwareMedical/kwneuro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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