Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

util module

Additional helper functions.

import MRzeroCore as mr0
mr0.util.<function>()

get_signal_from_real_system

Wait for scanner TWIX files on the given path, and return if ready. Useful if a shared network folder between scanner and research PC is available.

Note

This is developed for internal use and might not be useful for others.

ParameterDescription
pathpath to TWIX file
NRepnumber of repetitions
NReadnumber of ADC samples per repetition
ncoilsnumber of recieve channels
heuristic_shiftneeded to remove garbage data from the file

insert_signal_plot

Insert a measured signal into a currently open pypulseq plot. This is only supported by newer pulseq versions, which do not show (and close) the figure immediately if plot_now=False.

seq.plot(plot_now=False)  # option doesn't exist for older pulseq versions
mr0.util.insert_signal_plot(seq, signal)
plt.show()
ParameterDescription
seqpulseq sequence, needed to align the signal with the ADC samples
signalsignal to insert into the ADC plot

pulseq_plot

Wrapper around insert_signal_plot, pulseq_plot_142 and pulseq_plot_pre14 which selects the appropriate plotting function based on the installed pulseq version.

ParameterDescription
seqsequence object
typeignored
time_rangesame as for pulseq plot()
time_dispsame as for pulseq plot()
show_blockssame as for pulseq plot()
clearignored
signalinsert simulated signal into the ADC plot
figidignored

pulseq_plot_142

Use only with pypulseq versions 1.4.x / tested with 1.4.2

Identical to pulseq plot(), but returns the generated axes! This is needed to insert the signal into the ADC plot. Modified from pypulseq 1.4.2 sequence.py - plot() - see pulseq documentation for details.

ParameterDescription
seqsequence object
labelsame as for pulseq plot()
show_blockssame as for pulseq plot()
savesame as for pulseq plot()
time_rangesame as for pulseq plot()
time_dispsame as for pulseq plot()
grad_dispsame as for pulseq plot()
plot_nowsame as for pulseq plot()

pulseq_plot_pre14

Use only with pypulseq versions before 1.4

Pulseq sequence plot with some aesthetical changes. Most important, it can insert the simulated signal into the ADC plot. Modified from pypulseq 1.2.0post1 sequence.py - plot() - see pulseq documentation for details.

ParameterDescription
seqsequence object
typesame as for pulseq plot()
time_rangesame as for pulseq plot()
time_dispsame as for pulseq plot()
clearclear matplotlib figures before plotting
signalinsert simulated signal into the ADC plot
figiduse specific figure IDs (to reuse previously created figures)

imshow

Modified version of matplotlib imshow(), tailored for showing MR reconstructions. reco is expected to be an array with dimensions [x, y], [x, y, z] or [coil, x, y, z]

  • plots images in RAS+
    • x is left-to-right
    • y is bottom-to-top
  • plots 3d data (z) as a side-by-side grid of its slices
  • applies quadratic coil-combination for multi-coil data
# Replace
import matplotlib.pyplot as plt
plt.imshow(reco, *args, **kwargs)

# with
import MRzeroCore as mr0
mr0.util.imshow(reco, *args, **kwargs)

load_phantom

Download a phantom from the MR-zero repository (or a custom URL) for getting started quickly.

DEFAULT_PHANTOM_URL = "https://github.com/MRsources/MRzero-Core/raw/main/documentation/playground_mr0/numerical_brain_cropped.mat"
ParameterDescription
sizescale phantom if desired
urlwhere to load the phantom from, defaults to DEFAULT_PHANTOM_URL
dB0_fB0(offset, scaling) floats to modify the \(B_0\) map
dB1_fB1(offset, scaling) floats to modify the \(B_1\) map
B0_polynomialoptional 2d, 2nd degree polinomial to modify the \(B_0\) map

simulate

Helper function to simulate using PDG.

ParameterDescription
seqMR-zero sequence, pulseq sequence or file name
phantomVoxelGridPhantom, CustomVoxelPhantom or .npz / .mat file name
sim_sizescales phantom if set
accuracysets both min_emitted_signal and min_latent_signal for the PDG sim
noise_leveladd normal distributed noise with the given std to the signal

simulate_2d

Caution

Deprecated - use load_phantom + simulate instead. For parameter descriptions, look at these functions.