MS3RecordBatch

class pymseed.MS3RecordBatch(data, cols, columns, arrays, sourceids)[source]

Bases: object

Header fields and raw bytes of consecutive miniSEED records, as columns.

Read batches with MS3RecordBatchReader. Each column is a read-only memoryview with one element per record, e.g. batch.starttimes[i]; wrap one with numpy.frombuffer for an array without copying. to_arrow() converts the batch to a pyarrow.RecordBatch, also without copying.

A batch holds only the columns its reader was asked for; reading another raises ValueError.

Records’ bytes are not copied: a batch with the record column references the buffer it was read from, keeping it alive. Don’t modify a buffer passed to MS3RecordBatchReader.from_buffer() while batches read from it are in use.

Parameters:
  • data (Any)

  • cols (Any)

  • columns (tuple[Column, ...])

  • arrays (dict[str, Any])

  • sourceids (list[str])

property num_records: int

Number of records in the batch.

property sourceids: list[str]

The batch’s distinct source identifiers, indexed by sourceid_indices.

property sourceid_indices: memoryview

Each record’s source identifier, as an index into sourceids (int32).

property starttimes: memoryview

Each record’s first sample time, in nanoseconds since the epoch (int64).

property endtimes: memoryview

Each record’s last sample time, in nanoseconds since the epoch (int64).

NSTERROR where it isn’t representable, e.g. with a corrupt sample rate; Arrow exports have nulls there.

property samprates: memoryview

Each record’s nominal sample rate in Hz (float64).

property samplecnts: memoryview

Each record’s number of samples (int64).

property encodings: memoryview

Each record’s data encoding, see DataEncoding (int16).

property pubversions: memoryview

Each record’s publication version (uint8).

property formatversions: memoryview

Each record’s miniSEED format major version (uint8).

property record_offsets: memoryview

Where each record starts in records, followed by where the last ends (int32).

property records: memoryview

The batch’s raw records, back to back.

record(i)[source]

Raw bytes of the batch’s i-th record (copy).

Parameters:

i (int)

Return type:

bytes

sourceid(i)[source]

Source identifier of the batch’s i-th record.

Parameters:

i (int)

Return type:

str

__arrow_c_array__(requested_schema=None)[source]

Export the batch as arrow_schema and arrow_array PyCapsules.

The Arrow PyCapsule interface, through to_arrow(): a struct array with a field per column, referencing the batch’s columns and records without copying them. Requires pyarrow.

Parameters:

requested_schema (Any)

Return type:

tuple[Any, Any]

__arrow_c_stream__(requested_schema=None)[source]

Export the batch as a one-batch arrow_array_stream PyCapsule.

For consumers that only read streams, e.g. DuckDB. Requires pyarrow.

Parameters:

requested_schema (Any)

Return type:

Any

to_arrow()[source]

Convert to a pyarrow.RecordBatch without copying the records or columns.

Columns, of those read: sourceid (dictionary of string), starttime and endtime (timestamp[ns, UTC]), samprate (float64), samplecnt (int64), encoding (int16), pubversion and formatversion (uint8), and record (binary, the raw record). Only endtime is nullable: null where the end time isn’t representable, see endtimes.

The Arrow arrays reference the batch’s columns and records, keeping them alive. Requires pyarrow 14 or later (the [pyarrow] optional dependency).

Return type:

pa.RecordBatch