Blastware prints OORANGE for an interval's vector sum when it exceeds
the range in an interval where Blastware also clamped a channel: 17 / 17
DL2 cells, SFM's sum 10.01 .. 17.33 in/s (sqrt 3 x 10.005). The
saturation carve-out now covers intervals.Geo PVS in/s with that rule,
per interval, as it already did for PeakVectorSum. The 4 other cells
left mismatching sit 4e-6 past a rounding boundary (Blastware's
arithmetic is a hair lower) and stay mismatches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Group B of the file-only decode, measured on DL2 2026-11-03:
- Frequency = (sample rate / 2) / half-period: 527,915 / 527,915 cells
at 1024 sps and 1,725 / 1,725 at 2048. #50: half_period_to_hz took a
fixed 512 and halved every 2048-sps frequency; it now takes the rate
(default 1024). Blastware prints 'N/A' for a half-period of 0, '>100'
('>200' at 2048) at 5 samples or fewer, '<1.0' below 1 Hz.
- Each interval's vector sum, sqrt(PVS^2) at the event's range:
771,354 / 771,354.
- Interval size: uint16 seconds at k - 40 (Series IV [8:10]).
- Stop: the footer's (2,995 / 2,999 sampled; 4 print a second earlier).
Event gains histogram_interval_sec, interval_half_periods, interval_pvs
and stop_time; the .h5 gains /intervals/half_period/<ch>,
/intervals/pvs_ips and a histogram_interval_sec attr. The decoder walks
a histogram once (histogram_codec.channels_from_records) and takes the
event's PVS from the same records. The checker compares each interval
column, number or Blastware's word; the test that pinned Tran Freq Hz
as blank now pins the match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
K441LA17.IN0W's report says Units 'in/s and psi(L)' yet prints
MicTriggerLevel '125.0 dB(L)'. The value states its own unit, so that
is the one compared; the report's Units is the fallback. It was the
only MicTriggerLevel mismatch in DL2 (SFM's 0.005158 psi is 125.0 dB).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Group A of the file-only decode, every field matched against every DL2
report (2026-11-03):
- Identity block before the setup name, what the live read gets from
SUB FE: serial k-202, firmware k-147, DSP version k-138, calibration
date k-132 + 'by' k-128, manufacturer k-94, model k-72, firmware
minor k-193. Event.device_info (DeviceInfo gains calibration_date /
calibrated_by). Serial, Version and Calibration 69,983 / 69,983.
- Battery: uint16 hundredths of a volt at k-190 (Event.battery_volts).
69,729 exact; the other 254 are Blastware rounding half up.
- Trigger source: the two bytes between the embedded event record's
lead and fe 80, a bitmask (0x01 Tran 0x02 Vert 0x04 Long 0x08 MicL
0x200 Manual): 6,493 / 6,493. Event.triggered_by.
- Trigger settings in Series IV's 0x1A layout: sources bitmask k-19,
stop mode k-31 (0 = Fixed), each channel's float32 level at
label+30 (geo in/s, mic psi), mic type code at MicL+4 (2 = Linear
Weighting). Geo level 6,447 / 6,447, mic 4,403 / 4,403; Blastware
prints a level when its channel is a trigger source and the event
was not Manual. The mic level's dB uses 6895 Pa/psi (4,272 / 4,272
against 4,271 at 6894.757).
- .h5 attrs for all of them (additive).
- Checker: SFM's side reports the ten fields; the mic trigger level
follows the report's dB/psi. Carve-out
units-is-a-display-preference: dB or psi is Blastware's PC setting
when it wrote the report -- DL2's reports switch fleet-wide in 61
clean runs by write time, and no byte of the file separates them.
Two tests that pinned BatteryLevel / Calibration as blank now pin the
match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Every DL2 file ends in a valid footer: 0e 08 and two valid times on
70,041 / 70,041. The decoder took the first '0e 08 + plausible year'
instead, and 14 files also hold an earlier record, ~1.1 KB before the
end, with the stop time followed by zeros:
- a histogram started at its own stop -- a day late on BE9558's daily
histograms (K558L9XP.FK0H: 2025-10-08 19:10:01 for Blastware's
2025-10-07 19:14:08); T003LCYV.JD0H got no time at all;
- a waveform lost its stop, so the trigger was never computed and the
stop was stamped instead (K440I4LG.JK0W: 11:14:12 for 11:14:08).
The last 26 bytes are now taken when they are a footer; otherwise the
old search stands unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Three causes behind the histograms the checker found decoding wrongly:
1. The file decoder tried the waveform codec first, whatever the record
type. It accepted BE9440 / BE9557 / BE17354's 2018 5 s histograms and
returned ~5x too many 'samples' (K440HDXX.XH0H: SFM 44,504, Blastware
6,976). The codec now follows STRT[18] (0x46 / 0x0A on 70,041 /
70,041 DL2 files); only an unknown type falls back to trial order, and a
chosen codec that fails is a decode problem rather than a silent switch.
2. The sub-minute layout check required each record's 'zero word' to be
0000. It is the high word of the interval's PVS squared, non-zero above
1.28 in/s, so a one-block histogram with a loud interval was not
recognised (T193KR5M.X90H, K440HA3C.JM0H, R352HFZ7.530H decoded to
nothing). The check is now the measured relation peak <= PVS <=
sqrt(3) * peak, which holds on 34,502,955 / 34,502,955 DL2 sub-minute
intervals. The no-terminal-tail trim uses the same test. Two test
builders wrote PVS bytes no real record has (one still in the retracted
little-endian layout); they now write peak^2 in the measured layout, and
the retraction test keeps a legacy builder of its own.
3. Checker carve-out interval-count-is-duration: Blastware's Number of
Intervals is (stop - start) / interval from the footer times, and its
own interval table lists one block fewer when the unit never wrote the
last minute. SFM matches the table (T193KSWP.FF0H: 2,880 vs 2,850).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
The setup block has Series IV's 0x1A layout here too: report flags at
k - 9 (bit 0x02 = job number shown) and the number, uint16 BE, at k - 8,
kept while switched off. The flag matches Blastware's JobNumber on
2,997 / 2,997 DL2 events that print one and 66,986 / 66,986 that don't.
Every printed value is 1 and matches; hidden ones hold real numbers
(802, 1012, 1013, 622), so the value is only proven for 1.
- ProjectInfo.job_number_enabled / job_number, named as in
micromate.setup_block.
- write_event_hdf5 stores both as .h5 attrs when read (additive).
- The checker reports the number only when shown, and scores a number
only SFM shows as a mismatch. The old test that pinned JobNumber as
sfm_blank now checks only the ZC cases it also covered.
Not carried into the DB, the API or the PDF report yet (needs a column).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
In the setup's channel blocks, the byte 29 after each geophone label is
the range: 0x00 Normal (10 in/s), 0x01 Sensitive (1.25 in/s). It matches
Blastware's GeoRange on 70,042 / 70,042 DL2 events, all three channels
agreeing on every one (35 Sensitive). SFM's live 1A has the same byte
at label+33. SFM assumed Normal, so every Sensitive event's peaks,
vector sum and .h5 samples read 8x high.
- Event.geo_range (0 / 1, None when not read -- channels disagreeing,
an unknown value or a missing block -- with a decode_problems entry).
- decode_blastware_bytes scales peaks and the histogram vector sum by it.
- event_hdf5.write_event_hdf5: geo_range defaults to None = the event's
own, else Normal; an explicit argument still wins.
- waveform_store.save_imported_bw and scripts/backfill_sidecars.py stop
forcing 'normal', so imports and the backfill store the file's range.
The waveform_store line was agreed with the parity session, which owns
that file; its own branch keeps a geo_range parameter, defaulting to
None at its next dev merge.
- The checker's SFM side converts at the event's range and reports
GeoRange; tests that pinned the old 8x gap now pin the fix, and the
saturation carve-out is still tested against an 8x value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
The checker caught 280 regressions in the first mic fix: every one a dB
value at count 129, where 20 log10(129 x 0.25 Pa / 20 uPa) = 124.149997
rounds to 124.1 and Blastware prints 124.2. Blastware's dB offset sits in
[81.9383, 81.9385] -- any value there matches its dB(L) on 1,729,252 /
1,729,253 DL2 intervals (the last printed '0.000'); exact 81.93820 rounds
count 129 down, and the old 81.94 misses counts 119 and 132. Single
precision does not explain it. psi keeps 0.25 Pa per count, which
matches every interval.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
SFM converted mic counts to psi with a '~0.5 psi full-scale' guess
(0.0125 / 32768 psi per count). Measured against 1,729,253 DL2
histogram intervals' 'MicL Peak' columns: one count is exactly 0.25 Pa.
count x 0.25 Pa matches Blastware's psi(L) on every interval, and
20 log10(count x 0.25 Pa / 20 uPa) its dB(L) on all but 17 exact
half-way cases.
- event_file_io: _MIC_FS_PSI -> _MIC_PSI_PER_COUNT = 0.25 / 6894.757
(3.626e-5 psi per count, was 3.81e-7). The event's mic peak in psi,
and with it the .h5 mic trace (event_hdf5 back-solves its scale from
that peak), come right on events with no report.
- waveform_codec.mic_count_to_db: the offset is 20 log10(0.25 / 20e-6)
= 81.938, not 81.94 -- the old value missed 49 of those intervals at a
rounding edge (count 119 printed 123.4, 81.94 gave 123.451).
The decoded count was always right: count 16 on K441LTON.900 is
Blastware's 106.0 dB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Every histogram interval carries its peak vector sum SQUARED, uint32 BE
in 0.005 in/s units: bytes [21:25] of a standard block (long documented
as 'constant 00 00' plus 'purpose unknown'), the last 4 bytes of a
sub-minute record (the undecoded 'meta_var'). sqrt(stored) x 0.005 is
the Geo PVS Blastware prints: 1,668,073 / 1,668,074 standard and 34.5 M
sub-minute DL2 intervals checked against the _XML.XML reports.
SFM computed the event's PVS from each channel's interval peak, which
can come from different moments, and read high on 86% of DL2's
histograms (T004JTRF.ME0H: 1.782 against Blastware's 1.358). It now
takes the largest stored interval value. histogram_codec.interval_pvs
returns the per-interval series; records gain 'pvs_sq'. Waveforms are
unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
STRT[18] is the record-type byte: 0x46 on every one of DL2's 6,577
waveform files, 0x0A on every one of its 63,535 histograms. The decoder
read the type from the filename's last letter, so an event with no
Blastware name -- SFM's own downloads, the call-in path -- or a manual
download ('.QZ0') came out 'Waveform' whatever it was.
The filename is now a cross-check that logs a disagreement; the bytes
win. An unknown byte (Manual / Event / Combo never occur in DL2) is
record_type None with a decode_problems entry, not a guess.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
- A matching event that now fails outright is a regression: compare_runs
walks the previous run's matching rows, so a check that collapses to
one error row no longer hides every field it used to match. Counts
moved are taken over the events both runs checked.
- The default baseline is the newest completed run (run.json written) of
the same scope; a 2,000-event sample is no baseline for a full run.
changes.md names the previous run's scope.
- The PVS saturation carve-out now needs Blastware's OORANGE, a channel
Blastware clamped at SFM's ceiling, and SFM's sum within three channels
at the ceiling -- an unclipped Sensitive-range channel read 8x can no
longer let an 8x sum through.
- 'Fields fully matching' needs a match: an always-empty element proves
nothing. Events without a report are a line of their own.
- CLAUDE.md: histogram PVS described correctly; 35 sub-minute histograms
plus 2 one-minute no-mic ones, not '~37 sub-minute'.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Each run is diffed against the previous one (--compare-to, or the newest
other run in ~/dl2-archive/checker-runs): changes.md lists every
(event, field) that matched before and no longer does, how many now
match, and how each field's counts moved; summary.md leads with the
regression count. --file NAME checks one event and prints its table,
writing no run folder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
summary.md for Brian: per field, events per verdict, how many fields
fully match, non-matches by event year, carve-out counts. details.json
for Claude: each non-matching (field, verdict) with the attribute values
its failures concentrate in (>= 10% of the failures; concentrated at
>= 95% of compared events) and example events, each with a one-event
re-run command. On a 2,000-event sample the event-type mismatches group
as 'type = Full Histogram, 1815/1815' -- #41, named by the report.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
check_s3_decode.py pairs each Series 3 event file with its _XML.XML
report (deduped by basename -- Sent/ mirrors the root), checks each in a
process pool, and writes results.jsonl.gz and run.json to a run folder
outside the repo. A missing report or any failure is one row for that
event; the run goes on. Partial runs by serial, year, type, field
prefix or random sample.
Timing: --sample 2000 --jobs 4 took 35 s on tmi-dev (~20 min projected
for all 70,042).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
A mismatch becomes 'accepted' only through a written carve-out whose
evidence does not rest on SFM's output. Saturation: Blastware clamps a
clipped channel to the range maximum and prints OORANGE, while the file
holds counts past full scale. SFM's value must sit at the ceiling
(r - 0.0006 .. r * 1.01), so a Sensitive-range event read 8x high on
SFM's Normal assumption stays a mismatch; a vector sum is accepted when
a clipped channel under it is at the ceiling. series_pairs() is now the
one place waveform rows and interval columns are paired.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Every field the report carries (bar its format version and Blastware's
file name), the notes in order, the job number, the channel list, every
waveform sample and every histogram interval column. Numbers match at
Blastware's printed precision, halves rounding away from zero; N/A and
empty text are no_reference; >100 needs SFM's above-range flag; OORANGE
is a mismatch unless a carve-out says otherwise. Waveform rows pair
cells with the channels still running, so channels that end early
(T438HGTZ.B30W) match, and any row-length disagreement is counted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
decode_blastware_bytes with no filename and no report: the values SFM
produces today in Blastware's field names, its notes, channels and raw
counts, with its Normal-range assumption kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
The reference for the Series 3 decode checker: scalars and value units,
channels, the job number, the user notes in order under their
operator-edited labels, waveform rows as printed (ragged where channels
end at different lengths) and histogram intervals. Seven real DL2
events as fixtures, each covering a case the comparison must handle.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Without a paired ASCII report, a Blastware import stored no sample rate,
the record-type byte as its record time (every waveform read "70 s"), a
pre-trigger and sample count read from STRT bytes that are neither, and
blank notes (the reader stopped at the NUL after each label).
- The recording-setup block is found by structure -- 1c 08, the setup
name, NUL -- not by the name "Standard Recording Setup", which 37% of
DL2's files do not use. One match in each of 70,041 archive files.
- Sample rate (uint16 BE, name-42), pre-trigger (f32 BE, name-36) and
record time (f32 BE, name-30). A waveform's sample count is the
decoded count. A histogram gets a sample rate only: Blastware reports
neither a record time nor a pre-trigger for one.
- The setup name and the four user notes by position, as bw_ascii_report
reads them: the labels are operator-editable ("Seis. Loc:",
"Location:", "Project: ").
- STRT now yields only the waveform key.
Verified against Blastware's own _XML.XML event reports for the 70,042
DL2 archive events that have one (2016-2026): sample rate 70,042/70,042,
record time 6,524/6,524, pre-trigger 6,484/6,484, notes 70,042/70,042,
sample count 6,523/6,524 (one waveform the decoder ends 3 samples short;
separate). Events imported with an ASCII report are unchanged -- the
report still overlays.
Not changed: the waveform-time estimate still finds the record time by
the marker; moving it would add a validation constraint for 37% of files
and is to be measured first. The job number is not read yet (2,997
archive events carry one).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
Brian: keep an event whose time is only an estimate (no validated embedded
event record) -- never discard a measurement for want of an exact timestamp --
but it must not silently cause an overwrite, merge or dedup collision.
insert_events, for timestamp_source 'estimate' (_estimate_guard):
- never restamps (moves) a row;
- if its file (a Blastware name) is already stored under another time, writes
nothing -- no second row, the stored time kept;
- if a different event already holds that second, writes nothing -- the old
upsert would have written this event over that one;
- otherwise stores it, or refreshes its own row at the same second, as before.
Each refusal is a WARNING naming both sides; the file and sidecar (which says
'estimate' and carries the decode problem) are already in the store. A generic
upload name ('imported.bw') is not taken as identity.
Tests: each rule, an estimate on a free second kept, generic names, and an
import end to end (a corrupted record next to a different event's second).
3 mutants, each caught. Suite vs clean origin/dev: the same 16 failing tests,
failure reasons byte-identical; 582 passed vs 553.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
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
Brings fix/waveform-time-restamp (847900b, abb671a, 3948dc1): insert_events
restamps a re-stored event's row by its Blastware filename; a paired report's
ISO-dated event time is read and survives a backfill; a waveform's time comes
from its filename. Deploy rehearsal on prod's 2026-09-30 snapshot (11,827
files): waveforms 1,016 -> 1,394 of 1,394 on Blastware's exact time, every id
kept, no row lost or merged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
The review of this branch measured (and I re-measured) that the binary's
trigger -- ts2 minus the record time, from 1e76d08 -- is a second off on 260 of
prod's 1,394 waveforms (2026-09-30 snapshot): 199 late, 61 early. A Blastware
filename encodes Blastware's own time to the second: it equals the report's
Event Time on 81/81 prod and 1,249/1,249 DL2 report-paired waveforms.
The cost of the second was real, not cosmetic:
- events is unique on (serial, timestamp), and on BE9558 the 61 early
waveforms land on their histogram twin's second -- a fresh import wrote each
waveform over its histogram's row (888 files -> 827 rows on dev);
- the release backfill would have moved 161 prod rows that v0.31.0 already had
exactly right a second off.
Same-second collisions across all 11,827 prod-snapshot files: 61 with the
binary's times, 0 with waveform names. Histograms keep the binary's ts1: their
name is Blastware's start time too (13,089/13,089) and ts1 runs a second early
on 97% of them, but with both on Blastware's times a waveform and its
histogram share a second 209 times -- the key cannot hold that. Correcting
histogram times needs the key changed; not here.
- blastware_file.blastware_filename_time(): the inverse of
blastware_filename(), V10.72 'AB0' names only, None for anything else.
- read_blastware_file(path, *, name=None): a waveform takes the name's time;
save_imported_bw passes the upload's real name (it reads a temp file).
- insert_events' restamp matches only Blastware names (every unnamed upload is
'imported.bw', so two events could share it) and, of several copies, moves a
reviewed one with a time first (review items M1, M2).
Tests: the decoder (documented names, encoder round trip, other names), a
waveform's name time, a temp-named read, histograms unchanged, the twin
collision on BE9441's own ZI0 (binary 14:23:43, Blastware 14:23:42), and both
review items. 5 mutants, each caught. Suite: only the 16 known failures.
Codec-library change: TOOL_VERSION to be bumped at release. No schema change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
Measured 2026-10-26. A sub-minute histogram block is [00][segment][ctr LE][0a]
(5 bytes), then one record per interval of BIG-endian peak / half-period pairs
per channel, then 0000 and one more word, then a 7-byte trailer. A record is 20
bytes with the mic and 16 without (4 x channels + 4); the standard 32-byte block
is the same thing holding one record. The last block is short, not padded: it
holds only the intervals recorded and ends on 9c 06 00 42.
#47: a mic-off histogram (16-byte records) decoded to nothing, so a Blastware
import carried no histogram data and SFM's download check would refuse it.
BE9441's K441LTOK.QZ0 (2 s, 22 intervals; fixture) now matches its Blastware
export on 66/66 peaks and 66/66 frequencies.
#49: the old reader took the mic-on records as little-endian from byte 6 -- the
same bytes shifted by one, identical while every high byte is zero. It also
required byte 5 to be 0 (the first record's Tran peak high byte) and read the
last block at full stride, trimming what it overran.
Regression over every DL2 histogram with a Blastware ASCII export (13,089
files, interval counts + every geo peak, frequency and mic dB): old reader
13,087 exact, new 13,089. The two the old one got wrong were one interval each:
K440KZP4.560H #4764 (Long half-period 1 read as 257, mic peak 389 as 133) and
M462KZUD.6R0H #145 (mic peak 6 read as 262).
Walk: blocks follow by block_ctr + 1, or the next segment every 256 blocks; the
last block is bounded by its terminal tail; with no terminal tail the old
trimming rule remains as the fallback. Mic-off records give m_peak None and an
empty MicL channel, as a mic-off waveform does. Inferred, not yet seen in a
file: mic-off 1-minute (28-byte) and 15 s / 5 s mic-off strides.
Not fixed here, noted on #47: half_period_to_hz assumes 1024 sps (512/hp); the
2048-sps histogram's frequencies are 1024/hp.
Operational: a decoder change -- needs a TOOL_VERSION bump at release, then
backfill_sidecars.py + backfill_event_shape.py (~2 h on the NAS) to regenerate
stored histograms. No schema change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
The event-time fix makes a Blastware report's Event Time + Event Date
authoritative over the binary, which gives the trigger only to the second.
On prod's own data it never applied (measured on the 2026-09-30 store
snapshot, all 81 report-paired Series-3 waveforms):
- every one of those reports writes Event Date as ISO ('2026-08-14');
_parse_event_date read only 'August 14, 2026', so event_datetime was None
(Brian's own laptop writes the long form -- it follows the PC's settings);
- the sidecar's bw_report block never stored the event time, and
apply_bw_report_dict_to_event -- the backfill's overlay -- never set it.
The binary's trigger matched Blastware's printed time on 66 of the 81 and was
a second late on 15; 8 of those 15 hold the right time in prod today, so the
release backfill would have made them a second worse.
- _parse_event_date accepts ISO dates too (81/81 now parse to the time
Blastware printed; 0/81 before).
- _bw_report_to_dict stores event_datetime (additive key).
- apply_bw_report_dict_to_event applies it, as apply_report_to_event does.
Prod's sidecars were written by the old parser, so the deploy runs
backfill_sidecars.py with --reparse-txt to re-read the saved .TXTs.
Tests: both date forms, the round trip through the saved block, a block with
no time, and the backfill (--force --reparse-txt) on a prod-shaped row.
Suite: only the 16 known fixture failures.
Codec-library change (report parser): TOOL_VERSION to be bumped at release.
No schema or DB migration.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
The waveform event-time fix (a84a46e / 1e76d08, on dev since 2026-09-20)
changed what time a Series-3 waveform decodes to: the trigger, where v0.31.0
stamped the monitoring-session start -- hours off. events is unique on
(serial, timestamp), so re-storing an old event at its corrected time matched
nothing and inserted it a second time.
Measured 2026-10-26: files stored with v0.31.0 (prod's code), then dev's
backfill_sidecars --force -- the release's own deploy step -- gave every
waveform two rows, one at each time. N844LQHB.ZT0W (BE12844): 06:00:13 and
10:33:29, its false-trigger mark only on the wrong-time copy. A Blastware
re-forward of an old event would do the same with no backfill at all. Prod
has not run the new decoder, so it holds no duplicates yet.
insert_events now matches a row by its stored file first (serial +
blastware_filename; a Blastware name encodes the serial and the second): one
under another time is moved to the new time in place -- same id, review kept --
and the usual refresh follows. When a different stored file already holds the
corrected second, nothing moves and nothing is written; the old upsert wrote
this event's file and peaks over that other event's row. Rows with no stored
file are matched on time alone, as before.
Tests: the move (id, review, refresh), a different file, no file, the
collision, a duplicate already at the new time, and the release backfill end
to end on a v0.31.0-shaped row. Re-checked across versions: v0.31.0 import,
then this branch's backfill -- 5 real files, every row corrected in place, no
duplicates. Suite: only the 16 known fixture failures.
No schema change, no migration, no codec change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
Every idf-import .h5 converted Thor's raw geo counts with the MiniMate
body-codec scale, full_scale / _GEO_INT16_FS. A Thor count is
0.000310308 in/s (micromate.idf_file._GEO_LSB_IPS), so the float samples
disagreed with the event's own peak by a constant:
10/32768 (until 686ab6e, 2026-08-25) samples -1.65%
10/32000 (since) samples +0.71%
v0.30.0's LSB fix (726c2ce) never reached this path. It corrected the
decoder's peaks, which were already right in the DB, sidecar and h5
peak attrs. The sample arrays go through the shared .h5 writer instead.
write_event_hdf5 now takes geo_ips_per_count. save_imported_idf and
backfill_thor_events (which replays the same bridge with its own write)
both pass _GEO_LSB_IPS. MiniMate callers are unchanged.
Measured: all 8 thor-idf fixtures (4 IDFW + 4 IDFH, 24 channels) go from
max|sample| / peak = 1.00706 to 1.00000 through the real ingest path.
Operational consequence: no schema change, no migration, TOOL_VERSION
not bumped here. Existing idf-import .h5 files keep the wrong scale
until regenerated: scripts/backfill_thor_events.py (--force, or bump
TOOL_VERSION at release), then backfill_event_shape.py, because the
offset detector reads these samples. Series-3 files are unaffected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MicromateClient.get_setup() reads SUB 0x1A once and returns a MicromateSetup:
record mode, sample rate, histogram interval, pre-trigger, stop mode, record
time, auto-stop, active sensors, trigger sources, the three geophone trigger
levels, mic type and (linear) mic trigger, job number, scaled distance, and
the four notes. MEASURED FIELDS ONLY -- everything graded inferred or
unknown in the reference stays in .raw.
micromate/setup_block.py holds the decode as pure functions (no I/O), plus
crc_ok(): one checksum rule for 0x1A, 0x08 and 0x2E. A failed checksum
raises SetupChecksumError (a ProtocolError) unless verify=False; a short
block raises either way.
Two things the decoder gets right that a naive one would not:
- the mic comes from channel block 4 (the ACTIVE mic), never blocks 5/6,
which hold the stored settings of whichever mic is NOT fitted;
- distance and charge weight convert back with the unit's own 3.2808 and
2.21, so 45 lb entered on the unit reads 45.0, not 44.89.
TESTS: 69 new. 15 real fixtures (2,103 B each) -- 14 UM20147 reads from the
10-17/10-19 keypad passes, chosen so every field takes at least two values,
plus UM12947's read from Thor's 9-24 capture (other firmware line).
Expected values are what the operator read off the unit's screen, never the
decoder's own output. Fixtures force-added, per the tests/fixtures/
convention. Full suite 541 passed; the 16 pre-existing failures
(test_bw_ascii_report.py 15, test_event_file_io.py 1) are unchanged.
VERIFIED ON HARDWARE: bridges/mm_client_check.py now prints the decoded
setup; against UM20147 every line matched the unit's screen (Brian, 10-19).
Also: the scratch harness uses the library checksum and checks all three
blocks; mm_client_check's stale labels fixed (0x06 content[4:8] is the
likely monitor-log count, not "unexplained"; 11.0BD is no longer "the first
one this code has met").
No codec, store or DB change; no backfill.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
The chunk-size ceiling, measured on UM20147 with every size checked
byte-for-byte against a known-good download:
1024 / 2048 / 4096 / 8192 / 16384 -> served in full
32768 / 65535 -> SILENTLY CLAMPED to 16384
The clamp is the important part: a 32,768 B request returns 16,384 B of perfectly
good data and no error. Nothing in the response says it was truncated; the
length is the only signal.
THAT DICTATES HOW THE LOOP MUST BE WRITTEN. read_event_file() now tracks its
offset by BYTES RECEIVED rather than striding by chunk index. A fixed stride
would either fail on a clamp or skip the bytes it never collected; tracking what
actually arrived makes a clamp cost one extra request, and makes the loop
self-correcting against any short response -- precisely the failure mode that has
bitten the Series III side repeatedly.
Consequence of that change, recorded because it reverses an earlier decision: a
short chunk is NO LONGER AN ERROR. It used to raise, on the principle that a
silently short event is this codebase's recurring bug. But the device returns
short legitimately, and the real protection is the offset arithmetic plus the
final total-length check -- which still raises on a genuinely truncated event.
The test was rewritten rather than deleted, and says why.
CHUNK_SIZE = 16384. For UM20147's events: 4,796 B goes 5 requests -> 1,
30,230 B goes 30 -> 2, and 72,560 B goes 71 -> 5. Over cellular at ~0.65 s per
round trip that is ~46 s -> ~3.2 s on the large one.
Measured on one unit over USB, so THOR_CHUNK_SIZE = 1024 stays available and the
replay tests pin it -- reproducing THOR's exact traffic is one argument away, and
client.download_event()/get_event() take chunk_size for a link where large
responses are not surviving.
Full suite: 472 passed, 16 pre-existing failures unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
UM20147's event 055d4a83 downloaded at exactly its promised size over USB,
exercising the carry into params[1] on chunks 64-70. The uint32 reading was
inference for one commit; it is now evidence, and the 64 KB cap that would have
made this event unfetchable is closed.
Worth noting what the same run prices: 71 chunks x ~0.65 s is roughly 46 SECONDS
for one 72 KB histogram over cellular, against 0.2 s over USB. That is the
round-trip cost model doing real work -- the bytes are nothing, the commands are
everything. A unit holding several events this size is a multi-minute call, so
the untested single-request offset_hi = 0x10 streaming mode (which would collapse
a download to one round trip) moves up the list.
Docstrings and the protocol reference downgraded from "inference" to "confirmed"
only where the hardware actually settled it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
UM20147 holds a 72,560-byte event. chunk_params() wrote the offset as a uint16
at params[2:4], because every offset THOR was observed to send fits in two bytes
(largest 0x3400 = 13,312), which caps a download at 65,536 B -- so that event
could not have been fetched at all.
params[0:4] is demonstrably ONE 4-byte field: chunk 0 puts the 4-byte event key
there. Writing the offset as a uint32 BE in the same slot is BYTE-IDENTICAL for
every offset below 65,536, so nothing verified against THOR's 74 captured frames
changes -- the replay test still matches all of them -- and the range extends to
4 GB.
Above 64 KB this is inference and the docstring says so: the field's width is
established, the device's handling of a non-zero high byte is not.
Also newly reachable: at offset 1 MiB params[1] is 0x10, which must go out as
`10 10`. Nothing below 64 KB can produce that, so the uint32 change is what
first makes the case possible -- and an unescaped 0x10 in 5A params is the exact
bug that cost the Series III walk a release. Tested.
THIS IS THE SERIES III 64 KB PAGE-BOUNDARY BUG WEARING A DIFFERENT HAT. There,
parse_strt_end_offset() discards the key's page byte and the walk crashes once a
unit's buffer crosses 64 KB; that one is still open. The transferable lesson:
an address field whose high bytes are zero in every capture is not a narrow
field, it is an untested one. Same mistake, found twice, in code written years
apart.
Confirmed in the same run: 0x06 content[0:4] IS the event count -- UM20147 holds
5 events and reads 5, making it three for three across both firmware lines
(0->0, 6->6, 5->5). And content[4:8] is a CONSTANT, not a count: it reads 9 on
a unit with 6 events and on a unit with 5. list_events() still walks to the
sentinel; the count is worth adopting as a pre-check, not a replacement.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Step 4 of docs/micromate_client_spec.md. MicromateEventRef plus list_events(),
iter_events(), download_event(), get_event() and decode_error(). 14 new tests;
112 micromate tests total.
The load-bearing test replays THOR's captured six-event download session through
iter_events() + get_event() and asserts EVERY BYTE WE EMIT MATCHES THOR'S, in
order -- 74 frames -- while decoding all six events and cross-checking each
waveform's peak vector sum against the float the device computed itself.
Two design decisions worth recording:
1. iter_events() EXISTS BECAUSE THOR INTERLEAVES. Its captured order is
0x93 -> 1E -> 0C -> 5A*n -> 0x93 -> 1F -> 0C -> 5A*n, downloading each event
before advancing the chain. list_events() walks to the end first, which is
fine for browsing but leaves the device cursor parked past the event a later
download addresses. 0x5A is key-addressed so it very probably does not care
-- but nothing observed says either way, so the interleaved path is the one
offered for downloads, and it is the one the replay test exercises.
2. get_event(verify=True) RECOMPUTES THE PEAK VECTOR SUM from the decoded
samples and compares it against the device's own 0x0C float. Two independent
computations over the same samples, so a disagreement means our decode is
wrong. Agreement on the bench events is 0.000%. Cheap insurance in a
codebase whose decode failures have historically been silent -- unhandled
block tags shorten a channel and nothing raises. It is a decode-correctness
check, NOT a truncation detector: a channel cut after its peak still yields
the right PVS, and the docstring says so. A test corrupts a stored peak to
prove the check actually fires.
MicromateEventRef.uid is SERIAL:key, because the key alone is ambiguous across
units, and .filename generates THOR's name (<serial>_<YYYYMMDDHHMMSS>.IDFW/H)
-- returning None rather than guessing when the record type is unknown, since
read_idf_file() dispatches on exactly that suffix.
Recorded as a CANDIDATE, not used: 0x06 content[0:4] looks like the EVENT COUNT
-- 6 on a unit holding 6 events, zeros on an empty one, and THOR reads it BEFORE
the walk then downloads exactly six events without ever reading the chain
sentinel. If it holds it lets a caller decide whether to walk at all, which
over cellular is the useful part. Two samples on one unit, and content[4:8]
reads 9 unexplained, so list_events() still walks to the sentinel: slower by one
round trip and correct on evidence rather than inference.
Full suite: 465 passed, 16 pre-existing failures unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
UM20147 captured over USB with mm_client_check.py --capture, read out with
scratch/mm_frame_parse.py: 11 frames each direction, 0 bad checksums. The two
BD-specific response data sections are now verbatim fixtures; only the frame
wrapper is rebuilt, which is sound because the framing is verified 251/251
elsewhere in the same file, and the reconstruction is pinned against the
payload length the parser reported.
Every field lands where the forward-offset model says it should:
data[0] = 0x30 = 48 = 59 - 11 (CB declares 0x2C = 44; the +4 holds)
content[1] = 0x0e monitoring
content[2:10] = 30 Sep 2026 14:00:49 matches the wall clock
content[34:36] = 3.50 V
content[36:44] = 15,000,000 total / 14,848,448 free
AND THE WARNING IS NOW DEMONSTRATED ON THE UNIT IT PREDICTED. Series III reads
battery from data[-10:-8], which on this block is e1 c0 -> 577.92 V. That is
the exact figure the A/B section named, and there is now a test asserting it,
so the reason the offsets are forward cannot be quietly refactored away.
Two corrections to the reference:
1. The four extra BD bytes are `0f a0 00 04`, not `0f a0 00 00`. Only the
first two look fixed. Nothing reads them, but the last is not padding.
2. POLL content[3] VARIES BETWEEN UNITS -- 0x50 on UM12947, 0x56 on UM20147.
It is printable in both cases ("P" and "V"), which is a second, independent
reason the POLL block cannot be parsed by scanning for printable runs: a
scan returns "PInstantel" on one unit and "VInstantel" on the other. The
fixed offset content[4] was the right call for a reason I had not seen.
The model string sits at content[26] on both firmware lines; only its tail
differs, so anchoring on "MM/" remains correct.
98 micromate tests pass. Full suite unchanged at 16 pre-existing failures.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
UM20147 read over USB by mm_client_check.py. The Thor firmware line was
entirely inference until now, and two of its three differences were covered
only by SYNTHESISED test frames. All three held:
- flags = 0x03 identifies the line -> reported firmware_line="thor". That is
only reachable if `10 03` in the flags position destuffs before indexing,
since 0x03 is ETX -- so the escaped-flags case is confirmed too.
- the model string is shorter -> reported "MM/ISEE/S" exactly. Anchoring the
search on b"MM/" rather than a fixed span is what made this work.
- the 0x1C block is 4 bytes longer with the extras TRAILING, so from-the-start
offsets survive -> battery 3.55 V and a clock correct to the second.
That last one is the one that mattered. Series III's from-the-end offsets
would have given this unit 577.92 V, which is why mm_client_check watches for
an impossible voltage: it is a free self-check on exactly the inference most
likely to be wrong.
Also clean: serial UM20147, 5 setups (factory.MMB -> test2.mmb), active setup
test2.mmb, 15,000,000 B total and free, 21 reads / 2,165 B in.
"One protocol stack drives the whole fleet regardless of firmware line" -- the
headline finding of 2026-09-23 -- is now demonstrated by a working client
rather than by matching response SUBs.
Test and docstring claims downgraded from inference to confirmed where the
hardware settled them, and left as synthesised-frame notes where it did not:
the BEHAVIOUR is confirmed but raw BD bytes are still not in the repo.
Added --capture DIR to mm_client_check: writes a raw_bw_*/raw_s3_* pair in the
layout scratch/mm_frame_parse.py already reads, so a run on an unfamiliar unit
becomes a test fixture without setting up a relay. Verified by round-tripping
its own output through that parser: 28 frames, 0 bad checksums.
Still not covered: a download from a BD unit (UM20147 had no events stored, so
the chunk walk remains CB-only), raw BD fixture bytes, a monitoring unit, a
nearly-full buffer, and the inbound call-home session.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Step 3 of docs/micromate_client_spec.md: micromate/client.py, two models in
micromate/models.py, 26 offline tests. Every response constant in the tests
is a real captured data section from UM12947.
Field offsets were measured rather than taken from the spec, which turned up
one general rule and one trap:
THE RESPONSE SHAPE. Every response carries an 11-byte prefix and content
starts at data[11]. One rule, every command.
THE TRAP: data[0] is the content length & 0xFF, with no high byte anywhere in
the prefix. It is therefore correct for every response under 256 bytes --
most of them -- and then reports 44 for a 2,092-byte setup block, 30 for a
286-byte monitor-log record, and 0 for a 1,024-byte download chunk. 182 of
251 captured responses agree with a naive read; the 69 that disagree are
exactly the ones >= 256 bytes.
That is the third length in this protocol read too narrow, after
payload[9]-vs-payload[8:10] in the probe response. The client takes content
as data[11:] and lets the frame's own length bound it -- nothing needs the
declared length, since the frame already knows how long it is.
Also measured:
- POLL content[3] is 0x50, printable as "P", immediately before "Instantel".
A generic printable-run scan therefore returns "PInstantel" -- it caught a
test, not a unit. Vendor comes from a fixed offset; the model is found by
searching for "MM/", which is structural rather than positional and so
survives the Thor line's shorter "MM/ISEE/S".
- The setup walk terminates on an EMPTY NAME, not an error: 23 responses, 22
names, factory.MMB first through TEST1.mmb last.
- The 0x1C clock has an unidentified byte at content[6]; the hour is at
content[7]. The protocol reference's 0x1C section already had this right
and names the byte -- its one-line summary in the divergences list reads as
six contiguous fields and is the version not to trust. Re-verified against
three captures: 19:12:25, 19:13:34 and 01:14:05 against filenames stamped
19:12:14, 19:12:14 and 01:14:03.
- Battery and memory are read FORWARD from content start, never backward from
the end. This block is 4 bytes longer on the Thor line; the Series III
from-the-end offsets give a 11.0BD unit 577.92 V. A test appends the four
trailing bytes and asserts the forward offsets survive.
connect() is narrower than the spec asked. The spec said to mirror Thor's
POLL -> SERIAL -> 0x49 -> POLL "because it is known-good"; measurement showed
that is Thor's connection check (3 of 8 sessions) and its fourth frame repeats
its first. So connect() sends the three reads that gather something, and
0x01 is not read at all -- Thor never reads it, its layout is unmapped, and
firmware_line comes free from any response's flags byte. If a unit ever
refuses the next command after a cold connect, put the fourth POLL back and
record it.
A dead clock battery yields device_time=None rather than failing the whole
state read; an unreadable active setup yields active_setup=None rather than
failing connect. Both are real device states.
Still verified only against 11.0CB and only over USB. The BD offsets follow
from the extra bytes being trailing, which is documented but not something
this code has seen.
Full suite unchanged at 16 pre-existing failures; 445 passed, up 26.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Step 2 of docs/micromate_client_spec.md: micromate/protocol.py plus 35
offline tests. Reads only; nothing here writes, erases or changes
monitoring state.
The tests replay Thor's captured responses through a scripted transport and
assert the bytes we emit are the bytes Thor emits -- including a full replay
of the six-event download session, all 56 0x5A frames byte-for-byte. A
passing test therefore means a real unit has already answered exactly that
frame.
Measuring the spec's command table against the captures found three more
errors in it, on top of the three the framing work found:
1. SUB 0x0A is the MONITOR-LOG WALK, not a keyed "event header, 30 B list
record" read. The same request repeated returns successive 297-byte
records -- serial, mode, thresholds -- until an 11-byte ack ends the
list. The device holds the cursor; nothing in the request selects a
record, and all nine captured frames carry identical params.
Structural divergence worth noting: Series III reaches the same data via
a record-type discriminator on its event chain, so partials and events
share one walk. Here the monitor log has its own cursor and the event
chain never sees it.
2. 0x1E/0x1F carry token 0xFE at params[7]. The protocol reference
documents all-zero params -- that was our own browse probing, which also
worked. Thor sends 0xFE on browse and download alike.
3. SUB 0x01 (device info) is never read by Thor in any captured session.
Its 0xFFFF offset comes from our own probes, so it is the one read in
the table with no Thor precedent. Flagged in the docstring.
Two useful negatives, both from absence rather than presence:
- No SESSION_RESET (41 03). Series III needs that 2-byte signal or a
monitoring unit will not answer POLL over TCP. Zero occurrences across
all 8 sessions, including 40 frames exchanged with a unit that WAS
monitoring.
- No universal preamble. The only invariant is that a session opens with
POLL; POLL -> SERIAL -> 0x49 -> POLL is Thor's connection check and
appears in 3 of 8 sessions. Setup pushes and scheduler reads open
differently.
Two deliberate divergences from the Series III sibling:
- strict_checksums defaults True and RAISES. minimateplus logs and
continues because its parser cannot always tell an inner-frame delimiter
from a checksum byte; that does not apply here, where the rule is exact
on 251/251 frames. The lenient default is instructive -- it hid a wrong
checksum rule for two days.
- read_event_file() raises ShortRead rather than returning a truncated
event. The expected length is known up front, so the check is free, and
a silently short event is the failure mode this codebase keeps hitting.
Every exchange resets the parser before sending, so a leftover frame is
discarded rather than answered with -- expected_sub catches a mismatched
SUB, but a same-SUB leftover would sail through with data for the wrong key.
File transfer (0x94/0x48) is deliberately out of scope: it needs a
data-carrying request frame, which is the frame type writes use, and that
boundary is worth keeping crisp in a read-only pass.
Full suite unchanged at 16 pre-existing failures (missing gitignored
fixtures); 419 passed, up 35.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Step 1 of docs/micromate_client_spec.md: micromate/framing.py plus 31
offline tests. Every rule was checked against the captures BEFORE being
written, which is the only reason this commit is not a bug.
Three things the spec asserted are wrong, all of which fail silently:
1. Requests are NOT plain Series III frames. A Micromate escapes four
byte values -- 0x02 0x03 0x04 0x10 -- where Series III escapes one.
minimateplus.build_bw_frame reproduces 161 of Thor's 218 captured read
frames; build_request() reproduces 218/218. The 57 it missed include
EVERY 0x5A download (offset 0x0400 puts a literal 0x04 in offset_hi)
and the scheduler enable. An unescaped 0x03/0x04 terminates the frame,
so the unit never answers -- indistinguishable from a dead unit, and
event download would have hit it on the first request ever sent.
2. The checksum is plain SUM8 of the destuffed payload, not the DLE-aware
variant. 251/251 both directions. The DLE-aware form is correct
paired with Series III destuffing, which leaves an escaped byte as two
bytes; after uniform destuffing it subtracts the correction twice and
disagrees with the wire on 55 of 251 responses.
scratch/mm_frame_parse.py shipped with exactly that pairing and looked
clean only because it accepts either rule -- so it labelled those 55
"SUM8" and never flagged one bad. "Zero bad checksums" was true and
carried no information. A tool that tries N candidate rules cannot
falsify any of them. Fixed to validate against SUM8 alone.
3. SUB 0x5A is a 1024-byte chunk loop, not one request per event. Thor's
form, verified on all six bench events (4,076 -> 13,424 B): chunks =
ceil(size/1024), offset = min(1024, size - 1024*i) as a byte count,
params[2:4] = the byte offset, response data = offset + 11.
sum(offsets) == size exactly, every time.
This does not retract the earlier single-request observation -- that
used offset_hi = 0x10, which in Series III is the bulk-stream marker,
so it is plausibly a distinct streaming mode returning several frames.
Those captures never landed in the repo, so it cannot be re-derived.
Implement Thor's form; the other is worth one bench test.
Also: a 0x10 inside request params needs no special handling (settled --
Thor sends it, the wire doubles it), so the planned NotImplementedError
guard is gone. declared_length -> probe_length, because it is only
meaningful in a probe reply and Thor never probes.
Synthesised test frames are marked and each says what it stands in for.
The flags=0x03 case is the only coverage of the Thor firmware line -- it
wants a real 11.0BD capture next time UM20147 is on a bench.
No writes. Read-path framing only; nothing here can originate a command.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Follow-up to the ts1→ts2 fix: get the trigger to the second from the binary
alone, instead of falling back to the stop time (~record-duration late) for
no-report events.
The configured post-trigger record time is a big-endian float32 in the
recording-setup config block, exactly 30 bytes before the "Standard Recording
Setup" marker. _parse_record_time_seconds reads it; the waveform branch now
stamps trigger = ts2 - record_time. Verified: the field reads 1.0 / 2.0 / 3.0 s
across different setups in the corpus, and all 7 BE12844 oracle events now
decode to their exact Blastware trigger (N844LQHB 10:33:29) from the binary,
no paired .TXT needed. Falls back to ts2 (the stop) if the config block is
absent. A paired report's event_datetime stays authoritative (clock drift).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
read_blastware_file built ev.timestamp from footer ts1, which for a WAVEFORM is
the monitoring-session start (a unit arming at 06:00 stamps 06:00 on every event
that day) — so every waveform's time was hours off (vomit-list #3, "~4.5 h off").
The event time is footer ts2 (the recording stop); BW's displayed Date/Time is
the trigger = ts2 - record duration.
Root cause proven against the BE12844 oracle set: 5 of 7 events decoded to the
identical 06:00:13 (the shared session start); ts2 gives distinct plausible
event times (N844LQHB ts2 = 10:33:32, BW trigger 10:33:29 = ts2 - 3.0 s rectime).
* read_blastware_file now uses ts2 for waveforms (discriminated by which codec
decoded the body, not the filename — save_imported_bw passes a tmp name).
Histograms keep ts1 (the ~24 h window start, which IS the event time).
* Binary-only decode can't get the exact trigger: the STRT record-time byte is
a misparsed record-type marker (0x46=70), so ts2 (the stop, ~record duration
after the trigger) is the best estimate. A paired BW report carries the exact
trigger — apply_report_to_event now overlays event.timestamp from
report.event_datetime, matching the existing build-path override (line ~441).
Tests: waveform → ts2, histogram → ts1 unchanged, report → exact trigger.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
Make the sensor self-check a first-class part of the standardized decoded event
so SFM stops decoding it at report time — device-agnostic, per the store's
decoder→standardized-.h5→SFM model.
* Event gains a `sensor_check` field; both decoders attach the traces where
they set raw_samples — series-3 in event_file_io.read_blastware_file
(minimateplus.sensor_check), series-4 in waveform_store's IDF path
(micromate.sensor_check). Covers ingest and backfill (both re-decode).
* event_hdf5 bumps schema_version 1→2 and writes an optional /sensor_check
group (raw counts, int32, per channel present). read_event_hdf5 returns
it; plot_json_from_hdf5 carries it as a top-level key. Old v1 files still
read cleanly (no group → None), so nothing breaks before the backfill.
* gather_report_data reads sensor_check_waveforms from the .h5 and drops the
report-time series-3 decode — the report no longer reaches into a decoder,
and a series-4 event now lights up the same strip automatically.
Stored as raw counts (a shape diagnostic, rendered fit-to-box): the per-series
count scale differs and a physical mic unit is ill-defined, so conversion would
add complexity for no display benefit — easy to add later if a numeric use
appears.
Tests: .h5 roundtrip + backward-compat + plot_json + real series-3 decode
attaches to the Event.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
The Thor/Micromate (series-4) IDFW binary carries the sensor self-check in its
fixed-header region (before the waveform body), as up to four records tagged
01 0e 3c/3d/3e/3f — the SAME channel ids as series-3 (Tran/Vert/Long/MicL).
Unlike series-3's delta-coded trailing block, series-4 stores each trace as a
raw int16-BE array after an 18-byte record header (2-byte sample count at
offset +8). Three-channel (mic-disabled) units carry only 3c/3d/3e.
New micromate/sensor_check.py: decode_idf_sensor_check(raw) locates the record
chain (id-ordered marker run, so a stray body match can't chain) and reads each
trace's int16 samples → {Tran,Vert,Long[,MicL]: [counts]}, or {} when absent.
Reverse-engineered + validated against 4 UM oracle events (added as fixtures):
clean geophone ring-downs on all, mic pulse trains on the 4-channel units,
correctly no MicL on the two 3-channel units. Validated by shape + cross-event
consistency (no Thor report strip to exact-match, unlike series-3's BW reports).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
The Blastware Event Report draws a "Sensor Check" strip on the right of the
waveform panel — the little traces the unit records when it pulses each sensor
before monitoring. Those live in the series-3 binary's trailing block, after
the main waveform record-chain and the per-channel calibration records, as four
length-prefixed records tagged 0x3c-0x3f (Tran/Vert/Long geophone ring-downs +
MicL pulse train). Reverse-engineered against 7 BE12844 oracle events.
New minimateplus/sensor_check.py: decode_sensor_check(raw) locates the record
chain (validated by walking the ids 0x3c->0x3f via their length prefixes) and
decodes each record's delta stream (payload[20:len-8]) with the same 10/20/30/00
delta-block tags as the main waveform codec, from an anchor of 0. Returns
{Tran,Vert,Long,MicL: [samples]} in raw 16-count units, or {} when absent.
Validated: mic pulse-train zero-crossing frequency = 20.1 Hz (exact match to
BW's mic Channel Test freq); geophone ring-downs are consistent ~-990 raw
deflections that damp to a ~-310 settle across all 7 events (a fixed
calibration pulse, so near-identical every run).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
sfm/compliance.py renders the velocity-vs-frequency blasting compliance chart
Blastware draws on its Event Report:
- limit_at()/limit_curve() — the RI8507 Fig B-1 / 30 CFR 816.67 curve as data
(Drywall 0.75 + plaster 0.50 lines): 0.030in low-freq bound, plateau, 0.008in
rising diagonal to a 2.0 in/s cap at ~40 Hz, drawn continuous.
- channel_compliance_points() — the per-cycle (freq, peak-velocity) scatter by
the zero-crossing method (matches Blastware; cloud ceiling = channel PPV).
- draw_compliance_chart() — matplotlib rendering (both lines + scatter, BW tick
scales + channel markers).
Verified against 7 BE12844 Blastware reports. docs/ri8507_compliance_curve.md
captures the curve construction, the SHM basis, and the scatter method.
Not yet wired into report_pdf.py — that placeholder is the next step.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
channel_spectrum(samples, sps) → the single-sided amplitude spectrum Blastware's
FFT Report draws, and dominant_frequency() picks its peak in the 2–250 Hz band.
Reverse-engineered against 7 BE12844 (MiniMate Plus) events with Blastware FFT
reports as ground truth. Recipe: DC-remove, NO window (a window smears the peak
and worsens the match), zero-pad to 4096 (→ 0.25 Hz bins at 1024 sps — the
resolution every reported dominant frequency lands on), single-sided 2/N
amplitude. Reproduces Blastware's dominant frequency to the exact bin on all
28 channels and the amplitude to report precision.
This is the missing piece for both the USBM RI8507 compliance chart (its scatter
is these (freq, amp) points vs the limit curve) and the FFT view.
Pure numpy, series-agnostic (feed it in/s samples from either decoder). The 7
events land in tests/fixtures as the oracle (force-added past the fixtures
gitignore, matching 5-11-26 / decode-re-5-8-26).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
annotate_blastware_binary(raw) → a gap-free tiling of labelled Spans
(header / STRT / per-channel sample records / footer / unknown) for a hex
viewer to paint. Every byte is covered; anything the decoder can't account
for is a first-class `unknown` span, so undecoded regions stand out.
Composes the existing waveform_codec.walk_records over the body between the
STRT record and the 26-byte footer. On the cracking fixtures this already
surfaces a ~1700-byte undecoded trailing region (stream-end marker + serial +
…) per file — a candidate home for stored spectral/FFT data.
TDD: tests assert the spans tile the whole file, STRT is located, the geo
sample records are labelled, and the footer is last.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
data_block_len() rejected any `40 NN` block with NN > 0x08. That guard had
no evidence behind it: every corpus available when it was written used only
NN in {1,2,3,4,8}, so it was never exercised. Loud UM12947 events use NN of
12, 16, 20 ... up to 196.
Because walk_body/run stop at the first unrecognised tag rather than
raising, rejecting those blocks surfaced as silently short channels -- e.g.
Tran 1812 / Vert 2132 / Long 2324 on a file whose export carries 2324 for
all three. The real bound is the buffer; the caller additionally clamps to
the record end.
Verified against Thor's own CSV exports for UM12947 (2025-07-14 .. 09-25,
167 waveforms, supplied as CSV.zip):
length mismatches 22 -> 0
per-sample exact 1,476,242 / 1,476,249
These are NOT truncated recordings, which was the competing hypothesis --
the exports carry the full sample count.
tests/test_waveform_codec.py asserted the cap as intended behaviour. That
assertion encoded an assumption, not a verified fact, and is replaced with
one pinning the opposite plus the evidence.
Across all three ground-truth corpora: 459 waveform files,
3,807,158 / 3,807,165 samples exact. Production IDFW is now 575/575 with
zero truncations and zero decode failures (median PPV error -0.0007% across
8 units). Series-3 re-verified unchanged at 14,338/14,338.
The 7 residual samples each differ by one 4th-decimal tick and are Thor's
own rounding: intersecting the per-sample rounding constraints over that
corpus is infeasible (binding pair contradict by 2.3e-11, 7e-5 relative),
so no single linear LSB reproduces every printed value. _GEO_LSB_IPS is
already pinned to ~1e-11; do not retune it to chase these.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Verified against a second Thor corpus (9-10-26-csv-req: UM11402, UM12947,
UM20147) with per-sample CSV exports: 139/139 waveforms exact
(1,273,380/1,273,380 samples) and 877/877 histograms within 2% of Thor's
reported PPV -- up from 66.9% and 56.6%.
Some units run with the microphone disabled, which changes two structural
things that were both hardcoded to the 4-channel shape:
- Waveform body head sat below the scan floor. A 3-channel unit has a
shorter fixed header and puts its record chain head at 0x0dba, under the
old _BODY_SCAN_FLOOR of 0x0E00. The scan could not see it and fell
through to the Vert segment-0 record, decoding a body shifted one
position around the channel rotation -- Vert came up exactly 512 samples
short. Floor lowered to 0x0C00. The body-offset scoring also had to stop
requiring four channels, or `equal` is permanently False for these events
and the pick falls back to raw sample count.
- Histogram interval record is 56 bytes, not 72. It is
16 * n_channels + 8, and is not inferable from the segment length alone.
The interval count now comes from the segment's cumulative counter
(n = counter - prev_counter) and the stride is derived from it. Assuming
72 read 7 intervals out of every 10-interval segment, then walked off
alignment into garbage that decoded as ~10 in/s peaks -- inflating some
files' PPV by up to 191,000%. Also recovers 4 files that previously
decoded no intervals at all.
Combined across both corpora: 292/292 waveform files,
2,330,916/2,330,916 samples exact. Production IDFW truncations 41 -> 22.
Series-3 unaffected (no shared-codec change in this commit; last full run
14,338/14,338).
Known open, diagnosed but NOT verified: the remaining 22 unequal + 1 failing
production IDFW files (all UM12947, 2025-07-14..09-23) stop the block walker
on tag 40 0c. data_block_len() caps the 40 NN int16 block at NN > 0x08 while
those files use NN up to 196. Both verified corpora only ever use
NN in {1,2,3,4,8}, so the cap is untested there and lifting it leaves both at
100.000% -- which is not evidence it decodes these correctly. Deliberately
not shipped; needs Thor CSV exports for UM12947 in that date range.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
Verified against Thor's own CSV exports, which carry a per-sample
four-column block beside every binary (CSV/<name>.IDFW.csv). Those 1,012
paired files were in the corpus all along; the decoder had been pinned to
a superseded walker on the stated grounds that "Thor has no ASCII ground
truth in the corpus and its geo scaling is separately suspect". Both
premises were false.
IDFW per-sample exact 39.1% -> 100.000% (1,057,536/1,057,536)
IDFW files fully exact 0/153 -> 153/153
IDFW PPV median error -3.32% -> -0.002%
IDFH within 2% of Thor PPV 51.1% -> 100.0% (858/858)
prod IDFW, 8 units -3.3% -> -0.001%
Four independent root causes:
- Geo LSB was 0.0003, the 4-dp *display rounding* of the real
0.000310308 mistaken for the LSB, so every series-4 geophone sample
read 3.3% low. Pinned to +-6e-11 by intersecting 991,415 rounding
constraints; corroborated by the +-full-scale seed (+-32226) left in
unwritten IDFH slots. IDFH had a separate, also wrong, 10.0/32768.
- IDFH histograms were capped at 250 intervals: the segment validator
required the interval counter's high byte to be zero, but the counter
is a uint16 cumulative index, so every segment past interval 255 was
rejected. Runs over ~4 hours lost their tail, often the peak.
540/858 corpus files affected.
- Record mode 00 00 (raw int16, 10-byte header) was unhandled and fell
through the dispatch, silently dropping each channel's first 512
samples -- the long-standing "loud events truncate" symptom.
MODE_ABSOLUTE is now also accepted as a segment-0 preamble.
- The body-offset search matched 00 02 00 *inside* record headers,
selecting a candidate part-way down the chain and decoding a
rotation-shifted body. It now anchors on record headers and takes the
chain head (6 ms/file).
Also fixes the separately tracked "UM-series decodes ~1000x low" bug.
Series-3 re-verified unchanged at 14,338/14,338 exact after the shared
waveform_codec change.
Known open: 41/575 prod IDFW files (7%, mostly UM12947/UM20147) decode
with unequal channel lengths and also fail metadata extraction -- a
different header variant with no Thor export in the store.
NOTE: this is a codec change; the Thor store owes a regeneration via
scripts/backfill_thor_events.py.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL