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

MRI Sequence definitions

The MRzeroCore Sequence is a Python list of Repetitions, each of which is starting with an instantaneous Pulse. To construct sequences, you can

import MRzeroCore as mr0
import numpy as np

seq = mr0.Sequence()

# Iterate over the repetitions
for i in range(64):
    rep = seq.new_rep(2 + 64 + 2)
    
    # Set the pulse
    rep.pulse.usage = mr0.PulseUsage.EXCIT
    rep.pulse.angle = 5 * np.pi/180
    rep.pulse.phase = i**2 * 117*np.pi/180

    # Set encoding
    rep.gradm[:, :] = ...

    # Set timing
    rep.event_time[:] = ...

    # Set ADC
    rep.adc_usage[2:-2] = 1
    rep.adc_phase[2:-2] = np.pi - rep.pulse.phase

Sequence

Defines an MRI sequence. Derived from a Python list.

Sequence(repetitions, normlized_grads=True)
ParameterDescription
repetitionIterable over Repetitions to initialize the list
normalize_gradsIf set, simulation will scale gradients to match the phantom size. Simplifies writing sequences by assuming a FOV of 1.
  • Sequence.cpu(): move sequence data to CPU
  • Sequence.cuda(device=None): move sequence data to selected or default CUDA device
  • Sequence.device (property): the device of the repetition data
  • Sequence.clone(): make a copy of the repetition with cloned
  • Sequence.new_rep(event_count): appends a Repetition.zero(event_count) to the sequence
  • Sequence.get_kspace(): Returns the kspace trajectory of the measured signal as a single tensor (ADC events only, concatenated repetitions)
  • Sequence.get_full_kspace(): Returns the full kspace trajectory as a list of per-repetition tensors (containing all events)
  • Sequence.plot_kspace_trajectory(): Plot the result of get_full_kspace()
  • Sequence.get_contrast_mask(contrast): Returns a bool mask for the selected contrast which can be applied to the simulated signal or kspace
  • Sequence.get_contrasts(): Returns a list of all used contrast IDs (apply for all repetitions)
  • Sequence.shift_contrasts(offset): Shift all contrast IDs by offset (apply for all repetitions)
  • get_duration(): Return the total duration of the sequence in seconds

Sequences can be imported from Pulseq .seq files or Siemens .dsv files:

Sequence.import_file(file_name, exact_trajectories, print_stats, default_shim, ref_voltage, resolution)
ParameterDescription
file_namePath to .seq file or .dsv folder + file stem
exact_trajectoriesIf true generates more events for accurate diffusion calculation
print_statsPrint more information during import
default_shimshim_array for pulses that don’t specify it themselves
ref_voltage.dsv only: used to convert volts to RF amplitudes
resolution.dsv only: defines samples per ADC block. If not set, this is determined by the .dsv time step + ADC duration.

chain

Helper function to combine multiple sequences into a multi-contrast sequence.

chain(*sequences, oneshot=False)

Returns a new sequence object. If oneshot is set to:

  • True, sequences are simply concatenated.
  • False, the adc_usages are shifted so that every sub-sequence has their own set of IDs.

Repetition

Part of a Sequence, containing an RF pulse and a list of event_count events.

Repetition(pulse: Pulse, event_time, gradm, adc_phase, adc_usage)
ParameterDescription
pulseThe pulse at the start of the repetition
event_timeShape [event_time]: Durations in seconds
gradmShape [event_time, 3]: Gradient moments in 1/m
adc_phaseShape [event_time]: ADC phases in radians
adc_usageShape [event_time]: 0/1 = ADC off/on, other values can be used to distinguish images in multi-contrast sequences
  • Repetition.event_count (property): number of events in this repetition
  • Repetition.cpu(): move repetition data to CPU
  • Repetition.cuda(device=None): move repetition data to selected or default CUDA device
  • Repetition.device (property): the device of the repetition data
  • Repetition.zero(event_count): create a zero’d repetition with the given number of events
  • Repetition.clone(): make a copy of the repetition with cloned
  • Repetition.get_contrasts(): return a list of all used adc_usage values (except zero)
  • Repetition.shift_contrasts(offset): add offset to all adc_usage values (except zero)

Pulse

Contains the definition of an instantaneous RF Pulse.

Pulse(usage: PulseUsage, angle, phase, shim_array, selective)
ParameterDescription
usagePulseUsage - not used in simulation
angle, phaseValues in radians
shim_arrayChannel amplitudes and phases for pTx - use [[1, 0]] for 1Tx
selectiveUsed by legacy exporters to emit slice-selective pulses
  • Pulse.cpu(): move pulse data to CPU
  • Pulse.cuda(device=None): move pulse data to selected or default CUDA device
  • Pulse.device (property): the device of the pulse data
  • Pulse.zero(): alternative constructor which zero-initializes everything
  • Pulse.clone(): make a copy of the pulse with cloned

PulseUsage

Used for computing the k-space trajectory or to select the pulse type in legacy exporters.

AttributeValueDescription
UNDEF"undefined"No specified use case.
EXCIT"excitation"Will set the kspace position back to zero or the position stored by the last STORE pulse.
REFOC"refocussing"Mirrors the kspace position.
STORE"storing"Stores the current kspace position. Can be used for DREAM-like sequences.
FATSAT"fatsaturation"Not handled differently by get_kspace(), but can be used by Pulseq exporters to emit a fat-saturation pulse.