Skip to main content

kwneuro

Actions Status Documentation Status

PyPI version PyPI platforms

GitHub Discussion

kwneuro is a Python package for building MRI analysis workflows around diffusion microstructure and structural MRI data.

It works with ordinary NIfTI images and FSL-style .bval/.bvec files, then gives you composable Python objects for common steps: denoising, DTI, NODDI, CSD, brain masks, T1 bias correction, tissue segmentation, parcellation, registration, template building, harmonization, and cached reruns of expensive work.

What kwneuro is for

kwneuro is designed for workflows that:

  • fit diffusion microstructure models and write scalar maps such as FA, MD, NDI, ODI, and free-water fraction;
  • combine DWI and structural MRI data through masking, registration, segmentation, and region-level analysis;
  • build study-specific templates or harmonize scalar maps across sites;
  • write Python pipeline code without managing each backend tool's file formats and coordinate conventions yourself.

kwneuro is not intended to be a replacement for the full power of FSL or MRtrix3. It is a lightweight layer for researchers who want standard structural or dMRI analyses with minimal friction.

Installation

pip install kwneuro              # Core DWI, structural, registration, templates
pip install "kwneuro[all]"       # All optional backends

Individual optional extras can also be installed separately:

pip install "kwneuro[hdbet]"      # Brain extraction (HD-BET)
pip install "kwneuro[noddi]"      # NODDI estimation (AMICO)
pip install "kwneuro[tractseg]"   # Tract segmentation (TractSeg)
pip install "kwneuro[combat]"     # ComBat harmonization (neuroCombat)
pip install "kwneuro[antspynet]"  # Deep structural segmentation/parcellation

Some optional extras install PyTorch- or TensorFlow-backed tools. If the selected wheel does not match your GPU or driver, install the CPU-only or CUDA-specific backend appropriate for that machine before installing the extra.

Requires Python 3.10-3.13.

Quick starts

DWI microstructure

from kwneuro import read_dwi_fsl, write_volume

# .bval and .bvec are inferred from the DWI NIfTI path when they
# use the same BIDS-style stem.
dwi = read_dwi_fsl("sub-01_dwi.nii.gz").load()

dwi_denoised = dwi.denoise()
dti = dwi_denoised.estimate_dti()
fa, md = dti.get_fa_md()

write_volume(dti.volume, "output/dti.nii.gz")
write_volume(fa, "output/fa.nii.gz")
write_volume(md, "output/md.nii.gz")

Pass explicit bval= or bvec= paths to read_dwi_fsl() when those files do not share the DWI NIfTI stem.

Structural MRI

from kwneuro import read_structural, write_structural, write_volume

t1 = read_structural("sub-01_T1w.nii.gz").load()

t1_corrected = t1.correct_bias()
tissue_labels = t1_corrected.segment_tissues()

write_structural(t1_corrected, "output/sub-01_T1w_n4.nii.gz")
write_volume(tissue_labels, "output/sub-01_tissues.nii.gz")

The file helpers are convenience adapters for file-first scripts and notebooks. The resource model remains the core API for reusable pipelines.

Caching

Wrap pipeline code in a Cache context to persist outputs and reuse them when the same inputs and parameters are seen again:

from kwneuro import Cache, read_dwi_fsl

dwi = read_dwi_fsl("sub-01_dwi.nii.gz")

with Cache("cache/sub-01"):
    dwi_denoised = dwi.denoise()
    dti = dwi_denoised.estimate_dti()

Outside a Cache context, the same functions run normally.

Command line

Common one-step workflows are also exposed through the kwneuro command:

kwneuro --help

kwneuro dwi dti \
  --dwi sub-01_dwi.nii.gz \
  --out-dti output/dti.nii.gz \
  --out-fa output/fa.nii.gz \
  --out-md output/md.nii.gz

kwneuro structural segment-tissues \
  --image sub-01_T1w.nii.gz \
  --out output/tissues.nii.gz

kwneuro registration dwi-to-structural \
  --dwi sub-01_dwi.nii.gz \
  --structural sub-01_T1w.nii.gz \
  --out-transform output/dwi_to_t1_transform

What's included

Area Capability Powered by Install
DWI Patch2Self denoising, DTI, FA/MD, CSD response/peaks DIPY core
DWI NODDI maps: NDI, ODI, free-water fraction AMICO [noddi]
DWI White-matter tract segmentation from CSD peaks TractSeg [tractseg]
Structural N4 bias correction and Atropos tissue segmentation ANTsPy core
Structural Brain extraction HD-BET [hdbet]
Structural Deep Atropos segmentation and DKT parcellation ANTsPyNet [antspynet]
Cross-modal DWI/T1 registration, transforms, and template building ANTsPy core
Group data ComBat harmonization of scalar maps neuroCombat [combat]
Pipelines Lazy resources, file helpers, CLI commands, caching kwneuro core

Tutorials

Start with the tutorial that matches the job:

Contributing

Contributions are welcome! Set up a dev environment with uv:

uv sync --extra dev
uv run pre-commit install

Run the tests and linter:

uv run pytest
uv run pre-commit run -a

See the Developer Guide for the full guide, including a non-uv setup option.

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.

Metadata

Release files for kwneuro 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kwneuro 1.0.0
File Size Uploaded
kwneuro-1.0.0.tar.gz 5.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for kwneuro 1.0.0
File Interpreter ABI Platform
kwneuro-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.6 MB

Release files / kwneuro-1.0.0.tar.gz

Download URL kwneuro-1.0.0.tar.gz
Size 5.5 MB
Tags Source
SHA-256 checksum
How to use checksums
017ad573ed72393757d7745b9b3ba65ffa0be5c50261919ee653bb5e08c82c01
BLAKE2b-256 checksum
How to use checksums
0b8e62988b48a22a8177c78a12aadd781418c4dafc111f3548a9e3e937db72c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

Release files / kwneuro-1.0.0-py3-none-any.whl

Download URL kwneuro-1.0.0-py3-none-any.whl
Size 57.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d269ecadc995a1bfe1c675099831161d9869356f3cfefdefc05d615e9fe1e4e
BLAKE2b-256 checksum
How to use checksums
ea910eca85b0bcbb1152171767b13b410c892ccb79985f3081e305378b4218c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page