fix(sfm): Thor .h5 samples use Thor's LSB, not the MiniMate count scale (#42)

Every idf-import .h5 converted Thor's raw geo counts with the MiniMate
body-codec scale, full_scale / _GEO_INT16_FS.  A Thor count is
0.000310308 in/s (micromate.idf_file._GEO_LSB_IPS), so the float samples
disagreed with the event's own peak by a constant:

  10/32768 (until 686ab6e, 2026-08-25)   samples -1.65%
  10/32000 (since)                       samples +0.71%

v0.30.0's LSB fix (726c2ce) never reached this path.  It corrected the
decoder's peaks, which were already right in the DB, sidecar and h5
peak attrs.  The sample arrays go through the shared .h5 writer instead.

write_event_hdf5 now takes geo_ips_per_count.  save_imported_idf and
backfill_thor_events (which replays the same bridge with its own write)
both pass _GEO_LSB_IPS.  MiniMate callers are unchanged.

Measured: all 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.

Operational consequence: no schema change, no migration, TOOL_VERSION
not bumped here.  Existing idf-import .h5 files keep the wrong scale
until regenerated: scripts/backfill_thor_events.py (--force, or bump
TOOL_VERSION at release), then backfill_event_shape.py, because the
offset detector reads these samples.  Series-3 files are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-23 13:05:51 -04:00
1 parent 618fcb7770
commit e506bcff9b
5 files changed
+124 -10

No files matched your search

+20
View File
@@ -132,6 +132,26 @@ def test_hdf5_samples_in_physical_units_sensitive_range(tmp_path: Path):
assert abs(max(vert) - expected_peak) < 1e-4
def test_hdf5_geo_ips_per_count_replaces_range_scale(tmp_path: Path):
"""A source whose counts have their own scale passes it explicitly.
The range-derived ``full_scale / 32000`` is the MiniMate body codec's
count; a Thor count is 0.000310308 in/s. Using the MiniMate scale for
Thor counts read every sample 0.71% high (issue #42)."""
ev = _make_event_with_samples()
h5 = tmp_path / "t.h5"
event_hdf5.write_event_hdf5(
h5, ev, serial="UM12947", geo_range="normal",
geo_ips_per_count=0.000310308,
)
data = event_hdf5.read_event_hdf5(h5)
vert = data["samples"]["Vert"]
assert abs(max(vert) - 32767 * 0.000310308) < 1e-5
# The range attrs still describe the range, not the count scale.
assert data["attrs"]["geo_full_scale_ips"] == 10.0
def test_hdf5_includes_int16_samples(tmp_path: Path):
ev = _make_event_with_samples()
h5 = tmp_path / "i.h5"