Sequence#

class pypulseqpp.Sequence[source]#

A Pulseq sequence containing events, blocks and definitions.

Parameters:
  • system (Opts, default=None) – System limits and rasters. Defaults to the shared system; rasters are recorded in the native sequence.

  • use_block_cache (bool, default=True) – Compatibility flag, retained but not used to cache decoded blocks.

Attributes:
  • system (Opts | None, default=None) – The limits the sequence was constructed with.

  • num_blocks (int) – Number of blocks; equivalent to len(seq).

  • block_durations (MutableMapping[int, float]) – Duration of each block in seconds, keyed by 1-based block index. Assigning an entry changes the stored block duration.

  • block_events (dict[int, NDArray[np.int32]]) – Event IDs of each block, keyed by 1-based block index: delay, RF, gx, gy, gz, ADC and extension. The delay column is zero for Pulseq 1.5. Reading it allocates a dictionary for all blocks.

  • definitions (dict[str, Any]) – The definitions written to the [DEFINITIONS] section.

  • grad_raster_time (float) – Gradient raster in seconds.

  • rf_raster_time (float) – RF raster in seconds.

  • adc_raster_time (float) – ADC dwell raster in seconds.

  • block_duration_raster (float) – Block duration raster in seconds; every block duration is a whole number of these.

  • version_major (int) – Major version of the Pulseq format the sequence is held as. A file older than 1.5 is converted as it is read, so this is the format of the sequence in memory, not the version its file declared.

  • version_minor (int) – Minor version of the format the sequence is held as.

  • version_revision (int) – Revision of the format the sequence is held as.

  • signature_type (str | None) – Hash algorithm of the signature carried by the last file written, or by the last binary file read: 'md5', or None when it had none.

  • signature_file (str | None) – Format that file was written in, 'text' or 'bin'.

  • signature_value (str | None) – The signature itself.

Examples

>>> import pypulseqpp as pp
>>> seq = pp.Sequence(pp.Opts())
>>> seq.add_block(pp.make_trapezoid("x", area=1000, duration=2e-3))
1
>>> seq.add_block(pp.make_delay(1e-3))
2
>>> seq.num_blocks, round(seq.duration()[0], 6)
(2, 0.003)

Blocks#

add_block

Append one block playing events.

set_block

Write events over the block at index, 1-based.

get_block

Decode a block by its 1-based index.

find_block_by_time

Return the 1-based index of the block containing time t in seconds.

remove_duplicates

Merge identical library rows and renumber the references to them.

Definitions and labels#

set_definition

Record key in [DEFINITIONS].

get_definition

Return the value recorded for key, or '' when it is not defined.

copy_definitions

Copy every definition from other_seq into this sequence.

evaluate_labels

Evaluate running label values in block order.

add_trid

Append a block setting TRID to the number assigned to label_name.

get_or_create_trid_id

Return the TRID number assigned to label_name, assigning one if new.

Soft delays#

apply_soft_delay

Set each named soft delay to the value given.

get_default_soft_delay_values

Return each soft delay's default value.

Reading and writing#

read

Replace this sequence with the one in file_path.

write

Write Pulseq text and record its signature metadata.

write_binary

Write Pulseq binary, with float32 shape samples.

write_v141

Write Pulseq 1.4.1 text, for an interpreter predating Pulseq 1.5.

libraries

Return the block table and every library, as a Pulseq file of the sequence holds them.

Waveforms and k-space#

waveforms

Return gradient corners as time (s) over amplitude (Hz/m), per axis.

waveforms_and_times

Return the gradient waveforms, the RF pulse timing and the ADC sampling.

get_gradients

Return physical-axis gradient splines in Hz/m over seconds.

calculate_kspace

Integrate physical-axis gradients with excitation resets and refocusing.

adc_kspace

Return the k-space location of each ADC sample, in 1/m.

adc_times

Return ADC sample times (s) and per-window frequency (Hz) and phase (rad).

rf_times

Return RF pulse centre times with their frequency and phase offsets.

duration

Return total duration, block count and per-event block counts.

Checks and reports#

check_timing

Check timing, gradient continuity and the stored total duration.

test_report

Return sequence timing, encoding and gradient statistics, formatted as text.

test_report_dict

Return timing, encoding and gradient statistics.

calc_rf_power

Return the RF's mean power, peak power, RMS amplitude and energy.

rf_flip_angles

Return the flip angle of each RF event of the library, in degrees.

rf_channels

Return the transmit channels each RF event of the library holds.

Gradient edits#

flip_grad_axis

Negate the amplitude of every gradient on axis.

mod_grad_axis

Scale the amplitude of every gradient on axis by modifier.

Plotting#

plot

Open the sequence in the SeqEyes viewer.

paper_plot

Draw a publication-style diagram of one repetition, using mrsd.