Skip to main content

DTI Pre-Processing for Sim4Life

Build Actions Status License PyPI version

This Python package provides pre-processing functions to help Sim4Life users prepare diffusion tensor images (DTI) for use in low-frequency electro-magnetic simulations. The primary goal is to convert DTI into a format supported by Sim4Life, enabling the assignment of anisotropic inhomogeneous conductivity maps in tissue models.

Features

  • Align diffusion weighted images (DWI) to structural images, e.g. T1-weighted MRI (using SimpleITK)
  • Noise removal for DWI (using dipy)
  • DTI reconstruction from DWI (using dipy)
  • Save DTI in Sim4Life compatible ordering (XX, YY, ZZ, XY, YZ, ZX) (see reconstruct.py)
  • Example data is automatically downloaded

Installation

pip install s4l-dti

or

pip install git+https://github.com/dyollb/s4l-dti.git#egg=s4l-dti

Usage

Download IXI025 head dataset:

from s4l_dti.data import download_ixi_025

download_dir = Path.home() / "Models" / "IXI025"
download_files = download_ixi_025(download_dir)

for key in download_files:
    print(f"Downloaded {key}: {download_files[key].relative_to(download_dir)}")

Reconstruction and saving as Sim4Life compatible Nifti file:

from s4l_dti.reconstruct import reconstruct_dti

dwi_image_file = download_files["dwi"]
bvec_file = download_files["bvec"]
bval_file = download_files["bval"]
mask_file = download_files["labels"]
s4l_dti_file = download_dir / "DTI-s4l.nii.gz"

reconstruct_dti(
    img_file=dwi_aligned_denoised_image_file,
    bvec_file=bvec_file,
    bval_file=bval_file,
    mask_file=mask_file,
    s4l_dti_file=s4l_dti_file,
)

To use an existing mask as a containment control rather than as the fitting mask, set use_mask_as_otsu_control=True and provide mask_file. The control mask is resampled onto the DWI grid with nearest-neighbor interpolation. Reconstruction runs median_otsu starting at otsu_mask_dilation=2 and increases the dilation by one until all control voxels are inside the Otsu mask. The final Otsu mask (not its intersection with the control) is used for fitting. Set otsu_mask_save_path to save that mask. Control mode requires a positive initial dilation and raises an error if the Otsu mask is empty or stops growing before containment is reached.

The CLI exposes the same settings as --use-mask-as-otsu-control, --otsu-mask-dilation, and --otsu-mask-save-path, together with --mask-file.

For more examples, see the Jupyter notebook.

Metadata

Release files for s4l-dti 1.3.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 s4l-dti 1.3.0
File Size Uploaded Provenance Actions
s4l_dti-1.3.0.tar.gz 20.0 kB Without provenance Details for s4l_dti-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for s4l-dti 1.3.0
File Interpreter ABI Platform Actions
s4l_dti-1.3.0-py3-none-any.whl Python 3 none any Details for s4l_dti-1.3.0-py3-none-any.whl

Total release size: 36.6 kB

Release files / s4l_dti-1.3.0.tar.gz

Download URL s4l_dti-1.3.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b4cbace326f6bc788f3113a604ff50c8237ab3302dc689cc7221cce11f2ca7eb
BLAKE2b-256 checksum
How to use checksums
ce1aef3f7283c3458aeac8d1ce62954eee69f2cea19c0b2f2ff893f2951db4f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / s4l_dti-1.3.0-py3-none-any.whl

Download URL s4l_dti-1.3.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b1f2c9a11d6571ca1946fa47d1f751fe7898e818825cf2228a3af7aadd3461a
BLAKE2b-256 checksum
How to use checksums
8dceb50eda09ed35ece409a0da0f61591cdcca909eb1b2f2b0b7d437eead5351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for s4l-dti 1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

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