Skip to main content

dmipy-fit

Diffusion Microstructure Imaging in Python — the analytical inverse engine: fit multi-compartment tissue models to diffusion-MRI data, voxel-by-voxel, and recover interpretable microstructure maps (axon density and dispersion, diffusivities, cell size, volume fractions, T2, and more).

One shared G(t) + substrate across the whole loop — design the sequence, simulate the signal, fit the tissue: dmipy-design · deliverable sequence design  ·  dmipy-sim · Monte-Carlo forward  ·  dmipy-fit · analytical inverse (you are here)  ·  dmipy · umbrella + docs.

Docs: dmipy.org  ·  coming from the 2019 toolbox? What's changed in 2.x

It models the diffusion signal plus the transverse-relaxation contrasts that ride on it — T2 and surface relaxivity — as composable, occupancy-gated factors that attach to any compartment. Every analytical model is validated effect-by-effect against the dmipy-sim Monte-Carlo simulator (the two share one free-waveform sequence/substrate interface; the dependency is one-directional, fit → sim).

from dmipy_fit.signal_models.gaussian_models import G1Ball
from dmipy_fit.signal_models.cylinder_models import C1Stick
from dmipy_fit.core.modeling_framework import MultiCompartmentModel

ball_stick = MultiCompartmentModel([G1Ball(), C1Stick()])
fit = ball_stick.fit(scheme, data, solver="jax")     # whole slice on GPU
intra_fraction = fit.fitted_parameters["partial_volume_1"]

The signal model

dmipy-fit models the measured signal as a sum of compartments, each carrying its diffusion attenuation times its (transverse) relaxation contrasts:

$$ S ;=; S_0 \sum_i f_i ; \underbrace{E^{\mathrm{diff}}i(b)}{\text{diffusion}} ; \underbrace{e^{-\mathrm{TE}/T_{2,i}}}_{T_2} ; \underbrace{\hat B^{\mathrm{surf}}i(\mathrm{TE})}{\text{surface relaxivity}} $$

Magnetisation is treated as fully transverse (ideal instantaneous pulses). Each non-diffusion effect is an occupancy-gated factor — a multiplicative attenuation that attaches to any compartment via OccupancyGatedModel, so any subset composes by listing more factors.

What's here

  • Signal models (signal_models/) — sticks/cylinders, sphere, Gaussian (ball/zeppelin), plane, capped cylinder, tissue-response; b-tensor / free-waveform aware.
  • Occupancy-gated factors (signal_models/attenuation.py) — OccupancyGatedModel + TransverseRelaxation, IntraPoreSurfaceRelaxivity, ExteriorSurfaceRelaxivity. Relaxation and surface relaxivity as composable add-ons to any compartment.
  • Fitting framework (core/) — MultiCompartmentModel, spherical-mean and spherical-harmonics frameworks, fitted-model properties.
  • Distributions (distributions/) — Watson / Bingham dispersion, Gamma diameter.
  • Optimizers — brute2fine, MIX, multi-tissue NNLS; CSD (Tournier / cvxpy / OSQP-JAX); IVIM / impulsed / 3-tissue custom optimizers.
  • GPU fitting (jax/) — diffusion signal models, multicompartment, CSD, DTI, fractions, vmap_fit; whole-slice fitting in seconds with solver="jax".
  • White matter (white_matter/):
    • build_white_matter_model() — a decoupled, diffusion-only canonical WM model (stick + zeppelin + stuck-myelin dot + optional CSF ball), each compartment gated with T2 + surface-relaxivity. Because the intra-pore and exterior surface factors differ per compartment, surface relaxivity introduces a b-independent signal weighting between intra and extra (true spin fractions ≠ apparent fractions) — a physical effect that plain stick+zeppelin models omit.
    • t2_spectrum_mwf() — standard regularised NNLS T2-spectrum myelin-water fraction (Whittall–MacKay / DECAES). Estimate MWF directly from a multi-echo T2 decay, including one generated by a dmipy-sim CPMG-style multi-TE series.
  • Rician noise model, b-tensor / free-waveform schemes, and a Monte-Carlo bridge to dmipy-sim.
  • Flagship example (examples/flagship_canonical_wm/) — the canonical WM signal computed both ways (this analytical model and the dmipy-sim Monte-Carlo), agreeing for diffusion and surface relaxivity; fully reproducible (regenerates the cached MC bit-exactly). The clearest entry point to what the two engines are for.

Installation

pip install dmipy-fit                    # core only
pip install "dmipy-fit[jax]"             # + JAX GPU fitting
pip install "dmipy-fit[jax,data,viz]"    # + bundled-data loaders + plotting
pip install "dmipy-fit[all]"             # everything

Myelin water fraction from a Monte-Carlo CPMG decay

dmipy_sim.simulate_cpmg returns the full echo train from a single walk; feed it to the NNLS T2-spectrum estimator:

import numpy as np
import dmipy_sim as ds
from dmipy_fit.white_matter.mwf import t2_spectrum_mwf

geom = ds.MyelinatedCylinder(inner_radius=2.5e-6, outer_radius=3.57e-6, orientation=(0, 0, 1),
    D_intra=1.7e-9, D_myelin_radial=0.1e-9, D_myelin_tangential=0.5e-9, D_extra=1.7e-9,
    T2_intra=0.080, T2_myelin=0.015, T2_extra=0.080)

TE, n_echoes = 8e-3, 32
wf = ds.cpmg(n_echoes=n_echoes, TE=TE, G_magnitude=0.0, bvecs=[[1, 0, 0]], n_t_per_echo=60)
S = np.asarray(ds.simulate_cpmg(40000, None, wf, geom)).ravel()      # (n_echoes,), one walk
echo_times = np.arange(1, n_echoes + 1) * TE
mwf, T2_grid, spectrum = t2_spectrum_mwf(S / S[0], echo_times)

Testing

pytest -q                       # analytical + numerical (dipy/MISST references)
pytest -q -m "not slow"         # skip the heavy GPU battery

Tests assert against analytical results, MISST/dipy references, or analytic ↔ Monte-Carlo parity against dmipy-sim.

License

Dual-licensed: GNU AGPL-3.0 for open-source use, or a commercial license for proprietary/closed use. See LICENSE and LICENSING.md (commercial: rutger.fick@dmrai-lab.org).

Download files

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

Source Distribution

dmipy_fit-2.2.0.tar.gz (622.7 kB view details)

Uploaded Source

Built Distribution

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

dmipy_fit-2.2.0-py3-none-any.whl (717.0 kB view details)

Uploaded Python 3

File details

Details for the file dmipy_fit-2.2.0.tar.gz.

File metadata

  • Download URL: dmipy_fit-2.2.0.tar.gz
  • Upload date:
  • Size: 622.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for dmipy_fit-2.2.0.tar.gz
Algorithm Hash digest
SHA256 3e9dc4f199d3f9271790c6bf921dccd976a92d0900b1c7ef0e4e2c309f57d76f
MD5 a0bb3f455fb266adf991b4f3cacfb5ab
BLAKE2b-256 edcf735062ba13387da7466db961d2d965852d537c5972fcea926584e5907d99

See more details on using hashes here.

Provenance

The following attestation bundles were made for dmipy_fit-2.2.0.tar.gz:

Publisher: publish.yml on dmrai-lab/dmipy-fit

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

File details

Details for the file dmipy_fit-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: dmipy_fit-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 717.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for dmipy_fit-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 733a7110e1eaf1d678c84eed64cc0472c1571c73509505bce7e3a99bc9f1b959
MD5 bef1bce406f9cfe8344088c219297a9e
BLAKE2b-256 0e752df67d66e05b3ce5a8277ea1c068ca55647621a1f090b98ea11e5f9b98a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dmipy_fit-2.2.0-py3-none-any.whl:

Publisher: publish.yml on dmrai-lab/dmipy-fit

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

Release history Release notifications | RSS feed

2.3.0

2 files

This release

2.2.0 This release

2 files

2.1.0

2 files

2.0.0

2 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