mri package¶
Module contents¶
This is a collection of modules specific to MRI. (E.g., reading raw files, simulations, etc.)
Submodules¶
mri.blochsequence module¶
mri.cardiac module¶
Various functions related to cardiac MRI
-
mri.cardiac.
ContrastFrameNumbers
(data)¶ Generates the frame numbers where contrast enters the blood and tissue.
- Parameters
data (array_like) – 3D array (y, x, t) to be analyzed
- Returns
frameNumbers – Tuple of the frame numbers (pdEnd, numPrecontrastBlood, numPrecontrastTissue)
- Return type
tuple (int, int, int)
mri.epg module¶
Framework module providing functions for EPG simulations. This is based heavily on Brian Hargreaves’ EPG functions for Matlab (it is a translation some slight modifications).
Example is provided below:
flipangle = 160./180*np.pi
etl = 70
T1 = 50. # ms
T2 = 300. # ms
esp = 3.5 # ms
angle = 90./180*np.pi
signal = epg.epg_cpmg(flipangle, etl, T1, T2, esp)
print("signal for:")
for ii in range(len(signal)):
print(" echo[%i] = %f" % (ii, abs(signal[ii])))
Where the epg.epg_cpmg (which is provided) is structured as follows
P = np.zeros((3, (2*etl)),dtype=complex) # Allocate all known states, 2 per echo.
P[2,0] = 1. # Initial condition/equilibrium.
Pstore = np.zeros(((4*etl), etl),dtype=complex) # Store F,F* states, with 2 gradients per echo
Zstore = np.zeros(((2*etl), etl),dtype=complex) # Store Z states, with 2 gradients per echo
# -- 90 excitation
P = epg.epg_rf(P, (np.pi/2.), (np.pi/2.)) # Do 90 tip.
s = np.zeros((etl),dtype=complex) # Allocate signal vector to store.
for ech in range(etl):
P = epg.epg_grelax(P, T1, T2, (esp/2.), 1., 0., 1., 1.) # -- Left crusher
P = epg.epg_rf(P, np.abs(flipangle[ech]), np.angle(flipangle[ech])) # -- Refoc. RF
P = epg.epg_grelax(P, T1, T2, (esp/2.), 1., 0., 1., 1.) # -- Right crusher
s[ech] = P[0,0] # Signal is F0 state.
Pstore[2*etl-1:4*etl-1, ech] = P[1,:].T # Put in negative states
Pstore[0:2*etl,ech] = np.flipud(P[0,:].T) # Put in positive, overwrite center.
Zstore[:,ech] = P[2,:].T
return s
where s is the output signal in the F0 state.
-
mri.epg.
epg_FZ2spins
(FpFmZ, N=0, frac=0)¶ Function returns a 3xN array of the magnetization vectors [Mx My Mz]’ that is represented by the EPG state FpFmZ. Note that the magnetization assumes that a “voxel” is divided into N states, as is necessary to make the conversion N must be at least as large as twice the number of F+ states minus one.
- Parameters
FpFmZ (array_like) – F,Z states, 3xQ vector where there are Q states, where rows represent F+, F-, and Z states starting at 0.
N (int) – number of spins used to represent the states. Default is minumum.
frac (float, optional) – fraction of state to increment/decrement so if frac=1, this is equivalent to first passing FpFmZ through epg_grad(). This is mostly just to make plots
- Returns
M – magnetization vector
- Return type
array_like
-
mri.epg.
epg_cpmg
(flipangle, etl, T1, T2, esp)¶ EPG Simulation of CPMG sequence. First flip angle is 90 about y axis, and others by default are about x-axis (make flipangle complex to change that).
Note that if refoc flip angle is constant, less than pi, and etl > 1 the first refocusing flip angle is the average of 90 and the desired refocusing flip angle, as proposed by Hennig.
All states are kept, for demo purposes, though this is not really necessary.
- Parameters
flipangle (float) – the flipangle in radians, can be scalar or vector
etl (int) – the echo train length
T1 (float) – relaxation time
T2 (float) – relaxation time
esp (float) – echo spacing
- Returns
s – signal vector
- Return type
array_like
-
mri.epg.
epg_cpmg_phase
(flipangle, etl, T1, T2, esp, angle)¶ This is essentially the same thing as epg_cpmg but allows the user to add an arbitrary starting phase to the tipdown 90 pulse in order to simulate nCPMG effects.
- Parameters
flipangle (float) – the flipangle in radians, can be scalar or vector
etl (int) – the echo train length
T1 (float) – relaxation time
T2 (float) – relaxation time
esp (float) – echo spacing
angle (float) – angle for initial tipdown
- Returns
s – signal vector
- Return type
array_like
-
mri.epg.
epg_grad
(FpFmZ, noadd=0)¶ Propagate EPG states through a “unit” gradient.
- Parameters
FpFmZ (array_like) – 3xN vector of F+, F- and Z states.
noadd (bool) – True to NOT add any higher-order states - assume that they just go to zero. Be careful - this speeds up simulations, but may compromise accuracy!
- Returns
FpFmZ – updated FpFmZ array
- Return type
array_like
-
mri.epg.
epg_grelax
(FpFmZ, T1, T2, T, kg, D, Gon=1, noadd=0)¶ Propagate EPG states through a period of relaxation, and diffusion over an interval T, with or without a gradient. Leave last 3 blank to exclude diffusion effects.
- Parameters
FpFmZ (array_like) – 3xN vector of F+, F- and Z states.
T1 (float) – Relaxation time (s)
T2 (float) – Relaxation time (s)
T (float) – Relaxation time(s)
kg (float) – k-space traversal due to gradient (rad/m) for diffusion
D (float) – Diffusion coefficient (m^2/s)
Gon (bool) – False if no gradient is on, True if gradient is on
noadd (bool) – True to NOT add any higher-order states - assume that they just go to zero. Be careful - this speeds up simulations, but may compromise accuracy!
- Returns
FpFmZ – updated FpFmZ array
- Return type
array_like
-
mri.epg.
epg_mgrad
(FpFmZ, noadd=False)¶ Propagate EPG states through a NEGATIVE “unit” gradient. (States move the opposite direction to epg_grad!)
- Parameters
FpFmZ (array_like) – 3xN vector of F+, F- and Z states.
noadd (bool) – True to NOT add any higher-order states - assume that they just go to zero. Be careful - this speeds up simulations, but may compromise accuracy!
- Returns
FpFmZ – updated FpFmZ array
- Return type
array_like
-
mri.epg.
epg_relax
(FpFmZ, T1, T2, T)¶ Propagate EPG states through a period of relaxation over an interval T
- Parameters
FpFmZ (array_like) – 3xN vector of F+, F- and Z states.
T1 (float) – Relaxation time (s)
T2 (float) – Relaxation time (s)
T (float) – Relaxation time(s)
- Returns
FpFmZ – updated FpFmZ array
- Return type
array_like
-
mri.epg.
epg_rf
(FpFmZ, alpha, phi=-1.5707963267948966)¶ Propogate EPG states through RF pulse.
- Parameters
FpFmZ (array_like) – 3xN vector of F+, F- and Z states.
alpha (float) – flip angle in radians
phi (float) – phase angle in radians
- Returns
FpFmZ – updated FpFmZ array
- Return type
array_like
mri.rawloadX module¶
Framework for getting filetype-specific metadata.
Instantiate appropriate class with filename. Returned object acts like a dictionary, with key-value pairs for each piece of metadata.
>>>import rawloadX
>>>pFile = rawloadX.geX("PfileName")
>>>data = pFile.rawloadX()
While the naming convention is sort of confusing, this follows the convention from the Hargreaves matlab implementation.
-
class
mri.rawloadX.
geX
(filename=None, verbose=True)¶ Bases:
collections.UserDict
This class initiates the object to return the pfile object. This code should work on most recent GE releases, though it could be easily modified by using this convention.
- Parameters
filename (str) – The pfile to be read
verbose (bool) – Verbose output for the initiation
-
rawloadX
(verbose=True)¶ Loads a pfile to python as a matrix
- Parameters
verbose (str) – displays the pfile header information.
- Returns
data – complex ndarray (coils, slices, echoes, phase, freq) of the data
- Return type
array_like
mri.study module¶
-
class
mri.study.
GetStudy
(studyNumber=None)¶ Bases:
object
This class initiates an object that will read in the study information file and returns the appropriate data in a clean fashion.
- Parameters
studyNumber (str (optional)) – The number of the study in the DiBella format (“P—–”). If nothing is passed then it will list the 2D and 3D file numbers.
-
FrameNumbers
()¶ Returns the proton density images, precontrast blood, and precontrast tissue.
- Returns
numProton (int) – Number of proton density images
numPrecontrastBlood (int) – Number of images (not including proton density) before blood contrast
numPrecontrastTissue (int) – Number of images (not including proton desnity) before tissue contrast
-
RawData
()¶ Returns the raw data in python form.
- Returns
dataRaw – The data pre-registration
- Return type
array_like
-
RegisteredData
()¶ Returns the registered data in python form.
- Returns
dataReg – The data after registration
- Return type
array_like
-
TimePoints
()¶ Returns the time points for the acquisition.
- Returns
timePoints – The time points in a 1D array
- Return type
array_like