Brian's requirements: the instrument's data is the only time source; a filename is a cross-check, never a fallback (an event SFM receives itself has none). The record (found by reading a seismo_lab Inspector dump; Series-III reference §7.8.9): 00 28 05 00 ?? ?? | fe 80 | trigger | stop, times dd mm yyyy(BE) 00 hh mm ss. Measured on 7,935 waveforms (DL2 + prod store): exactly one candidate validates in every file; trigger = Blastware's report 1,320/1,320, = filename 7,935/7,935, = the unit's 0C record 10/10. Provenance (requirement 6, measured): in Blastware's download of 8 BE9441 events the record -- with 24 B before and 22 after -- occurs exactly once in the unit's own A5 reply payloads; SFM-only downloads (no Blastware) carry it too. It is instrument data, not Blastware's. - _embedded_event_record(): every fe 80 before the footer is a candidate; it counts only with the lead bytes, two well-formed times (zero byte zero), footer ts1 <= trigger <= stop, stop = footer ts2 or a second before, and a length matching the record time. Exactly one must count; none or several is a decode problem, never a guess. - Without one: the footer estimate, timestamp_source 'estimate', a decode_problems entry, a WARNING. No filename fallback. - A filename that disagrees is logged; the decoded time is kept. A paired report fills in only without a validated record (apply_report_to_event, the sidecar dict overlay, event_to_sidecar_dict) and is logged when it disagrees. - decode_blastware_bytes(raw, name=None): no file or name needed; save_imported_bw uses it (no temp file). Event gains timestamp_source and decode_problems; the sidecar records both. - Histograms unchanged (#51): their record (fe f5) is noted, not used. Tests: raw bytes with no name (ZI0, 7 BE12844 oracles), a disagreeing name, each validation rule alone, two valid candidates, no filename fallback, report precedence, sidecar. 7 mutants, each caught. Real data, decoded with no name: 7,961/7,961 waveforms on the record, 0 disagreements with filename or report; 10,433/10,433 prod histograms unchanged. Suite: only the 16 known failures. Open (reported, not changed): 3 DL2 files named as waveforms whose body the waveform codec does not recognise keep the footer start, 4 s off, as on dev. None in prod. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
56 lines
2.7 KiB
Python
56 lines
2.7 KiB
Python
"""Event timestamp decode — waveform trigger/stop vs histogram window start.
|
|
|
|
The Blastware footer holds two timestamps: ts1 = footer[2:10], ts2 = footer[10:18].
|
|
Their meaning depends on record type:
|
|
|
|
* Waveform: ts1 is the monitoring-SESSION start (e.g. 06:00 for a unit that
|
|
arms at 06:00 daily — shared across every event that day), and ts2 is THIS
|
|
event's recording STOP. read_blastware_file used to stamp events with ts1 →
|
|
every waveform showed the session start (~4.5 h off). Binary-only, the best
|
|
estimate is ts2 (the stop); the exact trigger BW displays (= ts2 - record
|
|
duration) comes from the paired report's event_datetime, since the binary
|
|
STRT record-time byte is a misparsed record-type marker.
|
|
* Histogram: ts1/ts2 are the ~24 h window [start, stop]; the event time is the
|
|
window start = ts1 (unchanged).
|
|
"""
|
|
import datetime
|
|
from pathlib import Path
|
|
|
|
from minimateplus.event_file_io import read_blastware_file, apply_report_to_event
|
|
from minimateplus.bw_ascii_report import BwAsciiReport
|
|
from minimateplus.models import Event
|
|
|
|
FIX = Path(__file__).parent / "fixtures"
|
|
WAVEFORM = FIX / "fft-oracle-2026-09-14" / "N844LQHB.ZT0W" # footer ts2 = 2026-08-25 10:33:32
|
|
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H" # window start 2026-05-10 19:04:50
|
|
|
|
|
|
def _tuple(ts):
|
|
return (ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second)
|
|
|
|
|
|
def test_waveform_timestamp_is_exact_trigger_from_binary():
|
|
ev = read_blastware_file(WAVEFORM)
|
|
# The EXACT Blastware trigger, from the binary alone: ts2 (stop 10:33:32)
|
|
# minus the config record time (3.0 s) = 10:33:29 — NOT the 06:00:13
|
|
# monitoring-session start the old decode used.
|
|
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 33, 29), _tuple(ev.timestamp)
|
|
|
|
|
|
def test_histogram_timestamp_is_window_start_unchanged():
|
|
ev = read_blastware_file(HISTOGRAM)
|
|
# Histogram event time = the window start (ts1); must NOT get the waveform
|
|
# ts2 treatment (that would land ~24 h off).
|
|
assert _tuple(ev.timestamp) == (2026, 5, 10, 19, 4, 50), _tuple(ev.timestamp)
|
|
|
|
|
|
def test_a_report_does_not_override_the_instruments_event_record():
|
|
# Superseded 2026-10-26: the exact trigger is the instrument's embedded event
|
|
# record, and a paired report (Blastware's copy of the same unit time) is a
|
|
# cross-check -- they agree on 1,320/1,320. A disagreement is logged.
|
|
ev = read_blastware_file(WAVEFORM)
|
|
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 33, 29) # exact, from the record
|
|
apply_report_to_event(ev, BwAsciiReport(
|
|
event_datetime=datetime.datetime(2026, 8, 25, 10, 35, 0)))
|
|
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 33, 29) # the record stands
|