Skip to main content

A flexible Bloch simulation framework enabling large parameter space investigations, such as for Arterial Spin Labelling (ASL)

Project description

MRI Bloch Simulation

GigaBlochs is a flexible Bloch simulation framework enabling large parameter space investigations in Magnetic Resonance Imaging (MRI). The Bloch equations describe the time-evolution of magnetization in a magnetic field resulting from radiofrequency (RF) pulses, gradients waveforms, off-resonance effects, and motion of hydrogen nuclei (or "spins") through these fields, as in the case of pulsatile blood flow in arteries.

The capability to handle arbitrary, multi-dimensional spin properties which evolve at every timestep, combined with tools for flow modelling, allows for realistic simulations of complex sequences, such as Arterial Spin Labelling (ASL). ASL is a technique that uses the magnetization of blood as an endogenous contrast agent for quantification of perfusion.

Features

  • Simulate the full time-evolution of the magnetization following an arbitrary pulse sequence
  • Avoids the hard pulse approximation, constructing all B-field components from RF and gradient waveforms along with off-resonance effects
  • Uses numpy-style broadcasting to effectively run up to millions of Bloch simulations in parallel
  • Sophisticated blood flow modelling tools to incorportate friction and pulsatile flow effects when relevant
  • GPU acceleration using CuPy, with CPU fallback, for seamless and fully device-agnostic simulation code
  • Visualise the effect on magnetization of whole parameter grids using Bokeh
  • Animations of the magnetization dynamics in 3D on the Bloch Sphere using Manim

ASL Features

  • Simulate PASL sequences or background suppression using adiabatic pulses
  • Simulate CASL with constant concurrent RF and gradients
  • Simulate PCASL with a train of RF sinc pulses and gradients
  • Use arbitrary flow trajectories to simulate the effect of pulsatile blood flow
  • Use the rigid tube model to simulate viscosity and vessel wall friction across arteries

Example

Pulsed ASL (PASL) uses an adiabatic pulse to label a slab of blood in one go. Here's an animation on the Bloch sphere of an adiabatic inversion pulse in a reference frame rotating at the instantaneous frequency of the pulse (which only coincides with the Larmor frequency when passing through the transverse plane):

.. video:: _static/BlochScene_PASL.mp4 :width: 800 :loop:

.. code-block:: python

from gigablochs import animation
animation.bloch_sphere(downsampled_magnetization, downsampled_b_field, time_interval)

See examples/Adiabatic Inversion Animation.ipynb <https://github.com/nathanielatom/gigablochs/blob/main/examples/Adiabatic%20Inversion%20Animation.ipynb>__ for the full simulation code.

.. .. toctree:: :maxdepth: 2 :caption: Examples :hidden:

    adiabatic_pulse_demo

.. pcasl_demo flow_demo background_suppression_demo

Installation

To install GigaBlochs, simply run:

.. code-block:: bash

pip install git+https://github.com/nathanielatom/gigablochs

Advanced Installation

For GPU acceleration using cupy, ensure you have a compatible NVIDIA GPU and CUDA toolkit <https://docs.cupy.dev/en/stable/install.html#requirements>__, then install GigaBlochs with the gpu extra:

.. code-block:: bash

pip install git+https://github.com/nathanielatom/gigablochs[gpu]

For 3D animations on the Bloch sphere using manim, install dependencies <https://docs.manim.community/en/stable/installation.html>__ as shown below and include the animation extra:

.. tab-set::

.. tab-item:: Ubuntu / Debian / Windows Subsystem for Linux (WSL)

    .. code-block:: bash

        sudo apt update
        sudo apt install build-essential pkg-config libcairo2-dev libpango1.0-dev
        pip install git+https://github.com/nathanielatom/gigablochs[animation]

.. tab-item:: macOS

    .. code-block:: bash

        # install brew package manager if not already installed
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
        brew install cairo pkg-config
        pip install git+https://github.com/nathanielatom/gigablochs[animation]

Both extras can be installed at once with gigablochs[animation,gpu].

See dependencies in the pyproject.toml file for required and optional packages. To install the very latest commit from github run:

.. code-block:: bash

pip install git+https://github.com/nathanielatom/gigablochs

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

gigablochs-0.2.4.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

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

gigablochs-0.2.4-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file gigablochs-0.2.4.tar.gz.

File metadata

  • Download URL: gigablochs-0.2.4.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gigablochs-0.2.4.tar.gz
Algorithm Hash digest
SHA256 1b22fce48afce098f7036bdf44a3534c7e1fc1aad3363e70879f9c6ef600e672
MD5 4cf499a42c90a44838a5672002d646c1
BLAKE2b-256 8ee2997515a317faa8c305ca2ec8481a09f20841c2267a8d94954ffa408adfbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for gigablochs-0.2.4.tar.gz:

Publisher: build.yml on nathanielatom/gigablochs

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

File details

Details for the file gigablochs-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: gigablochs-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gigablochs-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d9bf43821f48afe5cc280dfcee285d97afe391d3d78c21afd355d272f06bf23d
MD5 8d709c79a559853d76735d06c0173003
BLAKE2b-256 2ad51ac2e21fb46a70046b4958735c692a305895fcdaff3109be9115a784d5cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for gigablochs-0.2.4-py3-none-any.whl:

Publisher: build.yml on nathanielatom/gigablochs

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

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