read#
- pypulseqpp.io.read()[source]#
Read a Pulseq file into a sequence whose system describes what is in it.
Unlike
read(), which keeps the system the sequence was constructed with, this builds the system from the file, so that the checks ofpypulseqpp.safetycompare the sequence with its own limits. Text and binary files are detected from their contents.The rasters come from the file. The gradient limit, slew-rate limit and
B0come from theMaxGrad,MaxSlewandB0definitions when the file states them, and frommax_gradandmax_slewwhen given, which take precedence. A limit that neither supplies is the larger of theOptsdefault and the largest value the file reaches. Dead times are not recorded in a.seqfile and keep their defaults.- 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.
Nonetakes 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) – Assign a use to each RF event without one, as
detect_rf_use()does. Files before revision 1.5.0 record no use.remove_duplicates (bool, default=True) – Collapse identical library rows after reading.
verify (bool, default=False) – Check the file against the signature it carries; a file without one is refused.
- Returns:
The sequence, with
systembuilt from the file.- Return type:
- Raises:
FileNotFoundError – If
file_pathdoes not exist.RuntimeError – If the file cannot be parsed, or
verifyis set and the signature does not match.TypeError – If a file object returns text, as one opened in text mode does.
See also
writeThe other direction.
pypulseqpp.Sequence.readRead 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)