read

Contents

read#

pypulseqpp.io.read()[source]#

Read a Pulseq file into a sequence whose system describes what is in it.

read() replaces a sequence’s contents and takes its rasters from the file, but leaves the sequence on whatever system it was constructed with. The limits and rasters of that system are what the design helpers solve against and what the checks in pypulseqpp.safety compare a waveform with, so a file read onto the shared default system is measured against limits that have nothing to do with it. This builds the system from the file instead.

The rasters always come from the file. A limit or a field strength comes from the file when it states one, as _LIMITS names the definitions, and from the argument here when one is given, which wins. A gradient limit that neither supplies is the larger of the Opts default and the largest amplitude the file actually reaches, so that the sequence read back satisfies the checks it was written under. Dead times are not recorded in a .seq file and stay at their defaults.

Text and binary are told apart by what is in the bytes.

Parameters:
  • file_path (str | os.PathLike[str] | BinaryIO) – The file to read, or a binary file object whose read() returns its contents.

  • max_grad (float, default=None) – Gradient amplitude limit (Hz/m) for the system built. None takes the file’s own, or the larger of the default and what the file reaches.

  • max_slew (float, default=None) – Slew-rate limit (Hz/m/s), resolved the same way.

  • detect_rf_use (bool, default=False) – Work out what each unlabelled pulse is for, from what it does. A file written before revision 1.5.0 has nowhere to record it.

  • remove_duplicates (bool, default=True) – Collapse identical library rows after reading.

  • verify (bool, default=False) – Check the file against the signature it carries.

Returns:

The sequence, on a system built from the file.

Return type:

pypulseqpp.Sequence

Raises:
  • FileNotFoundError – If file_path does not exist.

  • RuntimeError – If the file cannot be parsed, or verify is set and the signature does not match.

  • TypeError – If a file object returns text, as one opened in text mode does.

See also

write

The other direction.

pypulseqpp.Sequence.read

Read into an existing sequence, keeping its system.

Examples

>>> import pathlib, tempfile
>>> import pypulseqpp as pp
>>> path = pathlib.Path(tempfile.mkdtemp()) / "gre.seq"
>>> system = pp.Opts(max_grad=80.0, grad_unit="mT/m")
>>> seq = pp.Sequence(system)
>>> seq.add_block(pp.make_trapezoid("x", area=4000, duration=2e-3, system=system))
1
>>> _ = pp.io.write(seq, path)

The file states no limit, so the one built admits what the file reaches, which is more than the default system allows:

>>> loaded = pp.io.read(path)
>>> loaded.num_blocks, loaded.system.max_grad > pp.Opts().max_grad
(1, True)