MS3RecordBatchReader¶
- class pymseed.MS3RecordBatchReader(batches, columns)[source]¶
Bases:
objectReads miniSEED records as
MS3RecordBatches; also an Arrow stream.Create one with
from_file(),from_buffer()orfrom_filelike(). Iterate over it for batches, or pass it to an Arrow library to read them all as one stream, e.g.pyarrow.table(reader),polars.DataFrame(reader)or a DuckDB query. Either way, each batch is read once: a stream continues from wherever iteration left off.- Parameters:
batches (Iterator[MS3RecordBatch])
columns (tuple[Column, ...])
- COLUMNS = ('sourceid', 'starttime', 'endtime', 'samprate', 'samplecnt', 'encoding', 'pubversion', 'formatversion', 'record')¶
The names of the columns a reader can read, in batch order.
- classmethod from_buffer(buffer, *, columns=None, batch_size=8192, skip_not_data=False, validate_crc=True, verbose=0)[source]¶
Read batches of the records in a buffer.
- Parameters:
buffer (Any) – A bytes-like object holding miniSEED records back to back.
columns (Iterable[Literal['sourceid', 'starttime', 'endtime', 'samprate', 'samplecnt', 'encoding', 'pubversion', 'formatversion', 'record']] | None) – The columns to read, from
COLUMNS; all of them by default. Others are neither filled nor allocated, and withoutrecord, batches don’t keep the buffer alive.batch_size (int) – Records per batch, at most, up to
2**30. A batch may hold fewer at the end of a block, or before input skipped withskip_not_data.skip_not_data (bool) – Skip input that isn’t miniSEED, a byte at a time, until a record is found, including an incomplete record at the end and records that fail CRC validation or can’t be decoded.
validate_crc (bool) – Validate CRCs when present (miniSEED 3).
verbose (int) – libmseed verbosity.
- Raises:
MiniSEEDError – While reading, if a record can’t be parsed, or the buffer ends partway through one, after yielding the records before it. Not raised for either with
skip_not_data.- Return type:
- classmethod from_filelike(fh, *, columns=None, block_size=8388608, batch_size=8192, skip_not_data=False, validate_crc=True, verbose=0)[source]¶
Read batches of the records read from a file-like object.
Reads
block_sizebytes at a time withfh.read. A batch never spans blocks: a record straddling two is read with the second, which is read in after a copy of the record withfh.readintoiffhhas it, else copied after the record. With therecordcolumn, a batch references the block it was read from.- Parameters:
fh (Any) – An object with a
read(n)method returning bytes.readmust block until data is available, as an empty result ends the input.block_size (int) – Bytes read at a time.
columns (Iterable[Literal['sourceid', 'starttime', 'endtime', 'samprate', 'samplecnt', 'encoding', 'pubversion', 'formatversion', 'record']] | None) – As for
from_buffer().batch_size (int) – As for
from_buffer().skip_not_data (bool) – As for
from_buffer().validate_crc (bool) – As for
from_buffer().verbose (int) – As for
from_buffer().
- Raises:
MiniSEEDError – As for
from_buffer().- Return type:
- classmethod from_file(filename, *, columns=None, block_size=8388608, batch_size=8192, skip_not_data=False, validate_crc=True, verbose=0)[source]¶
Read batches of the records in a file. See
from_filelike().The file is opened when reading starts, and closed when it ends or the reader is closed.
- Parameters:
- Return type:
- close()[source]¶
Stop reading, closing a file opened by
from_file().- Return type:
None
- __arrow_c_stream__(requested_schema=None)[source]¶
Export the remaining batches as an
arrow_array_streamPyCapsule.The Arrow PyCapsule interface, through
to_arrow(). The consumer pulls batches as it reads, each referencing the batch’s columns and records without copying them. A batch that fails to read ends the stream with an error. Requirespyarrow.