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 sum 625bc39, mic psi
5644dbd, the file's geophone range 4844135), 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:
serversdownandClaude Opus 5.5 committed 2026-11-02 13:48:59 -05:00
1 parent d0c14aaec8
commit f98c4ff129
4 files changed
+150 -77

No files matched your search

+39 -29
View File
@@ -66,36 +66,41 @@ def _already_stored(dl: DownloadedEvent, row: dict) -> EventDownload:
)
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.
def _file_geo_range(bw_bytes: bytes) -> Any:
"""The geophone range a Blastware file was recorded at (0 Normal, 1 Sensitive),
or None when it does not read -- or the file does not decode at all."""
from minimateplus import event_file_io
try:
return event_file_io.decode_blastware_bytes(bw_bytes).geo_range
except Exception: # noqa: BLE001 -- the store reports it
return None
* 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.
def _overlay_s3_record(ev: Any, unit_peaks: Any, unit_range: Any) -> None:
"""The unit's own 0C peaks over the file's -- only where the file cannot be trusted.
The file reads everything Blastware reports (checked on 70,042 events): the
channel peaks and the vector sum, scaled by the geophone range in its own
setup block (4844135), and the mic (5644dbd). The 0C summary is read at
fixed offsets and can shift -- BE9441's read 0 and -0.0 for vector sums
(bench #4) -- so the file's values stand.
Except when the file's range does not read (`ev.geo_range` None; never seen
in DL2): the decoder then assumes Normal, 8x off for a Sensitive unit. Then
the unit's settings decide: Normal confirmed (`unit_range` 0) keeps the
file's peaks; Sensitive or unread keeps the unit's own, as before -- a vector
sum below the largest channel peak is impossible and is not kept. The mic
is the file's either way: its scale does not depend on the geophone range.
"""
if unit_peaks is None or getattr(ev, "geo_range", None) is not None:
return
if unit_range in (0, "normal"):
return
from minimateplus.models import PeakValues
if unit_peaks is None:
return
if ev.peak_values is None:
ev.peak_values = PeakValues()
pv = ev.peak_values
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:
@@ -149,18 +154,23 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo
family = "series4"
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 0C mic
# goes over the file's, and its peaks too unless Normal range is
# confirmed (_overlay_s3_record).
# event is decoded from the file -- samples, histogram, peaks, vector sum,
# mic, sample rate, record time and the geophone range it was recorded
# at -- not from the live 5A decode. The unit's 0C summary is the
# download check (verify_s3_download); it fills in only when the file's
# range does not read (_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
unit_range = getattr(dl.compliance, "geo_range", None) if dl.compliance else None
# The file's range is the setting when it recorded; the live 1A is the
# unit's setting now, which may have changed since -- the fallback only.
# None lets the store scale by the file's own range.
ev, rec = store.save_imported_bw(dl.bw_bytes, source_path=Path(dl.filename),
serial_hint=dl.serial, source_kind="sfm-live",
geo_range=geo_range if geo_range is not None else "normal")
geo_range=None if _file_geo_range(dl.bw_bytes) is not None
else unit_range)
if ev is not None and dl.event is not None:
_overlay_s3_record(ev, getattr(dl.event, "peak_values", None), geo_range)
_overlay_s3_record(ev, getattr(dl.event, "peak_values", None), unit_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")