Sequence.expand_repeats

Sequence.expand_repeats#

Sequence.expand_repeats()[source]#

Repeat the scan in place by extending the block table.

A block whose ONCE label is 1 plays in the first repetition only, 2 in the last only, and 0 in every one. ONCE is sticky and is read per block, a block’s LABELSET statements before its LABELINC ones. Each repetition starts with every counter at zero except label, which numbers the repetitions: the first block of each repetition after the first resets the counters left nonzero by the previous one, other than those it sets itself, and sets label to the repetition’s 0-based index.

No event row is added. A recorded TotalDuration is replaced by the duration of the expanded scan. repeats=1 leaves the scan as it is.

Parameters:
  • repeats (int) – How many times the scan plays.

  • label (str, default="AVG") – Label counting the repetitions; empty for none.

  • strip_once (bool, default=True) – Remove the ONCE labels from the expanded table.

Returns:

repeats, blocks_before and blocks_after, and the number of blocks of one pass whose ONCE is 1, 0 and 2: prep_blocks, body_blocks and cooldown_blocks.

Return type:

dict[str, int]

Raises:
  • ValueError – If repeats is below 1.

  • RuntimeError – If a block’s ONCE is outside 0, 1 and 2, if repeats exceeds 1 and no block plays on every repetition, or if the scan already writes label.

Examples

>>> import pypulseqpp as pp
>>> seq = pp.Sequence(pp.Opts())
>>> _ = seq.add_block(pp.make_delay(1e-3), pp.make_label("ONCE", "SET", 1))
>>> _ = seq.add_block(pp.make_delay(2e-3), pp.make_label("ONCE", "SET", 0))
>>> seq.expand_repeats(3)["blocks_after"]
4