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
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-29 19:27:01 -04:00
1 parent 3662d2fac1
commit ff7dd908a7
3 files changed
+180 -59

No files matched your search

+74 -59
View File
@@ -184,71 +184,86 @@ def _series_result(field: str, n_bw: int, n_sfm: int, diffs: list[tuple[int, flo
)
def _compare_samples(sfm: SfmSide, ref: XmlReport) -> list[FieldResult]:
"""One result per reference channel. A row holds only the channels still
running, so row j's cells pair, in order, with the reference channels SFM
has more than j samples of."""
rows = ref.sample_rows or []
def _sample_converters(ref: XmlReport) -> dict[str, Callable[[int], float]]:
convert: dict[str, Callable[[int], float]] = {ch: (lambda c: c * GEO_IPS_PER_COUNT) for ch in _GEO}
mic = _mic_converter(ref)
convert = {ch: (lambda c: c * GEO_IPS_PER_COUNT) for ch in _GEO}
if mic is not None:
convert["MicL"] = mic
lens = {ch: len(sfm.counts.get(ch, [])) for ch in ref.channels}
diffs: dict[str, list[tuple[int, float]]] = {ch: [] for ch in ref.channels}
row_len = {ch: 0 for ch in ref.channels}
for j, row in enumerate(rows):
running = [ch for ch in ref.channels if lens[ch] > j]
if len(running) != len(row):
for ch in ref.channels:
row_len[ch] += 1
continue
for ch, cell in zip(running, row):
if ch in convert:
d = _cell_diff(convert[ch](sfm.counts[ch][j]), cell)
if d is not None:
diffs[ch].append((j, d))
out = []
for ch in ref.channels:
if ch not in convert or not lens[ch]:
out.append(FieldResult(f"samples.{ch}", "sfm_blank", f"{len(rows)} rows", None))
continue
extra = max(0, lens[ch] - len(rows)) # SFM samples with no row at all
out.append(_series_result(f"samples.{ch}", len(rows), lens[ch], diffs[ch],
row_len[ch] + extra))
return out
return convert
def _interval_converter(title: str) -> Optional[Callable[[int], float]]:
"""SFM keeps each interval's peaks; it drops their frequencies and geo PVS."""
ch, _, rest = title.partition(" ")
if rest.startswith("Peak") and ch in _GEO:
return lambda c: c * GEO_IPS_PER_COUNT
if ch == "MicL" and rest == "Peak dB(L)":
return mic_count_to_db
if ch == "MicL" and rest == "Peak psi(L)":
return lambda c: c * _MIC_FS_PSI
return None
def series_pairs(sfm: SfmSide, ref: XmlReport,
field: str) -> Optional[tuple[list[tuple[int, str, float]], int]]:
"""For a `samples.<ch>` or `intervals.<column>` field: the (index, printed
cell, SFM value) pairs and the count of row-length disagreements, or None
when SFM has no conversion or no data for it.
A waveform row holds only the channels still running, so row j's cells
pair, in order, with the reference channels SFM has more than j samples of;
a row whose cell count differs is a disagreement for every channel."""
if field.startswith("samples."):
ch = field[len("samples."):]
convert = _sample_converters(ref).get(ch)
counts = sfm.counts.get(ch, [])
if convert is None or not counts:
return None
rows = ref.sample_rows or []
lens = {c: len(sfm.counts.get(c, [])) for c in ref.channels}
pairs, row_len = [], 0
for j, row in enumerate(rows):
running = [c for c in ref.channels if lens[c] > j]
if len(running) != len(row):
row_len += 1
elif ch in running:
pairs.append((j, row[running.index(ch)], convert(counts[j])))
return pairs, row_len + max(0, len(counts) - len(rows))
if field.startswith("intervals."):
title = field[len("intervals."):]
columns = ref.interval_columns or []
convert = _interval_converter(title)
counts = sfm.counts.get(title.partition(" ")[0], [])
if convert is None or not counts or title not in columns:
return None
i = columns.index(title)
cells = [row[i] if i < len(row) else "" for _, row in (ref.intervals or [])]
pairs = [(j, cell, convert(c)) for j, (cell, c) in enumerate(zip(cells, counts))]
return pairs, abs(len(cells) - len(counts))
return None
def _compare_series(field: str, n_bw: int, sfm: SfmSide, ref: XmlReport) -> FieldResult:
got = series_pairs(sfm, ref, field)
if got is None:
return FieldResult(field, "sfm_blank", f"{n_bw} rows", None)
pairs, row_len = got
diffs = [(j, d) for j, cell, v in pairs if (d := _cell_diff(v, cell)) is not None]
n_sfm = len(sfm.counts.get(field.split(".", 1)[1].partition(" ")[0], []))
return _series_result(field, n_bw, n_sfm, diffs, row_len)
def _compare_samples(sfm: SfmSide, ref: XmlReport) -> list[FieldResult]:
"""One result per reference channel."""
n = len(ref.sample_rows or [])
return [_compare_series(f"samples.{ch}", n, sfm, ref) for ch in ref.channels]
def _compare_intervals(sfm: SfmSide, ref: XmlReport) -> list[FieldResult]:
"""One result per column, plus the interval times. SFM keeps each
interval's peaks; it drops their frequencies and the geo PVS."""
intervals = ref.intervals or []
out = [FieldResult("intervals.Time", "sfm_blank", f"{len(intervals)} rows", None)]
mic_db, mic_psi = mic_count_to_db, (lambda c: c * _MIC_FS_PSI)
for i, title in enumerate(ref.interval_columns or []):
field = f"intervals.{title}"
ch, _, rest = title.partition(" ")
if rest.startswith("Peak") and ch in _GEO:
convert = lambda c: c * GEO_IPS_PER_COUNT # noqa: E731
elif ch == "MicL" and rest == "Peak dB(L)":
convert = mic_db
elif ch == "MicL" and rest == "Peak psi(L)":
convert = mic_psi
else:
out.append(FieldResult(field, "sfm_blank", f"{len(intervals)} rows", None))
continue
counts = sfm.counts.get(ch, [])
if not counts:
out.append(FieldResult(field, "sfm_blank", f"{len(intervals)} rows", None))
continue
cells = [row[i] if i < len(row) else "" for _, row in intervals]
diffs = []
for j, (cell, c) in enumerate(zip(cells, counts)):
d = _cell_diff(convert(c), cell)
if d is not None:
diffs.append((j, d))
out.append(_series_result(field, len(cells), len(counts), diffs,
abs(len(cells) - len(counts))))
return out
"""One result per column, plus the interval times, which SFM does not keep."""
n = len(ref.intervals or [])
return ([FieldResult("intervals.Time", "sfm_blank", f"{n} rows", None)]
+ [_compare_series(f"intervals.{t}", n, sfm, ref) for t in ref.interval_columns or []])
def compare(sfm: SfmSide, ref: XmlReport, carveouts: Sequence["Carveout"] = ()) -> list[FieldResult]: