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 withsolver="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).
Metadata
Release files for dmipy-fit 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dmipy_fit-2.3.0.tar.gz | 644.4 kB | With provenance | Details for dmipy_fit-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dmipy_fit-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for dmipy_fit-2.3.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / dmipy_fit-2.3.0.tar.gz
| Download URL | dmipy_fit-2.3.0.tar.gz |
|---|---|
| Size | 644.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f69d5c439d006d6cfcbcd3ba6b08ea4aa64e9246106347fc14623609d076eeb9
|
|
BLAKE2b-256 checksum How to use checksums |
24507df2a5a7971af1285c138f172221a02f77c9d97c2a3a6ab733f48331d54f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 23, 2026.
Transparency logRelease files / dmipy_fit-2.3.0-py3-none-any.whl
| Download URL | dmipy_fit-2.3.0-py3-none-any.whl |
|---|---|
| Size | 743.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c74652c843b263f6e695bc87cb1aa80eefaf060b96df06c643e316f86848401
|
|
BLAKE2b-256 checksum How to use checksums |
2f1f1732d08369cce532848325b95bb780a04110647801d88086df2333b04919
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 23, 2026.
Transparency logSecurity for dmipy-fit 2.3.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dmipy_fit-2.3.0.tar.gz
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 Jul 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.