MS3RecordBatch¶
- class pymseed.MS3RecordBatch(data, cols, columns, arrays, sourceids)[source]¶
Bases:
objectHeader fields and raw bytes of consecutive miniSEED records, as columns.
Read batches with
MS3RecordBatchReader. Each column is a read-onlymemoryviewwith one element per record, e.g.batch.starttimes[i]; wrap one withnumpy.frombufferfor an array without copying.to_arrow()converts the batch to apyarrow.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
recordcolumn references the buffer it was read from, keeping it alive. Don’t modify a buffer passed toMS3RecordBatchReader.from_buffer()while batches read from it are in use.- Parameters:
- 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).
NSTERRORwhere 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.
- __arrow_c_array__(requested_schema=None)[source]¶
Export the batch as
arrow_schemaandarrow_arrayPyCapsules.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. Requirespyarrow.
- __arrow_c_stream__(requested_schema=None)[source]¶
Export the batch as a one-batch
arrow_array_streamPyCapsule.For consumers that only read streams, e.g. DuckDB. Requires
pyarrow.
- to_arrow()[source]¶
Convert to a
pyarrow.RecordBatchwithout copying the records or columns.Columns, of those read:
sourceid(dictionary of string),starttimeandendtime(timestamp[ns, UTC]),samprate(float64),samplecnt(int64),encoding(int16),pubversionandformatversion(uint8), andrecord(binary, the raw record). Onlyendtimeis nullable: null where the end time isn’t representable, seeendtimes.The Arrow arrays reference the batch’s columns and records, keeping them alive. Requires
pyarrow14 or later (the[pyarrow]optional dependency).- Return type:
pa.RecordBatch