Git Product home page Git Product logo

epg's Introduction

EPG

Python implementation of the Extended Phase Graph (EPG) algorithm for multi-echo MRI.

A MATLAB version can be find within the same project as https://github.com/imr-framework/epg-matlab

For the theory, see https://www.ncbi.nlm.nih.gov/pubmed/24737382 (Weigel, 2015) or read this powerpoint presentation.

Introduction

The extended phase graph algorithm is an alternative to time-domain Bloch simulations. Operating in the Fourier domain, it enables straightforward echo detection and is valuable for multi-echo sequences such as Turbo Spin Echo. The current scripts are capable of simulating the response to regularly spaced RF pulses with arbitrary phase and flip angle with linear gradients and T1, T2 relaxation effects. By “regularly spaced”, we mean that the intervals between pulses are integer multiples of the same Δt. Arbitrary spacing may be approximated with a small Δt and a large number of intervals, but the simulation will be slow.

The code has been translated from the MATLAB version, which was developed by Gehua Tong and Sairam Geethanath based on Weigel's paper (2015).

Quick Start

After cloning the repository and installing the dependencies, run the following code to simulate and visualize a simple TSE sequence.

import epg
import psd_library as pl

# Make a predefined sequence
S = pl.make_tse_sequence(alpha=120, N=5, esp=100, use_y90=True, t1t2=(1000,100))
# Initialize & run EPG
epg1 = epg.EPG(S)
epg1.simulate()
# Displays EPG diagram
epg1.display()
# Displays echo strengths 
epg1.plot_echoes()

Using the EPG functions

Core functions for the EPG algorithm:

  • rf_rotation(phi, alpha)
  • relaxation(tau, t1, t2, omega)
  • grad_shift(dk, omega)

Classes and class methods for running EPG:

  • Sequence(rf, grad, events, time, t1t2=(0,0), name="")
  • EPG(seq)
  • EPG.simulate()
  • EPG.reset()

Class methods for display & output:

  • Sequence.plot_seq()
  • EPG.find_echoes()
  • EPG.plot_echoes()
  • EPG.display()
  • EPG.get_sim_history()

The psd_library.py script includes functions for making pre-defined sequences (with custom parameters) for simulation.

Operators

EPG represents the magnetization in terms of configuration states. At any time, the configuration matrix Ω looks like this:

There are three basic operators in EPG simulation: RF pulse, gradient shift, and T1 & T2 relaxation, represented by the following functions:

  • rf_rotation(phi, alpha) returns a 3 x 3 rotation matrix
  • relaxation(tau, t1, t2, omega) returns the new omega after relaxation over interval tau
  • grad_shift(dk, omega) takes the configuration states and shifts it by an integer dk

RF Rotation

The rotation operator exchanges the F+, F-, and Z populations within each k. The operator is equivalent to a matrix multiplication, Ω=T(Φ,α)Ω, where:

Gradient shift

A positive unit gradient (dk = 1) moves all the F populations to a higher k but keeps the Z populations in place. For example:

With a negative gradient, the populations move in the opposite direction, and as gradients are applied, the matrix grows more columns.

T1 & T2 Relaxation

T1 and T2 relaxation are represented together in the following operator. Over a time interval τ, the relaxation factors are E1=exp(-τ/T1) and E2=exp(-τ/T2).

For k = 0:

And for k ≠0,

References

Weigel, Matthias. "Extended phase graphs: dephasing, RF pulses, and echoes ‐ pure and simple." Journal of Magnetic Resonance Imaging 41.2 (2015): 266-295.

Hennig J, Scheffler K. Hyperechoes. Magnetic Resonance in Medicine: An Official Journal of the International Society for Magnetic Resonance in Medicine. 2001 Jul;46(1):6-12.

epg's People

Contributors

imr-framework avatar tonggehua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

epg's Issues

Odd results when performing a TSE sequence

I am implementing on matlab an EPG but I encountered some mismatch when generating a TSE sequence.

I download this repousitory, and implemented a TSE similar to the example given, allowing it for an automatic design for any number of echoes.

Here is the input I am using:

%% Simulate double spin echoes with EPG
% -------------------- Tissues in (ms) -----------------------------
T1_GM = 1300;
T2_GM = 180;

% -------------------- initial parameters ---------------------------
seq.TE       = 50;                          % TE ms
seq.FA       = 170;                          % Flip angle ->20º

nechos       = 20;
seq.events   = [];
seq.time     = [];
event        = {'relax', 'rf','grad','relax'};
Tstart_event = [0 seq.TE/2];
Gstart_event = [1];
seq.events   = {'rf','grad'};
seq.time     = Tstart_event;
seq.grad     = [Gstart_event];

phi      = [90 zeros(1,nechos)];       % CPMG 
FA       = [90 ones(1,nechos)*seq.FA]; % FA for GM in the start
seq.rf  = [phi; FA];

for neco = 1:nechos
    seq.events = [seq.events , event];                              % Sequence of events
    seq.time   = [seq.time   , seq.TE*neco-seq.TE/2, seq.TE*neco-seq.TE/2, seq.TE*neco, seq.TE*neco];   % Time in ms
    seq.grad   = [seq.grad, 1];
end
seq.T1     = T1_GM;
seq.T2     = T2_GM;

% ------------------- Get EPG ----------------------------------
% IMR - Framework EPG
[om_store,echoes] = EPG_custom(seq); 

For a Flip Angle (FA) of 180º , I get a well behaviour and expected plot Fig1. However, if I vary the FA the behaviour seems to be unexpected. Specially, when considering up and down oscilations for the Intensity of the signal. Fig2 (FA=170) or Fig3 (FA=30)

Could you please let me know what am I doing wrong, and how can I overcome this issue?

Best
Tiago

Fig1. FA = 180º
FIG1

Fig2. FA = 170º
FIG2

Fig3. FA = 30º
FIG3

arbitrary spacing

Hi, thank you very much for this great code.
From the description I understand that the code is also able to simulate a sequence with arbitrary rf spacing, but I didn't quite understand what you mean with "Arbitrary spacing can be approximated with a small Δt". Do you have any documentation on how to do that?

Thank you!

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.