Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb14a8f7bb | ||
|
|
e9c01ce8d4 | ||
|
|
d2258dad4e | ||
|
|
e050e602c2 | ||
|
|
fc1c7c7936 | ||
|
|
7d0d12079b | ||
|
|
5203aab849 | ||
|
|
5b65718b72 | ||
|
|
483762607e | ||
|
|
d0b66368d5 | ||
|
|
2eb1d25028 | ||
|
|
cc821f9ee3 |
No files matched your search
@@ -4,60 +4,6 @@ All notable changes to seismo-relay are documented here.
|
||||
|
||||
---
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
- **A Blastware file's geophone range comes from its setup, so Sensitive
|
||||
events no longer read 8× high.**
|
||||
- **Where it is:** in the setup's channel blocks, the byte 29 after each
|
||||
geophone label. `0x00` is Normal (10 in/s full scale), `0x01` is Sensitive
|
||||
(1.25 in/s). SFM's live 1A read has the same byte at label+33.
|
||||
- **Measured:** it matches Blastware's GeoRange on 70,042 / 70,042 DL2
|
||||
events, all three channels agreeing on every one (35 Sensitive).
|
||||
- **Before:** SFM assumed Normal, so every Sensitive event's peaks, vector
|
||||
sum and `.h5` samples read 8× high.
|
||||
- **`Event.geo_range`** is new: 0 or 1, or None when it isn't read (the
|
||||
channels disagree, an unknown value, or a missing block). None comes with
|
||||
a `decode_problems` entry, and peaks then assume Normal as before.
|
||||
- **`decode_blastware_bytes`** scales peaks and the histogram vector sum by
|
||||
the range.
|
||||
- **`event_hdf5.write_event_hdf5`:** `geo_range` now defaults to None,
|
||||
meaning the event's own range, else Normal. An explicit argument still
|
||||
wins.
|
||||
- **`waveform_store.save_imported_bw` and `scripts/backfill_sidecars.py`**
|
||||
no longer force `"normal"`. The `waveform_store` line was agreed with the
|
||||
parity session, which owns that file.
|
||||
- **Decode checker:** GeoRange 70,042 / 70,042, and geophone samples exact
|
||||
on **6,524 / 6,524** waveforms (was 6,491). PPV mismatches about halved,
|
||||
and 10 of 88 fields fully match (was 6). 70,287 comparisons fixed, 0
|
||||
regressions.
|
||||
- ⚠ **Codec change: bump `TOOL_VERSION` at the next release.** The backfill
|
||||
(`backfill_sidecars.py` then `backfill_event_shape.py`) rewrites stored
|
||||
Sensitive events' peaks and `.h5` files. No schema change.
|
||||
|
||||
### Protocol / Documentation
|
||||
- **`docs/instantel_protocol_reference.md` gains Appendix D.6:** the bytes
|
||||
and DL2 verification for every field SFM reads from a Blastware event file.
|
||||
- the record type, `STRT[18]`
|
||||
- the recording-setup block: sample rate, pre-trigger, record time and the
|
||||
four notes
|
||||
- the geophone range
|
||||
- each histogram interval's PVS²
|
||||
- the mic scale
|
||||
- **Retracted in place:**
|
||||
- `STRT[20]` as the record time: it is `00` on every DL2 file.
|
||||
- The 2026-08-26 reading of sub-minute histogram records as little-endian:
|
||||
they are big-endian from byte 5 (#47/#49), and the "2-word tail" is the
|
||||
PVS². This is corrected in CLAUDE.md too.
|
||||
- **#48 is still open.** The event file's setup block puts the pre-trigger where
|
||||
the 1A "stable anchor" `be 80 00 00 00 00` sits. In the file, though, it is
|
||||
**each event's own pre-trigger**, not the unit's setting: it varies on the
|
||||
same unit on the same day, and Blastware reports it per event. So the files
|
||||
say little about whether the live 1A read loses its anchor. (Corrected the
|
||||
same day; the first version read the file's value as the setting.)
|
||||
- **CLAUDE.md "Where things stand"** now reflects the range fix.
|
||||
- Docs only: no code change, no migration.
|
||||
|
||||
## v0.33.0 — 2026-11-01
|
||||
|
||||
**SFM reads Series-3 events from the file alone, and proves it against
|
||||
|
||||
@@ -10,7 +10,7 @@ pair — lives in `../terra-view/docs/tmi-stack.md`, which is also loaded as
|
||||
|
||||
---
|
||||
|
||||
## Where things stand (updated 2026-11-02)
|
||||
## Where things stand (updated 2026-11-01)
|
||||
|
||||
Read this first when picking the project back up.
|
||||
|
||||
@@ -25,16 +25,14 @@ Read this first when picking the project back up.
|
||||
`~/dl2-archive/checker-runs/` and is never committed.
|
||||
- **The rule:** every mismatch is SFM's bug unless a carve-out with evidence
|
||||
covers it.
|
||||
- **Byte layouts** of every field read from the file:
|
||||
`docs/instantel_protocol_reference.md` Appendix **D.6**.
|
||||
|
||||
**As of v0.33.0, plus the range fix on `dev` (`057df47`, 2026-11-02):**
|
||||
**As of v0.33.0:**
|
||||
- ✅ **Match on every event:** sample rate, record time, pre-trigger, notes,
|
||||
event type (#41, from STRT[18]), and geophone range (`dev`).
|
||||
- ✅ **Geophone samples** are exact on **6,524 / 6,524** waveforms in every
|
||||
year (`dev`). v0.33.0 had 6,491: the 33 others were on the 1.250 in/s
|
||||
range, 8× high under SFM's old Normal-range assumption.
|
||||
- ✅ **Histogram PVS** = the stored per-interval PVS²: 69,952 / 70,042.
|
||||
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:**
|
||||
@@ -46,13 +44,8 @@ Read this first when picking the project back up.
|
||||
- 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, units, monitor log.
|
||||
- 🔶 **#48 is still open.** The event file's setup block puts the pre-trigger
|
||||
where the 1A "stable anchor" `be 80 00 00 00 00` sits. In the file, though,
|
||||
it is **each event's own pre-trigger**, not the setting: 253–256 samples at
|
||||
1024 sps, alternating on the same unit on the same day, and reported that
|
||||
way by Blastware. So the files say little about whether the live 1A read
|
||||
loses its anchor (reference D.6.2).
|
||||
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
|
||||
@@ -236,9 +229,8 @@ Read this first when picking the project back up.
|
||||
over) needs a BW capture of a spanning event first. Do not ship layer one
|
||||
alone without a loud truncation warning — a silently short event is the
|
||||
failure mode this codec has been bitten by repeatedly.
|
||||
- **Open, not blocking:** ~~14 sensitive-range files show an exact 8x
|
||||
(= 10.0/1.25) units discrepancy~~ (**resolved on `dev` 2026-11-02:** the
|
||||
range is read from the file, reference D.6.4); `scripts/backfill_sidecars.py --force` also
|
||||
- **Open, not blocking:** 14 sensitive-range files show an exact 8x
|
||||
(= 10.0/1.25) units discrepancy; `scripts/backfill_sidecars.py --force` also
|
||||
inserts DB rows for store files that have none (one-time per store) and the
|
||||
dry-run does not report that count.
|
||||
- **After any codec change, regenerate the store** — `backfill_sidecars.py`
|
||||
@@ -648,14 +640,6 @@ block still covers exactly one minute:
|
||||
| 15 s | 4 | 92 |
|
||||
| 2 s | 30 | 612 |
|
||||
|
||||
> ⚠ **CORRECTED in v0.32.0 (#47/#49), recorded here 2026-11-02.** The
|
||||
> records are **big-endian, starting at byte 5**. Each holds a uint16 peak
|
||||
> and a uint16 half-period per channel, then the interval's **PVS² as a
|
||||
> uint32 BE**. Record = 4 × channels + 4 bytes: 20 with the mic, 16
|
||||
> without. `stride = 12 + n × record`. The little-endian reading below was
|
||||
> the same words shifted by one byte. Its "2-word tail" is the PVS²
|
||||
> (reference D.6.5).
|
||||
|
||||
`stride = 12 + n * 20`. Block = `[00][segment][ctr uint16 LE][0a][00]`,
|
||||
then n x 20-byte records of 8 x uint16 **LITTLE**-endian values
|
||||
(`T_peak, T_halfp, V_peak, V_halfp, L_peak, L_halfp, M_peak, M_halfp`)
|
||||
@@ -663,7 +647,6 @@ plus a 2-word tail whose first word is `0000` on every real interval,
|
||||
then a 6-byte block trailer.
|
||||
|
||||
⚠ The standard 32-byte block is BIG-endian; this variant is LITTLE-endian.
|
||||
*(Retracted: both are big-endian; see the box above.)*
|
||||
|
||||
Recovers **415 files** (216 on BE18193, 199 on BE9440) that decoded to
|
||||
nothing. Ground truth `BE9440/K440L3AQ.T70H` matches its BW ASCII export
|
||||
@@ -691,9 +674,6 @@ block has its own tail signature. Two long-standing errors:
|
||||
`1e 0a 00 00`, with arbitrary bytes at `[21:23]`. Rejecting it
|
||||
dropped the final interval of nearly every histogram — frequently the
|
||||
one holding the event peak, so the file's PPV read low.
|
||||
- **`[21:25]` is the interval's PVS² as a uint32 BE** (v0.33.0, reference
|
||||
D.6.5). The "arbitrary bytes" above are probably its high half
|
||||
(inferred).
|
||||
|
||||
Verified against 1211 production histograms paired with their BW ASCII
|
||||
exports: **1211/1211 decode exactly** (interval count plus every
|
||||
@@ -702,13 +682,11 @@ with zero mismatches. Before: 1 of 1196.
|
||||
|
||||
### What's NOT solved
|
||||
|
||||
- ~~**MicL channel conversion to dB(L)** — the codec emits MicL as
|
||||
- **MicL channel conversion to dB(L)** — the codec emits MicL as
|
||||
raw ADC counts (same format as geo channels), but BW's ASCII export
|
||||
shows mic in dB(L) with ~6 dB quantization steps. Need to map
|
||||
ADC counts → dB(L) for direct comparison; likely
|
||||
`dB = 20*log10(|counts|) + offset` or similar.~~ **Solved in v0.33.0.**
|
||||
One count = 0.25 Pa, and dB(L) = 81.9384 + 20·log10(|count|), an offset
|
||||
measured from Blastware's printed values (reference D.6.6).
|
||||
`dB = 20*log10(|counts|) + offset` or similar.
|
||||
- **Variable-prefix segment descriptors** — 3 of the 75 ground-truth
|
||||
production events still truncate. The walk reaches a segment header
|
||||
whose channel-id field is preceded by a *variable-width* prefix (2, 4
|
||||
@@ -1367,7 +1345,7 @@ Do NOT use fixed absolute offsets for sample_rate or record_time.
|
||||
| trigger_level_geo | float32 BE, located in channel block |
|
||||
| alarm_level_geo | float32 BE, adjacent to trigger_level_geo |
|
||||
| geo_hardware_constant (adc_scale_factor) | float32 BE at **channel_label+28** in both read (E5) and write (SUB 71) payloads — reads **6.206053** on BOTH tested units (BE11529 and BE18189); identical across all geo channels (Tran/Vert/Long) and all captures. **Confirmed 2026-04-17 from Interface Handbook §4.5**: this is the **ADC-to-velocity scale factor** = 1/sensitivity = (in/s per V). Firmware uses it as: `PPV (in/s) = ADC_voltage × 6.206053`. Cross-check: `1.61133 V (ADC full-scale) × 6.206053 = 10.000 in/s` (Normal range ✅). Do NOT write this field — it is a hardware/firmware constant. |
|
||||
| geo_range (sensitivity selector) | **uint8 at channel_label+33** in both read (E5) and write (SUB 71) payloads (an event file's setup copy has it at label+29: reference D.6.4) — **CONFIRMED 2026-04-20** from 4-20-26 geo sensitivity captures: `0x00` = Normal 10.000 in/s (standard gain), `0x01` = Sensitive 1.250 in/s (high gain). Present in all three geo channel blocks (Tran, Vert, Long). **NOTE: `channel_label+20` reads `0x01` on ALL captures regardless of range setting — it is NOT this field.** Note: the "SUB 71 write offset = +29" that appears in earlier analysis was an artifact of incorrect BW-style destuffing applied to write frame data — write frame data is RAW, so the literal `0x10` bytes in the channel block header are preserved, and the offset is the same as in the E5 read payload. |
|
||||
| geo_range (sensitivity selector) | **uint8 at channel_label+33** in both read (E5) and write (SUB 71) payloads — **CONFIRMED 2026-04-20** from 4-20-26 geo sensitivity captures: `0x00` = Normal 10.000 in/s (standard gain), `0x01` = Sensitive 1.250 in/s (high gain). Present in all three geo channel blocks (Tran, Vert, Long). **NOTE: `channel_label+20` reads `0x01` on ALL captures regardless of range setting — it is NOT this field.** Note: the "SUB 71 write offset = +29" that appears in earlier analysis was an artifact of incorrect BW-style destuffing applied to write frame data — write frame data is RAW, so the literal `0x10` bytes in the channel block header are preserved, and the offset is the same as in the E5 read payload. |
|
||||
| setup_name | ASCII, null-padded, in cfg body |
|
||||
| project / client / operator / sensor_location | ASCII, label-value pairs |
|
||||
|
||||
|
||||
@@ -11,10 +11,9 @@
|
||||
|
||||
| Date | Section | Change |
|
||||
|---|---|---|
|
||||
| 2026-11-02 | Appendix D.3.1, D.6 (NEW), §15 | ✅ **Event fields SFM reads from the file alone (v0.33.0, plus the range on `dev`).** New D.6 records the bytes and the DL2 verification for each field: the record type `STRT[18]`, the recording-setup block (sample rate, pre-trigger, record time, the four notes), the geophone range (label + 29 in the setup's channel blocks), each histogram interval's PVS², and the mic scale (one count = 0.25 Pa). **Retracted in place:** D.3.1's `STRT[20]` = record time (it is `00` on every DL2 file; the "70 s" SFM used to report was `STRT[18]`, the record-type byte), and the 2026-08-26 reading of sub-minute histogram records as little-endian (big-endian from byte 5 since v0.32.0, #47/#49). **For #48:** the file's copy of the block puts the pre-trigger where the 1A "stable anchor" `be 80 00 00 00 00` sits. In the file, though, it is each event's own pre-trigger, which varies on the same unit on the same day (253–256 samples at 1024 sps), and Blastware reports it per event. So the file says little about whether the live 1A loses its anchor, and #48 stays open. |
|
||||
| 2026-10-26 (5) | §7.8.9 | ✅ **The embedded event record: the instrument's trigger time, inside the 5A stream.** Every Blastware waveform file carries `00 28 05 00 ?? ?? fe 80 [trigger 8 B][stop 8 B]`, times as `dd mm yyyy(BE) 00 hh mm ss`. The trigger equals Blastware's report 1,320/1,320, the filename 7,935/7,935 and the unit's 0C record 10/10. It occurs once in the unit's own A5 payloads (8/8 events) and in SFM-only downloads (2/2): instrument data, not Blastware's. The footer's `ts2 - record time` is only an estimate, a second off on ~19%. Decoder rule, validation and an open case (3 waveform-named files the codec does not recognise) in §7.8.9. 🔶 The §7.5 `0C` "sub_code" timestamp variants look like the same 8-byte form read with its escapes. |
|
||||
| 2026-10-17 | §7.6.1 | 🔶 **OPEN — the 6-byte "stable anchor" may be two settings at their defaults, not a constant.** Series IV's `0x1A` has the same field order as the S3 compliance block, and a keypad diff pass on a Micromate (UM20147) measured the bytes in the anchor's position: `[f32 BE pre-trigger, negative seconds][record stop mode, 00 00 = Fixed]`. `be 80 00 00` is exactly −0.25 s. If S3 matches — **inferred, not measured on S3** — then any S3 unit set to Record Stop Mode = Auto (a basic Blastware Compliance Setup option) or a non-default pre-trigger loses the anchor, and `client.py` silently decodes no recording mode / sample rate / interval / record time and skips them on write. No S3 capture has ever been taken in Auto stop mode (see the 2026-03-09 Auto Window rows), which would explain why the anchor never broke. To settle: one BW capture with Record Stop Mode = Auto. See `docs/micromate_protocol_reference.md` → *The `0x1A` field map from a keypad pass*. |
|
||||
| 2026-08-26 | S7.6.2, S15 | **MULTI-INTERVAL HISTOGRAM BLOCKS - sub-minute intervals pack several per block.** ⚠ *Corrected 2026-11-02: the records are big-endian from byte 5, not little-endian (v0.32.0, #47/#49), and the "2-word tail" is the interval's PVS². See D.6.5.* The device always writes one minute of data per block, so a shorter histogram interval means more intervals packed into a longer block: 1 min -> 1 (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612), with `stride = 12 + n * 20`. Each 20-byte record holds 8 x uint16 **little**-endian values (peak/half-period per channel) plus a 2-word tail whose first word is `0000` on every real interval. The standard block is big-endian - the variant is not. This recovers **415 files** (216 on BE18193 at 2 s, 199 on BE9440 at 15 s) that previously decoded to nothing, and before that were being accepted by the WAVEFORM codec and returning garbage up to 400x the device-reported PPV. |
|
||||
| 2026-08-26 | S7.6.2, S15 | **MULTI-INTERVAL HISTOGRAM BLOCKS - sub-minute intervals pack several per block.** The device always writes one minute of data per block, so a shorter histogram interval means more intervals packed into a longer block: 1 min -> 1 (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612), with `stride = 12 + n * 20`. Each 20-byte record holds 8 x uint16 **little**-endian values (peak/half-period per channel) plus a 2-word tail whose first word is `0000` on every real interval. The standard block is big-endian - the variant is not. This recovers **415 files** (216 on BE18193 at 2 s, 199 on BE9440 at 15 s) that previously decoded to nothing, and before that were being accepted by the WAVEFORM codec and returning garbage up to 400x the device-reported PPV. |
|
||||
| 2026-08-25 (3) | S7.6.1, S15 | **THE WAVEFORM BODY IS A RECORD CHAIN, NOT A TAG STREAM — supersedes the segment-header model entirely.** Records are self-delimiting: `off+2` is a uint16 BE length and `next = off + 2 + len`; the chain ends on a record whose chan_id is `0x06`. `off+8` holds a 3-valued mode enum - `02 00` (14-byte header, anchors, cumulative deltas), `01 00` (10-byte, no anchors, ABSOLUTE values), `00 03` (10-byte, no tags at all, raw 12-bit absolute). **`40 NN` is an ordinary int16 BE data block of length 2*NN+2**, never a header; reading it as a 2*NN+16 header is what made walks drift, and the 'variable prefix' of 0/2/4/6/8 bytes reported earlier the same day was walker drift, exactly `4 - (old_stop - true_record_start)`. Verified: chain terminates on `06` in 1387/1388 files; all four channels equal length in **1388/1388** (was 156/1388); ASCII sample-count exact 72/75 -> **75/75**, fully exact 70/75 -> **73/75**; device PPV on a live decode **1306/1306** waveform (mean abs ratio error 0.00000) and **4458/4459** histogram. Also eliminated the walker-over-read class: 24 of those files were histograms the waveform codec was wrongly accepting. The superseded model is retained as `decode_waveform_legacy` because `micromate/idf_file.py` pins it for Thor IDFW body-offset search. |
|
||||
| 2026-08-25 (2) | S7.6.2, S15 | **HISTOGRAM BLOCK IS BIG-ENDIAN + terminal block tail.** The 32-byte histogram block's per-channel fields are uint16 **big-endian** (`T_peak` [5:7], `T_halfperiod` [7:9], `V_peak` [9:11], `V_halfperiod` [11:13], `L_peak` [13:15], `L_halfperiod` [15:17], `M_peak` [17:19], `M_halfperiod` [19:21]); only `block_ctr` [2:4] is little-endian. The marker is `block[4]` alone - the previous uint16 LE marker test at [4:6] forced `block[5] == 0` and thereby capped every geo peak at 255 counts (1.275 in/s), silently clipping larger peaks. The byte previously documented as a per-channel "annotation" is the high byte of the big-endian half-period, which is why it was non-zero exactly on sub-Hz intervals. Separately, the **final block of each stream carries tail `9c 06 00 42`** rather than `1e 0a 00 00` and holds arbitrary bytes at [21:23]; rejecting it dropped the last interval of nearly every histogram. Verified against 1211 production histograms paired with their Blastware ASCII exports: 1211/1211 decode exactly, plus 842,442 per-interval frequency comparisons with zero mismatches (previously 1 of 1196 files fully correct). |
|
||||
| 2026-08-25 | §7.6.1, §15, Appendix E (NEW) | **BODY CODEC + SCALE PASS — five findings, all verified against 75 production events paired with their preserved Blastware ASCII exports.** (1) **Geo full scale is 32000 ADC counts, not 32768** — one decoder unit (16 counts) is exactly 0.005 in/s, so 10.000 in/s = 32000 counts. Consumers dividing by 32768 read every geophone sample and derived peak **2.34% low**; the error scales with amplitude so it was invisible on quiet events and worst on loud ones. 216 per-channel comparisons: 32768 → 151/216 exact (worst 0.238 in/s on a 10 in/s event); 32000 → 216/216 exact, worst 1 LSB. Affects waveforms, histograms and series-4 alike. (2) **Wide-NN RLE `0X NN`** — the 12-bit NN encoding already known for `1X`/`2X` also applies to the `00 NN` RLE tag (runs > 252 samples). (3) **`30 NN` is not capped at NN=0x10** — data-section blocks reach at least 0x18; the length formula was already right. (4) **`40 NN` segment headers are variable width** — NN counts the previous-channel continuation deltas, so the header is `2*NN + 16` bytes; `40 01` and `40 03` occur alongside `40 02`. A header can also appear **tagless** (the NN=0 case): just the 14-byte tail. (5) **The header field documented as a "monotonic uint32 LE counter" is really `[channel_id][00][00][segment_index]`** with 0x46=Tran 0x47=Vert 0x48=Long 0x49=MicL — verified on 1697/1697 segment headers, zero disagreements. Decoders should take the channel from this field, not from rotation position. Items (2)–(5) each caused **silent channel truncation**: an unhandled tag ends the walk and the decoder returns short channels with no error. Corpus result end-to-end: exact 37 → 72, truncated 23 → 3, full-length value errors 15 → 0. New Appendix E documents the field-observed "offset" device fault. |
|
||||
@@ -3171,7 +3170,7 @@ The `.bin` files produced by `s3_bridge` are **not raw wire bytes**. The logger
|
||||
| **RV55 DCD/DTR default** — newer Sierra Wireless RV55 firmware does not assert DCD/DTR by default, so the MiniMate Plus never detects TCP disconnect and stays idle instead of resuming monitoring. Root cause: RV55 ACEmanager `DCD Control` setting. Workaround not yet found. | MEDIUM | 2026-04-11 | Still open |
|
||||
| ~~**Variable-prefix segment descriptors**~~ - **RESOLVED 2026-08-25:** there is no variable prefix. The body is a chain of self-delimiting records (see S7.6.1); the 0/2/4/6/8-byte prefix was walker drift from reading `40 NN` as a segment header. All 25 affected files now chain cleanly to the `06` terminator. | RESOLVED | 2026-08-25 | Resolved 2026-08-25 |
|
||||
| ~~**Histogram codec drops trailing intervals (series-3)**~~ - **RESOLVED 2026-08-25.** Two errors, both in the block model. (1) The block is **uniformly big-endian**: peaks and half-periods are uint16 BE (`T_peak` [5:7], `T_halfperiod` [7:9], `V_peak` [9:11], ...); only `block_ctr` [2:4] is LE. The old uint8-peak + "annotation"-byte model silently clipped any peak above 1.275 in/s, and the "annotation" byte was really the half-period high byte - non-zero exactly on the sub-Hz intervals BW renders `<1.0`. The marker is `block[4]` alone; testing [4:6] as a uint16 LE marker forced `block[5] == 0`, which is what capped the peak at one byte. (2) The **final block of the stream carries tail `9c 06 00 42`** instead of `1e 0a 00 00`, with arbitrary bytes at [21:23]; rejecting it dropped the last interval of nearly every histogram - often the one holding the event peak. Verified on 1211 production histograms vs their BW ASCII exports: **1211/1211 exact** (interval count + every per-interval peak) and 842,442 frequency comparisons with zero mismatches; was 1/1196. | RESOLVED | 2026-08-25 | Resolved 2026-08-25 |
|
||||
| ~~**Unmapped histogram block variant (415 files, 2 units)**~~ - **RESOLVED 2026-08-26.** ⚠ *Corrected 2026-11-02: the records are big-endian from byte 5, not little-endian (v0.32.0, #47/#49), and the "2-word tail" is the interval's PVS². See D.6.5.* When the histogram interval is SHORTER than one minute the device packs several intervals into a single block so each block still covers exactly one minute: 1 min -> 1 interval (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612). `stride = 12 + n * 20`. Block is `[00][segment][ctr uint16 LE][0a][00]` then n x 20-byte records of 8 x uint16 **LITTLE**-endian `T_peak,T_halfp,V_peak,V_halfp,L_peak,L_halfp,M_peak,M_halfp` plus a 2-word tail whose first word is `0000` on every real interval (a session ending mid-block leaves buffer garbage in the remaining slots), then a 6-byte block trailer. **Note the endianness flip** - the standard 32-byte block is big-endian. Ground truth `BE9440/K440L3AQ.T70H` (5,710 intervals at 15 s) decodes with 17,130/17,130 geo peaks, 22,840/22,840 frequencies and 5,710/5,710 mic dB(L) matching its Blastware ASCII export exactly; across all 455 affected files 1,354/1,365 channel peaks (99.2%) match the device-reported PPV. | RESOLVED | 2026-08-25 | Resolved 2026-08-26 |
|
||||
| ~~**Unmapped histogram block variant (415 files, 2 units)**~~ - **RESOLVED 2026-08-26.** When the histogram interval is SHORTER than one minute the device packs several intervals into a single block so each block still covers exactly one minute: 1 min -> 1 interval (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612). `stride = 12 + n * 20`. Block is `[00][segment][ctr uint16 LE][0a][00]` then n x 20-byte records of 8 x uint16 **LITTLE**-endian `T_peak,T_halfp,V_peak,V_halfp,L_peak,L_halfp,M_peak,M_halfp` plus a 2-word tail whose first word is `0000` on every real interval (a session ending mid-block leaves buffer garbage in the remaining slots), then a 6-byte block trailer. **Note the endianness flip** - the standard 32-byte block is big-endian. Ground truth `BE9440/K440L3AQ.T70H` (5,710 intervals at 15 s) decodes with 17,130/17,130 geo peaks, 22,840/22,840 frequencies and 5,710/5,710 mic dB(L) matching its Blastware ASCII export exactly; across all 455 affected files 1,354/1,365 channel peaks (99.2%) match the device-reported PPV. | RESOLVED | 2026-08-25 | Resolved 2026-08-26 |
|
||||
| **Micromate (UM-series) IDF decode is ~1000x low** — e.g. `UM11402_20260406130113.IDFW` decodes a Tran peak of 0.0009 in/s against a device-reported 1.1168. Distinct from the Thor IDF path, which decodes sanely. Suspect a different per-count LSB or a body offset that does not hold for UM-series files. | MEDIUM | 2026-08-25 | Still open |
|
||||
| **Thor IDF per-count LSB** — after the 32000 geo full-scale correction, series-4 Thor peaks sit at a median 0.983 of the device-reported peak (was 0.960 under 32768). Closer, but the residual ~1.7% suggests Thor uses its own per-count LSB rather than the BW 16-count/0.005 in/s convention. A code comment in `sfm/waveform_store.py` claims Thor's LSB is 0.0003 in/s, which would predict Thor reading *high* — the measurement shows the opposite, so that comment is unverified. | LOW | 2026-08-25 | Still open |
|
||||
|
||||
@@ -3398,16 +3397,8 @@ The STRT record immediately follows the 22-byte header.
|
||||
| 4 | 2 | `ff fe` | Fixed |
|
||||
| 6 | 4 | event key (key4) | 4-byte waveform key |
|
||||
| 10 | 4 | device-specific | NOT a repeat of key4 — device-internal field |
|
||||
| 14 | 4 | device-specific | not identified (see the retraction below) |
|
||||
| 18 | 1 | **record type** ✅ | `0x46` waveform, `0x0A` histogram: 6,541 / 6,541 `…W` and 63,500 / 63,500 `…H` DL2 files (2026-11-02). See D.6.1 |
|
||||
| 19 | 2 | `00 00` | zero on 70,041 / 70,041 DL2 files |
|
||||
|
||||
> ⚠ **RETRACTED 2026-11-02.** This table used to end `| 14 | 6 | device-specific |` and
|
||||
> `| 20 | 1 | rectime | uint8 seconds |`. `STRT[20]` is `0x00` on every DL2 file, so it is not
|
||||
> the record time. Until v0.33.0, SFM read a record time from `STRT[18]`, the record-type byte,
|
||||
> which is why every waveform reported "70 s" (`0x46`). It also read pre-trigger and sample count
|
||||
> from `[16:18]`; both were wrong (#45). The record time and pre-trigger live in the
|
||||
> recording-setup block (D.6.2).
|
||||
| 14 | 6 | device-specific | NOT zero-padded — device-internal fields |
|
||||
| 20 | 1 | rectime | uint8 seconds |
|
||||
|
||||
**Critical:** The STRT record must be copied verbatim from A5[0].data[7+strt_pos:] — bytes [10:20] contain device-specific values that cannot be reconstructed from protocol-level Event fields alone.
|
||||
|
||||
@@ -3585,10 +3576,6 @@ observed) and does NOT follow the AB0T formula.
|
||||
|
||||
**DLE-shift offset note for reading recording_mode from N00/9T0 body:**
|
||||
|
||||
> ⚠ **2026-11-02:** this note finds the block by the 6-byte anchor. In an event file that anchor
|
||||
> exists only when the event's own pre-trigger is exactly −0.25 s: 3,886 / 6,541 DL2 waveforms,
|
||||
> and no histogram. Find the block by its setup name instead (D.6.2).
|
||||
|
||||
The compliance block in the file body has been through `_strip_inner_frame_dles`. The 0x10 constant at logical `anchor−7` (between recording_mode and sample_rate_HI) gets stripped when sample_rate_HI = `0x04` (1024 sps), because `0x10` precedes `0x04 ∈ {0x02,0x03,0x04}`. After stripping, the anchor shifts left by 1, so:
|
||||
|
||||
| 1024 sps (strip occurs) | 2048 or 4096 sps (no strip) |
|
||||
@@ -3607,155 +3594,6 @@ file[anc−4]: histogram_interval_HI
|
||||
file[anc−3]: histogram_interval_LO
|
||||
```
|
||||
|
||||
### D.6 Event fields read from the file alone ✅ 2026-10-29 → 2026-11-02
|
||||
|
||||
Since v0.33.0, SFM decodes the fields below from an event file's bytes alone: no filename, no
|
||||
Blastware report. The code is in `minimateplus/event_file_io.py`, `histogram_codec.py` and
|
||||
`waveform_codec.py`.
|
||||
|
||||
Each field was proven by the decode checker, `scratch/check_s3_decode.py`. It compares SFM's
|
||||
decode with Blastware's `_XML.XML` report for every DL2 event: 70,042 events, 2016–2026, local
|
||||
copy in `~/dl2-archive`. Counts below are from that archive unless stated otherwise.
|
||||
|
||||
#### D.6.1 Record type — `STRT[18]` ✅
|
||||
|
||||
| `STRT[18]` | Type | DL2 |
|
||||
|---|---|---|
|
||||
| `0x46` | Waveform | 6,541 / 6,541 `…W` files |
|
||||
| `0x0A` | Histogram | 63,500 / 63,500 `…H` files |
|
||||
|
||||
- The 5A stream shows the same byte after the STRT keys (§7.8.5, `data[35]`).
|
||||
- The filename's `W` / `H` is only a cross-check. On a disagreement SFM logs it and keeps the
|
||||
byte (#41).
|
||||
- Checker, event type: 70,042 / 70,042.
|
||||
|
||||
#### D.6.2 Recording-setup block — sample rate, pre-trigger, record time ✅
|
||||
|
||||
**Find the block by structure:** `1c 08`, then the setup name (1–40 printable ASCII), then `00`.
|
||||
That pattern occurs exactly once in every DL2 file. Do not search for the name "Standard
|
||||
Recording Setup": 37% of DL2 files use another name.
|
||||
|
||||
Offsets are from `k`, the first byte of the setup name:
|
||||
|
||||
| Offset | Type | Field | Notes |
|
||||
|---|---|---|---|
|
||||
| `k − 42` | uint16 BE | sample rate | 1024 / 2048 / 4096 |
|
||||
| `k − 36` | float32 BE | pre-trigger | seconds, ≤ 0: `−0.25` is a quarter second before the trigger. **This event's own length, not the unit's setting** (below) |
|
||||
| `k − 32` | 2 bytes | — | `00 00` on 70,041 / 70,041 files |
|
||||
| `k − 30` | float32 BE | record time | seconds |
|
||||
|
||||
- Pre-trigger samples = `round(−pre-trigger × sample rate)`.
|
||||
- A histogram carries the block too, with pre-trigger `0.0` (63,500 / 63,500). Blastware reports
|
||||
no record time or pre-trigger for a histogram, and SFM reports none.
|
||||
- Sample rate, record time and pre-trigger match Blastware on every DL2 event that reports them
|
||||
(#44, #45).
|
||||
|
||||
⚠ **The file's pre-trigger is the event's, not the setting (measured 2026-11-02).**
|
||||
- **It varies from event to event on the same unit, often on the same day.** BE18193 has both
|
||||
−0.25 and −0.248 on 2026-08-21.
|
||||
- At 1024 sps the common values −0.25, −0.249, −0.248 and −0.2471 are 256, 255, 254 and 253
|
||||
samples.
|
||||
- At 4096 sps, BE18193's events range from −0.002 to −0.249 s.
|
||||
- **Blastware reports the same per-event value** as `Pre-triggerLength`, for example
|
||||
`-0.094 sec` for `T193KMX5.4Z0W`.
|
||||
- 🔶 Inferred: the unit's setting stays fixed while the captured length falls short of it. Why it
|
||||
falls short is unknown.
|
||||
|
||||
**What this means for #48 (the 1A "stable anchor"):**
|
||||
- This is the 1A compliance layout. Sample rate at anchor − 6 and record time at anchor + 6
|
||||
(§7.6.1) put the anchor at `k − 36`, so the 6-byte `be 80 00 00 00 00` is a pre-trigger of
|
||||
−0.25 s followed by the `00 00` at `k − 32`.
|
||||
- **In a file**, the anchor bytes appear only when that event's pre-trigger is exactly −0.25 s:
|
||||
3,886 / 6,541 waveforms, and no histogram (histogram files store 0.0). A file parser that
|
||||
searches for the anchor breaks on the rest. SFM's file decoder finds the block by its setup
|
||||
name instead.
|
||||
- **The live 1A read holds the setting, not an event's length.** So these files say little about
|
||||
whether the live read loses its anchor; #48 is still unsettled.
|
||||
- `k − 32 : k − 30` is `00 00` on all 70,041 files. 🔶 If `[17]` is the stop mode, as on
|
||||
Series IV, no DL2 event was recorded in Auto stop mode, so the archive cannot test that case.
|
||||
- The two blocks differ in at least one field. A live 1A in Histogram mode showed the anchor
|
||||
(−0.25 s), but histogram files store 0.0.
|
||||
|
||||
#### D.6.3 Notes — four label/value pairs after the name ✅
|
||||
|
||||
- After the name's `00`, NUL-terminated `label`, `value` pairs fill four slots, in order:
|
||||
project, client, operator ("User Name") and sensor location ("Seis Loc").
|
||||
- **Read them by position, never by label.** Blastware lets the operator relabel the slots
|
||||
("Seis. Loc:", "Location:", "Project: ").
|
||||
- An empty value means none.
|
||||
- They match Blastware on every DL2 event.
|
||||
- Not read yet: extended notes, job number.
|
||||
|
||||
#### D.6.4 Geophone range — the setup's channel blocks ✅ 2026-11-01
|
||||
|
||||
The channel blocks follow the notes, within 2,000 bytes of the name: `00 00 01` then `Tran` /
|
||||
`Vert` / `Long`. The range is the byte at label + 29, where label is the first byte of
|
||||
`Tran` / `Vert` / `Long`:
|
||||
|
||||
| label + 29 | Range | Full scale |
|
||||
|---|---|---|
|
||||
| `0x00` | Normal | 10.000 in/s |
|
||||
| `0x01` | Sensitive | 1.250 in/s |
|
||||
|
||||
- It matches the report's `GeoRange` on 70,042 / 70,042 events. The three channels agree on
|
||||
every event, and 35 are Sensitive.
|
||||
- The live 1A carries the same byte at label + 33 (§7.6, confirmed 2026-04-20).
|
||||
- Full scale is 32,000 counts at either range, so a Sensitive count is 8× smaller.
|
||||
- Until `dev` `057df47` (2026-11-02), SFM assumed Normal and read every Sensitive event 8× high.
|
||||
- If the channels disagree, a value is unknown or a block is missing, SFM reports no range, logs
|
||||
a decode problem and assumes Normal.
|
||||
|
||||
#### D.6.5 Histogram interval peak vector sum ✅ 2026-10-30
|
||||
|
||||
Each interval stores its peak vector sum **squared**:
|
||||
|
||||
| Block | Where | Type |
|
||||
|---|---|---|
|
||||
| Standard 32-byte block (intervals of a minute or more) | `[21:25]` | uint32 BE |
|
||||
| Sub-minute record | the record's last 4 bytes | uint32 BE |
|
||||
|
||||
- `PVS = √value × unit`. The unit is 16 counts: 0.005 in/s at Normal, 0.000625 in/s at
|
||||
Sensitive.
|
||||
- **The event's PVS is the largest interval's.** Combining the three channel peaks instead read
|
||||
high on 86% of DL2 histograms, because the peaks can come from different moments.
|
||||
- **Verified:** √value matches Blastware's "Geo PVS" on 34.5 M DL2 sub-minute intervals, and the
|
||||
event PVS matches on 69,952 / 70,042 events. The rest are the open histogram cases in D.6.7.
|
||||
- 🔶 On the stream's last block, the "arbitrary bytes at [21:23]" in the 2026-08-25 note are
|
||||
probably the high half of this field (inferred from the layout, not measured).
|
||||
|
||||
**Sub-minute records (corrected in v0.32.0, #47/#49):**
|
||||
- They are **big-endian, starting at byte 5** of the block.
|
||||
- Each holds, per channel, a uint16 peak and a uint16 half-period (Tran, Vert, Long, and MicL
|
||||
when the mic is on), then the uint32 PVS².
|
||||
- Record = 4 × channels + 4 bytes: 20 with the mic, 16 without. `stride = 12 + n × record`.
|
||||
|
||||
> ⚠ **RETRACTED:** the 2026-08-26 notes (Changelog, §15) read these records as 8 × uint16
|
||||
> little-endian after a 6-byte header. That was the same big-endian words shifted by one byte.
|
||||
> Their "2-word tail whose first word is 0000" is the PVS², whose high word reads `0000`.
|
||||
|
||||
#### D.6.6 Mic ✅ v0.33.0
|
||||
|
||||
- One count = **0.25 Pa**, so psi = count × 0.25 / 6894.757.
|
||||
- dB(L) = **81.9384** + 20·log10(|count|).
|
||||
- The exact value, 20·log10(0.25 Pa / 20 µPa), is 81.9382. Blastware's printed values pin the
|
||||
offset in [81.9383, 81.9385] instead.
|
||||
- With the exact value, 280 events mismatched, all at count 129.
|
||||
- float32 rounding does not explain the difference.
|
||||
- **Verified:** interval psi mismatches fell from 42,783 to 26, and mic peak mismatches from 345
|
||||
to 40.
|
||||
|
||||
#### D.6.7 Not read from the file yet
|
||||
|
||||
- **Fields:** job number, extended notes, ZC frequency, acceleration, displacement, time of
|
||||
peak, sensor check results, battery, calibration, units, monitor log.
|
||||
- **Open cases:**
|
||||
- histogram start times are 1 s early (#51)
|
||||
- 35 sub-minute histograms and 2 one-minute mic-off histograms decode wrongly
|
||||
- 26 histogram start dates are a day off
|
||||
- the per-interval PVS is not stored
|
||||
- Blastware prints `OORANGE` when the vector sum alone exceeds the range (a carve-out still to
|
||||
prove)
|
||||
|
||||
---
|
||||
|
||||
*All findings reverse-engineered from live RS-232 bridge captures.*
|
||||
|
||||
@@ -18,13 +18,12 @@ from dataclasses import dataclass
|
||||
from typing import Callable, Optional, Sequence
|
||||
|
||||
from .bw_xml_report import XmlReport
|
||||
from .event_file_io import (_GEO_FS_BY_RANGE, _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT,
|
||||
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
|
||||
|
||||
# SFM's conversion at the Normal range (10 in/s full scale = 32000 counts),
|
||||
# which SFM assumes when it cannot read the event's range from the file.
|
||||
# SFM's conversion: it cannot yet read the geophone range from the file, and
|
||||
# assumes Normal (10 in/s full scale = 32000 counts).
|
||||
GEO_IPS_PER_COUNT: float = _GEO_NORMAL_FS_INS / _GEO_INT16_FS
|
||||
|
||||
_CHANNELS = ("Tran", "Vert", "Long", "MicL")
|
||||
@@ -39,7 +38,6 @@ class SfmSide:
|
||||
job_number: Optional[str] # None until the decoder reads it
|
||||
channels: list[str] # channels with decoded data, in Tran/Vert/Long/MicL order
|
||||
counts: dict[str, list[int]] # waveform samples or histogram interval peaks
|
||||
geo_ips_per_count: float = GEO_IPS_PER_COUNT # at the event's range, as SFM read it
|
||||
|
||||
|
||||
def sfm_side(raw: bytes) -> SfmSide:
|
||||
@@ -57,7 +55,6 @@ def sfm_side(raw: bytes) -> SfmSide:
|
||||
# SFM's interval count is its decoded entry count; the reference
|
||||
# carries this field for histograms only.
|
||||
"NumberofIntervals": len(counts["Tran"]) or None,
|
||||
"GeoRange": _GEO_FS_BY_RANGE.get(ev.geo_range),
|
||||
}
|
||||
if ts is not None:
|
||||
date = f"{ts.year:04d}-{ts.month:02d}-{ts.day:02d}"
|
||||
@@ -81,7 +78,6 @@ def sfm_side(raw: bytes) -> SfmSide:
|
||||
job_number=None,
|
||||
channels=[ch for ch in _CHANNELS if counts[ch]],
|
||||
counts=counts,
|
||||
geo_ips_per_count=_GEO_FS_BY_RANGE.get(ev.geo_range, _GEO_NORMAL_FS_INS) / _GEO_INT16_FS,
|
||||
)
|
||||
|
||||
|
||||
@@ -188,20 +184,19 @@ def _series_result(field: str, n_bw: int, n_sfm: int, diffs: list[tuple[int, flo
|
||||
)
|
||||
|
||||
|
||||
def _sample_converters(sfm: SfmSide, ref: XmlReport) -> dict[str, Callable[[int], float]]:
|
||||
k = sfm.geo_ips_per_count
|
||||
convert: dict[str, Callable[[int], float]] = {ch: (lambda c: c * k) for ch in _GEO}
|
||||
def _sample_converters(ref: XmlReport) -> dict[str, Callable[[int], float]]:
|
||||
convert: dict[str, Callable[[int], float]] = {ch: (lambda c: c * GEO_IPS_PER_COUNT) for ch in _GEO}
|
||||
mic = _mic_converter(ref)
|
||||
if mic is not None:
|
||||
convert["MicL"] = mic
|
||||
return convert
|
||||
|
||||
|
||||
def _interval_converter(title: str, sfm: SfmSide) -> Optional[Callable[[int], float]]:
|
||||
def _interval_converter(title: str) -> Optional[Callable[[int], float]]:
|
||||
"""SFM keeps each interval's peaks; it drops their frequencies and geo PVS."""
|
||||
ch, _, rest = title.partition(" ")
|
||||
if rest.startswith("Peak") and ch in _GEO:
|
||||
return lambda c: c * sfm.geo_ips_per_count
|
||||
return lambda c: c * GEO_IPS_PER_COUNT
|
||||
if ch == "MicL" and rest == "Peak dB(L)":
|
||||
return mic_count_to_db
|
||||
if ch == "MicL" and rest == "Peak psi(L)":
|
||||
@@ -220,7 +215,7 @@ def series_pairs(sfm: SfmSide, ref: XmlReport,
|
||||
a row whose cell count differs is a disagreement for every channel."""
|
||||
if field.startswith("samples."):
|
||||
ch = field[len("samples."):]
|
||||
convert = _sample_converters(sfm, ref).get(ch)
|
||||
convert = _sample_converters(ref).get(ch)
|
||||
counts = sfm.counts.get(ch, [])
|
||||
if convert is None or not counts:
|
||||
return None
|
||||
@@ -237,7 +232,7 @@ def series_pairs(sfm: SfmSide, ref: XmlReport,
|
||||
if field.startswith("intervals."):
|
||||
title = field[len("intervals."):]
|
||||
columns = ref.interval_columns or []
|
||||
convert = _interval_converter(title, sfm)
|
||||
convert = _interval_converter(title)
|
||||
counts = sfm.counts.get(title.partition(" ")[0], [])
|
||||
if convert is None or not counts or title not in columns:
|
||||
return None
|
||||
|
||||
@@ -704,11 +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
|
||||
# Full scale per geo_range: 0 Normal, 1 Sensitive.
|
||||
_GEO_FS_BY_RANGE = {0: _GEO_NORMAL_FS_INS, 1: _GEO_SENSITIVE_FS_INS}
|
||||
# A histogram's geo values are decoder units of 16 counts: 0.005 in/s at the
|
||||
# Normal range, scaled by the range's full scale like the samples above.
|
||||
_HIST_GEO_COUNTS_PER_UNIT = 16
|
||||
# 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 MicL count: one count is 0.25 Pa
|
||||
# (waveform_codec.MIC_PA_PER_COUNT, measured against Blastware's psi(L) on
|
||||
@@ -751,19 +749,17 @@ def _decode_samples_4ch_int16_le(stream: bytes) -> dict[str, list[int]]:
|
||||
}
|
||||
|
||||
|
||||
def _peaks_from_samples(samples: dict[str, list[int]],
|
||||
geo_fs_ins: float = _GEO_NORMAL_FS_INS) -> PeakValues:
|
||||
def _peaks_from_samples(samples: dict[str, list[int]]) -> PeakValues:
|
||||
"""
|
||||
Compute peaks from raw int16 samples at the given geophone full scale
|
||||
(Normal, 10 in/s, unless the file's range says otherwise). Used by the
|
||||
BW-importer when the 0C waveform record (the device's authoritative peaks)
|
||||
is unavailable.
|
||||
Compute approximate peaks from raw int16 samples assuming Normal-range
|
||||
geophone sensitivity. Used by the BW-importer when the 0C waveform
|
||||
record (the device's authoritative peaks) is unavailable.
|
||||
"""
|
||||
def _peak_ins(ch: list[int]) -> float:
|
||||
if not ch:
|
||||
return 0.0
|
||||
m = max(abs(int(v)) for v in ch)
|
||||
return m / _GEO_INT16_FS * geo_fs_ins
|
||||
return m / _GEO_INT16_FS * _GEO_NORMAL_FS_INS
|
||||
|
||||
tran = _peak_ins(samples.get("Tran", []))
|
||||
vert = _peak_ins(samples.get("Vert", []))
|
||||
@@ -777,7 +773,7 @@ def _peaks_from_samples(samples: dict[str, list[int]],
|
||||
pvs = 0.0
|
||||
n = min(len(samples.get("Tran", [])), len(samples.get("Vert", [])), len(samples.get("Long", [])))
|
||||
if n:
|
||||
scale = geo_fs_ins / _GEO_INT16_FS
|
||||
scale = _GEO_NORMAL_FS_INS / _GEO_INT16_FS
|
||||
T = samples["Tran"]; V = samples["Vert"]; L = samples["Long"]
|
||||
for i in range(n):
|
||||
t = T[i] * scale
|
||||
@@ -1000,32 +996,6 @@ def _setup_notes(raw: bytes) -> ProjectInfo:
|
||||
operator=operator, sensor_location=location)
|
||||
|
||||
|
||||
# The geophone range sits in the setup's channel blocks, which follow the
|
||||
# notes: the byte 29 after each geophone label (`00 00 01 Tran ...`). 0x00 is
|
||||
# Normal, 0x01 Sensitive -- Blastware's GeoRange on 70,042 / 70,042 DL2 events,
|
||||
# all three channels agreeing on every one (measured 2026-11-01). SFM's live
|
||||
# 1A read has the same byte at label+33.
|
||||
_RANGE_AFTER_LABEL = 29
|
||||
_CHANNEL_BLOCK_SPAN = 2000 # how far past the setup name the blocks may sit
|
||||
|
||||
|
||||
def _setup_geo_range(raw: bytes) -> tuple[Optional[int], Optional[str]]:
|
||||
"""(geo_range, problem): 0 Normal or 1 Sensitive when all three geophone
|
||||
channels say the same, else None and why."""
|
||||
k = _setup_name_at(raw)
|
||||
if k is None:
|
||||
return None, "no recording-setup block to read the geophone range from"
|
||||
found = {}
|
||||
for label in (b"Tran", b"Vert", b"Long"):
|
||||
i = raw.find(b"\x00\x00\x01" + label, k, k + _CHANNEL_BLOCK_SPAN)
|
||||
p = i + 3 + _RANGE_AFTER_LABEL
|
||||
found[label.decode()] = raw[p] if i >= 0 and p < len(raw) else None
|
||||
values = set(found.values())
|
||||
if len(values) == 1 and values <= {0, 1}:
|
||||
return values.pop(), None
|
||||
return None, f"geophone range not read: channel range bytes {found}"
|
||||
|
||||
|
||||
def read_blastware_file(path: Union[str, Path], *, name: Optional[str] = None) -> Event:
|
||||
"""Parse a Blastware event file into an Event: `decode_blastware_bytes` on its
|
||||
bytes, `name` defaulting to the file's own (see there -- never a time source)."""
|
||||
@@ -1186,9 +1156,6 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
# every waveform used to read "70 s". A histogram has no record time or
|
||||
# pre-trigger -- Blastware reports neither.
|
||||
ev.sample_rate = _setup_sample_rate(raw)
|
||||
ev.geo_range, range_problem = _setup_geo_range(raw)
|
||||
if range_problem:
|
||||
ev.decode_problems.append(range_problem + "; peaks assume the Normal range")
|
||||
if is_waveform_body:
|
||||
ev.rectime_seconds = _setup_record_time(raw)
|
||||
ev.total_samples = len(samples["Tran"]) or None
|
||||
@@ -1277,17 +1244,14 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
# None, and ``apply_report_to_event`` overlays from a paired ASCII
|
||||
# report when one is supplied.
|
||||
has_samples = any(samples.get(ch) for ch in ("Tran", "Vert", "Long", "MicL"))
|
||||
# The geophone full scale is the file's range; Normal when it wasn't read.
|
||||
geo_fs = _GEO_FS_BY_RANGE.get(ev.geo_range, _GEO_NORMAL_FS_INS)
|
||||
ev.peak_values = _peaks_from_samples(samples, geo_fs) 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_COUNTS_PER_UNIT * geo_fs / _GEO_INT16_FS)
|
||||
ev.peak_values.peak_vector_sum = max(pvs) * _HIST_GEO_UNIT_INS
|
||||
ev._a5_frames = None # not recoverable from BW file
|
||||
|
||||
return ev
|
||||
@@ -543,9 +543,6 @@ class Event:
|
||||
total_samples: Optional[int] = None # from STRT record: expected total sample-sets
|
||||
pretrig_samples: Optional[int] = None # from STRT record: pre-trigger sample count
|
||||
rectime_seconds: Optional[int] = None # from STRT record: record duration (seconds)
|
||||
# Geophone range from the recording setup, as ComplianceConfig.geo_range:
|
||||
# 0 Normal (10 in/s full scale), 1 Sensitive (1.25 in/s). None: not read.
|
||||
geo_range: Optional[int] = None
|
||||
|
||||
# Sensor self-check traces keyed by channel label — the short diagnostic
|
||||
# waveforms the unit records when it pulses each sensor before monitoring
|
||||
|
||||
@@ -428,7 +428,8 @@ def main(argv=None) -> int:
|
||||
try:
|
||||
event_hdf5.write_event_hdf5(
|
||||
hdf5_path, ev,
|
||||
serial=serial, # range: the event's own, from its setup
|
||||
serial=serial,
|
||||
geo_range="normal",
|
||||
source_kind=source_kind,
|
||||
)
|
||||
hdf5_filename = hdf5_path.name
|
||||
|
||||
+1
-6
@@ -180,7 +180,7 @@ def write_event_hdf5(
|
||||
event: Event,
|
||||
*,
|
||||
serial: str,
|
||||
geo_range = None,
|
||||
geo_range = "normal",
|
||||
source_kind: str = "sfm-live",
|
||||
tool_version: Optional[str] = None,
|
||||
captured_at: Optional[datetime.datetime] = None,
|
||||
@@ -190,9 +190,6 @@ def write_event_hdf5(
|
||||
"""
|
||||
Persist a decoded Event as an HDF5 file with samples in physical units.
|
||||
|
||||
``geo_range`` left as None takes the event's own (``event.geo_range``,
|
||||
which a Blastware file's decode reads from its setup block), else Normal.
|
||||
|
||||
``geo_ips_per_count`` overrides the range-derived MiniMate count scale
|
||||
for sources whose counts differ — Thor IDF imports pass
|
||||
``micromate.idf_file._GEO_LSB_IPS`` (issue #42).
|
||||
@@ -205,8 +202,6 @@ def write_event_hdf5(
|
||||
pv = event.peak_values
|
||||
pi = event.project_info
|
||||
|
||||
if geo_range is None:
|
||||
geo_range = event.geo_range if getattr(event, "geo_range", None) is not None else "normal"
|
||||
geo_fs = _resolve_geo_full_scale(geo_range)
|
||||
geo_range_str = _normalise_range(geo_range)
|
||||
captured_at = captured_at or datetime.datetime.utcnow()
|
||||
|
||||
@@ -412,7 +412,8 @@ class WaveformStore:
|
||||
try:
|
||||
event_hdf5.write_event_hdf5(
|
||||
hdf5_path, ev,
|
||||
serial=serial, # range: the event's own, read from the file's setup
|
||||
serial=serial,
|
||||
geo_range="normal", # BW file doesn't carry the range; assume Normal
|
||||
source_kind="bw-import",
|
||||
)
|
||||
hdf5_filename = hdf5_path.name
|
||||
|
||||
BIN
Binary file not shown.
-3207
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
@@ -1,167 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Event>
|
||||
<FileVersion>8.0</FileVersion>
|
||||
<EventType>Full Histogram</EventType>
|
||||
<SerialNumber>BE11010</SerialNumber>
|
||||
<Version>V 10.72-8.17 MiniMate Plus</Version>
|
||||
<FileName>M010HR6K.OA0H</FileName>
|
||||
<HistogramStartTime>17:02:34</HistogramStartTime>
|
||||
<HistogramStartDate>2019-01-08</HistogramStartDate>
|
||||
<HistogramStopTime>17:20:00</HistogramStopTime>
|
||||
<HistogramStopDate>2019-01-08</HistogramStopDate>
|
||||
<Channels>
|
||||
<Channel>Tran</Channel>
|
||||
<Channel>Vert</Channel>
|
||||
<Channel>Long</Channel>
|
||||
<Channel>MicL</Channel>
|
||||
</Channels>
|
||||
<NumberofIntervals>18.00</NumberofIntervals>
|
||||
<IntervalSize>1 minute</IntervalSize>
|
||||
<SampleRate>1024 sps</SampleRate>
|
||||
<BatteryLevel>6.8 Volts</BatteryLevel>
|
||||
<Calibration>December 17, 2018 by Instantel</Calibration>
|
||||
<Units>in/s and dB(L)</Units>
|
||||
<Project>Wampum Ave-ECMS 29301-215 Joseph St</Project>
|
||||
<Client>Brayman Construction</Client>
|
||||
<UserName>Terra-Mechanics Inc - D. Bartholomae</UserName>
|
||||
<Seis.Loc>Loc, #1 - 215 Joseph Street</Seis.Loc>
|
||||
<GeoRange>
|
||||
<Value>1.250</Value>
|
||||
<Units>in/s</Units>
|
||||
</GeoRange>
|
||||
<TranPPV>
|
||||
<Value>0.008</Value>
|
||||
<Units>in/s</Units>
|
||||
</TranPPV>
|
||||
<VertPPV>
|
||||
<Value>0.009</Value>
|
||||
<Units>in/s</Units>
|
||||
</VertPPV>
|
||||
<LongPPV>
|
||||
<Value>0.005</Value>
|
||||
<Units>in/s</Units>
|
||||
</LongPPV>
|
||||
<TranZCFreq>
|
||||
<Value>11</Value>
|
||||
<Units>Hz</Units>
|
||||
</TranZCFreq>
|
||||
<VertZCFreq>
|
||||
<Value>73</Value>
|
||||
<Units>Hz</Units>
|
||||
</VertZCFreq>
|
||||
<LongZCFreq>
|
||||
<Value>16</Value>
|
||||
<Units>Hz</Units>
|
||||
</LongZCFreq>
|
||||
<TranPeakTime>17:11:34</TranPeakTime>
|
||||
<TranPeakDate>2019-01-08</TranPeakDate>
|
||||
<VertPeakTime>17:03:34</VertPeakTime>
|
||||
<VertPeakDate>2019-01-08</VertPeakDate>
|
||||
<LongPeakTime>17:11:34</LongPeakTime>
|
||||
<LongPeakDate>2019-01-08</LongPeakDate>
|
||||
<PeakVectorSum>
|
||||
<Value>0.009</Value>
|
||||
<Units>in/s</Units>
|
||||
</PeakVectorSum>
|
||||
<PeakVectorSumTime>17:11:34</PeakVectorSumTime>
|
||||
<PeakVectorSumDate>2019-01-08</PeakVectorSumDate>
|
||||
<Microphone>Linear Weighting</Microphone>
|
||||
<MicLPSPL>
|
||||
<Value>134.1</Value>
|
||||
<Units>dB(L)</Units>
|
||||
</MicLPSPL>
|
||||
<MicLTime>17:03:34</MicLTime>
|
||||
<MicLDate>2019-01-08</MicLDate>
|
||||
<MicLZCFreq>
|
||||
<Value>9.7</Value>
|
||||
<Units>Hz</Units>
|
||||
</MicLZCFreq>
|
||||
<TranTestFreq>7.2 Hz.</TranTestFreq>
|
||||
<TranTestRatio>4.3</TranTestRatio>
|
||||
<TranTestResults>Passed</TranTestResults>
|
||||
<VertTestFreq>7.6 Hz.</VertTestFreq>
|
||||
<VertTestRatio>3.4</VertTestRatio>
|
||||
<VertTestResults>Passed</VertTestResults>
|
||||
<LongTestFreq>7.2 Hz.</LongTestFreq>
|
||||
<LongTestRatio>3.8</LongTestRatio>
|
||||
<LongTestResults>Passed</LongTestResults>
|
||||
<MicLTestFreq>20.1 Hz.</MicLTestFreq>
|
||||
<MicLTestAmplitude>583 mv</MicLTestAmplitude>
|
||||
<MicLTestResults>Passed</MicLTestResults>
|
||||
<UsbSummaryChannels>
|
||||
</UsbSummaryChannels>
|
||||
<MonitorLog>2019-01-08 17:02:33 - 2019-01-08 17:20:00 "Event Recorded Modem Exit"</MonitorLog>
|
||||
<HistogramData>
|
||||
<HistogramDataColumnTitle>
|
||||
<ColumnTitle> Tran Peak in/s </ColumnTitle>
|
||||
<ColumnTitle> Tran Freq Hz </ColumnTitle>
|
||||
<ColumnTitle> Vert Peak in/s </ColumnTitle>
|
||||
<ColumnTitle> Vert Freq Hz </ColumnTitle>
|
||||
<ColumnTitle> Long Peak in/s </ColumnTitle>
|
||||
<ColumnTitle> Long Freq Hz </ColumnTitle>
|
||||
<ColumnTitle> Geo PVS in/s </ColumnTitle>
|
||||
<ColumnTitle> MicL Peak psi(L) </ColumnTitle>
|
||||
<ColumnTitle> MicL Peak dB(L) </ColumnTitle>
|
||||
<ColumnTitle> MicL Freq Hz </ColumnTitle>
|
||||
</HistogramDataColumnTitle>
|
||||
<HistogramDataIntervals>
|
||||
<Time>2019-01-08 17:03:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>47</Cell><Cell>0.009</Cell><Cell>73</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.009</Cell><Cell>0.015</Cell><Cell>134.1</Cell><Cell>9.7</Cell></Row>
|
||||
<Time>2019-01-08 17:04:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>21</Cell><Cell>0.007</Cell><Cell>27</Cell><Cell>0.002</Cell><Cell>85</Cell><Cell>0.007</Cell><Cell>0.000</Cell><Cell>87.96</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:05:34</Time>
|
||||
<Row>
|
||||
<Cell>0.004</Cell><Cell>20</Cell><Cell>0.004</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.005</Cell><Cell>0.003</Cell><Cell>119.1</Cell><Cell>7.5</Cell></Row>
|
||||
<Time>2019-01-08 17:06:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>34</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>51</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:07:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>51</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>39</Cell></Row>
|
||||
<Time>2019-01-08 17:08:34</Time>
|
||||
<Row>
|
||||
<Cell>0.004</Cell><Cell>12</Cell><Cell>0.004</Cell><Cell>16</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.005</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>13</Cell></Row>
|
||||
<Time>2019-01-08 17:09:34</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>51</Cell><Cell>0.002</Cell><Cell>64</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:10:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>12</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:11:34</Time>
|
||||
<Row>
|
||||
<Cell>0.008</Cell><Cell>11</Cell><Cell>0.005</Cell><Cell>13</Cell><Cell>0.005</Cell><Cell>16</Cell><Cell>0.009</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>19</Cell></Row>
|
||||
<Time>2019-01-08 17:12:34</Time>
|
||||
<Row>
|
||||
<Cell>0.006</Cell><Cell>13</Cell><Cell>0.004</Cell><Cell>14</Cell><Cell>0.004</Cell><Cell>51</Cell><Cell>0.007</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>20</Cell></Row>
|
||||
<Time>2019-01-08 17:13:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>57</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>87.96</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:14:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>47</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>13</Cell></Row>
|
||||
<Time>2019-01-08 17:15:34</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>95.92</Cell><Cell>2.5</Cell></Row>
|
||||
<Time>2019-01-08 17:16:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>13</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>85</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>93.98</Cell><Cell>9.1</Cell></Row>
|
||||
<Time>2019-01-08 17:17:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>17</Cell><Cell>0.002</Cell><Cell>85</Cell><Cell>0.002</Cell><Cell>73</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:18:34</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>87.96</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:19:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>73</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>20</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>6.1</Cell></Row>
|
||||
<Time>2019-01-08 17:20:00</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>37</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>18</Cell></Row>
|
||||
</HistogramDataIntervals>
|
||||
</HistogramData>
|
||||
<HistogramDataUsbChannels>
|
||||
</HistogramDataUsbChannels>
|
||||
|
||||
</Event>
|
||||
@@ -206,73 +206,3 @@ 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)
|
||||
|
||||
|
||||
# ── The geophone range: Normal or Sensitive ─────────────────────────────────
|
||||
# In the setup's channel blocks, the byte 29 after each geophone label is the
|
||||
# range: 0x00 Normal (10 in/s full scale), 0x01 Sensitive (1.25 in/s). It
|
||||
# matches Blastware's GeoRange on 70,042 / 70,042 DL2 events, all three
|
||||
# channels agreeing on every one (35 Sensitive), measured 2026-11-01. Until
|
||||
# now SFM assumed Normal, so a Sensitive event read 8x high.
|
||||
|
||||
from minimateplus.event_file_io import _setup_name_at # noqa: E402
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,want", [
|
||||
("bw-import-fields-10-29-26/R352HIUI.F40W", 0),
|
||||
("geo-range-11-01-26/K557J1KB.RQ0W", 1), # waveform, XML GeoRange 1.250
|
||||
("geo-range-11-01-26/M010HR6K.OA0H", 1), # histogram, XML GeoRange 1.250
|
||||
])
|
||||
def test_geo_range_comes_from_the_file(rel, want):
|
||||
assert read_blastware_file(_FIX / rel).geo_range == want
|
||||
|
||||
|
||||
# (file, Blastware's Tran / Vert / Long PPV and Peak Vector Sum, from its XML)
|
||||
@pytest.mark.parametrize("rel,peaks", [
|
||||
("geo-range-11-01-26/K557J1KB.RQ0W", ("0.019", "0.055", "0.019", "0.061")),
|
||||
("geo-range-11-01-26/M010HR6K.OA0H", ("0.008", "0.009", "0.005", "0.009")),
|
||||
])
|
||||
def test_sensitive_range_peaks_are_not_8x(rel, peaks):
|
||||
pv = read_blastware_file(_FIX / rel).peak_values
|
||||
for got, want in zip((pv.tran, pv.vert, pv.long, pv.peak_vector_sum), peaks):
|
||||
assert abs(got - float(want)) <= 0.0005 + 1e-9, (got, want)
|
||||
|
||||
|
||||
def test_channels_that_disagree_give_no_range_and_a_problem():
|
||||
raw = bytearray((_FIX / "geo-range-11-01-26/K557J1KB.RQ0W").read_bytes())
|
||||
i = raw.find(b"\x00\x00\x01Vert", _setup_name_at(bytes(raw)))
|
||||
raw[i + 3 + 29] = 0x00 # Vert Normal, Tran / Long Sensitive
|
||||
ev = decode_blastware_bytes(bytes(raw), name=None)
|
||||
assert ev.geo_range is None
|
||||
assert any("range" in p for p in ev.decode_problems)
|
||||
|
||||
|
||||
def test_the_h5_takes_the_events_range(tmp_path):
|
||||
import h5py
|
||||
from sfm import event_hdf5
|
||||
ev = read_blastware_file(_FIX / "geo-range-11-01-26/K557J1KB.RQ0W")
|
||||
event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE9557")
|
||||
with h5py.File(tmp_path / "e.h5", "r") as f:
|
||||
assert f.attrs["geo_range"] == "sensitive"
|
||||
assert abs(float(abs(f["samples/Vert"][:]).max()) - 0.055) <= 0.0005 + 1e-9
|
||||
|
||||
|
||||
def test_an_imported_file_and_the_backfill_store_its_range(tmp_path):
|
||||
import h5py
|
||||
import scripts.backfill_sidecars as backfill
|
||||
from sfm import event_hdf5
|
||||
from sfm.waveform_store import WaveformStore
|
||||
|
||||
src = _FIX / "geo-range-11-01-26/K557J1KB.RQ0W"
|
||||
store = WaveformStore(tmp_path / "waveforms")
|
||||
ev, _ = store.save_imported_bw(src.read_bytes(), source_path=src)
|
||||
h5 = store.hdf5_path_for("BE9557", src.name)
|
||||
with h5py.File(h5, "r") as f:
|
||||
assert f.attrs["geo_range"] == "sensitive"
|
||||
|
||||
# A file stored before this fix carries "normal"; the backfill rewrites it.
|
||||
event_hdf5.write_event_hdf5(h5, ev, serial="BE9557", geo_range="normal")
|
||||
assert backfill.main(["--store-root", str(tmp_path / "waveforms"),
|
||||
"--db-path", str(tmp_path / "seismo_relay.db"), "--force"]) == 0
|
||||
with h5py.File(h5, "r") as f:
|
||||
assert f.attrs["geo_range"] == "sensitive"
|
||||
@@ -28,8 +28,7 @@ def test_find_pairs_dedupes_and_pairs(tmp_path):
|
||||
def test_check_event_rows_and_attrs():
|
||||
out = run.check_event("M007HVWF.K30W", str(FIX / "M007HVWF.K30W"), str(FIX / "M007HVWF_K30W_XML.XML"))
|
||||
assert out["attrs"]["range"] == "1.250" and out["attrs"]["model"] == "MiniMate Plus"
|
||||
# clipped at its own 1.250 ceiling: accepted under the saturation carve-out
|
||||
assert ["TranPPV", "accepted"] in [r[:2] for r in out["results"]]
|
||||
assert any(r[0] == "TranPPV" and r[1] == "mismatch" for r in out["results"])
|
||||
|
||||
|
||||
def test_bad_input_is_one_error_row(tmp_path):
|
||||
@@ -129,7 +128,7 @@ def test_compare_to_marks_the_summary(tmp_path):
|
||||
def test_file_prints_one_event(tmp_path, capsys):
|
||||
assert run.main([str(FIX), str(FIX), "--file", "M007HVWF.K30W"]) == 0
|
||||
out = capsys.readouterr().out
|
||||
assert any("TranPPV" in line and "accepted" in line for line in out.splitlines())
|
||||
assert any("TranPPV" in line and "mismatch" in line for line in out.splitlines())
|
||||
|
||||
|
||||
# ── Final review fixes ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -114,23 +114,8 @@ def test_clipped_normal_range_is_accepted():
|
||||
assert (res[f].verdict, res[f].carveout) == ("accepted", "saturation")
|
||||
|
||||
|
||||
def test_a_clipped_sensitive_event_is_accepted_at_its_own_ceiling():
|
||||
# SFM reads the 1.250 range from the file; the clipped channels sit at 1.2506.
|
||||
def test_sensitive_range_8x_stays_a_mismatch():
|
||||
res = _results("M007HVWF.K30W", CARVEOUTS)
|
||||
assert res["GeoRange"].verdict == "match" and res["samples.Tran"].verdict == "match"
|
||||
for f in ("TranPPV", "PeakVectorSum"):
|
||||
assert (res[f].verdict, res[f].carveout) == ("accepted", "saturation")
|
||||
|
||||
|
||||
def test_the_carveout_never_accepts_an_8x_value():
|
||||
# What SFM produced while it assumed Normal on a Sensitive unit: 8x high.
|
||||
# The saturation rule must leave it a mismatch.
|
||||
raw = (FIX / "M007HVWF.K30W").read_bytes()
|
||||
side = sfm_side(raw)
|
||||
side.values.update(TranPPV=10.005, VertPPV=10.005, LongPPV=10.005, PeakVectorSum=17.33)
|
||||
side.geo_ips_per_count = 10.0 / 32000
|
||||
res = {r.field: r for r in compare(side, parse_xml_report_file(FIX / "M007HVWF_K30W_XML.XML"),
|
||||
CARVEOUTS)}
|
||||
assert res["TranPPV"].verdict == "mismatch" and res["samples.Tran"].verdict == "mismatch"
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
@@ -148,14 +133,13 @@ def test_pvs_carveout_needs_oorange_from_blastware():
|
||||
|
||||
|
||||
def test_pvs_carveout_needs_the_clipped_channel_at_the_ceiling():
|
||||
# 1.250 range, Blastware PVS OORANGE, but no channel Blastware clamped: an
|
||||
# UNclipped channel's 8x value landing in the 1.250 band must not let a vector
|
||||
# sum through, even one inside the sqrt(3) bound.
|
||||
# 1.250 range, Blastware PVS OORANGE; an UNclipped channel's 8x value happens to land
|
||||
# in the 1.250 band -- that must not let SFM's 8x vector sum through.
|
||||
raw = (FIX / "M007HVWF.K30W").read_bytes()
|
||||
ref = parse_xml_report_file(FIX / "M007HVWF_K30W_XML.XML")
|
||||
ref.scalars.update(TranPPV="0.157", VertPPV="0.157", LongPPV="0.157")
|
||||
ref.scalars["TranPPV"] = "0.157"
|
||||
side = sfm_side(raw)
|
||||
side.values.update(TranPPV=1.256, PeakVectorSum=2.0)
|
||||
side.values["TranPPV"] = 1.256
|
||||
res = {r.field: r for r in compare(side, ref, CARVEOUTS)}
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
@@ -163,12 +147,3 @@ def test_pvs_carveout_needs_the_clipped_channel_at_the_ceiling():
|
||||
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"
|
||||
|
||||
|
||||
def test_a_sensitive_range_event_now_matches():
|
||||
gr = FIX.parent / "geo-range-11-01-26"
|
||||
raw = (gr / "K557J1KB.RQ0W").read_bytes()
|
||||
res = {r.field: r for r in compare(sfm_side(raw), parse_xml_report_file(gr / "K557J1KB_RQ0W_XML.XML"))}
|
||||
for f in ("GeoRange", "TranPPV", "VertPPV", "LongPPV", "PeakVectorSum",
|
||||
"samples.Tran", "samples.Vert", "samples.Long"):
|
||||
assert res[f].verdict == "match", (f, res[f])
|
||||
Reference in new issue
Block a user