merge: dev into feat/series4-sfm-parity -- a histogram's peak vector sum from the unit's stored value
Brings0fc6806(fix625bc39, changelogdc42ae0) 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
This commit is contained in:
commit
69450093f6
4 files changed
+96
-2
No files matched your search
@@ -7,6 +7,34 @@ All notable changes to seismo-relay are documented here.
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Fixed
|
### 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
|
- **A Blastware event's record type comes from its bytes, not its filename
|
||||||
(#41).**
|
(#41).**
|
||||||
- STRT[18] is the record-type byte: `0x46` on every one of DL2's 6,577
|
- STRT[18] is the record-type byte: `0x46` on every one of DL2's 6,577
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ from . import blastware_file as _bw # avoid circular reference at module load
|
|||||||
from .bw_ascii_report import BwAsciiReport
|
from .bw_ascii_report import BwAsciiReport
|
||||||
from . import waveform_codec as _wc
|
from . import waveform_codec as _wc
|
||||||
from .waveform_codec import decode_waveform_v2, decoded_to_adc_counts
|
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).
|
# 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
|
# 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
|
# 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.
|
# waveform by 2.3%. Confirmed 2026-08-25 against the BW ASCII corpus.
|
||||||
_GEO_INT16_FS = 32000.0
|
_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
|
# Microphone scale factor, psi per ADC count. Approximate — exact factor
|
||||||
# depends on the geophone-vs-mic ADC scaling and the firmware reference.
|
# 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.
|
# report when one is supplied.
|
||||||
has_samples = any(samples.get(ch) for ch in ("Tran", "Vert", "Long", "MicL"))
|
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
|
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
|
ev._a5_frames = None # not recoverable from BW file
|
||||||
|
|
||||||
return ev
|
return ev
|
||||||
@@ -40,6 +40,13 @@ iterate 32-stride and stop before the tail.
|
|||||||
[24:28] 4-byte variable purpose unknown (possibly CRC or timestamp delta)
|
[24:28] 4-byte variable purpose unknown (possibly CRC or timestamp delta)
|
||||||
[28:32] block-end signature see "Two block tails" below
|
[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).
|
**Every per-channel field is uint16 BIG-endian** (confirmed 2026-08-25).
|
||||||
Only ``block_ctr`` at [2:4] is little-endian.
|
Only ``block_ctr`` at [2:4] is little-endian.
|
||||||
|
|
||||||
@@ -124,6 +131,7 @@ record list.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import math
|
||||||
import struct
|
import struct
|
||||||
from typing import List, Optional, Tuple
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
@@ -216,6 +224,7 @@ def _decode_block(block: bytes) -> Optional[dict]:
|
|||||||
"m_peak": m_peak,
|
"m_peak": m_peak,
|
||||||
"m_halfp": m_halfp,
|
"m_halfp": m_halfp,
|
||||||
"meta_var": var_meta,
|
"meta_var": var_meta,
|
||||||
|
"pvs_sq": int.from_bytes(block[21:25], "big"),
|
||||||
"is_terminal": block[28:32] == _BLOCK_TAIL_TERMINAL,
|
"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
|
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]:
|
def half_period_to_hz(halfp: int) -> Optional[float]:
|
||||||
"""Convert a half-period in samples to frequency in Hz.
|
"""Convert a half-period in samples to frequency in Hz.
|
||||||
|
|
||||||
@@ -356,7 +375,10 @@ def geo_count_to_ins(count: int) -> float:
|
|||||||
# [4] 0x0a
|
# [4] 0x0a
|
||||||
# [5 ...] one record per interval: per channel a BIG-endian uint16 peak and
|
# [5 ...] one record per interval: per channel a BIG-endian uint16 peak and
|
||||||
# half-period (Tran, Vert, Long[, MicL]), then 0x0000, then one more
|
# 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
|
# [-7:] trailer: 3 bytes, then the 4-byte tail -- 9c 06 00 42 on the
|
||||||
# stream's LAST block
|
# 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_peak": be16(q + 12) if mic else None,
|
||||||
"m_halfp": be16(q + 14) if mic else None,
|
"m_halfp": be16(q + 14) if mic else None,
|
||||||
"meta_var": bytes(body[q + z:q + z + 4]),
|
"meta_var": bytes(body[q + z:q + z + 4]),
|
||||||
|
"pvs_sq": int.from_bytes(body[q + z:q + z + 4], "big"),
|
||||||
"is_terminal": False,
|
"is_terminal": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,3 +146,36 @@ def test_an_unknown_type_byte_is_unknown_not_a_guess():
|
|||||||
ev = decode_blastware_bytes(bytes(raw), name=None)
|
ev = decode_blastware_bytes(bytes(raw), name=None)
|
||||||
assert ev.record_type is None
|
assert ev.record_type is None
|
||||||
assert any("record type" in p for p in ev.decode_problems)
|
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)
|
||||||
Reference in new issue
Block a user