MSeedWriter Job
The MSeedWriter thread is responsible for long-term data persistence. It buffers incoming samples in memory and flushes them to disk using the industry-standard MiniSEED format and SDS (SeisComP Data Structure) hierarchy.
Architecture
Section titled “Architecture”The writer consumes raw data and coordinates with the Trigger Processor to prioritize earthquake data.
- Input:
msed_writer_queue(Raw ADC counts). - Trigger:
earthquake_event(Signals an immediate flush). - Output: Structured SDS archive on local disk.
SDS Directory Structure
Section titled “SDS Directory Structure”To ensure compatibility with global seismological tools (like SeisComP or ObsPy), data is organized into a nested date/station hierarchy:
Directorydata/
Directoryarchive/
Directory2026/
DirectoryXX/ (Network)
DirectoryRPI3/ (Station)
DirectoryEHZ.D/ (Channel.Type)
- XX.RPI3.00.EHZ.D.2026.095 (Full Record)
Initialization & State
Section titled “Initialization & State”The writer maintains internal buffers to minimize disk I/O operations, which is critical for extending the life of SD cards on Raspberry Pi deployments.
| Parameter | Type | Purpose |
|---|---|---|
output_dir | Path | The root of the SDS archive. |
earthquake_event | Event | Shared signal to trigger a 5-minute “event flush.” |
write_interval | float | Default: 1800s (30 minutes) between writes. |
| Variable | Format | Description |
|---|---|---|
_buffer | dict | Keyed by channel (e.g., {"EHZ": [...]}). |
_start_time | float | Unix timestamp of the first sample in current buffer. |
The Flush Procedure
Section titled “The Flush Procedure”Flushing data to disk is a non-trivial process that involves time alignment and file merging.
- Midnight Check: The buffer is scanned for midnight boundaries using
split_buffer_at_midnight(). If a buffer spans two days, it is sliced into two separate chunks. - Trace Construction: Each slice is converted into an ObsPy
Traceobject with correct FDSN metadata (Network, Station, Location, Channel). - SDS Pathing: The target file path is calculated based on the sample timestamp.
- Merge Logic:
- If file exists: The existing day-file is read, the new data is appended, and ObsPy
merge(method=1)is called to handle overlaps or gaps. - If new file: A new MiniSEED file is initialized with Steim-2 compression.
- If file exists: The existing day-file is read, the new data is appended, and ObsPy
- Disk Write: The stream is written to disk with a fixed record length of 512 bytes.
Earthquake Early Flush
Section titled “Earthquake Early Flush”While the default flush happens every 30 minutes, earthquakes require faster persistence to ensure data isn’t lost if the system loses power during an event.
Storage & Performance
Section titled “Storage & Performance”MiniSEED uses Steim-2 compression, which is lossless and highly efficient for seismic integer data.
Capacity Estimates (3 Channels @ 100Hz)
Section titled “Capacity Estimates (3 Channels @ 100Hz)”| Metric | Raw Data (int32) | Steim-2 (Compressed) |
|---|---|---|
| Per Hour | ~4.3 MB | ~2.1 MB |
| Per Day | ~104 MB | ~51 MB |
| Per Month | ~3.1 GB | ~1.5 GB |
Resource Usage
Section titled “Resource Usage”- Memory: ~2.2 MB (for a full 30-minute buffer).
- IO Latency: ~200ms during a “Merge” operation (Reading existing file + Writing back).
Error Recovery
Section titled “Error Recovery”- Disk Full: If an
OSErroroccurs during write, the error is logged asCRITICAL. The current buffer is cleared to prevent memory exhaustion, though that specific 30-minute block of data is lost. - Corrupt Files: If an existing day-file cannot be read for merging, the writer logs an error and attempts to overwrite it with the current buffer to resume recording.