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:
1 parent
99b6b315d6
commit
aec4a38473
12 files changed
+434
-29
No files matched your search
@@ -439,16 +439,34 @@ def _stride(rec: int, n: int) -> int:
|
||||
|
||||
|
||||
def _records_plausible(body: bytes, off: int, rec: int, m: int) -> bool:
|
||||
"""Every record's zero word is 0000 -- what tells a 16-byte layout from a
|
||||
20-byte one when both strides happen to fit (492 = 12 + 16x30 = 12 + 20x24)."""
|
||||
"""Every record's last 4 bytes are its vector sum squared, consistent with
|
||||
its channel peaks: at least the largest peak, at most sqrt(3) times it (one
|
||||
unit of rounding either way). That is what tells a 16-byte layout from a
|
||||
20-byte one when both strides happen to fit (492 = 12 + 16x30 = 12 + 20x24);
|
||||
misread, those bytes are other fields. Holds on 34,502,955 / 34,502,955 DL2
|
||||
sub-minute intervals (2026-11-02).
|
||||
|
||||
⚠ RETRACTED 2026-11-02: "every record's zero word is 0000". It is the high
|
||||
word of the PVS², non-zero on any interval above 1.28 in/s, so a short
|
||||
histogram with one loud interval was not recognised at all (T193KR5M.X90H,
|
||||
K440HA3C.JM0H decoded to nothing)."""
|
||||
z = rec - 4
|
||||
for k in range(m):
|
||||
q = off + _MULTI_HEADER_LEN + rec * k
|
||||
if q + rec > len(body) or body[q + z] or body[q + z + 1]:
|
||||
if q + rec > len(body):
|
||||
return False
|
||||
peak = max((body[q + i] << 8) | body[q + i + 1] for i in (0, 4, 8))
|
||||
if not _pvs_consistent(peak, int.from_bytes(body[q + z:q + z + 4], "big")):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _pvs_consistent(peak: int, pvs_sq: int) -> bool:
|
||||
"""A record's vector sum squared against its largest geo peak, one unit of
|
||||
rounding either way: peak <= PVS <= sqrt(3) * peak."""
|
||||
return max(peak - 1, 0) ** 2 <= pvs_sq <= 3 * (peak + 1) ** 2
|
||||
|
||||
|
||||
def detect_multi_interval_layout(body: bytes) -> Optional[Tuple[int, int]]:
|
||||
"""``(record_len, per_block)`` of a multi-interval body, or None.
|
||||
|
||||
@@ -543,8 +561,8 @@ def walk_multi_interval_blocks(body: bytes,
|
||||
recs = [_decode_record(body, off + _MULTI_HEADER_LEN + rec * k, rec, off)
|
||||
for k in range(max(m, 0))]
|
||||
for k, r in enumerate(recs):
|
||||
if (r["meta_var"][:2] != b"\x00\x00"
|
||||
or max(r["t_peak"], r["v_peak"], r["l_peak"]) > _GEO_MAX_COUNTS):
|
||||
peak = max(r["t_peak"], r["v_peak"], r["l_peak"])
|
||||
if not _pvs_consistent(peak, r["pvs_sq"]) or peak > _GEO_MAX_COUNTS:
|
||||
del recs[k:]
|
||||
break
|
||||
out.extend(recs)
|
||||
|
||||
Reference in new issue
Block a user