Compare commits
23
Commits
342c69602d
...
v0.33.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb14a8f7bb | ||
|
|
6c7c6b0a15 | ||
|
|
287ef2a653 | ||
|
|
30a249ef57 | ||
|
|
18951505f0 | ||
|
|
5644dbd5ad | ||
|
|
dc42ae041a | ||
|
|
0fc68065fe | ||
|
|
625bc39116 | ||
|
|
b6fc71bd28 | ||
|
|
ede6292e4d | ||
|
|
46daea17b2 | ||
|
|
e9c01ce8d4 | ||
|
|
d2258dad4e | ||
|
|
e050e602c2 | ||
|
|
fc1c7c7936 | ||
|
|
7d0d12079b | ||
|
|
5203aab849 | ||
|
|
5b65718b72 | ||
|
|
483762607e | ||
|
|
d0b66368d5 | ||
|
|
2eb1d25028 | ||
|
|
cc821f9ee3 |
No files matched your search
+154
-1
@@ -4,9 +4,120 @@ All notable changes to seismo-relay are documented here.
|
||||
|
||||
---
|
||||
|
||||
## Unreleased
|
||||
## v0.33.0 — 2026-11-01
|
||||
|
||||
**SFM reads Series-3 events from the file alone, and proves it against
|
||||
Blastware.**
|
||||
|
||||
**What was broken.** A Blastware event that reached SFM without its ASCII
|
||||
report used to come in half-decoded:
|
||||
- no sample rate
|
||||
- a "70 s" record time, which was really the record-type byte
|
||||
- blank notes
|
||||
- every histogram typed as a waveform
|
||||
- a histogram vector sum built from channel peaks taken at different moments
|
||||
- a mic reading about 95× low in psi
|
||||
|
||||
That matters more now: every DL2 event from before 2025 arrives with no report,
|
||||
and SFM's own download and call-in paths never have one.
|
||||
|
||||
**What this release does.** It reads all of those from the event file itself,
|
||||
and adds the decode checker that proves it. The checker compares SFM's
|
||||
file-only decode, field by field and sample by sample, with Blastware's own
|
||||
`_XML.XML` event reports for the 70,042 DL2 events that have one (2016–2026).
|
||||
|
||||
**Where that stands now:**
|
||||
- sample rate, record time, pre-trigger, notes and event type match on every
|
||||
event
|
||||
- geophone samples are exact on 6,491 / 6,524 waveforms (the 33 others are on
|
||||
the 1.250 in/s range, which SFM cannot read from the file yet)
|
||||
- the histogram vector sum matches on 69,919
|
||||
- the mic matches on all but a few dozen
|
||||
|
||||
Events imported with an ASCII report are unchanged on prod; the report still
|
||||
overlays.
|
||||
|
||||
⚠ **This release owes prod a backfill.** It does not move stored event times;
|
||||
see *Migration* below.
|
||||
|
||||
### Fixed
|
||||
- **The mic in psi was ~95× low: one MicL count is 0.25 Pa.**
|
||||
- SFM converted mic counts with a "~0.5 psi full-scale" guess (0.0125 /
|
||||
32768 psi per count). The decoded count was always right: count 16 on
|
||||
`K441LTON.900` is Blastware's 106.0 dB.
|
||||
- Measured against 1,729,253 DL2 histogram intervals' "MicL Peak"
|
||||
columns: count × 0.25 Pa matches Blastware's psi(L) on every one.
|
||||
- `event_file_io._MIC_FS_PSI` is now `_MIC_PSI_PER_COUNT` = 0.25 / 6894.757
|
||||
(3.626e-5 psi per count).
|
||||
- The event's mic peak comes right on events with no report, and so does
|
||||
the `.h5` mic trace (`event_hdf5` derives its scale from that peak).
|
||||
- **dB offset:** `waveform_codec.mic_count_to_db` now uses 81.9384, not
|
||||
81.94. Blastware's dB sits in a measured window, [81.9383, 81.9385], a
|
||||
hair above the exact 81.93820. Any value in the window matches on
|
||||
1,729,252 / 1,729,253 intervals.
|
||||
- The checker's first run of this fix flagged 280 regressions, every one
|
||||
count 129, which exact 0.25 Pa rounds to 124.1 against Blastware's
|
||||
124.2.
|
||||
- The old 81.94 misses counts 119 and 132.
|
||||
- Decode checker, against the pre-fix baseline: 45,035 fixed, 0
|
||||
regressions.
|
||||
|
||||
| Field | Mismatches before | After |
|
||||
|---|---|---|
|
||||
| interval psi | 42,783 | 26 |
|
||||
| interval dB | 974 | 20 |
|
||||
| mic peak | 345 | 40 |
|
||||
| waveform mic samples | 1,056 | 37 |
|
||||
|
||||
- ⚠ **Codec change, covered by the same release bump.** The backfill
|
||||
rewrites stored mic values on report-less events; report-paired events
|
||||
keep the report's. No schema change.
|
||||
- **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
|
||||
waveform files and `0x0A` on every one of its 63,535 histograms.
|
||||
- The decoder used to read the type from the filename's last letter. So an
|
||||
event with no Blastware name came out "Waveform" whatever it was: SFM's
|
||||
own downloads, the call-in path, and a manual download (`.QZ0`).
|
||||
- The filename is now only a cross-check that logs a disagreement.
|
||||
- An unknown byte gives `record_type` None and a `decode_problems` entry,
|
||||
not a guess. Manual, Event and Combo types never occur in DL2, so their
|
||||
bytes are unknown.
|
||||
- Decode checker: `EventType` matches on 70,042 / 70,042 events (was 6,524),
|
||||
0 regressions.
|
||||
- ⚠ **Codec change, covered by the same release bump as #44/#45.** The
|
||||
backfill rewrites stored `record_type`. Files named `…W` / `…H` keep their
|
||||
type. A histogram stored from a 3-character manual-download name flips
|
||||
from Waveform to Histogram, which also changes how it pairs with its
|
||||
waveform twin. No schema change.
|
||||
- **A Blastware event imported without its ASCII report now carries its
|
||||
setup and notes (#44, #45).** Until now such an event stored no sample
|
||||
rate, a record time of "70 s" (the STRT record-type byte, 0x46), a
|
||||
@@ -86,6 +197,9 @@ All notable changes to seismo-relay are documented here.
|
||||
- job number, ZC frequency, acceleration, displacement, time of peak,
|
||||
sensor check, battery, calibration, range, units and monitor log
|
||||
are not read yet
|
||||
- Later in this release, the record type (#41), the histogram vector sum
|
||||
and the mic conversion were fixed. See their entries above; each was
|
||||
proven by a full checker run with 0 regressions.
|
||||
- It replaces `scratch/verify_bw_fields_against_xml.py`, added and
|
||||
removed within this release.
|
||||
- **Operational consequence: none.** Nothing on the ingest path changes.
|
||||
@@ -114,6 +228,45 @@ All notable changes to seismo-relay are documented here.
|
||||
The old section stays below the banner as history.
|
||||
Docs only: no code or schema change, no migration, `TOOL_VERSION` unchanged.
|
||||
|
||||
### Migration
|
||||
|
||||
⚠ **This release owes prod a backfill.** It does not move stored event times.
|
||||
|
||||
**Before you start:**
|
||||
- `TOOL_VERSION` is bumped to **0.33.0**, which gates the regeneration, so no
|
||||
`--force` is needed.
|
||||
- No parser change, so no `--reparse-txt` is needed.
|
||||
- No schema change.
|
||||
- **Back up `seismo_relay.db` first.**
|
||||
|
||||
**Then, in the `sfm` container, in this order** (the scripts default to
|
||||
`bridges/captures/seismo_relay.db` and its `waveforms/`):
|
||||
|
||||
1. `python scripts/backfill_sidecars.py` re-decodes every Series-3 event file
|
||||
whose sidecar predates 0.33.0. Sidecars and `.h5` files regenerate, and each
|
||||
DB row refreshes in place (id and review kept). ⚠ **~2 h on the NAS.**
|
||||
- **Report-less events** pick up the new values: sample rate, record time,
|
||||
pre-trigger, notes, record type, histogram vector sum, mic.
|
||||
- **Report-paired events** keep the report's values.
|
||||
- **The record type** stays the same for every ACH file (`…W` / `…H`). Only a
|
||||
histogram stored under a 3-character manual-download name flips from
|
||||
Waveform to Histogram.
|
||||
2. `python scripts/backfill_event_shape.py --db-path bridges/captures/seismo_relay.db
|
||||
--store-root bridges/captures/waveforms` recomputes the shape and offset
|
||||
metrics from the regenerated files.
|
||||
|
||||
Series-4 (Thor) events are untouched; nothing in their decode changed.
|
||||
|
||||
**Not rehearsed on a prod snapshot** (v0.32.0 was). The risk is lower:
|
||||
- Event times do not move, so every row is matched in place.
|
||||
- No row is created or removed.
|
||||
- The full decode checker ran clean against all 70,112 DL2 event files before
|
||||
release.
|
||||
|
||||
**Afterwards**, the DL2 watcher can be widened for the 2016–2024 backfill:
|
||||
`MAX_EVENT_AGE_DAYS = 2130` reaches 2021. Set it back to 365 when done,
|
||||
because the same setting widens the heartbeat's scan.
|
||||
|
||||
---
|
||||
|
||||
## v0.32.0 — 2026-10-27
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Ground-up Python replacement for **Blastware**, Instantel's Windows-only software for
|
||||
managing MiniMate Plus seismographs. Connects over direct RS-232 or cellular modem
|
||||
(Sierra Wireless RV50 / RV55). Current version: **v0.32.0**.
|
||||
(Sierra Wireless RV50 / RV55). Current version: **v0.33.0**.
|
||||
|
||||
Stack-level context — which repo owns what, and how the three project versions
|
||||
pair — lives in `../terra-view/docs/tmi-stack.md`, which is also loaded as
|
||||
@@ -10,36 +10,42 @@ pair — lives in `../terra-view/docs/tmi-stack.md`, which is also loaded as
|
||||
|
||||
---
|
||||
|
||||
## Where things stand (updated 2026-10-19)
|
||||
## Where things stand (updated 2026-11-01)
|
||||
|
||||
Read this first when picking the project back up.
|
||||
|
||||
- **🔑 The Series-3 decode checker (2026-10-29).** Goal: SFM produces everything
|
||||
Blastware reports, from the event file alone (spec/plan in `docs/superpowers/`).
|
||||
Run it with `scratch/check_s3_decode.py ~/dl2-archive/files ~/dl2-archive/xml`.
|
||||
It decodes each event from its bytes only (no filename, no report) and
|
||||
compares every field, sample and interval with Blastware's `_XML.XML`: 70,042
|
||||
events, 2016–2026, ~22 min at `--jobs 4`. Run output (`summary.md`,
|
||||
`details.json`, `changes.md`) goes to `~/dl2-archive/checker-runs/` and is
|
||||
never committed. The rule: every mismatch is SFM's bug unless a carve-out
|
||||
with evidence covers it.
|
||||
**First full run:**
|
||||
- ✅ Sample rate, record time, pre-trigger and notes match everywhere.
|
||||
- ✅ Geophone samples are exact on 6,491 / 6,524 waveforms in every year. The
|
||||
33 others are the 1.250 in/s range, 8× under SFM's Normal-range assumption.
|
||||
- ❌ Every histogram reads as a waveform without its filename (#41), and
|
||||
their start times are 1 s early (#51).
|
||||
- ❌ Open findings:
|
||||
- histogram PVS: SFM takes the vector magnitude of each channel's interval
|
||||
peak (peaks that may come from different moments); Blastware takes the
|
||||
per-interval vector sum
|
||||
- mic psi conversion
|
||||
- mic dB off by 0.05–0.1 on ~1,000 events
|
||||
- **🔑 The Series-3 decode checker (2026-10-29; v0.33.0).**
|
||||
- **Goal:** SFM produces everything Blastware reports, from the event file
|
||||
alone (spec and plan in `docs/superpowers/`).
|
||||
- **Running it:** `scratch/check_s3_decode.py ~/dl2-archive/files
|
||||
~/dl2-archive/xml` decodes each event from its bytes only (no filename, no
|
||||
report). It compares every field, sample and interval with Blastware's
|
||||
`_XML.XML`: 70,042 events, 2016–2026, ~22 min at `--jobs 4`.
|
||||
- **Output** (`summary.md`, `details.json`, `changes.md`) goes to
|
||||
`~/dl2-archive/checker-runs/` and is never committed.
|
||||
- **The rule:** every mismatch is SFM's bug unless a carve-out with evidence
|
||||
covers it.
|
||||
|
||||
**As of v0.33.0:**
|
||||
- ✅ **Match on every event:** sample rate, record time, pre-trigger, notes,
|
||||
and event type (#41, from STRT[18]).
|
||||
- ✅ **Geophone samples** are exact on 6,491 / 6,524 waveforms in every year.
|
||||
The 33 others are the 1.250 in/s range, 8× under SFM's Normal-range
|
||||
assumption.
|
||||
- ✅ **Histogram PVS** = the stored per-interval PVS²: 69,919 / 70,042.
|
||||
- ✅ **Mic: one count = 0.25 Pa,** with Blastware's dB offset at 81.9384. It
|
||||
fails on only a few dozen events.
|
||||
- ❌ **Open:**
|
||||
- histogram start times are 1 s early (#51)
|
||||
- 35 sub-minute (5 s / 2 s) histograms decode wrongly, plus 2 one-minute
|
||||
no-mic histograms (`R352HFZ7`-shaped, likely a separate cause)
|
||||
- 26 histogram start dates are a day off
|
||||
- ⬜ Not read yet: job number, ZC frequency, acceleration, displacement, time
|
||||
of peak, sensor check, battery, calibration, range, units, monitor log.
|
||||
- the per-interval PVS is not stored
|
||||
- Blastware prints `OORANGE` when the vector sum alone exceeds the range
|
||||
(a carve-out to prove)
|
||||
- ⬜ **Not read yet:** job number, ZC frequency, acceleration, displacement,
|
||||
time of peak, sensor check, battery, calibration, range, units, monitor
|
||||
log.
|
||||
- **The Series-4 LIVE wire protocol is reverse-engineered end to end
|
||||
(2026-09-25).** `docs/micromate_protocol_reference.md` is the Series-4
|
||||
Rosetta Stone, sibling to `instantel_protocol_reference.md`. **A Micromate
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# seismo-relay `v0.32.0`
|
||||
# seismo-relay `v0.33.0`
|
||||
|
||||
A ground-up replacement for **Blastware** — Instantel's aging Windows-only
|
||||
software for managing seismographs. Supports both the **MiniMate Plus
|
||||
@@ -74,6 +74,27 @@ over direct RS-232 or cellular modem (Sierra Wireless RV50 / RV55).
|
||||
>
|
||||
> ⚠ The deploy owes a backfill and moves stored waveform times; see the
|
||||
> changelog's *Migration*.
|
||||
>
|
||||
> **v0.33.0 (2026-11-01)** reads Series-III events from the file alone, and
|
||||
> proves it.
|
||||
> - **Fields now read from the event file** when no Blastware report comes with
|
||||
> the event:
|
||||
> - sample rate, record time, pre-trigger and the four notes (#44/#45)
|
||||
> - the event type (#41)
|
||||
> - a histogram's peak vector sum, which the unit stores per interval
|
||||
> - the mic, at one count = 0.25 Pa (it read ~95× low in psi)
|
||||
>
|
||||
> This matters for every DL2 event from before 2025, and for SFM's own
|
||||
> download and call-in paths, none of which have a report.
|
||||
> - **The decode checker** (`scratch/check_s3_decode.py`) compares SFM's
|
||||
> file-only decode with Blastware's `_XML.XML` event reports, field by field
|
||||
> and sample by sample, for 70,042 DL2 events back to 2016:
|
||||
> - every setup field, the notes and the event type match on every event
|
||||
> - geophone samples are exact on 6,491 / 6,524 waveforms
|
||||
> - the histogram vector sum matches on 69,919
|
||||
>
|
||||
> ⚠ The deploy owes a backfill; it does not move event times. See the
|
||||
> changelog's *Migration*.
|
||||
> See [CHANGELOG.md](CHANGELOG.md) for full version history.
|
||||
|
||||
---
|
||||
@@ -600,7 +621,16 @@ Implementation steps (concrete):
|
||||
|
||||
### High-impact (unblocks product features)
|
||||
|
||||
- [ ] **Series III waveform body codec reverse-engineering.** The 5A bulk-stream body is some kind of compressed/encoded format (not raw int16 LE as previously assumed — see §7.6.1 retraction in `docs/instantel_protocol_reference.md`). Structural framing is ~50% decoded on branch `claude/codec-re-cBGNe` (tagged-block walker, segment counters); per-byte sample mapping is still open. Until this lands, the in-app waveform viewer renders garbage and BW-import peak values fall back to `_peaks_from_samples()` saturation noise. Workaround: pair every BW-imported event with its `_ASCII.TXT` so the device-authoritative peaks land in the DB regardless of codec.
|
||||
- [x] **Series III waveform body codec reverse-engineering.** ✅ The body codec is fully decoded (`minimateplus/waveform_codec.py`, `histogram_codec.py`), and verified per-sample against Blastware's own exports. As of v0.33.0, geophone samples are exact on 6,491 / 6,524 DL2 waveforms against their `_XML.XML` reports, across 2016–2026.
|
||||
- [ ] **SFM produces everything Blastware reports, from the event file alone.** The four-piece plan:
|
||||
1. the decode checker ✅ v0.33.0
|
||||
2. complete the file-only decode, one field group at a time, each proven by the checker
|
||||
3. flip ingest so reports are kept only for checking
|
||||
4. stop the watchers forwarding reports
|
||||
|
||||
**Done so far:** setup fields, notes, event type, histogram PVS, mic.
|
||||
|
||||
**Next:** histogram start times (#51), the 37 histograms that decode wrongly, the job number, the geophone range (Sensitive-range events read 8×), and the values Blastware computes itself (ZC frequency, acceleration, displacement, time of peak), plus the sensor check, battery, calibration and monitor log. Design: `docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md`.
|
||||
- [x] **Series IV (Thor IDF) binary codec reverse-engineering.** ✅ v0.21.0 — `micromate/idf_file.read_idf_file()` decodes both IDFW (waveform body at offset `0x0f1f`, reusing `decode_waveform_v2()`; 87–99% sample fidelity on quiet events) and IDFH (dedicated segment-based decoder: all 859 corpus files decode, 181,071 intervals, peaks within ~1.8% of sidecar values). `WaveformStore.save_imported_idf` now also projects parsed Thor data into a `bw_report` block via `micromate/idf_to_bw_report.py` so Thor events render in the existing Event Report PDF pipeline without a separate renderer.
|
||||
- [ ] **In-app waveform viewer accuracy.** Depends on Series III codec decode. Plot.v1 JSON pipeline + viewer skeleton already exist; will start showing real waveforms automatically once `_decode_a5_waveform` produces correct samples. Series IV waveforms come online when the IDF codec lands.
|
||||
- [ ] **Series IV live-device support.** Once the IDF binary is decoded, extend `micromate/` with `transport.py` / `framing.py` / `protocol.py` / `client.py` mirroring the `minimateplus/` package layout — depends on capturing Thor's wire protocol (TCP / RS-232 captures TBD).
|
||||
|
||||
@@ -18,7 +18,7 @@ from dataclasses import dataclass
|
||||
from typing import Callable, Optional, Sequence
|
||||
|
||||
from .bw_xml_report import XmlReport
|
||||
from .event_file_io import _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_FS_PSI, decode_blastware_bytes
|
||||
from .event_file_io import _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT, decode_blastware_bytes
|
||||
from .models import Event
|
||||
from .waveform_codec import mic_count_to_db
|
||||
|
||||
@@ -133,7 +133,7 @@ def _mic_converter(ref: XmlReport) -> Optional[Callable[[int], float]]:
|
||||
if "dB(L)" in units:
|
||||
return mic_count_to_db
|
||||
if "psi(L)" in units:
|
||||
return lambda c: c * _MIC_FS_PSI
|
||||
return lambda c: c * _MIC_PSI_PER_COUNT
|
||||
return None
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ def _interval_converter(title: str) -> Optional[Callable[[int], float]]:
|
||||
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 lambda c: c * _MIC_PSI_PER_COUNT
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -51,7 +51,7 @@ SIDECAR_KIND = "sfm.event"
|
||||
# bumped without a `pip install` re-run — leading to confusing stale
|
||||
# version stamps in sidecars. Bump this constant and CHANGELOG.md
|
||||
# together at release time.
|
||||
TOOL_VERSION = "0.32.0" # waveform times from the event record, report dates, histogram reader; gates the backfill regen
|
||||
TOOL_VERSION = "0.33.0" # setup + notes, record type, histogram PVS and mic from the file; gates the backfill regen
|
||||
|
||||
try:
|
||||
# Best-effort: prefer the installed metadata when it's NEWER than the
|
||||
@@ -704,11 +704,16 @@ _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.
|
||||
# We mark mic_psi as "computed approximate" in the sidecar.
|
||||
_MIC_FS_PSI = 0.0125 / _INT16_FS # ~0.5 psi full-scale assumption
|
||||
# Microphone scale factor, psi per MicL count: one count is 0.25 Pa
|
||||
# (waveform_codec.MIC_PA_PER_COUNT, measured against Blastware's psi(L) on
|
||||
# 1,729,253 DL2 intervals). It replaces a "~0.5 psi full-scale" guess,
|
||||
# 0.0125 / 32768, that read every mic peak ~95x low (2026-10-31).
|
||||
_PA_PER_PSI = 6894.757
|
||||
_MIC_PSI_PER_COUNT = _wc.MIC_PA_PER_COUNT / _PA_PER_PSI
|
||||
|
||||
|
||||
def _decode_strt(strt: bytes) -> dict:
|
||||
@@ -760,9 +765,9 @@ def _peaks_from_samples(samples: dict[str, list[int]]) -> PeakValues:
|
||||
vert = _peak_ins(samples.get("Vert", []))
|
||||
long_ = _peak_ins(samples.get("Long", []))
|
||||
|
||||
# Mic in psi (approximate)
|
||||
# Mic in psi: one count = 0.25 Pa
|
||||
mic_ch = samples.get("MicL", []) or []
|
||||
mic = max((abs(int(v)) for v in mic_ch), default=0) * _MIC_FS_PSI
|
||||
mic = max((abs(int(v)) for v in mic_ch), default=0) * _MIC_PSI_PER_COUNT
|
||||
|
||||
# Peak vector sum: max over time of sqrt(T^2 + V^2 + L^2)
|
||||
pvs = 0.0
|
||||
@@ -784,6 +789,12 @@ def _peaks_from_samples(samples: dict[str, list[int]]) -> PeakValues:
|
||||
)
|
||||
|
||||
|
||||
# STRT[18], the record-type byte (#41): 0x46 on every one of DL2's 6,577
|
||||
# waveform files and 0x0A on every one of its 63,535 histograms (measured
|
||||
# 2026-10-29). Manual / Event / Combo never occur there, so their bytes are
|
||||
# unknown and decode as None, not as a guess.
|
||||
_RECORD_TYPE_BY_STRT = {0x46: "Waveform", 0x0A: "Histogram"}
|
||||
|
||||
_RECORD_TYPE_BY_EXT_SUFFIX = {
|
||||
'H': 'Histogram',
|
||||
'W': 'Waveform',
|
||||
@@ -1128,12 +1139,17 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
ev = Event(index=-1)
|
||||
if strt_fields.get("waveform_key"):
|
||||
ev._waveform_key = bytes.fromhex(strt_fields["waveform_key"])
|
||||
# Derive record_type from the filename's extension suffix (H/W/M/E/C).
|
||||
# When called from save_imported_bw the path here is a tmp file with a
|
||||
# ".bw" suffix, so the derivation falls back to "Waveform" and the
|
||||
# caller overrides ev.record_type using the original filename — see
|
||||
# waveform_store.save_imported_bw.
|
||||
ev.record_type = derive_record_type_from_filename(name)
|
||||
# The record type comes from the bytes: STRT[18] (#41). The filename's
|
||||
# last letter is only a cross-check -- SFM's own downloads have no name,
|
||||
# and a manual download's (".QZ0") carries no type at all.
|
||||
type_byte = strt_raw[18]
|
||||
ev.record_type = _RECORD_TYPE_BY_STRT.get(type_byte)
|
||||
if ev.record_type is None:
|
||||
ev.decode_problems.append(f"unknown record type byte 0x{type_byte:02x} at STRT[18]")
|
||||
named_type = derive_record_type_from_filename(name, default=None) if name else None
|
||||
if named_type is not None and ev.record_type is not None and named_type != ev.record_type:
|
||||
log.warning("%s: record type %s from the file disagrees with the filename's %s; "
|
||||
"the file's is kept", label, ev.record_type, named_type)
|
||||
|
||||
# Setup fields come from the recording-setup block (#44/#45), not the STRT
|
||||
# record: STRT[18] is the record-type marker (0x46 / 0x0A), which is why
|
||||
@@ -1229,6 +1245,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
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
@@ -628,23 +628,34 @@ def decoded_to_adc_counts(decoded: dict) -> dict:
|
||||
}
|
||||
|
||||
|
||||
# One MicL count is 0.25 Pa (measured 2026-10-31): count x 0.25 Pa matches
|
||||
# Blastware's "MicL Peak psi(L)" on all 1,729,253 DL2 histogram intervals
|
||||
# checked.
|
||||
MIC_PA_PER_COUNT = 0.25
|
||||
|
||||
# Blastware's dB(L) offset sits a hair above the exact 20 log10(0.25 Pa /
|
||||
# 20 uPa) = 81.93820: any value in [81.9383, 81.9385] matches its dB on
|
||||
# 1,729,252 / 1,729,253 intervals (the one left printed "0.000"), while
|
||||
# 81.93820 rounds count 129 (162 intervals) to 124.1 against Blastware's
|
||||
# 124.2, and the 81.94 first fitted to a handful of values misses counts 119
|
||||
# and 132. Its display chain presumably carries rounded constants; the
|
||||
# window, not the physics, is what is measured.
|
||||
_MIC_DB_REF = 81.9384
|
||||
|
||||
|
||||
def mic_count_to_db(count: int) -> float:
|
||||
"""Convert a MicL ADC count to dB(L) for BW-display-compatible output.
|
||||
|
||||
Empirical formula (confirmed 2026-05-11 against V70 fixture: count=813
|
||||
→ 140.1 dB; count=±1 → ±81.94 dB; count=±24 → ±109.5 dB):
|
||||
dB = sign(count) × (81.9384 + 20 × log10(|count|)) for |count| ≥ 1
|
||||
dB = 0.0 for count == 0
|
||||
|
||||
dB = sign(count) × (81.94 + 20 × log10(|count|)) for |count| ≥ 1
|
||||
dB = 0.0 for count == 0
|
||||
|
||||
The constant 81.94 corresponds to 10^(81.94/20) ≈ 12490 mic ADC counts
|
||||
being the dB(L) reference level — almost certainly a calibration
|
||||
constant from the device's mic.
|
||||
81.9384 ≈ 20 log10(0.25 Pa / 20 µPa); see _MIC_DB_REF.
|
||||
count=±1 → ±81.94 dB; count=813 → 140.14 dB (the V70 fixture).
|
||||
"""
|
||||
if count == 0:
|
||||
return 0.0
|
||||
sign = 1.0 if count > 0 else -1.0
|
||||
return sign * (81.94 + 20.0 * math.log10(abs(count)))
|
||||
return sign * (_MIC_DB_REF + 20.0 * math.log10(abs(count)))
|
||||
|
||||
|
||||
# ── A5-frame entry point ────────────────────────────────────────────────────
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "seismo-relay"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
description = "Python client and REST server for MiniMate Plus seismographs"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
|
||||
@@ -111,3 +111,98 @@ def test_import_without_a_report_stores_the_file_fields(tmp_path: Path):
|
||||
assert sc["event"]["pretrig_samples"] == 253
|
||||
assert sc["project_info"]["project"] == "JV 241 - 1425 Spanlers Mill Rad"
|
||||
assert sc["project_info"]["sensor_location"] == "Loc #1 - 1425 Spanlers Mill Rd"
|
||||
|
||||
|
||||
# ── #41: the record type comes from the bytes ───────────────────────────────
|
||||
# STRT[18] is the record-type byte: 0x46 on every one of DL2's 6,577 waveform
|
||||
# files, 0x0A on every one of its 63,535 histograms (measured 2026-10-29).
|
||||
|
||||
from minimateplus import blastware_file as _bw # noqa: E402
|
||||
from minimateplus.event_file_io import decode_blastware_bytes # noqa: E402
|
||||
|
||||
_TYPES = [
|
||||
("bw-import-fields-10-29-26/R352HIUI.F40W", "Waveform"),
|
||||
("bw-import-fields-10-29-26/M529L4XQ.R30H", "Histogram"),
|
||||
("5-11-26/M529LL1A.SP0", "Waveform"), # name carries no type
|
||||
("histogram-mic-off-10-26-26/K441LTOK.QZ0", "Histogram"), # name carries no type
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,want", _TYPES)
|
||||
def test_record_type_comes_from_the_bytes_without_a_name(rel, want):
|
||||
assert decode_blastware_bytes((_FIX / rel).read_bytes(), name=None).record_type == want
|
||||
|
||||
|
||||
def test_the_bytes_win_over_a_filename_that_disagrees(caplog):
|
||||
raw = (_FIX / "bw-import-fields-10-29-26/M529L4XQ.R30H").read_bytes()
|
||||
ev = decode_blastware_bytes(raw, name="M529L4XQ.R30W")
|
||||
assert ev.record_type == "Histogram"
|
||||
assert "record type" in caplog.text
|
||||
|
||||
|
||||
def test_an_unknown_type_byte_is_unknown_not_a_guess():
|
||||
raw = bytearray((_FIX / "bw-import-fields-10-29-26/R352HIUI.F40W").read_bytes())
|
||||
raw[_bw._WAVEFORM_HEADER_SIZE + 18] = 0x99
|
||||
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)
|
||||
|
||||
|
||||
# ── The mic: one count = 0.25 Pa ────────────────────────────────────────────
|
||||
# Measured 2026-10-31 against 1,729,253 DL2 histogram intervals' "MicL Peak"
|
||||
# columns: count x 0.25 Pa matches Blastware's psi(L) on every one, and
|
||||
# 20 log10(count x 0.25 Pa / 20 uPa) its dB(L) on all but 17 exact half-way
|
||||
# cases. The old psi factor (a "~0.5 psi full-scale" guess) was ~95x small.
|
||||
|
||||
from minimateplus.waveform_codec import mic_count_to_db # noqa: E402
|
||||
|
||||
|
||||
@pytest.mark.parametrize("count,printed", [
|
||||
(1, "81.94"), # XML sample cell
|
||||
(119, "123.4"), # Blastware interval tables, where 81.94 + 20 log10 gave 123.451
|
||||
(132, "124.3"), # ... and 124.351
|
||||
(129, "124.2"), # 162 intervals; exactly 0.25 Pa gives 124.149997, a hair under half-way
|
||||
(813, "140.14"), # V70 fixture, Blastware display
|
||||
])
|
||||
def test_mic_db_matches_blastware(count, printed):
|
||||
d = len(printed.split(".")[1])
|
||||
assert abs(mic_count_to_db(count) - float(printed)) <= 0.5 * 10 ** -d + 1e-9
|
||||
|
||||
|
||||
def test_mic_peak_in_psi():
|
||||
# Blastware: MicL PSPL 106.0 dB(L) = 20 uPa x 10^(106/20) = 3.990 Pa = 5.787e-4 psi.
|
||||
ev = read_blastware_file(_FIX / "decode-checker-10-29-26/M529L4XQ.R30H")
|
||||
assert ev.peak_values.micl == pytest.approx(5.787e-4, rel=0.01)
|
||||
@@ -31,11 +31,10 @@ def test_histogram_interval_peak_in_counts():
|
||||
assert s.counts["Tran"] == [7776] and s.values["NumberofIntervals"] == 1
|
||||
|
||||
|
||||
def test_no_filename_reaches_the_decoder():
|
||||
# The type must come from the bytes; today they can't tell it (#41), so this
|
||||
# histogram reads as a waveform. Update to "Full Histogram" when #41 lands.
|
||||
def test_event_type_comes_from_the_bytes():
|
||||
# No filename reaches the decoder; the type is the STRT record-type byte (#41).
|
||||
s = sfm_side((FIX / "M529L4XQ.R30H").read_bytes())
|
||||
assert s.values["EventType"] == "Full Waveform"
|
||||
assert s.values["EventType"] == "Full Histogram"
|
||||
|
||||
|
||||
def test_report_fields_stay_blank():
|
||||
@@ -143,3 +142,8 @@ def test_pvs_carveout_needs_the_clipped_channel_at_the_ceiling():
|
||||
side.values["TranPPV"] = 1.256
|
||||
res = {r.field: r for r in compare(side, ref, CARVEOUTS)}
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
|
||||
def test_interval_mic_psi_matches():
|
||||
# psi(L) report: every interval's "MicL Peak psi(L)" now converts right
|
||||
assert _results("T004JTRF.ME0H")["intervals.MicL Peak psi(L)"].verdict == "match"
|
||||
Reference in new issue
Block a user