Files
seismo-relay/tests/test_decode_check.py
T
serversdownandClaude Opus 5.5 ff7dd908a7 feat(codec): carve-outs for proven Blastware differences -- saturation first
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
2026-10-29 19:27:01 -04:00

126 lines
5.3 KiB
Python

"""
The decode checker's SFM side and comparison (decode checker, Tasks 2-4).
Expected values come from the fixtures' Blastware XML reports. SFM's side is
built from the event bytes alone -- no filename, no report.
"""
from __future__ import annotations
from pathlib import Path
import pytest
from minimateplus.decode_check import sfm_side
FIX = Path(__file__).parent / "fixtures/decode-checker-10-29-26"
def test_waveform_side_from_bytes():
s = sfm_side((FIX / "R352HIUI.F40W").read_bytes())
assert s.values["SampleRate"] == 1024 and s.values["RecordTime"] == pytest.approx(1.0)
assert s.values["Pre-triggerLength"] == pytest.approx(-253 / 1024)
assert (s.values["EventDate"], s.values["EventTime"]) == ("2018-07-30", "16:13:52")
assert s.notes == ["JV 241 - 1425 Spanlers Mill Rad", "Walsh Granite JV",
"Terra-Mechanics Inc- D. Harrison", "Loc #1 - 1425 Spanlers Mill Rd"]
assert len(s.counts["Tran"]) == 1277 and s.job_number is None
def test_histogram_interval_peak_in_counts():
s = sfm_side((FIX / "M529L4XQ.R30H").read_bytes())
# Blastware: Tran interval peak 2.430 in/s = 7776 counts at 10/32000 in/s per count
assert s.counts["Tran"] == [7776] and s.values["NumberofIntervals"] == 1
def test_no_filename_reaches_the_decoder():
# The type must come from the bytes; today they can't tell it (#41), so this
# histogram reads as a waveform. Update to "Full Histogram" when #41 lands.
s = sfm_side((FIX / "M529L4XQ.R30H").read_bytes())
assert s.values["EventType"] == "Full Waveform"
def test_report_fields_stay_blank():
s = sfm_side((FIX / "T1905KDW.5F0W").read_bytes())
for tag in ("TranZCFreq", "TranPeakAcceleration", "BatteryLevel", "Calibration", "TranTestResults"):
assert s.values.get(tag) is None
# ── Task 3: the comparison ──────────────────────────────────────────────────
from minimateplus.bw_xml_report import parse_xml_report_file # noqa: E402
from minimateplus.decode_check import compare, matches_printed # noqa: E402
def _results(stem, carveouts=()):
raw = (FIX / stem).read_bytes()
ref = parse_xml_report_file(FIX / (stem.replace(".", "_") + "_XML.XML"))
return {r.field: r for r in compare(sfm_side(raw), ref, carveouts)}
def test_matches_printed_rounds_half_away():
assert matches_printed(-0.0625, "-0.063") and matches_printed(0.0015, "0.002")
assert not matches_printed(0.0026, "0.002")
def test_full_waveform_row_verdicts():
res = _results("R352HIUI.F40W")
for f in ("SampleRate", "RecordTime", "Pre-triggerLength", "EventDate", "EventTime",
"notes", "samples.Tran", "samples.Vert", "samples.Long"):
assert res[f].verdict == "match", (f, res[f])
assert res["TranZCFreq"].verdict in ("sfm_blank", "no_reference")
assert res["BatteryLevel"].verdict == "sfm_blank"
assert "FileName" not in res
def test_ragged_rows_match_by_running_channels():
# Tran/Vert/MicL end 3 samples before Long, in SFM and in Blastware's table alike
res = _results("T438HGTZ.B30W")
for ch in ("Tran", "Vert", "Long"):
assert res[f"samples.{ch}"].verdict == "match", res[f"samples.{ch}"]
def test_an_extra_reference_row_is_a_mismatch_with_detail():
raw = (FIX / "T1905KDW.5F0W").read_bytes()
ref = parse_xml_report_file(FIX / "T1905KDW_5F0W_XML.XML")
ref.sample_rows.append(["0.000", "0.000", "0.000", "0.000"])
res = {r.field: r for r in compare(sfm_side(raw), ref)}
assert res["samples.Tran"].verdict == "mismatch"
assert "row_length_disagreements=1" in res["samples.Tran"].detail
def test_job_number_na_and_above_range():
res = _results("T1905KDW.5F0W")
assert res["JobNumber"].verdict == "sfm_blank"
assert res["TranZCFreq"].verdict == "no_reference" # N/A
assert res["VertZCFreq"].verdict == "sfm_blank" # >100, SFM has no flag yet
def test_mic_units_pick_the_conversion():
res = _results("T004JTRF.ME0H") # psi(L)
assert res["intervals.MicL Peak dB(L)"].verdict in ("match", "mismatch")
assert res["intervals.Tran Freq Hz"].verdict == "sfm_blank"
fields = set(_results("R352HFZ7.530H")) # no mic
assert not any(f.startswith(("samples.MicL", "intervals.MicL")) for f in fields)
# ── Task 4: carve-outs ──────────────────────────────────────────────────────
from minimateplus.decode_check_carveouts import CARVEOUTS # noqa: E402
def test_clipped_normal_range_is_accepted():
# Blastware: Tran 5.445, Vert 6.310, Long OORANGE, PVS OORANGE; SFM Long 10.005, PVS 11.55
res = _results("T438HGTZ.B30W", CARVEOUTS)
assert res["TranPPV"].verdict == "match" and res["VertPPV"].verdict == "match"
for f in ("LongPPV", "PeakVectorSum"):
assert (res[f].verdict, res[f].carveout) == ("accepted", "saturation")
def test_sensitive_range_8x_stays_a_mismatch():
res = _results("M007HVWF.K30W", CARVEOUTS)
assert res["TranPPV"].verdict == "mismatch" and res["samples.Tran"].verdict == "mismatch"
assert res["PeakVectorSum"].verdict == "mismatch"
def test_every_carveout_has_evidence():
assert all(c.id and c.fields and len(c.evidence) > 40 for c in CARVEOUTS)