Sequence.read#
- Sequence.read()[source]#
Replace this sequence with the one in
file_path.Text or binary, told apart by what is in the bytes. Every revision from 1.2.0 is read, older ones by converting them.
- 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) – Work out what each unlabelled pulse is for, from what it does. Before revision 1.5.0 the format had nowhere to record it, so a file older than that arrives with its pulses unlabelled. Pulses the file does label are left alone.
remove_duplicates (bool, default=True) – Collapse identical library rows after reading.
verify (bool, default=False) – Check the file against the signature it carries.
- Raises:
RuntimeError – If
verifyis set and the signature the file 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