fix(decode): histograms go to the histogram codec, and a loud interval no longer hides a short one

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
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-02 16:20:32 -05:00
1 parent 99b6b315d6
commit aec4a38473
12 files changed
+434 -29

No files matched your search

+19 -9
View File
@@ -525,18 +525,28 @@ from minimateplus.histogram_codec import ( # noqa: E402
def _mk_multi_block(intervals, seg=0, ctr=256):
"""Build one multi-interval block from a list of 8-tuples."""
b = bytearray()
b += bytes([0x00, seg])
b += int(ctr).to_bytes(2, "little")
b += bytes([0x0A, 0x00])
"""Build one multi-interval block from a list of 8-tuples (T, Tf, V, Vf, L,
Lf, M, Mf) in the measured layout: big-endian from byte 5, each record ending
in its PVS squared -- here the largest geo peak squared, which every real
record is consistent with (34,502,955 / 34,502,955 DL2 intervals)."""
b = bytearray([0x00, seg]) + int(ctr).to_bytes(2, "little") + bytes([0x0A])
for iv in intervals:
for v in iv:
b += int(v).to_bytes(2, "big")
b += (max(iv[0], iv[2], iv[4]) ** 2).to_bytes(4, "big")
b += bytes(7)
assert len(b) == 12 + 20 * len(intervals)
return bytes(b)
def _mk_legacy_le_block(intervals, seg=0, ctr=256):
"""The retracted model's bytes: 8 x uint16 LITTLE-endian from byte 6."""
b = bytearray([0x00, seg]) + int(ctr).to_bytes(2, "little") + bytes([0x0A, 0x00])
for iv in intervals:
for v in iv:
b += int(v).to_bytes(2, "little")
b += (0).to_bytes(2, "little")
b += (5).to_bytes(2, "little")
b += (0).to_bytes(2, "little") + (5).to_bytes(2, "little")
b += bytes(6)
assert len(b) == 12 + 20 * len(intervals)
return bytes(b)
@@ -569,7 +579,7 @@ def test_multi_interval_values_are_not_little_endian_from_byte_6():
tests/test_histogram_multi_interval.py for the measured cases.
"""
ivs = [(0x0100, 1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1, 1, 1)]
body = _mk_multi_block(ivs) + _mk_multi_block(ivs, ctr=257)
body = _mk_legacy_le_block(ivs) + _mk_legacy_le_block(ivs, ctr=257)
assert walk_multi_interval_blocks(body)[0]["t_peak"] != 0x0100