Sequence.read#
- Sequence.read()[source]#
Replace this sequence with the one in a Pulseq text or binary file.
The format is detected from the contents. Revisions from 1.2.0 are read; those before 1.5.0 are converted to 1.5.
- Parameters:
file_path (str | os.PathLike[str] | BinaryIO) – The file to read, or a binary file object whose
read()returns its contents, such asio.BytesIOover bytes received without a file.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 that carries none is refused.
- Raises:
RuntimeError – If
verifyis set and the file carries no signature, or the signature it carries is not the signature of its contents.TypeError – If a file object returns text, as one opened in text mode does.
- Warns:
UserWarning – If
detect_rf_useis set and every pulse in the file already records what it is for.
Examples
>>> import pathlib, tempfile >>> import pypulseqpp as pp >>> path = pathlib.Path(tempfile.mkdtemp()) / "gre.seq" >>> seq = pp.Sequence(pp.Opts()) >>> seq.add_block(pp.make_trapezoid("x", area=1000, duration=2e-3)) 1 >>> _ = seq.write(path) >>> loaded = pp.Sequence() >>> loaded.read(path, verify=True) >>> loaded.num_blocks, loaded.grad_raster_time (1, 2e-05)
The same bytes, held in memory rather than in a file:
>>> import io >>> received = pp.Sequence() >>> received.read(io.BytesIO(path.read_bytes()), verify=True) >>> received.num_blocks 1