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

+32
View File
@@ -303,3 +303,35 @@ def test_the_h5_carries_the_job_number(tmp_path):
event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE9557")
with h5py.File(tmp_path / "e.h5", "r") as f:
assert (bool(f.attrs["job_number_enabled"]), int(f.attrs["job_number"])) == (False, 802)
# ── Histograms: the codec follows the record type, and loud short blocks ─────
_HD = "histogram-decode-11-02-26"
def test_a_histogram_body_goes_to_the_histogram_codec():
# BE9440, 2018, 5 s intervals. The waveform codec accepted this body when
# it was tried first, and returned ~5x too many "samples". Blastware's
# report: 6,976 intervals, PPV 0.180 / 0.195 / 0.215, PVS 0.270, start
# 2018-04-26 07:53:41.
ev = read_blastware_file(_FIX / _HD / "K440HDXX.XH0H")
assert ev.record_type == "Histogram"
assert len(ev.raw_samples["Tran"]) == 6976
pv = ev.peak_values
for got, want in zip((pv.tran, pv.vert, pv.long, pv.peak_vector_sum),
(0.180, 0.195, 0.215, 0.270)):
assert abs(got - want) <= 0.0005 + 1e-9, (got, want)
ts = ev.timestamp
assert (ts.year, ts.month, ts.day) == (2018, 4, 26)
@pytest.mark.parametrize("name,n", [
("T193KR5M.X90H", 9), # 2 s; its 8th interval is 5.8 in/s of vector sum
("K440HA3C.JM0H", 8), # 5 s
])
def test_a_loud_interval_does_not_hide_a_short_histogram(name, n):
# A short (one-block) sub-minute histogram is found by its record layout.
# An interval louder than 1.28 in/s has a vector sum squared above 65,535,
# which the old "first word is 0000" test rejected.
ev = read_blastware_file(_FIX / _HD / name)
assert len(ev.raw_samples["Tran"]) == n