Scanner sequences#
A scanner sequence is a plugin file, <name>.py in a --plugins directory,
defining one SequencePlugin subclass that binds a
sequence function to the scanner protocol:
# sequences/gre.py
from pypulseqpp.sequences.sequence.gre2D_sequence import gre2d
from pulserver.design import SequencePlugin
class Gre(SequencePlugin):
app = gre2d
The interpreter names it --plugin gre. Without protocol, the protocol is
the sequence function’s defaults. A PyPulseq script becomes a sequence function
by taking the scanner limits and its parameters as arguments and returning its
sequence
(from a PyPulseq script).
Protocol entries#
protocol maps the parameters of the interpreter’s table, the members of
ProtocolKey, to entries;
UIParam collects those of the UI controls. A plain
string naming a parameter is stored as its member, and a name outside the
table is refused when the class is defined. Each entry names the keyword
argument of the sequence function it sets.
>>> from pypulseqpp.sequences.sequence.gre2D_sequence import gre2d
>>> from pulserver.design import (FloatParam, IntParam, SequencePlugin, TEPreset,
... TimeParam, TRPreset, UIParam)
>>> class Gre2D(SequencePlugin):
... app = gre2d
... protocol = {
... UIParam.TE: TimeParam("te", range_min=1000, range_max=80000, range_incr=10,
... presets={TEPreset.MINIMUM: None}),
... UIParam.TR: TimeParam("tr", range_min=1000, range_max=5_000_000,
... presets={TRPreset.MINIMUM: None}),
... UIParam.FOV: FloatParam("fov_x", unit="mm", scale=1e-3,
... range_min=50.0, range_max=500.0),
... UIParam.NX: IntParam("n_x", range_min=32, range_max=512, range_incr=2),
... }
Entry |
UI |
Argument |
|---|---|---|
integer µs, with presets |
s |
|
the argument divided by |
as the sequence function takes it |
|
integer |
integer |
|
checkbox |
boolean |
|
dropdown |
the chosen member of a |
|
not shown |
none; a value declared to the interpreter |
|
read-only text |
none |
|
integer, the index of the option’s choice (Options) |
none; |
The options of the four string-list parameters are
SequenceType,
ImagingMode,
PreparationType and
TriggerType, which
ChoiceParam takes as its choices:
ChoiceParam("mode", ImagingMode). The argument receives the member, a str
equal to the option.
A preset is a negative value the interpreter sends in place of a time.
{TEPreset.MINIMUM: None} passes None, for which the sequence function
designs its shortest echo time. An entry’s default replaces the sequence
function’s default as the initial value, in UI units: default=TEPreset.MINIMUM
offers an initial protocol that a scanner with weaker gradients than the
function’s default assumes can play.
The class names no reconstruction: the reconstruction client, or the scan on a
console, names it (Reconstruction plugins). A recon or follows
attribute has no effect and raises a DeprecationWarning, as do ui and
ScannerSequence, the deprecated names of protocol and SequencePlugin, and
StringListParam().
Sequence functions#
A sequence function takes the scanner limits, a pypulseqpp.Opts, and
one keyword argument for each entry of protocol, and returns the designed
pypulseqpp.Sequence. A list of sequences is a chain, the prescans
first and the main sequence last; each file names the next as its
NextSequence definition. The initial value of an entry is the default of its
argument in the signature, so a functools.partial() is a sequence function
too. The default evaluation does not call the function;
generate() calls it when the design is
generated (Protocol evaluation).
>>> import numpy as np
>>> import pypulseqpp as pp
>>> def pulse_acquire(system, flip=90.0, tr=100e-3, averages=8):
... seq = pp.Sequence(system)
... rf = pp.make_block_pulse(np.deg2rad(flip), duration=1e-3, system=system)
... adc = pp.make_adc(256, duration=10e-3, system=system)
... for _ in range(averages):
... seq.add_block(rf)
... seq.add_block(adc)
... seq.add_block(pp.make_delay(tr - 11e-3))
... return seq
>>> class PulseAcquire(SequencePlugin):
... app = pulse_acquire
... protocol = {
... UIParam.FLIP: FloatParam("flip", unit="deg", range_min=1.0, range_max=180.0),
... UIParam.TR: TimeParam("tr", range_min=20000, range_max=5_000_000),
... UIParam.NEX: IntParam("averages", range_min=1, range_max=64),
... }
>>> listing = PulseAcquire().listing()
>>> {key.value: listing[key].value for key in PulseAcquire.protocol}
{'flip': 90.0, 'TR': 100000, 'nex': 8}
Protocol resolution#
listing() is the protocol with its
schema, as the list design call replies it:
>>> from pulserver.protocol import format_listing
>>> print(format_listing(Gre2D().listing()), end="")
[Protocol]
TE: int|dropdown|8000|1000|80000|10|us|-2
TR: int|dropdown|250000|1000|5000000|1|us|-1
fov: float|typein|220.0|50.0|500.0|1.0|mm
nx: int|typein|128|32|512|2|
nex: float|typein|1.0|1.0|16.0|1.0|
fov_offset_x: float|off|0.0|-1000.0|1000.0|0.1|mm
fov_offset_y: float|off|0.0|-1000.0|1000.0|0.1|mm
fov_offset_z: float|off|0.0|-1000.0|1000.0|0.1|mm
fov_rotation_11: float|off|1.0|-1.0|1.0|1e-06|
fov_rotation_12: float|off|0.0|-1.0|1.0|1e-06|
fov_rotation_13: float|off|0.0|-1.0|1.0|1e-06|
fov_rotation_21: float|off|0.0|-1.0|1.0|1e-06|
fov_rotation_22: float|off|1.0|-1.0|1.0|1e-06|
fov_rotation_23: float|off|0.0|-1.0|1.0|1e-06|
fov_rotation_31: float|off|0.0|-1.0|1.0|1e-06|
fov_rotation_32: float|off|0.0|-1.0|1.0|1e-06|
fov_rotation_33: float|off|1.0|-1.0|1.0|1e-06|
[Protocol End]
The last twelve entries are the prescription, which the interpreter fills from the scanner’s: the field-of-view offset, applied when the IR is built, and the rotation from the logical to the physical axes, in whose frame the design is checked (Protocol resolution). A plugin cannot bind them.
nex is the number of signal averages, listed by every plugin that does not
declare its own (AveragesParam). The design plays
its main sequence that many times, written into the block table once the
sequence is designed, each repetition past the first numbered by AVG, and the
scan time counts each. A plugin that binds nex to an argument of its sequence
function, as PulseAcquire above does, plays its averages itself.
validate() evaluates a request under the
scanner limits and returns the protocol the design plays. Entries the request
omits keep their initial values. The default evaluation accepts the protocol
unchanged, so the reply repeats the request, a preset included, and states no
scan time:
>>> system = pp.Opts(max_grad=40, grad_unit="mT/m", max_slew=150, slew_unit="T/m/s")
>>> reply = Gre2D().validate(system, {"TE": TEPreset.MINIMUM, "nx": 96})
>>> reply.valid, reply.duration, reply.info
(True, None, '')
>>> reply.values["TE"] is TEPreset.MINIMUM, reply.values["nx"]
(True, 96)
An evaluation that designs the sequence states the values the design achieved.
The TE and TR definitions of a pypulseqpp sequence record its echo time and
repetition time, and pypulseqpp.sequences.duration() sums the durations
of the sequences of a chain:
>>> from pypulseqpp import sequences
>>> from pulserver.design import Evaluation
>>> class Resolved(Gre2D):
... def evaluate(self, system, protocol):
... seq = self.app(system, **protocol.arguments)
... achieved = {UIParam.TE: seq.definitions["TE"][0],
... UIParam.TR: seq.definitions["TR"][0]}
... return Evaluation(protocol.replace(achieved), sequences.duration(seq))
>>> reply = Resolved().validate(system, {"TE": TEPreset.MINIMUM, "nx": 96})
>>> reply.valid, round(reply.duration, 3), reply.info
(True, 38.25, '')
>>> {name: reply.values[name] for name in ("TE", "TR", "fov", "nx")}
{'TE': 3080, 'TR': 250000, 'fov': 220.0, 'nx': 96}
The resolved TE is the shortest echo time of the design in place of the
preset. Values are rounded to the precision a scanner parameter stores, so a
resolved protocol sent back resolves to itself. A protocol the evaluation
rejects is invalid, and the message of the error it raised is the reply’s
info:
>>> reply = Resolved().validate(system, {"TE": 1000})
>>> reply.valid, reply.info
(False, 'the requested TE of 1.000 ms is shorter than the 3.400 ms this readout can achieve')
duration is the scan time in seconds. An evaluation that states a duration of
0.0 states no estimate: the protocol is valid, duration is None, and the
reply reports the scan time as unknown.
design() generates the design and writes
it as signed binary Pulseq, prescans first, and returns the written paths. The
first file is sequence.seq, and each file names the next as its
NextSequence definition. The generate design call then converts the design
to the IR cache and stores it (Architecture).
Protocol evaluation#
A plugin overrides evaluate() to check a
protocol and to state what the console shows with it. The hook takes the
scanner limits and the requested Protocol, in the
units of the sequence function’s arguments, and returns an
Evaluation: the protocol holding the values the
design achieves, the scan time in seconds, a note shown with the valid protocol
and, optionally, the RF layout (RF layout) and the figures a
console displays: the echo spacing of a train, the bandwidth of a pixel of an
oversampled readout and the time one frame of a scan of several takes
(Display figures). Returning None
accepts the protocol unchanged. Raising an exception makes the protocol
invalid:
>>> class Timed(PulseAcquire):
... def evaluate(self, system, protocol):
... if protocol[UIParam.TR] < 12e-3:
... raise ValueError("the TR is shorter than the pulse and the readout")
... scan_time = protocol[UIParam.NEX] * protocol[UIParam.TR]
... return Evaluation(protocol, scan_time, "256 samples per average")
>>> reply = Timed().validate(system, {"TR": 50000, "nex": 4})
>>> reply.valid, reply.duration, reply.info
(True, 0.2, '256 samples per average')
>>> reply = Timed().validate(system, {"TR": 10000})
>>> reply.valid, reply.info
(False, 'the TR is shorter than the pulse and the readout')
The default evaluation does not call the sequence function, so a protocol the
function cannot realize is found only when the sequence is generated, as an
error of that call, and not while the operator edits the protocol. An
evaluate that builds or checks the design rejects such a protocol when it is
evaluated.
The console waits for every evaluation, so evaluate is a simplified design
and not the design: it states the scan time exactly, an upper bound of the RF
and one repetition whose gradients stand for the scan’s, and leaves to
generate whatever takes a solve, an optimization or the whole scan. Where
the angles of a train are solved for, the train at their largest angle lasts
as long and bounds its RF; fse3d and fse_pd3d design that train, and ask
the solve only for the effective TE and for whether a train exists, once per
train under a warm design server.
ValueError and AssertionError, which pypulseqpp and PyPulseq raise for an
event or a timing they cannot realize, reject the protocol with the message of
the error as info, and are logged as a warning. Any other exception also
makes the protocol invalid, but the reply names only its type, as in
TypeError in Timed.evaluate, and the exception is logged as an error with its
traceback. A request that names an entry the protocol does not declare, or an
option a choice does not offer, is invalid in the same way.
An evaluation that designs the sequence, or a few repetitions of it, states that
design as its representative sequence: the repetitions whose gradients are
the largest of the scan, such as the views at the edges of k-space, so that
what is read on them bounds what the scan plays. The design service checks peripheral
nerve stimulation and slew rate on it, rotated to the prescription, and
evaluates the protocol again at a lower slew rate while it exceeds them, as
generate does with the whole design (Scanner limits); without one,
the console shows the protocol at the design limits and only generate lowers
the slew rate. A plugin that sets
strict_limits is never designed again:
its files set StrictLimits, and a design past a limit is refused.
generate() builds the sequence of a
requested protocol. The default calls the sequence function with the arguments
of the protocol; a plugin overrides it to return a sequence, or a list of them,
built another way. validate and design are not overridden: they are the
boundary between a request and the code of a plugin, and design writes
nothing for an invalid request.
Exam cache#
An evaluate or generate that declares an exam argument receives the
directory of the current exam’s cache, which the design calls take as
--exam, and reads what the exam’s reconstructions stored there, such as
b0_map, b1_map or coil_sensitivities, with
load_exam(). Without an exam the argument is not
passed:
from pulserver.design import Evaluation, SequencePlugin, load_exam
class Shimmed(SequencePlugin):
app = pulse_acquire
def evaluate(self, system, protocol, exam=None):
if exam is None:
return Evaluation(protocol, 0.0, "no B0 map")
b0_map = load_exam(exam)["b0_map"]
return Evaluation(protocol, 0.0, f"B0 map {tuple(b0_map.shape)}")
A key no reconstruction stored raises KeyError. The values are those of the
series that measured them, on their own grid. For such a plugin the files of
the exam’s cache are part of the design’s identity, so a new map yields a new
design.
RF layout#
An evaluation may state the RF its protocol plays, from which a scanner
estimates the RF of a prescription before the design is generated. The layout
is one TR: the RF instances that TR plays, with the TR as its period.
RfLayout.of takes the RF instances of a
sequence that is one TR, as pypulseqpp.Sequence.rf_instances() returns
them, and the control each instance’s amplitude follows: the flip angle,
UIParam.FLIP, or a float user entry, UIParam.user_value(n), either declared
in protocol. One control applies to every instance; a list gives one per
instance in play order, None for an instance no entry scales. The scanner
multiplies the amplitude of an instance by the ratio of the value of its
control in the protocol it plays to the value in the evaluated protocol. The
period is the TR in seconds, and the duration of the sequence where omitted:
>>> from pulserver.design import RfLayout
>>> from pulserver.protocol import format_rf_layout
>>> class Costed(PulseAcquire):
... def evaluate(self, system, protocol):
... one_tr = pulse_acquire(system, **(protocol.arguments | {"averages": 1}))
... layout = RfLayout.of(one_tr, UIParam.FLIP)
... scan_time = protocol[UIParam.NEX] * protocol[UIParam.TR]
... return Evaluation(protocol, scan_time, rf_layout=layout)
>>> reply = Costed().validate(system, {"nex": 4})
>>> print(format_rf_layout(reply.rf_layout), end="")
[RfLayout]
period 0.1
run 0 1 flip 1
[RfLayout End]
A sequence shorter than the TR, such as one TR without its closing delay, is
stated with the TR: RfLayout.of(seq, UIParam.FLIP, period=tr).
The layout is optional. An evaluation that states none is valid and states no
estimate; one whose control is not an entry of protocol, or has no positive
value in the evaluated protocol, is invalid. What the scanner checks before the
scan is the stored design, not the layout. The blocks that carry the layout are
described in Protocol resolution.
RF phase convention#
Phases and frequencies keep Pulseq’s units: an RF phase shape holds cycles, RF and ADC phase offsets and RF shim phases are in radians, and frequency offsets are in hertz. The ppm offsets are resolved to hertz and radians at the scanner’s Larmor frequency when the IR is built.
An RF waveform \(b_c(t)\) and an RF shim weight \(w_c\) are the complex drive of transmit channel \(c\), the envelope of a carrier \(e^{+i\omega_0 t}\). Protons precess clockwise about the static field, and the part of the field that turns them is the conjugate of the drive times the channel’s transmit sensitivity \(s^+_c\), the rotating field of a unit drive:
A drive of phase \(+\phi\), on one channel through its shim weight or its waveform, or on every channel through the pulse’s phase offset, turns the excited magnetization and the reconstructed image by \(-\phi\); an ADC phase offset of \(+\theta\) turns them by \(+\theta\), so a receiver that follows the pulse’s phase offset cancels it. A pulse of phase zero tips \(+z\) towards \(+y\). On the scanner, a channel driven at \(+\phi\) relative to another appears at \(-\phi\) in the reconstructed images, for RF shims and per-channel waveforms alike. The virtual scanner follows the same convention, and the VOP check takes the drives as they are written: the SAR of a pulse is \(v^H Q\, v\) for \(v_c = d\, w_c\, b_c(t)\), with \(d\) the drive per hertz of RF amplitude.
A per-channel image of a small-angle excitation has the phase of \(s^+_c\) plus the receive phase and a constant. A shim fitted to such maps under the model \(\sum_c w_c\, s^+_c\) is written as \(\overline{w_c}\).
Shipped sequences#
pulserver ships a plugin for each of these pypulseqpp sequences, searched after
every --plugins directory, so a file of the same name there replaces it:
Plugin |
Paired reconstruction |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The paired reconstruction is the one a console uses for a shipped sequence when the scan names none (Virtual scanner); a scan can name another, and a scanner’s reconstruction client names one in its config (Reconstruction client).
Console controls#
The excitation, the fat saturation, the multiband factor and the explicit saturation bands are the console’s own controls:
Plugin |
Entry |
Choice |
|---|---|---|
3D Cartesian, stack and MPRAGE plugins |
|
|
|
|
Fat saturation before every shot; on by default |
|
|
Simultaneous multislice factor; 1 plays one slice per excitation |
|
|
The explicit saturation bands placed, bit |
The saturation bands of gre2d and se2d are placed graphically, as a
scanner’s console places an explicit band, and each is played before every
excitation while it is placed; a plugin offers as many bands as its module
constant BANDS, 6, and refuses a mask placing more.
exsat<n>_normal_x, _y and _z, exsat<n>_loc and exsat<n>_thickness
give each band’s normal along the physical axes, the distance of its centre
from the isocentre along that normal, and its thickness, in mm. The
field-of-view offset and rotation leave a band where it was placed.
Options#
Choices that set what a sequence is, rather than a value an operator tunes from
scan to scan, are options: module constants a plugin declares with
option() at module level, before its class, so that
they shape its sequence function and the protocol it declares. Each option is a
user entry: the plugin lists it in user<n>_value as the index of its value
among its choices, 0 or 1 for a flag, and names it and the code of each choice
in user<n>_name. A design call loads the plugin at the options its request
holds in those entries, and list at those of the value block it is given, so
a protocol carries its options as it carries every other entry. A console lists
the plugin again when an option entry changes. An option shows or hides user
entries; it never gives one another meaning.
from pulserver.design import Description, FloatParam, SequencePlugin, UIParam, option
VARIABLE_DENSITY = option("variable_density", False, user=42, label="Variable density")
class Spiral(SequencePlugin):
app = spiral
protocol = {...}
if VARIABLE_DENSITY:
protocol |= {
UIParam.user_name(12): Description("Periphery undersampling"),
UIParam.user_value(12): FloatParam("undersampling", range_min=1.0),
}
An option that is not a flag names its choices, at most five. A request whose option entry holds no index of a choice is refused, and so is one stating an entry its options hide. The options join the design’s identity and its manifest.
The shipped plugins declare their shared options at user36 to user44, each
at the same user entry in every plugin. An option one plugin alone has takes
one of its own entries, from user12; user45 reaches no console entry on a
GE scanner:
Plugin |
Option |
User entry |
Choices |
Entries added |
|---|---|---|---|---|
|
|
|
|
Flip angle: the refocusing angle at TE for direct-angle designs, first/final maximum for Busse. Both dual-region options add |
|
PD controls |
|
First/final angles, startup count, explicit centre echo, crusher cycles, signal-tail onset fraction |
|
|
|
|
Off: shared train; on: centre/periphery controls with cubic transition |
|
|
|
|
Off: prescribed inverse-EPG train; on: CPU multi-tissue/B1 control fitting |
Requires the design extra |
|
|
|
Off: the signal-shape PD design; on: the target-signal design, inverse EPG of the signal of Buonincontri et al. with every angle at most |
|
|
|
|
|
None |
|
|
|
|
None |
|
Busse controls |
|
Minimum angle, centre angle, startup count, acquired centre echo ( |
Busse modes only; |
|
Crusher cycles |
|
Read-axis crusher area in cycles across one readout voxel, default 0.5 |
Every refocusing mode |
|
|
|
Three-plane navigators; the design sets |
None |
|
|
|
Wave-CAIPI; the calibration region is acquired first without the wave, and |
|
|
|
|
Only the phase encodes inside the ky-kz ellipse; on by default |
None |
|
|
|
Monopolar echoes, on by default; off reads even echoes reversed |
None |
|
|
|
|
None |
|
|
|
|
None |
|
|
|
Spokes ordered |
None |
|
|
|
|
None |
|
|
|
ECG gating: off, prospective, each slice triggered once and every heartbeat of the heart rate entered acquired once per cardiac phase; on, retrospective, each segment cycled over a heartbeat and binned into cardiac phases by the reconstruction |
None |
|
|
|
Variable-density spirals |
|
Every 3D FSE train is packed: the read prephaser shares the excitation block
and each echo’s rewinders end in the next refocusing pulse’s dead time, so the
train plays as one segment. Where the excitation and prephaser take more than
half an echo spacing, the first interval alone is longer, and in constant
and optimized modes its refocusing pulse is 180°. A TR or peripheral TR
shorter than the longest train is refused at evaluation as at generation.
The console’s RF estimate is the train of the largest RF power, each train
playing its own number of refocusing pulses in its own TR, the first as
designed and the rest at the train’s peak angle, which for a Busse or PD
train is the maximum angle prescribed, every pulse of the estimate playing
it; the designed sequence is costed at predownload. fse3d and fse_pd3d ask to be costed under the SAR
burst limits.
Busse modes play startup pulses without acquisition and use the same RF widths
and echo spacing in every shot. All shots retain the longest train layout,
with zero RF amplitude after each shot’s own ETL. TR, acquired ETL and angle
controls may vary;
intermediate controls follow the cubic transition between two independent
endpoint fits. In Busse modes, the TE control prescribes contrast-equivalent
TE, using relaxed and relaxation-free CPMG EPG with reference T1/T2 of
1000/100 ms. The nearest feasible centre echo is selected while retaining
its prescribed centre angle. The default uses the midpoint; an explicit
user17 echo index takes precedence. The optimizer preserves the selected
reference effective TE within 0.1 ms. The achieved value is recorded in
EffectiveEchoTime and reported to the UI and MRD header; TE remains the
physical excitation-to-centre-echo time. This reference contrast annotation
does not model all tissues, B1 variation or inter-shot steady state. The selected echo must precede the last acquired echo in every
train. busse_radial requires centre echo 0 and identical trains: the
evaluation refuses a TE other than Minimum for a constant or optimized train,
and a centre acquired echo other than 0 for a Busse or PD train, so the
console refuses such a prescription before it is downloaded. pclo
uses Rydén’s pivot-centre, linear-outer ring permutation for an arbitrary
centre echo in identical trains, except that a centre echo in the second half
of the train is not mirrored: the echoes after it take the outer rings in
order, so a train whose signal is flat up to the centre echo and decays
after it, as a Busse train’s is, weights k-space flat and then decreasing
outwards. radial selects PCLO for identical trains
or Buonincontri joint shot/echo assignment for a centre/periphery parameter
transition. The menu retains the same choice indices across refocusing modes.
Sampling acceleration and the CAIPI shift are independent of this ordering
choice. The PSF objective is an idealized design
model, not a measurement of the scanner reconstruction.
The fse_pd3d preset designs a PD signal evolution with an initial decrease,
near-constant middle and gently declining quadratic tail, following Mugler’s
prescribed-signal design principle. Relaxation-aware inverse EPG enforces
independent first, maximum and final angles. Minimum/centre angles and RF
peak position are calculated outputs. A final angle equal to the maximum
allows the RF maximum to extend to the final pulse. This is an independent PD design,
not a numerical reconstruction of Siemens PDvar*.
The optional control fit adjusts signal-tail onset, retaining the prescribed first/maximum/final angles, reference effective TE, centre signal and signed contrast constraints. The transition uses two endpoint fits and batched inverse EPG. ESP and RF widths are shared; every shot keeps the longest-train layout with zero RF amplitude after its own acquired ETL. Shared trains use PCLO/basic Busse radial; changing endpoint parameters uses Buonincontri joint assignment. Default inverse design, listing and evaluation import no Torch. First and final angles must not exceed the maximum. The reference signal prescription follows Mugler et al., ISMRM 1999, abstract 1631; numerical envelope controls are independently chosen.
The pd_target option designs instead from an explicit target signal: an
initial exponential decay, a sloped plateau and a power-law tail, its eight
controls fitted to the centre and peripheral trains of Fig. 1 of
Buonincontri et al., Proc. ISMRM 2025, abstract 566-05-007
(PD_CENTRE and PD_PERIPHERY in pypulseqpp). blochsim’s inverse EPG solves
each train for its signal with every angle bounded by flip; a pulse at the
bound holds the bound and the train continues from it. Its derivatives with
respect to the controls are exact, from the forward-mode tangents of the
solver, and the transition interpolates the controls between the two
endpoint trains.
Diffusion tables#
A diffusion sequence plays a table of b-values and directions read from a file,
as a scanner’s own diffusion sequences do: the console names the table by
number in the UIParam.DIFFUSION_TABLE entry, with the largest b-value in
UIParam.DIFFUSION_BVALUES and the number of directions in
UIParam.DIFFUSION_DIRECTIONS; the sequence function turns the number into the
file’s path with module constants a site sets, reads the file and records its
path with pypulseqpp.io.set_diffusion_table(). The proxy reads the same file
again, so the table reaches the reconstruction without being copied into the
sequence (Reconstruction plugins).
import os
import pypulseqpp as pp
from pulserver.design import FloatParam, IntParam, SequencePlugin, UIParam
TENSOR_DIRECTORY = "/data/diffusion"
TENSOR_PREFIX = "tensor"
TENSOR_SUFFIX = ".dat"
def dwi(system, table=1, b_value=1000.0, directions=30):
seq = pp.Sequence(system)
name = f"{TENSOR_PREFIX}{table}{TENSOR_SUFFIX}"
path = os.path.join(TENSOR_DIRECTORY, name)
b, g = pp.io.set_diffusion_table(seq, path, b_value, directions)
for volume, (b_volume, direction) in enumerate(zip(b, g)):
... # one volume, its REP label set to `volume`
return seq
class Dwi(SequencePlugin):
app = dwi
protocol = {
UIParam.DIFFUSION_TABLE: IntParam("table", range_min=1),
UIParam.DIFFUSION_BVALUES: FloatParam("b_value", unit="s/mm²"),
UIParam.DIFFUSION_DIRECTIONS: IntParam("directions", range_min=1),
}
The table is in the frame of the gradient channels, so its directions turn with the prescription.
Protocol conventions#
A 3D sequence takes its number of partitions from the number of slices.
Ryundersamples the phase encode of the Cartesian sequences, the blades ofgre_propeller2d,se_propeller2dand the stacks of blades, and the shells ofzte3d;Rzundersamples the partition encode of the 3D Cartesian ones.The
ETLofse_epi_propeller2dis its blade width.The MPRAGE sequences take their inversion time as
prep_time.
Shipped evaluation#
Each shipped plugin evaluates a protocol from a few repetitions of the scan:
the lines or partitions at the centre and edge of k-space, eight spokes,
interleaves or blade lines, an echo train or an inversion shot of one slice,
without dummy repetitions. Most call the sequence function with the
arguments that reduce it to those repetitions; epi3d and zte3d build one
repetition from the modules their function is built from.
Scan time. The duration of the repetition times the number of repetitions the prescription plays, with the slices that share a TR counted in the packets the sequence plays them in, plus the dummy repetitions: those of
user0, or, at −1, the countpypulseqpp.sequences.steady_state_dummies()gives for that TR and flip angle.Resolved values. Those the main sequence states for the prescription, where the plugin has the entry: the echo time and repetition time in its
TEandTRdefinitions (EffectiveEchoTimetakes precedence where supplied), the receiver bandwidth as the inverse of the dwell time of its first ADC event, and the slice thickness in itsSliceThicknessdefinition. A multi-echo sequence lists every echo time, and theTEentry holds the first.epi2dandepi3dstate in the protocol’s note why the bandwidth differs from the one asked: the sampling interval is a multiple of the ADC raster. EPI adds samples at that interval to cover the gradient-limited acquisition window. Where the receiver’s sample limit prevents that count, the interval increases instead. The displayed pixel bandwidth uses the achieved ADC window duration.Invalid protocols. A prescription the design refuses is invalid, with the message of its error.
Representative sequence. The repetitions on which the design service checks nerve stimulation and slew rate before the scan is designed. A Cartesian sequence designs the views at the centre and at the edge of each phase-encoding axis, a lattice at half the matrix with no calibration region, partial Fourier or CAIPI shift: the largest phase encode of each axis, at one edge of k-space.
mprage3ddesigns them as short shots beside the shot its scan time and RF are read from. A sequence that turns one readout about the slice axis, a spoke, a blade or an interleaf, designs eight of them, evenly spread in angle. The nerve response read on these is the scan’s largest under a nerve model that is the same on every axis, and so are the slew rate and the amplitude on an axis-aligned prescription. The slew rate on a physical axis of an oblique prescription is not bounded: the scan plays the other edge of k-space too, and over random rotations it read up to 11 % more than these views (gre3d,se3d,mprage3d;fse3d8 %), the nerve response never more. The design service holds their readings to 97 % of the limits, which takes up the first 3 %; past that the check of the generated design finds the excess andgeneratelowers the slew rate again. That offse3dandfse_pd3dis the packed echo train their evaluation designs, as long as the longest train, startup echoes included, at a constant refocusing angle: the largest of a Busse or PD train;epi3dstates none.RF layout. The first TR of the repetition, its shot repeated once per slice of the largest packet, with the TR as its period; for the balanced steady state, the TR after the half-angle pulse. The TR of a fast spin echo holds an echo train, that of an MPRAGE an inversion shot, and that of
epi3da volume. The flip angle is the control of every excitation of the plugins with aflipentry, which an MPRAGE’s inversion is not. The spin-echo plugins,fse3damong them, have none, and the amplitude of their excitation and refocusing pulses is that of the design. The calibration ofepi2dandepi3d, FLEET or gradient echo, repeats at its own shortest TR, which the console’s TR does not set, and a scanner costs each sequence of the chain over its own repetition. Where the calibration plays more RF power than a TR, which a slice a long TR apart or a few long 3D shots allow, the layout is its pulses, as many as it plays in a TR, over the TR, with no control: the console then refuses a protocol whose calibration exceeds the RF limits, whatever its TR. The calibration plays the excitation’s waveform atCALIBRATION_FLIP_DEGof the sequence function, 10 degrees, and the fat saturation ofepi2dis numbered after the excitation, so the excitation keeps the number the listing gives it with the fat saturation on or off.
Logging#
A plugin logs with the standard logging module, under a logger of its own
(logging.getLogger(__name__)). Under a warm design server, what a call logs,
prints or warns, and why it refuses a protocol, is appended to the file the
request names under log, or else to the server’s standard error
(Services).
See also#
Protocol resolution: resolution, presets, units and precision.
Scanner sequences: the scanner-sequence interface and its entries.
Sequence definitions: the definitions a design writes and the services read.