Coder Social home page Coder Social logo

py-baudin / epgpy Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 791 KB

A user-friendly python library for simulating NMR signals using the Extended Phase Graph (EPG) formalism.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
mri nmr physics simulation

epgpy's Introduction

epgpy

Description

A python library for simulating NMR signals using the Extended Phase Graph (EPG) formalism.

Its aims are:

  • Simplicity (few dependencies, user-friendly, pythonic syntax)
  • Generality (can be used for simulations, optimization, etc.)
  • Efficiency* (vectorization, GPU enabled)

*only some degree of efficiency can be expected from this implementation, if speed is really critical, other implementations may be more suitable.

A number of extensions are, or will be, implemented:

  • Arbitrary 3D gradients
  • Anisotropic diffusion
  • Multi-compartment exchanges, including magnetization transfer
  • (soon) Differentiability (e.g., for sequence optimization)
  • (soon) GPU compatible (via cupy)
  • (soon) General operator merging for faster simulations

Please look into the examples folder for concrete uses of the code.

Disclaimer : this is a research project, and the authors give no guaranty on the validity of the generated results.

Example usage

Simulate a multi-spin-echo NMR sequence using EPG operators:

from epgpy import operators, functions

FA = 120 # flip angle (degrees)
ESP = 10 # echo spacing (ms)
Nrf = 20 # num. rf

# relaxation times (multiple T2 values are simulated at once)
T1 = 150 # ms
T2 = [30, 40, 50] # ms

# operators
exc = operators.T(90, 90) # excitation
rfc = operators.T(FA, 0) # refocussing
rlx = operators.E(ESP/2, T1, T2) # relaxation
shift = operators.S(1, duration=ESP / 2) # spoiler gradients
adc = operators.ADC # reading flag

# concatenate operators (in nested lists)
seq = [exc] + [[shift, rlx, rfc, shift, rlx, adc]] * Nrf

# simulate the signal
signal = functions.simulate(seq)
# get adc times
times = functions.get_adc_times(seq)

#
# plot signal
from matplotlib import pyplot as plt
plt.plot(times, plt.np.abs(signal))
plt.title('MSE signal decay')
plt.xlabel('time (ms)')
plt.ylabel('magnitude (a.u)')
plt.legend(labels=[f'{t2} ms' for t2 in T2], title='T2 values')
plt.show()

plot

References

These references were used for the implementation:

  • Gao, Xiang, Valerij G. Kiselev, Thomas Lange, Jürgen Hennig, et Maxim Zaitsev. « Three‐dimensional Spatially Resolved Phase Graph Framework ». Magnetic Resonance in Medicine 86, nᵒ 1 (juillet 2021): 551‑60. https://doi.org/10.1002/mrm.28732.
  • Malik, Shaihan J., Rui Pedro A.G. Teixeira, et Joseph V. Hajnal. « Extended Phase Graph Formalism for Systems with Magnetization Transfer and Exchange: EPG-X: Extended Phase Graphs With Exchange ». Magnetic Resonance in Medicine 80, nᵒ 2 (août 2018): 767‑79. https://doi.org/10.1002/mrm.27040.
  • Weigel, M., S. Schwenk, V.G. Kiselev, K. Scheffler, et J. Hennig. « Extended Phase Graphs with Anisotropic Diffusion ». Journal of Magnetic Resonance 205, nᵒ 2 (août 2010): 276‑85. https://doi.org/10.1016/j.jmr.2010.05.011.
  • Weigel, Matthias. « Extended Phase Graphs: Dephasing, RF Pulses, and Echoes - Pure and Simple: Extended Phase Graphs ». Journal of Magnetic Resonance Imaging 41, nᵒ 2 (février 2015): 266‑95. https://doi.org/10.1002/jmri.24619.

epgpy's People

Contributors

py-baudin avatar

Stargazers

Kohei Sugimoto avatar Eric Hughes avatar Chaoguang Gong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.