Files
seismo-relay/minimateplus/decode_check_carveouts.py
T
serversdownandClaude Opus 5.5 6c2eda5f63 feat(decode): a Blastware file's identity, battery and trigger settings
Group A of the file-only decode, every field matched against every DL2
report (2026-11-03):

- Identity block before the setup name, what the live read gets from
  SUB FE: serial k-202, firmware k-147, DSP version k-138, calibration
  date k-132 + 'by' k-128, manufacturer k-94, model k-72, firmware
  minor k-193.  Event.device_info (DeviceInfo gains calibration_date /
  calibrated_by).  Serial, Version and Calibration 69,983 / 69,983.
- Battery: uint16 hundredths of a volt at k-190 (Event.battery_volts).
  69,729 exact; the other 254 are Blastware rounding half up.
- Trigger source: the two bytes between the embedded event record's
  lead and fe 80, a bitmask (0x01 Tran 0x02 Vert 0x04 Long 0x08 MicL
  0x200 Manual): 6,493 / 6,493.  Event.triggered_by.
- Trigger settings in Series IV's 0x1A layout: sources bitmask k-19,
  stop mode k-31 (0 = Fixed), each channel's float32 level at
  label+30 (geo in/s, mic psi), mic type code at MicL+4 (2 = Linear
  Weighting).  Geo level 6,447 / 6,447, mic 4,403 / 4,403; Blastware
  prints a level when its channel is a trigger source and the event
  was not Manual.  The mic level's dB uses 6895 Pa/psi (4,272 / 4,272
  against 4,271 at 6894.757).
- .h5 attrs for all of them (additive).
- Checker: SFM's side reports the ten fields; the mic trigger level
  follows the report's dB/psi.  Carve-out
  units-is-a-display-preference: dB or psi is Blastware's PC setting
  when it wrote the report -- DL2's reports switch fleet-wide in 61
  clean runs by write time, and no byte of the file separates them.
  Two tests that pinned BatteryLevel / Calibration as blank now pin the
  match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
2026-11-03 13:38:39 -05:00

131 lines
5.6 KiB
Python

"""
minimateplus/decode_check_carveouts.py — the proven ways Blastware's report
differs from the instrument's data.
Every disagreement between SFM and Blastware is SFM's bug until shown otherwise.
A carve-out is that showing: the fields it covers, the rule it applies, and
evidence that does not rest on SFM's own output -- Blastware contradicting
itself, the instrument's own data, a third source, or Instantel documentation.
`compare` turns a covered mismatch into `accepted` only when the rule holds,
and every run counts the events each carve-out covers.
Pure: no I/O, and no import from `sfm/`.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Callable
from .bw_xml_report import XmlReport
from .decode_check import FieldResult, SfmSide, _printed_number, series_pairs, matches_printed
@dataclass(frozen=True)
class Carveout:
id: str
fields: tuple[str, ...] # exact names, or prefixes ending in "."
evidence: str
applies: Callable[[SfmSide, XmlReport, FieldResult], bool]
_TOL = 0.0006
def _at_ceiling(value: float, r: float) -> bool:
"""SFM's value sits at the range ceiling: a decoder unit or two past nominal
full scale is the clipped count itself (32016 = 10.005 in/s). An 8x
Sensitive-range value is far above the band and does not qualify."""
return r - _TOL <= abs(value) <= r * 1.01
def _clamped(printed: str, r: float) -> bool:
if printed.strip() == "OORANGE":
return True
p = _printed_number(printed)
return p is not None and abs(p[0]) >= r - _TOL
def _saturation(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool:
try:
r = float(ref.scalars["GeoRange"])
except (KeyError, ValueError):
return False
if res.field in ("TranPPV", "VertPPV", "LongPPV"):
v = sfm.values.get(res.field)
return v is not None and _clamped(res.bw or "", r) and _at_ceiling(float(v), r)
if res.field == "PeakVectorSum":
# A vector sum can exceed the range without any clipping, so only
# Blastware's OORANGE counts. SFM's sum is bounded by three channels at
# the ceiling (11.55 on T438HGTZ.B30W), and a channel Blastware itself
# clamped must be the one SFM has at the ceiling -- an unclipped channel
# read 8x high on the Sensitive range does not qualify.
pvs = sfm.values.get("PeakVectorSum")
return ((res.bw or "").strip() == "OORANGE" and pvs is not None
and r - _TOL <= float(pvs) <= 3 ** 0.5 * r * 1.01
and any(_clamped(ref.scalars.get(f, ""), r) and sfm.values.get(f) is not None
and _at_ceiling(float(sfm.values[f]), r)
for f in ("TranPPV", "VertPPV", "LongPPV")))
got = series_pairs(sfm, ref, res.field)
if got is None or got[1]:
return False
differing = [(cell, v) for _, cell, v in got[0] if not matches_printed(v, cell)]
return bool(differing) and all(
_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)
SATURATION = Carveout(
id="saturation",
fields=("TranPPV", "VertPPV", "LongPPV", "PeakVectorSum",
"samples.Tran", "samples.Vert", "samples.Long",
"intervals.Tran Peak in/s", "intervals.Vert Peak in/s", "intervals.Long Peak in/s"),
evidence=("Blastware clamps a clipped channel to the range maximum and prints OORANGE; "
"the file holds counts past full scale (32016 counts = 10.005 in/s observed). "
"scratch/verify_against_ascii.py, 2026-08-28."),
applies=_saturation,
)
def _interval_count_is_duration(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool:
"""Blastware's count exceeds the intervals in its own table, and SFM decoded
exactly the table's."""
p = _printed_number(res.bw or "")
n = sfm.values.get("NumberofIntervals")
rows = len(ref.intervals or [])
return p is not None and n is not None and rows == n and p[0] > n
INTERVAL_COUNT_IS_DURATION = Carveout(
id="interval-count-is-duration",
fields=("NumberofIntervals",),
evidence=("Blastware's Number of Intervals is (stop - start) / interval from the file's "
"footer times -- exact on T193KSWP.FF0H (2,880), M462KSWR.1R0H (1,650) and "
"T193KY0A.740H (6,390). Its own interval table lists the intervals the file "
"holds: one block (30 at 2 s) fewer when the unit never wrote the last minute. "
"2026-11-02."),
applies=_interval_count_is_duration,
)
_MIC_UNITS = ("in/s and dB(L)", "in/s and psi(L)")
def _units_is_a_display_preference(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool:
"""Both sides say the event has a mic; they differ only in dB against psi."""
return (" ".join((res.bw or "").split()) in _MIC_UNITS
and sfm.values.get("Units") in _MIC_UNITS)
UNITS_IS_A_DISPLAY_PREFERENCE = Carveout(
id="units-is-a-display-preference",
fields=("Units",),
evidence=("dB(L) or psi(L) is Blastware's display preference on the PC when it wrote the "
"report, not the unit's: in report-write order (the _XML.XML mtimes) DL2's 70,034 "
"reports switch fleet-wide in 61 clean runs, every unit at once, and no byte or "
"bit of the event file separates the two (k-240 .. k+520, nor the 1.2 KB before "
"the footer). 2026-11-03."),
applies=_units_is_a_display_preference,
)
CARVEOUTS: tuple[Carveout, ...] = (SATURATION, INTERVAL_COUNT_IS_DURATION,
UNITS_IS_A_DISPLAY_PREFERENCE)