Micromate .h5 samples use the MiniMate count scale: waveforms read -1.65% (schema 1) / +0.71% (current) #42

Closed
opened 2026-10-22 22:22:53 -04:00 by serversdown · 4 comments
Owner

Summary

Micromate (Series 4) events stored as .h5 have their float32 geophone samples converted with the MiniMate's count scale instead of Thor's. The stored peaks (peak_*_ips) are right, because they come from the unit's report. Anything computed from the samples is off by a constant: waveform plots, a recomputed PPV, frequency analysis. The error is:

  • schema 1 files (tool_version 0.21.x, written with 10/32768): samples read −1.65%
  • schema 2 / current code (10/32000): samples read +0.71%

MiniMate (bw-import) files are exact: max|sample| equals the stored peak to float32.

Evidence

Found while building tmi-seismo's comparison tool (feat/minimate-compare), using the prod snapshot of the waveform store (seismo-relay-prod-snap/waveforms/, read-only).

files float32 per int16 count scale used max|v| / stored peak
Micromate, schema 1 (~260 good files) 305.176e-6 in/s 10/32768 0.9835 median (−1.65%)
Micromate, schema 2 (2 files, tool 0.31.0) 312.5e-6 in/s 10/32000 1.0071 median (+0.71%)
MiniMate, every file 312.5e-6 in/s 10/32000 1.000000
  • The stored Micromate peaks imply 310.35e-6 in/s per count (median). That is Thor's own LSB, _GEO_LSB_IPS = 0.000310308 (micromate/idf_file.py:144).
  • int16 × _GEO_LSB_IPS reproduces the stored peaks; the float32 samples don't.

Where (checked on origin/dev at 618fcb7)

  • sfm/waveform_store.py (save_imported_idf, ~line 690). Thor's raw counts go to event_hdf5.write_event_hdf5(..., geo_range="normal").
  • sfm/event_hdf5.py:95 and _samples_to_float (~152). These convert with full_scale / _GEO_INT16_FS = 10/32000. That is right for the MiniMate body codec, whose 16-count unit is exactly 0.005 in/s, but wrong for Thor counts.
  • sfm/waveform_store.py:657-661. The comment says the writer yields 10/32768 and the plots come out "~1.7% high". Both halves are out of date: the writer now uses 32000, and with 32768 the samples were 1.65% low, not high.

Suggested fix

  1. Write idf-import files with Thor's LSB: pass a per-source scale into write_event_hdf5, or convert before the call. Keep samples_int16 as it is.
  2. Regenerate the existing idf-import .h5 files. Schema 1 files are −1.65% and schema 2 files +0.71%, so the gate that triggers .h5 regeneration needs to cover this.
  3. Add a test: for an idf-import file, max|float32| equals the stored peak within float32.

Separate observation, worth its own look

  • On some UM11719 files, a channel's int16 samples also fall short of its reported peak, with max|v|/peak down to about 0.79. So the arrays don't contain the reported peak at all; the cause isn't the scale.
  • 295 of 557 Micromate schema-1 files have empty or unequal channel arrays: old imports from before the Series 4 sample decoder.

Notes

  • Brian: "known and I think we fixed it. I may need to reimport old events perhaps? It's possible we didn't fully fix it too." On origin/dev at 618fcb7 the writer still uses 10/32000 for Thor counts, so new imports would be +0.71%.
  • tmi-seismo's comparison tool now flags this for each reference, and offers --rescale-to-reported, which rescales by the schema constant above. It does not depend on this being fixed.
## Summary Micromate (Series 4) events stored as `.h5` have their **float32 geophone samples converted with the MiniMate's count scale instead of Thor's**. The stored peaks (`peak_*_ips`) are right, because they come from the unit's report. Anything computed from the samples is off by a constant: waveform plots, a recomputed PPV, frequency analysis. The error is: - **schema 1** files (`tool_version` 0.21.x, written with 10/32768): samples read **−1.65%** - **schema 2 / current code** (10/32000): samples read **+0.71%** MiniMate (`bw-import`) files are exact: max|sample| equals the stored peak to float32. ## Evidence Found while building tmi-seismo's comparison tool (`feat/minimate-compare`), using the prod snapshot of the waveform store (`seismo-relay-prod-snap/waveforms/`, read-only). | files | float32 per int16 count | scale used | max\|v\| / stored peak | |---|---|---|---| | Micromate, schema 1 (~260 good files) | 305.176e-6 in/s | 10/32768 | 0.9835 median (−1.65%) | | Micromate, schema 2 (2 files, tool 0.31.0) | 312.5e-6 in/s | 10/32000 | 1.0071 median (+0.71%) | | MiniMate, every file | 312.5e-6 in/s | 10/32000 | 1.000000 | - The stored Micromate peaks imply **310.35e-6 in/s per count** (median). That is Thor's own LSB, `_GEO_LSB_IPS = 0.000310308` (`micromate/idf_file.py:144`). - `int16 × _GEO_LSB_IPS` reproduces the stored peaks; the float32 samples don't. ## Where (checked on origin/dev at 618fcb7) - `sfm/waveform_store.py` (`save_imported_idf`, ~line 690). Thor's raw counts go to `event_hdf5.write_event_hdf5(..., geo_range="normal")`. - `sfm/event_hdf5.py:95` and `_samples_to_float` (~152). These convert with `full_scale / _GEO_INT16_FS = 10/32000`. That is right for the MiniMate body codec, whose 16-count unit is exactly 0.005 in/s, but wrong for Thor counts. - `sfm/waveform_store.py:657-661`. The comment says the writer yields 10/32768 and the plots come out "~1.7% high". Both halves are out of date: the writer now uses 32000, and with 32768 the samples were 1.65% **low**, not high. ## Suggested fix 1. Write `idf-import` files with Thor's LSB: pass a per-source scale into `write_event_hdf5`, or convert before the call. Keep `samples_int16` as it is. 2. Regenerate the existing `idf-import` `.h5` files. Schema 1 files are −1.65% and schema 2 files +0.71%, so the gate that triggers `.h5` regeneration needs to cover this. 3. Add a test: for an `idf-import` file, max|float32| equals the stored peak within float32. ## Separate observation, worth its own look - On some **UM11719** files, a channel's int16 samples also fall short of its reported peak, with max|v|/peak down to about 0.79. So the arrays don't contain the reported peak at all; the cause isn't the scale. - 295 of 557 Micromate schema-1 files have empty or unequal channel arrays: old imports from before the Series 4 sample decoder. ## Notes - Brian: "known and I think we fixed it. I may need to reimport old events perhaps? It's possible we didn't fully fix it too." On origin/dev at 618fcb7 the writer still uses 10/32000 for Thor counts, so new imports would be +0.71%. - tmi-seismo's comparison tool now flags this for each reference, and offers `--rescale-to-reported`, which rescales by the schema constant above. It does not depend on this being fixed.
serversdown added the Kind/Bug
Priority
Medium
3
labels 2026-10-22 22:22:53 -04:00
Author
Owner

Confirmed on dev, root cause found

Reproduced. On origin/dev 618fcb7 (feat/series4-sfm-parity has the same code in these files), I ran all 8 tests/fixtures/thor-idf files through the real WaveformStore.save_imported_idf into a temp store. Every channel of every file, IDFW and IDFH, comes out at max|float32| / stored peak = 1.00706. The per-count factor in the .h5 is 3.1250e-4, and 0.0003125 / 0.000310308 = 1.00706.

Why the v0.30.0 scale fix didn't cover this. 726c2ce changed micromate/idf_file._GEO_LSB_IPS (0.0003 → 0.000310308). That constant produces res.event.peaks and IdfInterval.peak_ips, which feed the DB peaks, the sidecar, the h5 peak_*_ips attrs and the PDF numbers. All of those are correct. But res.samples and iv.peak_count() are raw counts, and the .h5 writer converts them with 10 / event_hdf5._GEO_INT16_FS. That is the MiniMate body-codec scale. Its two values give the two schema eras in the issue:

  • 32768, until 686ab6e (2026-08-25, the MiniMate fix): Thor .h5 samples −1.65%
  • 32000 since then: Thor .h5 samples +0.71%

Neither change was aimed at Thor. The comment at sfm/waveform_store.py:657-661 deferred the problem ("refine with a Thor-aware h5 path later"), and that follow-up never happened.

Also affected. scripts/backfill_thor_events.py writes .h5 files through the same writer, so a reimport or regen today lands at +0.71%. shape_metrics.offset_from_h5 applies its 0.025 in/s floor to these samples, so for Thor that floor is effectively 0.71% lower. Crest factor and ZC frequency don't depend on scale.

About the prod snapshot. Its 1,177 tool-0.21.x Micromate .h5 files have sidecars at 0.21–0.23, and all of them predate the 2026-09-25 prod backfill. The snapshot looks like it adds new files without refreshing old ones (inferred), so it doesn't show what prod holds now. Prod is wrong either way: −1.65% for files that weren't regenerated, +0.71% for files that were.

Fix underway on a fix branch off dev: the writer takes a per-source geo scale, Thor passes its own LSB from both the importer and the backfill, plus a regression test. After it deploys: backfill_thor_events.py --force, then backfill_event_shape.py.

The UM11719 observation (int16 never reaches the reported peak) is a separate issue and isn't covered by this.

## Confirmed on dev, root cause found **Reproduced.** On origin/dev 618fcb7 (`feat/series4-sfm-parity` has the same code in these files), I ran all 8 `tests/fixtures/thor-idf` files through the real `WaveformStore.save_imported_idf` into a temp store. Every channel of every file, IDFW and IDFH, comes out at max|float32| / stored peak = **1.00706**. The per-count factor in the `.h5` is 3.1250e-4, and 0.0003125 / 0.000310308 = 1.00706. **Why the v0.30.0 scale fix didn't cover this.** 726c2ce changed `micromate/idf_file._GEO_LSB_IPS` (0.0003 → 0.000310308). That constant produces `res.event.peaks` and `IdfInterval.peak_ips`, which feed the DB peaks, the sidecar, the h5 `peak_*_ips` attrs and the PDF numbers. All of those are correct. But `res.samples` and `iv.peak_count()` are **raw counts**, and the `.h5` writer converts them with `10 / event_hdf5._GEO_INT16_FS`. That is the MiniMate body-codec scale. Its two values give the two schema eras in the issue: - 32768, until 686ab6e (2026-08-25, the MiniMate fix): Thor `.h5` samples **−1.65%** - 32000 since then: Thor `.h5` samples **+0.71%** Neither change was aimed at Thor. The comment at `sfm/waveform_store.py:657-661` deferred the problem ("refine with a Thor-aware h5 path later"), and that follow-up never happened. **Also affected.** `scripts/backfill_thor_events.py` writes `.h5` files through the same writer, so a reimport or regen today lands at +0.71%. `shape_metrics.offset_from_h5` applies its 0.025 in/s floor to these samples, so for Thor that floor is effectively 0.71% lower. Crest factor and ZC frequency don't depend on scale. **About the prod snapshot.** Its 1,177 tool-0.21.x Micromate `.h5` files have sidecars at 0.21–0.23, and all of them predate the 2026-09-25 prod backfill. The snapshot looks like it adds new files without refreshing old ones (inferred), so it doesn't show what prod holds now. Prod is wrong either way: −1.65% for files that weren't regenerated, +0.71% for files that were. **Fix underway** on a fix branch off `dev`: the writer takes a per-source geo scale, Thor passes its own LSB from both the importer and the backfill, plus a regression test. After it deploys: `backfill_thor_events.py --force`, then `backfill_event_shape.py`. The UM11719 observation (int16 never reaches the reported peak) is a separate issue and isn't covered by this.
Author
Owner

Fixed on feat/thor-h5-geo-scale (e506bcf). Not merged to dev yet.

  • write_event_hdf5 takes a new geo_ips_per_count. save_imported_idf and backfill_thor_events.py both pass _GEO_LSB_IPS. MiniMate callers are unchanged.
  • The 8 thor-idf fixtures (4 IDFW + 4 IDFH, 24 channels) go from max|sample| / peak = 1.00706 to 1.00000 through the real ingest path.
  • New tests/test_idf_h5_scale.py covers IDFW ingest, IDFH ingest and the backfill. All three failed before the fix with exactly 0.00706 relative error.

Still owed once it ships: regenerate the existing idf-import .h5 files (backfill_thor_events.py --force, or bump TOOL_VERSION at release), then run backfill_event_shape.py. Leaving this issue open until that's done.

**Fixed on `feat/thor-h5-geo-scale`** (e506bcf). Not merged to `dev` yet. - `write_event_hdf5` takes a new `geo_ips_per_count`. `save_imported_idf` and `backfill_thor_events.py` both pass `_GEO_LSB_IPS`. MiniMate callers are unchanged. - The 8 thor-idf fixtures (4 IDFW + 4 IDFH, 24 channels) go from max|sample| / peak = 1.00706 to **1.00000** through the real ingest path. - New `tests/test_idf_h5_scale.py` covers IDFW ingest, IDFH ingest and the backfill. All three failed before the fix with exactly 0.00706 relative error. **Still owed once it ships:** regenerate the existing idf-import `.h5` files (`backfill_thor_events.py --force`, or bump `TOOL_VERSION` at release), then run `backfill_event_shape.py`. Leaving this issue open until that's done.
Author
Owner

Backfill run on the dev box (2026-10-23), with origin/dev's fixed code (a5373de). The fixed code ran as a scratch copy inside terra-view-sfm-1, because the image is 0.31.0 and predates the fix.

  1. DB backup: bridges/captures/seismo_relay.db.pre-thor-lsb-20261023 (SQLite backup API, 19,293 events).
  2. backfill_thor_events.py --force: refreshed 4,706, skipped 1, errors 0, .h5 written 4,703.
  3. backfill_event_shape.py: updated 15,753; skipped 3,195 with no .h5 and 345 with no samples; cleared 0 stale.

Every waveform .h5, max|sample| / stored peak, before → after:

before after
Micromate schema 1: 1,372 channels, median 0.98002, 0% within 0.3%. Schema 2: 6 channels, median 1.00713. all files schema 2 / 0.31.0: 1,729 channels, median 0.99999, 89.3% within 0.3%
MiniMate median 1.00000 unchanged, identical figures

The Micromate channel count went up because the old empty imports were re-decoded.

DB changes, against the backup:

  • 4,659 Micromate rows changed, 120 of them in shape_offset.
  • 1 MiniMate row changed: BE18003 T003LCYV.JD0H, an IDFH whose shape metrics had never been computed (NULL → filled).

Left over, not a scale issue: 106 of 1,729 Micromate channels (6.1%) still read below their reported peak, at 0.50–0.93 (median 0.869).

  • By unit: UM20147 51, UM11719 47, UM12947 8.
  • The arrays don't contain the reported peak (truncated record, or the peak taken from a window the samples don't cover?). That's the "separate observation" above, now counted. It may deserve its own issue.

Prod still needs the same two steps at release, with a TOOL_VERSION bump or --force, and no backfill_sidecars.py.

**Backfill run on the dev box (2026-10-23), with origin/dev's fixed code (a5373de).** The fixed code ran as a scratch copy inside `terra-view-sfm-1`, because the image is 0.31.0 and predates the fix. 1. DB backup: `bridges/captures/seismo_relay.db.pre-thor-lsb-20261023` (SQLite backup API, 19,293 events). 2. `backfill_thor_events.py --force`: refreshed 4,706, skipped 1, errors 0, `.h5` written 4,703. 3. `backfill_event_shape.py`: updated 15,753; skipped 3,195 with no `.h5` and 345 with no samples; cleared 0 stale. **Every waveform `.h5`, max|sample| / stored peak, before → after:** | | before | after | |---|---|---| | Micromate | schema 1: 1,372 channels, median 0.98002, 0% within 0.3%. Schema 2: 6 channels, median 1.00713. | all files schema 2 / 0.31.0: 1,729 channels, median **0.99999**, 89.3% within 0.3% | | MiniMate | median 1.00000 | unchanged, identical figures | The Micromate channel count went up because the old empty imports were re-decoded. **DB changes, against the backup:** - 4,659 Micromate rows changed, 120 of them in `shape_offset`. - 1 MiniMate row changed: BE18003 T003LCYV.JD0H, an IDFH whose shape metrics had never been computed (NULL → filled). **Left over, not a scale issue:** 106 of 1,729 Micromate channels (6.1%) still read **below** their reported peak, at 0.50–0.93 (median 0.869). - By unit: UM20147 51, UM11719 47, UM12947 8. - The arrays don't contain the reported peak (truncated record, or the peak taken from a window the samples don't cover?). That's the "separate observation" above, now counted. It may deserve its own issue. **Prod still needs the same two steps at release,** with a `TOOL_VERSION` bump or `--force`, and no `backfill_sidecars.py`.
Author
Owner

Correction to the comment above: the 106 'below their reported peak' channels are not truncation. Every one of them reports a peak of exactly 0.0050 in/s, which is Thor's display floor; seismo-relay's CLAUDE.md records it for histogram PPV, and it evidently applies to IDFW waveform peaks too. Their samples are full length, and their true peaks are 0.0043–0.0047 in/s, below the floor. The samples are right, and the reported value is the floor. No separate issue needed. With the backfill done, every Micromate channel not at the floor reads max|sample|/peak = 1.0000 within rounding.

**Correction to the comment above: the 106 'below their reported peak' channels are not truncation.** Every one of them reports a peak of exactly **0.0050 in/s**, which is Thor's display floor; seismo-relay's CLAUDE.md records it for histogram PPV, and it evidently applies to IDFW waveform peaks too. Their samples are full length, and their true peaks are 0.0043–0.0047 in/s, below the floor. The samples are right, and the reported value is the floor. No separate issue needed. With the backfill done, every Micromate channel not at the floor reads max|sample|/peak = 1.0000 within rounding.
Sign in to join this conversation.