DIPY
raw JSON → 1.12.1 verified Fri May 01 auth: no python
DIPY is a Python library for diffusion MRI analysis, featuring tractography, reconstruction, registration, and signal processing. Current version is 1.12.1. It has a moderate release cadence with major versions every 1-2 years.
pip install dipy Common errors
error ModuleNotFoundError: No module named 'dipy.dti' ↓
cause Import path changed after DIPY 1.0.0; old top-level submodules no longer exist.
fix
Use from dipy.reconst.dti import TensorModel instead.
error AttributeError: module 'dipy' has no attribute 'data' ↓
cause dipy.data is not automatically imported; need to import explicitly.
fix
Try from dipy.data import get_data or import dipy.data as dpd.
error ValueError: bvals and bvecs must have same number of volumes ↓
cause bvals and bvecs files have mismatched lengths or are not aligned properly.
fix
Read both files with read_bvals_bvecs and verify shapes. Ensure they correspond to the same DW images.
Warnings
breaking DIPY 1.0.0 dropped support for Python 2 and changed many submodule paths. Some previously top-level functions moved to submodules. ↓
fix Update imports: e.g., from dipy.reconst.dti import TensorModel instead of dipy.dti.TensorModel.
deprecated The `dipy.data` module contains some deprecated fetchers. Prefer using `nibabel` to load data. ↓
fix Use `nib.load()` directly instead of `dipy.data.get_data()`.
gotcha gradient_table expects b-values in s/mm² and b-vectors as (N,3) array. Mixing units or shapes causes silent errors. ↓
fix Ensure bvals are numeric, bvecs are normalized, and use correct order: gradient_table(bvals, bvecs, b0_threshold=50).
gotcha DIPY's tractography algorithms (e.g., EuDX) require specific input formats. Incorrect seed masks can lead to empty streamlines. ↓
fix Check seed mask is binary and in same space as data. Use dipy.tracking.utils seeds_from_mask.
Install
conda install -c conda-forge dipy Imports
- dipy
import dipy - gtab wrong
from dipy.io.gradients import read_bvals_bvecs (not for creating gtab)correctfrom dipy.core.gradients import gradient_table
Quickstart
import numpy as np
from dipy.io import read_bvals_bvecs
from dipy.core.gradients import gradient_table
from dipy.reconst.dti import TensorModel
# Load data (example: replace with own files)
# data = nib.load('dwi.nii.gz').get_fdata()
# bvals, bvecs = read_bvals_bvecs('bvals.txt', 'bvecs.txt')
# gtab = gradient_table(bvals, bvecs)
# tenmodel = TensorModel(gtab)
# tenfit = tenmodel.fit(data)
# fa = tenfit.fa
print('DIPY DTI example ready')