feat(decode): over range inside a histogram's intervals, as in the event
Inside an interval the rule is the event's: a peak past 2,000 units (the mic in counts) is Blastware's OORANGE, and the interval's vector sum is OORANGE when any geophone is. DL2 (2026-11-09): numeric up to 1,846 (geophones) / 1,414 (mic), OORANGE from 2,001; vector sums 16 / 16 OORANGE with a geophone over, 2,862 / 2,862 numeric without. event_file_io.over_full_scale(count, channel); the checker renders those interval cells as OORANGE. The saturation carve-out compares SFM's own words properly (_differs): an OORANGE from SFM never counts as saturation, and an OORANGE equal to Blastware's is not a difference. Its interval tests run on the numeric values it used to see. 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
836c9e864b
commit
e25784d9db
4 files changed
+54
-10
No files matched your search
@@ -21,7 +21,7 @@ from typing import Callable, Optional, Sequence
|
||||
|
||||
from .bw_xml_report import XmlReport
|
||||
from .event_file_io import (interval_times, _GEO_FS_BY_RANGE, _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT,
|
||||
decode_blastware_bytes, mic_count_divisor)
|
||||
decode_blastware_bytes, mic_count_divisor, over_full_scale)
|
||||
from .histogram_codec import half_period_to_hz
|
||||
from .models import Event
|
||||
from .waveform_codec import mic_count_to_db
|
||||
@@ -189,7 +189,12 @@ def sfm_side(raw: bytes) -> SfmSide:
|
||||
for ch, hps in ev.interval_half_periods.items():
|
||||
interval_values[f"{ch} Freq Hz"] = [interval_frequency(h, ev.sample_rate) for h in hps]
|
||||
if ev.interval_pvs:
|
||||
interval_values["Geo PVS in/s"] = list(ev.interval_pvs)
|
||||
# OORANGE when any geophone passes full scale in that interval: 16 / 16
|
||||
# DL2 cells, and none of 2,862 without one (2026-11-09).
|
||||
geo = [counts[c] for c in _GEO if counts.get(c)]
|
||||
interval_values["Geo PVS in/s"] = [
|
||||
"OORANGE" if any(i < len(g) and over_full_scale(g[i], "Tran") for g in geo) else v
|
||||
for i, v in enumerate(ev.interval_pvs)]
|
||||
times = None
|
||||
n = len(counts["Tran"])
|
||||
if ev.record_type == "Histogram" and ts is not None and ev.histogram_interval_sec and n:
|
||||
@@ -352,13 +357,14 @@ def _sample_converters(sfm: SfmSide, ref: XmlReport) -> dict[str, Callable[[int]
|
||||
def _interval_converter(title: str, sfm: SfmSide) -> Optional[Callable[[int], float]]:
|
||||
"""SFM keeps each interval's peaks; it drops their frequencies and geo PVS."""
|
||||
ch, _, rest = title.partition(" ")
|
||||
# A peak past full scale is Blastware's OORANGE, in an interval as in the event.
|
||||
if rest.startswith("Peak") and ch in _GEO:
|
||||
return lambda c: c * sfm.geo_ips_per_count
|
||||
return lambda c: "OORANGE" if over_full_scale(c, ch) else c * sfm.geo_ips_per_count
|
||||
d = sfm.mic_divisor
|
||||
if ch == "MicL" and rest == "Peak dB(L)":
|
||||
return lambda c: mic_count_to_db(c / d)
|
||||
return lambda c: "OORANGE" if over_full_scale(c, ch) else mic_count_to_db(c / d)
|
||||
if ch == "MicL" and rest == "Peak psi(L)":
|
||||
return lambda c: c * _MIC_PSI_PER_COUNT / d
|
||||
return lambda c: "OORANGE" if over_full_scale(c, ch) else c * _MIC_PSI_PER_COUNT / d
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,14 @@ def _clamped(printed: str, r: float) -> bool:
|
||||
return p is not None and abs(p[0]) >= r - _TOL
|
||||
|
||||
|
||||
def _differs(v: object, cell: str) -> bool:
|
||||
"""A cell SFM disagrees with. SFM's own word (its OORANGE, since
|
||||
2026-11-09) agrees only when Blastware printed the same word."""
|
||||
if isinstance(v, str):
|
||||
return " ".join(v.split()) != " ".join(cell.split())
|
||||
return not matches_printed(v, cell)
|
||||
|
||||
|
||||
def _saturation(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool:
|
||||
try:
|
||||
r = float(ref.scalars["GeoRange"])
|
||||
@@ -76,16 +84,15 @@ def _saturation(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool:
|
||||
peaks = [cols.index(c) for c in ("Tran Peak in/s", "Vert Peak in/s", "Long Peak in/s")
|
||||
if c in cols]
|
||||
rows = ref.intervals or []
|
||||
differing = [(j, cell, v) for j, cell, v in got[0]
|
||||
if isinstance(v, str) or not matches_printed(v, cell)]
|
||||
differing = [(j, cell, v) for j, cell, v in got[0] if _differs(v, cell)]
|
||||
return bool(differing) and all(
|
||||
cell.strip() == "OORANGE" and not isinstance(v, str)
|
||||
and r - _TOL <= v <= 3 ** 0.5 * r * 1.01
|
||||
and any(_clamped(rows[j][1][p], r) for p in peaks if p < len(rows[j][1]))
|
||||
for j, cell, v in differing)
|
||||
differing = [(cell, v) for _, cell, v in got[0] if not matches_printed(v, cell)]
|
||||
differing = [(cell, v) for _, cell, v in got[0] if _differs(v, cell)]
|
||||
return bool(differing) and all(
|
||||
_clamped(cell, r) and _at_ceiling(v, r)
|
||||
not isinstance(v, str) and _clamped(cell, r) and _at_ceiling(v, r)
|
||||
and (cell.strip() == "OORANGE" or (v >= 0) == (_printed_number(cell)[0] >= 0))
|
||||
for cell, v in differing)
|
||||
|
||||
|
||||
@@ -1131,6 +1131,15 @@ _SUMMARY_CHANNEL_LEN = 21 # the payload; the record is 22 with its id
|
||||
_SUMMARY_FULL_SCALE = 2000
|
||||
|
||||
|
||||
def over_full_scale(count: int, channel: str) -> bool:
|
||||
"""Whether a decoded peak passes full scale: Blastware's OORANGE. A geophone
|
||||
count is in ADC counts (16 to the unit), the mic's in its own. The same rule
|
||||
holds inside a histogram's intervals: numeric up to 1,846 / 1,414, OORANGE
|
||||
from 2,001 (DL2, 2026-11-09)."""
|
||||
per_unit = 1 if channel == "MicL" else _HIST_GEO_COUNTS_PER_UNIT
|
||||
return abs(count) > _SUMMARY_FULL_SCALE * per_unit
|
||||
|
||||
|
||||
def _unit_summary(chain: dict[int, bytes]) -> Optional[dict]:
|
||||
"""The unit's per-channel event summary from a record chain:
|
||||
{"pvs_sample": int, "Tran": {...}, ...}, each channel {"min", "max",
|
||||
|
||||
@@ -329,7 +329,11 @@ def _pvs_oorange(unclamp=False):
|
||||
row = list(row)
|
||||
row[cols.index("Vert Peak in/s")] = "0.500"
|
||||
ref.intervals[0] = (t, row)
|
||||
res = {r.field: r for r in compare(sfm_side((hb / "T190LD5Q.LD0H").read_bytes()), ref, CARVEOUTS)}
|
||||
side = sfm_side((hb / "T190LD5Q.LD0H").read_bytes())
|
||||
# The carve-out's own path: SFM's numeric interval sums, as before it
|
||||
# rendered OORANGE itself (2026-11-09).
|
||||
side.interval_values["Geo PVS in/s"] = list(side.event.interval_pvs)
|
||||
res = {r.field: r for r in compare(side, ref, CARVEOUTS)}
|
||||
return res["intervals.Geo PVS in/s"]
|
||||
|
||||
|
||||
@@ -341,6 +345,24 @@ def test_an_oorange_interval_vector_sum_is_saturation():
|
||||
assert (r.verdict, r.carveout) == ("accepted", "saturation")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path,columns", [
|
||||
# a Vert interval past full scale: its peak and the interval's vector sum
|
||||
(FIX.parent / "histogram-intervals-11-03-26" / "T190LD5Q.LD0H", ("Vert Peak in/s", "Geo PVS in/s")),
|
||||
# a mic interval past full scale (2,001 counts)
|
||||
(FIX.parent / "over-range-11-09-26" / "K558KD43.NZ0H", ("MicL Peak dB(L)", "MicL Peak psi(L)")),
|
||||
])
|
||||
def test_interval_over_range_matches_blastware(path, columns):
|
||||
# Inside an interval the rule is the event's: a peak past 2,000 units (the
|
||||
# mic in counts) is OORANGE, and the vector sum when any geophone is. DL2:
|
||||
# numeric up to 1,846 / 1,414, OORANGE from 2,001; vector sums 16 / 16
|
||||
# OORANGE with a geophone over, 2,862 / 2,862 numeric without (2026-11-09).
|
||||
ref = parse_xml_report_file(path.with_name(path.name.replace(".", "_", 1) + "_XML.XML"))
|
||||
res = {r.field: r for r in compare(sfm_side(path.read_bytes()), ref, CARVEOUTS)}
|
||||
for c in columns:
|
||||
if c in (ref.interval_columns or []):
|
||||
assert res[f"intervals.{c}"].verdict == "match", (c, res[f"intervals.{c}"])
|
||||
|
||||
|
||||
def test_an_oorange_vector_sum_needs_a_clamped_channel_in_that_interval():
|
||||
assert _pvs_oorange(unclamp=True).verdict == "mismatch"
|
||||
|
||||
|
||||
Reference in new issue
Block a user