5 Commits
Author SHA1 Message Date
serversdownandClaude Opus 5.5 0a87d85202 fix(sfm): a MiniMate download's peaks come from its file when the unit confirms Normal range
Since the decode checker's histogram-PVS fix (625bc39, merged 6945009) the file
reads a histogram's vector sum as the unit stored it: K441LTON.900 stores
0.200 / 0.385 / 0.255 and a vector sum of 0.3852, as Blastware's report (was
0.503).  The 0C summary, read at fixed offsets, can shift (BE9441 read 0 and
-0.0, bench #4) -- and a shifted value can look plausible and pass the
impossible-value guard.  So the row now takes the file's channel peaks and
vector sum.

Only when the unit's settings confirm Normal range: the file reader computes
every peak as if the range were Normal (_GEO_SENSITIVE_FS_INS is defined but
unused), so a Sensitive unit's file peaks are 8x off (the checker's 33
waveforms).  For Sensitive, or a range not read (a monitoring unit's 1A has no
settings), the unit's own peaks stand, as before.  The mic is always the
unit's: the file still reads it as 0.  The 0C peaks remain the download check.

Store consequence: new live downloads only; no backfill, no migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-31 00:17:57 -04:00
serversdownandClaude Opus 5.5 69450093f6 merge: dev into feat/series4-sfm-parity -- a histogram's peak vector sum from the unit's stored value
Brings 0fc6806 (fix 625bc39, changelog dc42ae0) from the decode checker's
branch: a histogram's peak vector sum is the largest per-interval PVS the unit
stores (PVS^2 as uint32 BE), not a vector magnitude of per-channel interval
peaks.  K441LTON.900 reads 0.385, as Blastware's report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-31 00:13:15 -04:00
serversdownandClaude Opus 5.5 dc42ae041a docs(changelog): Unreleased -- a histogram's stored peak vector sum
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
2026-10-30 01:54:27 -04:00
serversdownandClaude Opus 5.5 0fc68065fe merge: a histogram's peak vector sum from the stored per-interval value
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
2026-10-30 01:53:54 -04:00
serversdownandClaude Opus 5.5 625bc39116 fix(decode): a histogram's peak vector sum is the one the unit stores
Every histogram interval carries its peak vector sum SQUARED, uint32 BE
in 0.005 in/s units: bytes [21:25] of a standard block (long documented
as 'constant 00 00' plus 'purpose unknown'), the last 4 bytes of a
sub-minute record (the undecoded 'meta_var').  sqrt(stored) x 0.005 is
the Geo PVS Blastware prints: 1,668,073 / 1,668,074 standard and 34.5 M
sub-minute DL2 intervals checked against the _XML.XML reports.

SFM computed the event's PVS from each channel's interval peak, which
can come from different moments, and read high on 86% of DL2's
histograms (T004JTRF.ME0H: 1.782 against Blastware's 1.358).  It now
takes the largest stored interval value.  histogram_codec.interval_pvs
returns the per-interval series; records gain 'pvs_sq'.  Waveforms are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
2026-10-30 01:29:58 -04:00
8 changed files with 164 additions and 23 deletions

No files matched your search

+28
View File
@@ -7,6 +7,34 @@ All notable changes to seismo-relay are documented here.
## Unreleased
### Fixed
- **A histogram's peak vector sum is now the one the unit stores.** SFM
computed it from each channel's interval peak, and those can come from
different moments. So on 86% of DL2's histograms with no report it read
high: `T004JTRF.ME0H` gave 1.782 against Blastware's 1.358.
- Every interval carries its peak vector sum SQUARED, a uint32 BE in
0.005 in/s units:
- bytes [21:25] of a standard block, long documented as "constant
`00 00`" plus "purpose unknown"
- the last 4 bytes of a sub-minute record (the undecoded `meta_var`)
- √stored × 0.005 is the "Geo PVS" Blastware prints. It matches on
1,668,073 / 1,668,074 standard and 34.5 million sub-minute DL2
intervals.
- The event's value is the largest interval's.
`histogram_codec.interval_pvs` returns the per-interval series, and
records gain `pvs_sq`. Waveforms are unchanged.
- Decode checker: `PeakVectorSum` matches on 69,919 events (was 15,097):
54,822 fixed, 0 regressions. The 80 left are three things:
- the 35 Sensitive-range events (8×, SFM's Normal-range assumption)
- 27 of the 5-second histograms that decode wrongly
- about a dozen waveforms Blastware prints `OORANGE` for when the
vector sum alone exceeds 10 in/s — a likely carve-out, still to be
shown
- The per-interval series is not stored yet, so the checker still scores
`intervals.Geo PVS` as SFM blank.
- ⚠ **Codec change, covered by the same release bump as #44/#45 and
#41.** The backfill rewrites stored histogram PVS, but only where no
ASCII report overlays it. Report-paired events keep the report's value.
No schema change.
- **A Blastware event's record type comes from its bytes, not its filename
(#41).**
- STRT[18] is the record-type byte: `0x46` on every one of DL2's 6,577
+2 -1
View File
@@ -223,7 +223,8 @@ Read this first when picking the project back up.
**Batch 1 fixed (2026-10-29):** #1 (`b320a53`, settings read after unescaping:
mode −7, rate −6, interval −4, record time +6), #9 (`ce441a0`, one reconnect for
the read-back), #8 (`9492e49`, downloads stored through `save_imported_bw` with
the unit's peaks/mic/vector sum overlaid and its range passed). #2 came with the
the unit's mic overlaid, its peaks/vector sum too unless Normal range is confirmed
-- since 2026-10-31, after the checker's histogram-PVS fix -- and its range passed). #2 came with the
`dev` merge. **#15 retracted** -- `sent` NULL is "unknown", by design.
Final review fixes: `dbd8a91` (wake before the reconnect's identity read),
`3a1d34a` ("already stored" by Blastware name too), `a72d3a9` (the 1A write
@@ -685,10 +685,12 @@ a short plan; #14 waits for the line-hold decision above.
7. `/db/events` 500 "database is locked" on the first page load against a new DB.
8. ✅ **Fixed `9492e49`**, plus `3a1d34a` ("already stored" also matches the Blastware
name: a histogram's row sits a second off its 0C time). The download carries the assembled Blastware file and is
stored through `save_imported_bw` (`source.kind` "sfm-live"); the unit's 0C peaks,
mic and vector sum are overlaid (the file path reads a histogram's vector sum as
0.503 vs 0.385, the mic as 0, and no sensitive range yet), and its range scales
the samples. The "Waveform" label waits for #41 from the checker branch.
stored through `save_imported_bw` (`source.kind` "sfm-live"), and its range scales
the samples. The unit's 0C mic is overlaid (the file reads it as 0). Its channel
peaks and vector sum were overlaid too until 2026-10-31; since the checker's
histogram-PVS fix (625bc39, merged `6945009`) the file's are taken when the unit
confirms Normal range, and the unit's stand for Sensitive or an unread range (the
file reader assumes Normal: 8x off). The label came with #41 (`a1d2b61`).
**S3 downloads are stored from the live waveform decoder** (`store.save`), not
the file reader that Series 4 uses (`save_imported_idf`): a histogram gets no
samples and is labelled Waveform. Fix: store S3 downloads through the
+11 -1
View File
@@ -30,7 +30,7 @@ from . import blastware_file as _bw # avoid circular reference at module load
from .bw_ascii_report import BwAsciiReport
from . import waveform_codec as _wc
from .waveform_codec import decode_waveform_v2, decoded_to_adc_counts
from .histogram_codec import decode_histogram_body
from .histogram_codec import decode_histogram_body, interval_pvs
# Reference pressure for dB(L) → psi conversion (20 µPa expressed in psi).
# Same constant as sfm/sfm_webapp.html so server-side and browser-side
@@ -704,6 +704,9 @@ _INT16_FS = 32768.0
# sfm.event_hdf5._GEO_INT16_FS or sidecar peaks disagree with the plotted
# waveform by 2.3%. Confirmed 2026-08-25 against the BW ASCII corpus.
_GEO_INT16_FS = 32000.0
# A histogram's geo values are in decoder units of 16 counts = 0.005 in/s at
# the Normal range (the same assumption as the samples above).
_HIST_GEO_UNIT_INS = 16 * _GEO_NORMAL_FS_INS / _GEO_INT16_FS
# Microphone scale factor, psi per ADC count. Approximate — exact factor
# depends on the geophone-vs-mic ADC scaling and the firmware reference.
@@ -1240,6 +1243,13 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
# report when one is supplied.
has_samples = any(samples.get(ch) for ch in ("Tran", "Vert", "Long", "MicL"))
ev.peak_values = _peaks_from_samples(samples) if has_samples else None
if not is_waveform_body and ev.peak_values is not None:
# A histogram stores each interval's vector sum (squared); the event's
# is the largest. Combining the channel peaks instead read high on 86%
# of DL2's histograms -- they can come from different moments.
pvs = interval_pvs(body)
if pvs:
ev.peak_values.peak_vector_sum = max(pvs) * _HIST_GEO_UNIT_INS
ev._a5_frames = None # not recoverable from BW file
return ev
+24 -1
View File
@@ -40,6 +40,13 @@ iterate 32-stride and stop before the tail.
[24:28] 4-byte variable purpose unknown (possibly CRC or timestamp delta)
[28:32] block-end signature see "Two block tails" below
⚠ CORRECTED 2026-10-30 (measured): [21:25] is the interval's peak vector sum
SQUARED, uint32 BE in 0.005 in/s units. sqrt([21:25]) x 0.005 is the "Geo PVS"
Blastware prints for the interval, on 1,668,073 / 1,668,074 standard DL2
intervals checked against the _XML.XML reports. [21:23] is zero only while the
square is below 65,536 (PVS < 1.28 in/s), which is why it looked constant; only
[25:28] is still unexplained. `interval_pvs` reads it.
**Every per-channel field is uint16 BIG-endian** (confirmed 2026-08-25).
Only ``block_ctr`` at [2:4] is little-endian.
@@ -124,6 +131,7 @@ record list.
from __future__ import annotations
import math
import struct
from typing import List, Optional, Tuple
@@ -216,6 +224,7 @@ def _decode_block(block: bytes) -> Optional[dict]:
"m_peak": m_peak,
"m_halfp": m_halfp,
"meta_var": var_meta,
"pvs_sq": int.from_bytes(block[21:25], "big"),
"is_terminal": block[28:32] == _BLOCK_TAIL_TERMINAL,
}
@@ -319,6 +328,16 @@ def decode_histogram_body_full(body: bytes) -> Optional[List[dict]]:
return records if records else None
def interval_pvs(body: bytes) -> Optional[List[float]]:
"""Each interval's peak vector sum, in the geo peak units (0.005 in/s at
Normal range): the square root of the square the device stores with every
interval. This is the vector sum at an instant, as Blastware prints it --
not the magnitude of the three channel peaks, which can come from
different moments. None when the body has no valid blocks."""
records = _walk_auto(body)
return [math.sqrt(r["pvs_sq"]) for r in records] if records else None
def half_period_to_hz(halfp: int) -> Optional[float]:
"""Convert a half-period in samples to frequency in Hz.
@@ -356,7 +375,10 @@ def geo_count_to_ins(count: int) -> float:
# [4] 0x0a
# [5 ...] one record per interval: per channel a BIG-endian uint16 peak and
# half-period (Tran, Vert, Long[, MicL]), then 0x0000, then one more
# word ("meta_var" keeps those 4 bytes)
# word ("meta_var" keeps those 4 bytes). Measured 2026-10-30: those
# 4 bytes are the interval's peak vector sum SQUARED, uint32 BE in
# 0.005 in/s units -- sqrt matches Blastware's "Geo PVS" on 34.5 M
# DL2 sub-minute intervals; the 0x0000 is its high word
# [-7:] trailer: 3 bytes, then the 4-byte tail -- 9c 06 00 42 on the
# stream's LAST block
#
@@ -486,6 +508,7 @@ def _decode_record(body: bytes, q: int, rec: int, off: int) -> dict:
"m_peak": be16(q + 12) if mic else None,
"m_halfp": be16(q + 14) if mic else None,
"meta_var": bytes(body[q + z:q + z + 4]),
"pvs_sq": int.from_bytes(body[q + z:q + z + 4], "big"),
"is_terminal": False,
}
+26 -12
View File
@@ -66,15 +66,23 @@ def _already_stored(dl: DownloadedEvent, row: dict) -> EventDownload:
)
def _overlay_s3_record(ev: Any, unit_peaks: Any) -> None:
"""The unit's own 0C peaks, mic and vector sum over the file's.
def _overlay_s3_record(ev: Any, unit_peaks: Any, geo_range: Any) -> None:
"""The unit's own 0C values over the file's, where the file's are not yet right.
Measured 2026-10-29 on BE9441: the file path reads the channel peaks right but
a histogram's vector sum as 0.503 where Blastware and the unit say 0.385 (the
decode checker's open finding), the mic as 0, and it cannot scale a sensitive
range. The unit's values are the accurate ones until the file decoder reads
them. A vector sum below the largest channel peak is impossible -- BE9441's
0C read -0.0 for some events (bench finding #4) -- so it is not kept.
* Mic: always the unit's -- the file reads it as 0 (its psi conversion is an
open checker finding).
* Channel peaks and vector sum: the file's when the unit's settings confirm
Normal range (`geo_range` 0). The file reads them as the unit stored them
-- K441LTON.900: 0.200 / 0.385 / 0.255 and 0.385, as Blastware's report,
since the decode checker's fix (625bc39, 2026-10-31) -- while the 0C summary
is read at fixed offsets and can shift (BE9441 read 0 and -0.0 for vector
sums, bench #4). But the file reader computes every peak as if the range
were Normal, so a Sensitive unit's come out 8x off (the checker's 33
waveforms): for Sensitive, or a range not read (a monitoring unit's 1A
carries no settings), the unit's own peaks stand, as before -- a vector
sum below the largest channel peak is impossible and is not kept.
The 0C peaks remain the download *check* (verify_s3_download) either way.
"""
from minimateplus.models import PeakValues
@@ -83,7 +91,12 @@ def _overlay_s3_record(ev: Any, unit_peaks: Any) -> None:
if ev.peak_values is None:
ev.peak_values = PeakValues()
pv = ev.peak_values
for name in ("tran", "vert", "long", "micl"):
micl = getattr(unit_peaks, "micl", None)
if micl is not None:
pv.micl = micl
if geo_range in (0, "normal"):
return
for name in ("tran", "vert", "long"):
value = getattr(unit_peaks, name, None)
if value is not None:
setattr(pv, name, value)
@@ -137,8 +150,9 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo
else:
# The same path production's watcher uses for Blastware's own files: the
# event is decoded from the file (samples, histogram, setup-block sample
# rate and record time), not from the live 5A decode. The unit's own 0C
# peaks, mic and vector sum then go over the file's (_overlay_s3_record).
# rate and record time), not from the live 5A decode. The unit's 0C mic
# goes over the file's, and its peaks too unless Normal range is
# confirmed (_overlay_s3_record).
if not dl.bw_bytes:
raise IngestError(f"{dl.filename}: the download carried no event file; nothing was stored")
geo_range = getattr(dl.compliance, "geo_range", None) if dl.compliance else None
@@ -146,7 +160,7 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo
serial_hint=dl.serial, source_kind="sfm-live",
geo_range=geo_range if geo_range is not None else "normal")
if ev is not None and dl.event is not None:
_overlay_s3_record(ev, getattr(dl.event, "peak_values", None))
_overlay_s3_record(ev, getattr(dl.event, "peak_values", None), geo_range)
family = "series3"
if ev is None or ev._waveform_key is None:
raise IngestError(f"{dl.filename}: stored the file but could not build a database row")
+33
View File
@@ -146,3 +146,36 @@ def test_an_unknown_type_byte_is_unknown_not_a_guess():
ev = decode_blastware_bytes(bytes(raw), name=None)
assert ev.record_type is None
assert any("record type" in p for p in ev.decode_problems)
# ── A histogram's peak vector sum is read, not computed from channel peaks ──
# Each interval stores the square of its vector sum (uint32 BE, in 0.005 in/s
# units): bytes [21:25] of a standard block, the last 4 bytes of a sub-minute
# record. sqrt(stored) x 0.005 matches Blastware's printed interval PVS on
# 1,668,073 / 1,668,074 standard and 34.5 M sub-minute DL2 intervals
# (measured 2026-10-30). The old value combined each channel's interval peak,
# which can come from different moments, and read high on 86% of histograms.
from minimateplus.histogram_codec import interval_pvs # noqa: E402
# (file, Blastware's summary Peak Vector Sum)
_HIST_PVS = [
("decode-checker-10-29-26/M529L4XQ.R30H", 3.095), # XML; 1-minute
("decode-checker-10-29-26/T004JTRF.ME0H", 1.358), # XML; SFM used to say 1.782
("histogram-mic-off-10-26-26/K441LTOK.QZ0", 1.083), # ASCII report; 2 s, mic off
]
@pytest.mark.parametrize("rel,pvs", _HIST_PVS)
def test_histogram_peak_vector_sum_is_the_stored_one(rel, pvs):
got = read_blastware_file(_FIX / rel).peak_values.peak_vector_sum
assert abs(got - pvs) <= 0.0005 + 1e-9, got
def test_interval_pvs_per_interval():
raw = (_FIX / "histogram-mic-off-10-26-26/K441LTOK.QZ0").read_bytes()
pvs = interval_pvs(raw[_bw._WAVEFORM_HEADER_SIZE + 21:])
assert len(pvs) == 22
# Blastware's interval table, first four "Geo PVS" values
for got, want in zip(pvs[:4], (0.065, 0.034, 0.015, 0.461)):
assert abs(got * 0.005 - want) <= 0.0005 + 1e-9, (got, want)
+34 -4
View File
@@ -307,14 +307,26 @@ def _with_unit_peaks(dl, *, tran, vert, long, micl, pvs):
return dl
def test_a_series3_download_keeps_the_units_peaks_mic_and_vector_sum(sdm):
def _range(geo_range):
cc = FakeMiniMateClient().compliance
cc.geo_range = geo_range
return cc
def test_a_series3_download_takes_its_peaks_from_the_file_and_its_mic_from_the_unit(sdm):
# 2026-10-31: the file now reads a histogram's vector sum as the unit stored it
# (0.385 here, as Blastware's report), so the row takes the file's peaks and
# vector sum. The unit's 0C summary is read at fixed offsets and can shift
# (bench #4 read 0 / -0.0); these believable-but-wrong values must not win.
# The mic still comes from the unit: the file reads it as 0.
store, db = sdm
dl = _with_unit_peaks(_hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36)),
tran=0.2, vert=0.385, long=0.255, micl=0.00058, pvs=0.38516)
tran=0.21, vert=0.36, long=0.27, micl=0.00058, pvs=0.40) # clears the old guard
dl.compliance = _range(0) # Normal, confirmed by the unit
row = db.get_event(persist_download(dl, store=store, db=db).db_event_id)
assert row["peak_vector_sum"] == pytest.approx(0.38516, abs=1e-5) # Blastware: 0.385; the file path says 0.503
assert row["mic_ppv"] == pytest.approx(0.00058, abs=1e-6)
assert row["peak_vector_sum"] == pytest.approx(0.3852, abs=1e-4) # Blastware: 0.385
assert (row["tran_ppv"], row["vert_ppv"], row["long_ppv"]) == pytest.approx((0.2, 0.385, 0.255), abs=1e-4)
assert row["mic_ppv"] == pytest.approx(0.00058, abs=1e-6)
def test_an_impossible_unit_vector_sum_is_not_kept(sdm):
@@ -409,3 +421,21 @@ def test_a_letterless_stored_name_still_matches_a_lettered_download(sdm):
store, db = sdm
_stored_as(store, db, "K441LTOK.QZ0")
assert db.find_event_by_blastware_name("BE9441", "K441LTOK.QZ0H")["blastware_filename"] == "K441LTOK.QZ0"
# The file reader computes every peak as if the unit were in Normal range (10 in/s);
# a Sensitive (1.25 in/s) unit's file peaks come out 8x off (the checker's 33
# waveforms). So the file's peaks are taken only when the unit's settings confirm
# Normal -- the download check's rule; Sensitive or unread keeps the unit's own.
@pytest.mark.parametrize("compliance", [_range(1), None], ids=["sensitive", "range-unread"])
def test_without_a_confirmed_normal_range_the_units_peaks_stand(sdm, compliance):
store, db = sdm
dl = _with_unit_peaks(_hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36)),
tran=0.025, vert=0.048, long=0.032, micl=0.00058, pvs=0.0481)
dl.compliance = compliance
row = db.get_event(persist_download(dl, store=store, db=db).db_event_id)
assert (row["tran_ppv"], row["vert_ppv"], row["long_ppv"]) == pytest.approx((0.025, 0.048, 0.032), abs=1e-6)
assert row["peak_vector_sum"] == pytest.approx(0.0481, abs=1e-6)
assert row["mic_ppv"] == pytest.approx(0.00058, abs=1e-6)