Skip to main content

A Python library for IVIM diffusion MRI model fitting

Project description

ivimfit

ivimfit is a modular Python library for fitting Intravoxel Incoherent Motion (IVIM) diffusion MRI models.
It supports monoexponential ADC fitting, biexponential (free and segmented) models, as well as Bayesian inference using PyMC.

Designed for researchers and clinicians working with DWI/IVIM datasets, this package offers signal filtering, robust modeling, and visualization tools for parameter evaluation.


📦 Features

  • ✅ Monoexponential ADC fitting
  • ✅ Full biexponential model (nonlinear free fit)
  • ✅ Segmented biexponential model (2-step D + [f, D*])
  • ✅ Bayesian IVIM modeling using MCMC via PyMC
  • ✅ Optional exclusion of b = 0
  • ✅ Automatic filtering of b-values > 1000
  • ✅ R² calculation and signal-fit visualization utilities

🧳 License

This project is licensed under the MIT License - see the [LICENSE] file for details.

📥 Installation

pip install ivimfit .

import numpy as np
import matplotlib.pyplot as plt
from ivimfit.utils import plot_fit, calculate_r_squared
from ivimfit.adc import fit_adc, monoexp_model

b = np.array([0, 50, 100, 200, 400, 600, 800])
s = np.array([800, 654,543,423,328,236,121])
#ADC Calculation
adc = fit_adc(b, s)
r2 = calculate_r_squared(s / s[0], monoexp_model(b, adc))

fig, ax = plot_fit(b, s, monoexp_model, [adc], model_name=f"ADC Fit (R² = {r2:.4f})")
plt.show()

#Biexponential Fitting
from ivimfit.biexp import fit_biexp_free, biexp_model

b = np.array([0, 50, 100, 200, 400, 600, 800])
s = np.array([800, 654,543,423,328,236,121])

f, D, D_star = fit_biexp_free(b, s)
r2 = calculate_r_squared(s / s[0], biexp_model(b, f, D, D_star))

fig, ax = plot_fit(b, s, biexp_model, [f, D, D_star], model_name=f"Free Fit (R² = {r2:.4f})")
plt.show()
#Segmented Fitting
from ivimfit.segmented import fit_biexp_segmented, biexp_fixed_D_model

b = np.array([0, 50, 100, 200, 400, 600, 800])
s = np.array([800, 654,543,423,328,236,121])

f, D_fixed, D_star = fit_biexp_segmented(b, s)
r2 = calculate_r_squared(s / s[0], biexp_fixed_D_model(b, f, D_star, D_fixed))

fig, ax = plot_fit(
    b, s,
    lambda b_, f_, D_star_,D_fixed: biexp_fixed_D_model(b_, f_, D_star_, D_fixed),
    [f, D_star,D_fixed],
    model_name=f"Segmented Fit (R² = {r2:.4f})"
)
plt.show()
#Bayesian Approach
from ivimfit.bayesian import fit_bayesian
from ivimfit.biexp import biexp_model

b = np.array([0, 50, 100, 200, 400, 600, 800])
s = np.array([800, 654,543,423,328,236,121])

if __name__ == "__main__":
    f, D, D_star = fit_bayesian(b, s, draws=500, chains=2)
    r2 = calculate_r_squared(s / s[0], biexp_model(b, f, D, D_star))

    fig, ax = plot_fit(b, s, biexp_model, [f, D, D_star], model_name=f"Bayesian Fit (R² = {r2:.4f})")
    plt.show()

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

ivimfit-0.1.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

ivimfit-0.1.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file ivimfit-0.1.2.tar.gz.

File metadata

  • Download URL: ivimfit-0.1.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for ivimfit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0ca6a5656da0597ac1be2cce00e958ecec432ede9a8bc2b0b0398c3fb1d68958
MD5 4311ae6db1c6055e19027c5854f35b59
BLAKE2b-256 8f75389ef8d1adfc47abd5fa8719d00dc5855201b36bfc11700c11ac386803b2

See more details on using hashes here.

File details

Details for the file ivimfit-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ivimfit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for ivimfit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 159058aa66ce09c1ed81de710fc189b9f4e0732f01bb2d57deb41c2870e4a47c
MD5 cfb5622aee04987f84b207ca87178f9a
BLAKE2b-256 1dc78063f2295284ac3d47fdc512e29adac2d164a1d23bd58b263e3fe2d158ef

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