From af703808dbd5b0a17be888a34f883adcbcf5912a Mon Sep 17 00:00:00 2001 From: serversdown Date: Thu, 29 Oct 2026 17:47:34 -0400 Subject: [PATCH] docs(spec): the Series 3 decode checker -- SFM's file-only decode against Blastware's XML reports The first of four pieces toward SFM producing everything Blastware reports from the event file alone: compare every field, sample and histogram interval with DL2's 70,042 _XML.XML reports (2016-2026), report what matches, what doesn't and what SFM can't produce yet, grouped for diagnosis, run after run. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9 --- .../2026-10-29-s3-decode-checker-design.md | 266 ++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md diff --git a/docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md b/docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md new file mode 100644 index 0000000..f27d240 --- /dev/null +++ b/docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md @@ -0,0 +1,266 @@ +# Series 3 decode checker — design + +**Date:** 2026-10-29 · **Branch:** `feat/s3-decode-checker` · **Status:** design + +## Why this exists + +SFM is meant to replace Blastware. Today, when a Series 3 event arrives with +Blastware's ASCII report, SFM takes many of its values from the report: ZC +frequency, acceleration, the sensor check and so on. Two of the four ways +events will reach SFM, its own serial/modem download and its future call-in +server, never have a report. So SFM must produce **everything Blastware +reports, from the event file alone**, and we need proof that it does. + +The checker is that proof, and the to-do list for getting there. It decodes +each event file the way SFM ingest does, with no report, and compares every +field with Blastware's own report of the same event. Then it says what +matches, what doesn't, and what SFM can't produce yet. + +It is the first of four pieces, agreed with Brian on 2026-10-29: + +1. **This checker.** +2. Completing SFM's file-only decode, one field group at a time, each slice + done when the checker shows it matching. Slice 1, the setup fields and + notes (#44/#45), merged to dev as `42fe35f`. +3. Flipping ingest to file-only. Reports are kept for checking only. This + happens only when piece 2 leaves no blanks and the checker proves it. + Prod keeps its current behaviour until then. +4. The watcher: it forwards the XML report while we verify, then stops + forwarding reports. + +## The reference: Blastware's XML event reports + +Every Blastware ACH machine keeps, in `Sent/`, a full XML event report for each +event: `__XML.XML` next to the binary `.`. DL2's backup +holds **70,042 of them for Series 3 events, from 2016 to 2026**. Its ASCII +reports, by contrast, cover only 2025–26. + +Local copies on the dev box (`tmi-dev`, 10.0.0.44): + +| what | where | count | +|---|---|---| +| event binaries (Series 3) | `~/dl2-archive/files/` (root + `Sent/` mirror, dedupe by basename) | 70,112 distinct | +| XML reports | `~/dl2-archive/xml/` (flat) | 75,958 = 70,042 Series 3 + 5,916 Micromate (`UM…_IDF?_XML.XML`) | +| ASCII reports | `~/dl2-archive/files/` | 14,338 (2025–26 only) | + +What the Series 3 XML contains (surveyed across all 75,958 on 2026-10-29): + +- **Identity:** `EventType` (`Full Waveform` 6,524, `Full Histogram` + 63,518), `SerialNumber`, `Version` (`V 10.72-8.17 MiniMate Plus` or + `… BlastMate III`), `FileName`. +- **Time:** waveform `EventDate`/`EventTime`; histogram + `HistogramStart*`/`HistogramStop*`. +- **Setup:** `Channels`, `Trigger`, `GeoTriggerLevel`, `MicTriggerLevel`, + `Pre-triggerLength`, `RecordTime`, `RecordStopMode` (only `Fixed` occurs), + `SampleRate`, `IntervalSize` (2 s / 5 s / 15 s / 1 min / 5 min), + `NumberofIntervals`, `GeoRange` (10.000: 75,923; 1.250: 35), `Units` (`in/s + and dB(L)` / `psi(L)` / `dB(A)` / `in/s`), `Microphone` (weighting). +- **Unit:** `BatteryLevel`, `Calibration` (date + by whom), `MicCalibration`. +- **Notes:** `JobNumber`, then up to four user notes. Each is tagged with its + operator-editable label (`Project`, `Location`, `Seis.Loc`, `SeisLocation`, + `SeismographLoc`, `Company`, `General`, …), and empty notes are omitted. + They sit between the top-level `` and ``. +- **Results:** per channel `PPV`, `ZCFreq`, `TimeofPeak`, `PeakAcceleration`, + `PeakDisplacement` (waveform) or `PeakDate`/`PeakTime` (histogram); + `PeakVectorSum` with its time; mic `PSPL`, time, `ZCFreq` (dB(A) + histograms carry `MicA*` fields instead). +- **Sensor check:** per geophone `TestFreq`, `TestRatio`, `TestResults`; mic + `TestFreq`, `TestAmplitude`, `TestResults`. +- **`MonitorLog`:** the session's start, stop and status text. +- **Data:** waveform `WaveformDataChannels/Data/Row/Cell` (4 cells per + sample: Tran, Vert, Long in in/s, MicL in the event's mic units); histogram + `HistogramDataIntervals` (a `Time` and a 10-cell `Row` per interval: + Tran/Vert/Long peak + freq, geo PVS, MicL psi, dB and freq). + +Value forms the parser must handle: numbers with units in the text (`6.7 +Volts`, `7.6 Hz.`, `3.0 sec.`, `-0.250 sec`); `>100` (ZC frequency above +range; 71,823 files), `N/A` (37,293 files), `OORANGE` (59 files: the channel +clipped), `Check` (2,193 files), and XML entities. Two `_XML.XML` details +matter: + +- Blastware prints each number to a fixed number of decimals and **rounds + halves away from zero** (−0.0625 s prints as −0.063). +- The small `_.XML` summary next to it uses **decimal commas**. + It is not the reference; the `_XML.XML` is. + +## Goals + +- For every Series 3 event file with an XML report, compare **every field the + XML carries**, plus every waveform sample and every histogram interval, + against SFM's file-only decode. +- Give each comparison one verdict: **match**, **mismatch**, **SFM blank** + (SFM produced nothing), **accepted difference** (covered by a written + carve-out), **no reference** (the XML lacks the field), or **error** (the + decode or parse failed). +- Produce two outputs: + - **A short summary for Brian:** per field, the counts of each verdict and + how far we are from done. + - **A detailed report for Claude** that groups failures by what the failing + events share, so 17,000 mismatches read as "one bug on 2048 sps + histograms". It gives example files with Blastware's value and SFM's, and + a one-line command to re-run a single event. +- **Run again and again.** Each run is compared with the previous one, so a + fix shows as numbers moving, and anything that used to match and stops is + called out. +- Keep the comparison as library code, so ingest can later run it on one + event as it arrives (piece 3/4). + +## What counts as "SFM's side" + +The SFM side is **what SFM produces from the event's bytes alone**: + +- **The `Event` that `decode_blastware_bytes` returns when given the bytes and + no filename.** + - SFM's own download and call-in paths never have a Blastware name. + - Today the event type comes only from the filename's extension, so every + histogram decodes as "Waveform". The checker reports that as it is: a + mismatch until the decoder reads the type from the file (#41). It must + not borrow the name to make it match. +- **Anything else SFM reads from those bytes outside the decoder**, such as the + serial. + - Ingest's `sfm/waveform_store._serial_from_bw_bytes` uses the filename to + validate what it finds. + - Whatever SFM can't get from the bytes alone is "SFM blank". +- **Values the codec computes but never puts on the `Event`** count as SFM + blank until they are wired through (piece 2). For example, histogram + half-periods in `histogram_codec.decode_histogram_body_full` give the + per-interval frequency. +- **SFM's assumptions included.** + - SFM cannot yet read the geophone range from the file, and assumes Normal + (10 in/s): `_peaks_from_samples` does, and ingest writes `.h5` with + `geo_range="normal"`. + - The checker compares what SFM actually produces under that assumption. + The range field itself is SFM blank. + - So the 35 events recorded on the 1.250 in/s range show as 8× mismatches, + not blanks. Example: `T438L713.QP0W` gives PPV 0.015/0.02/0.015 against + Blastware's 0.002. + - The range is never taken from the reference. + +So the comparison takes an SFM-side record plus the parsed reference. The +runner assembles that record from the decoder and any SFM helpers. The +comparison itself stays pure codec-library code; only the runner (a lab tool) +may import from `sfm/`. + +## The rule for disagreements (decided by Brian) + +**Every mismatch is an SFM bug until shown otherwise.** A mismatch becomes an +"accepted difference" only through a written carve-out that names the fields +it covers and the rule it applies. Its evidence must not rest on SFM's own +output: Blastware contradicting itself, the instrument's own data (counts +in the file, the unit's embedded record), a third source (another instrument, +a known signal), or Instantel documentation. Each run reports how many events +each carve-out covers. + +The carve-out list starts with one entry, already proven in +`scratch/verify_against_ascii.py`: **saturation**. On a clipped channel, +Blastware clamps its numbers to the range maximum and writes `OORANGE`, while +the file holds counts past full scale. Rounding to Blastware's printed +precision is a comparison rule, not a carve-out. + +## Non-goals + +- **Series 4 / Micromate.** Thor's IDF decode has its own CSV-based check, and + the 5,916 Micromate XMLs are noted for a later Series 4 checker. +- **Changing what SFM decodes.** The checker reports gaps; filling them is + piece 2. +- **Wiring the check into ingest, the watcher or Terra-View.** That's pieces + 3/4. Nothing on prod changes. +- **ASCII reports as a reference.** The XML covers every year, including the + 2025–26 events that have ASCII. The reference is parsed into a shape another + report format could fill later, but no ASCII adapter is built now. + +## Anti-goals (would make it a failure even if it runs) + +- **Comparing SFM with Blastware's own numbers.** The SFM side must come only + from the event file, through `decode_blastware_bytes` with no report + overlay. Nothing from the XML or ASCII report may reach the SFM side. +- **Hiding mismatches:** a carve-out without evidence, a tolerance looser + than Blastware's printed precision, or blanks counted as matches. +- **Wrong conversions:** counts converted to in/s with a range or scale that + came from the reference rather than the file. If SFM can't read the range + from the file yet, that is a gap to report, not something to borrow. +- **A report that only says "N mismatches"** without grouping and examples. + It must be usable to find the cause. +- **A full run so slow it isn't run after every fix.** + +## Constraints + +- **Hardware:** runs on the dev box (4 cores, ~17 GB free disk after the + 22 GB XML copy; Brian can add space). +- **Read-only:** it never writes to the corpus folders and needs no network. +- **Speed:** a full run over all 70,042 events in **under an hour**. A + partial run (by serial, year, event type or field group, or a random sample) + in **a few minutes**. The setup/notes harness covering ~6 fields took ~4 + minutes with 4 processes. Samples and intervals add parsing 22 GB of XML. + The standard library parses at ~45 MB/s per core (`lxml` is not + installed), which fits the budget. +- **Codec library purity (ADR 0003):** the codec library stays pure. Bench and + lab tools stay out of the production image. +- **Results contain customer project names**, so run output is kept outside + the repo and never committed. + +## What's decided, and by whom + +**Brian:** +- SFM's data comes only from the binary; reports are for checking. +- The disagreement rule and carve-outs above. +- The two outputs: a summary for him, a detailed report for Claude to diagnose. +- Repeated runs with run-to-run comparison. +- It lives in seismo-relay, and the comparison is library code. +- Series 3 only. Nothing on prod or in Terra-View changes. + +**Claude's calls (correct if wrong):** +- The XML is the single reference. +- **Placement:** + - The XML report parser belongs in the codec library, a sibling of + `minimateplus/bw_ascii_report.py`. + - The comparison (one decoded `Event` + one parsed report → verdicts per + field) is pure and belongs in the codec library too. + - The batch runner is a lab tool (`scratch/`), per ADR 0003. + - The carve-out list lives in the repo next to the comparison, as code or + data the comparison reads, with each entry's evidence written beside it. +- **Grouping attributes for the detailed report:** + - device model (from `Version`), serial + - event type, event year + - sample rate, geophone range, mic units/weighting, interval size + - whether the setup is named "Standard Recording Setup" + - which decoder path produced the samples, where the decoder exposes it +- `scratch/verify_bw_fields_against_xml.py` (committed `f46afaf`) is the + starting point. It already handles the notes/job-number layout and the + rounding rule. The checker replaces it. + +**Left to the builder:** +- module, function and file names; the output file formats +- how runs are stored and compared +- parallelism and any caching of decode or parse results +- the CLI shape, as long as the partial-run filters and single-event re-run + exist + +## What success looks like + +- **One command** produces the summary and the detailed report for all 70,042 + events within the time budget. +- **The first run reproduces what is known**, which is how we tell the + checker is honest: + - sample rate, record time, pre-trigger and notes match everywhere + - one waveform (`T438HGTZ.B30W`) is 3 samples short on Tran, Vert and + MicL; Long is full length + - samples and histogram intervals match on the 2025–26 events, as + `verify_against_ascii.py` showed, **except the events on the 1.250 in/s + range**, which are 8× high (5 of them in 2025–26, 35 in all) + - event type mismatches on every histogram, because no filename is given + (#41) + - job number and the calculated values (ZC frequency, acceleration, + displacement, time of peak, sensor check, battery, calibration, trigger + levels, range, units, monitor log) show up as SFM blank + - the three `#53` files fail loudly as waveform time mismatches, 4 s off. + The decoder picks an earlier, false footer and records no + `decode_problems`. The `#53` description in + `docs/instantel_protocol_reference.md`, which says they decode as + histograms, is out of date. +- Every non-match group in the detailed report carries example files and a + re-run command. +- Tests cover the XML parser on real fixture reports with literal expected + values, every comparison rule (rounding, `>100`, `N/A`, `OORANGE`, + units), carve-out accounting, and a guard that the SFM side never sees the + reference.