fix(sfm): a MiniMate download stores what its own file says, at the range it was recorded at (#17)
With the decode checker's fixes merged (histogram vector sum625bc39, mic psi5644dbd, the file's geophone range4844135), the event file reads everything Blastware reports. So a live download's row and samples are now the file's: peaks, vector sum, mic -- and the geophone range from the file's own setup block, the setting when the event was recorded. The live 1A is the unit's setting now, which may have changed since; it is the fallback only when the file's range does not read. Measured: K557J1KB.RQ0W (Sensitive waveform) downloaded with its settings unread -- e.g. while monitoring -- stores 0.019 / 0.055 / 0.019 and PVS 0.061, Blastware's report; its .h5 read 0.155 / 0.44 (8x) before. M010HR6K.OA0H (Sensitive histogram) likewise. K441LTON.900 (Normal) stores Blastware's values whatever the unit's current settings say, and its mic is 5.80e-4 psi (Blastware: 106.0 dB(L)). The unit's 0C summary stays the download check, and fills in the channel peaks and vector sum only when the file's range does not read (never seen in DL2) and the unit is not confirmed Normal -- the impossible-vector-sum guard kept there. The mic is the file's always. Closes the range part of open finding #17. 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
This commit is contained in:
1 parent
d0c14aaec8
commit
f98c4ff129
4 files changed
+150
-77
No files matched your search
+92
-33
@@ -296,9 +296,11 @@ def test_backfill_without_settings_changes_nothing():
|
||||
assert ev.sample_rate is None
|
||||
|
||||
|
||||
# The file path does not yet read a histogram's vector sum the way Blastware does
|
||||
# (the checker's open finding), the mic peak, or a sensitive range, so a live
|
||||
# download keeps the unit's own 0C values for those -- the Series-4 pattern.
|
||||
# Since 2026-11-02 a live download stores what its own file says -- peaks, vector
|
||||
# sum, mic, and the geophone range the event was recorded at -- and the unit's 0C
|
||||
# summary is only the download check. The file's range is the setting when it
|
||||
# recorded; the live 1A is the unit's setting now, which may have changed since.
|
||||
# Only when the file's range does not read (never seen in DL2) does the 1A decide.
|
||||
|
||||
def _with_unit_peaks(dl, *, tran, vert, long, micl, pvs):
|
||||
from minimateplus.models import PeakValues
|
||||
@@ -313,24 +315,99 @@ def _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.
|
||||
GEO_FIX = Path(__file__).parent / "fixtures" / "geo-range-11-01-26"
|
||||
WRONG = dict(tran=0.21, vert=0.36, long=0.27, micl=0.0009, pvs=0.40) # believable, wrong; clears the old guard
|
||||
|
||||
|
||||
def _download_from(path, serial):
|
||||
from minimateplus.blastware_file import blastware_filename_time
|
||||
when = blastware_filename_time(path.name)
|
||||
return DownloadedEvent(event_id=f"{serial}:01110000:{when:%Y%m%d%H%M%S}", serial=serial, series=3,
|
||||
filename=path.name, verified=None, bw_bytes=path.read_bytes(), timestamp=when)
|
||||
|
||||
|
||||
def _h5_peaks(store, serial, name):
|
||||
from sfm import event_hdf5
|
||||
plot = event_hdf5.plot_json_from_hdf5(store.hdf5_path_for(serial, name))
|
||||
return tuple(max(abs(v) for v in plot["channels"][c]["values"]) for c in ("Tran", "Vert", "Long"))
|
||||
|
||||
|
||||
def _file_range_unread(monkeypatch):
|
||||
# A file whose range does not read: the decoder then assumes Normal.
|
||||
# K441LTON.900 is a Normal file, so its peaks are what such a decode gives.
|
||||
import minimateplus.event_file_io as efi
|
||||
real = efi.decode_blastware_bytes
|
||||
|
||||
def unread(raw, **kw):
|
||||
ev = real(raw, **kw)
|
||||
ev.geo_range = None
|
||||
return ev
|
||||
monkeypatch.setattr(efi, "decode_blastware_bytes", unread)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("compliance", [_range(0), _range(1), None],
|
||||
ids=["unit-says-normal", "unit-says-sensitive", "settings-unread"])
|
||||
def test_a_series3_download_stores_what_its_file_says(sdm, compliance):
|
||||
# K441LTON.900 was recorded in Normal range, whatever the unit is set to now.
|
||||
store, db = sdm
|
||||
dl = _with_unit_peaks(_hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36)),
|
||||
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
|
||||
**WRONG)
|
||||
dl.compliance = compliance
|
||||
row = db.get_event(persist_download(dl, store=store, db=db).db_event_id)
|
||||
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)
|
||||
assert row["peak_vector_sum"] == pytest.approx(0.3852, abs=1e-4) # Blastware: 0.385
|
||||
assert row["mic_ppv"] == pytest.approx(5.80e-4, abs=2e-6) # Blastware: 106.0 dB(L)
|
||||
assert _h5_peaks(store, "BE9441", "K441LTON.900")[1] == pytest.approx(0.385, abs=0.006)
|
||||
|
||||
|
||||
def test_an_impossible_unit_vector_sum_is_not_kept(sdm):
|
||||
# Bench finding #4: BE9441's 0C read -0.0 for a vector sum whose channels reach 1.08.
|
||||
def test_a_sensitive_waveform_downloaded_with_its_settings_unread_is_blastwares(sdm):
|
||||
# e.g. downloaded while monitoring (the 1A carries no settings). The samples
|
||||
# were scaled as Normal before -- 8x: Vert read 0.44 in the .h5.
|
||||
store, db = sdm
|
||||
dl = _download_from(GEO_FIX / "K557J1KB.RQ0W", "BE9557")
|
||||
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.019, 0.055, 0.019), abs=6e-4)
|
||||
assert row["peak_vector_sum"] == pytest.approx(0.061, abs=6e-4) # Blastware's report
|
||||
assert _h5_peaks(store, "BE9557", "K557J1KB.RQ0W") == pytest.approx((0.019, 0.055, 0.019), abs=7e-4)
|
||||
|
||||
|
||||
def test_a_sensitive_histogram_downloaded_with_its_settings_unread_keeps_its_scale(sdm):
|
||||
from minimateplus.event_file_io import decode_blastware_bytes
|
||||
store, db = sdm
|
||||
path = GEO_FIX / "M010HR6K.OA0H"
|
||||
pv = decode_blastware_bytes(path.read_bytes()).peak_values
|
||||
persist_download(_download_from(path, "BE11010"), store=store, db=db)
|
||||
assert _h5_peaks(store, "BE11010", path.name) == pytest.approx((pv.tran, pv.vert, pv.long), abs=7e-4)
|
||||
assert max(_h5_peaks(store, "BE11010", path.name)) < 0.02 # not 8x (Vert would read ~0.07)
|
||||
|
||||
|
||||
def test_when_the_files_range_does_not_read_a_sensitive_units_own_peaks_stand(sdm, monkeypatch):
|
||||
_file_range_unread(monkeypatch)
|
||||
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.0009, pvs=0.0481)
|
||||
dl.compliance = _range(1)
|
||||
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(5.80e-4, abs=2e-6) # the mic's scale is not the geophones'
|
||||
assert _h5_peaks(store, "BE9441", "K441LTON.900")[1] == pytest.approx(0.385 / 8, abs=7e-4)
|
||||
|
||||
|
||||
def test_when_the_files_range_does_not_read_and_the_unit_says_normal_the_files_peaks_stand(sdm, monkeypatch):
|
||||
_file_range_unread(monkeypatch)
|
||||
store, db = sdm
|
||||
dl = _with_unit_peaks(_hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36)),
|
||||
**WRONG)
|
||||
dl.compliance = _range(0)
|
||||
row = db.get_event(persist_download(dl, store=store, db=db).db_event_id)
|
||||
assert (row["vert_ppv"], row["peak_vector_sum"]) == pytest.approx((0.385, 0.3852), abs=1e-4)
|
||||
|
||||
|
||||
def test_an_impossible_unit_vector_sum_is_not_kept(sdm, monkeypatch):
|
||||
# Bench finding #4: BE9441's 0C read -0.0 for a vector sum whose channels reach
|
||||
# 1.08. The unit's values are used only when neither range reads.
|
||||
_file_range_unread(monkeypatch)
|
||||
store, db = sdm
|
||||
dl = _with_unit_peaks(_hist_download("K441LTOK.R10", "011106a0", datetime.datetime(2026, 10, 26, 16, 6, 37)),
|
||||
tran=0.25, vert=1.08, long=0.195, micl=0.0001, pvs=-0.0)
|
||||
@@ -421,21 +498,3 @@ 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)
|
||||
Reference in new issue
Block a user