merge: dev 9b458b5 into the parity branch (group A/B, #51 histogram timing)

Brings the checker's file-only decode work onto the parity branch so the
phase-5 bench runs on the code that will ship.  One conflict, the CRLF
Series-III reference changelog: both kept, phase 5's row numbered
'2026-11-03 (5)' above dev's (4)/(3)/(2).  test_event_ingest's live-
histogram dedup test asserted the stored row sits a second off the 0C
time -- the #51 bug, fixed on dev -- so its premise now reads the event's
own second; the dedup it tests still holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-04 12:31:21 -05:00
commit f24913189b
31 files changed
+9577 -127

No files matched your search

Binary file not shown.
+116
View File
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<Event>
<FileVersion>8.0</FileVersion>
<EventType>Full Histogram</EventType>
<SerialNumber>BE18190</SerialNumber>
<Version>V 10.72-8.17 MiniMate Plus</Version>
<FileName>T190LD42.T00H</FileName>
<HistogramStartTime>13:29:24</HistogramStartTime>
<HistogramStartDate>2025-12-08</HistogramStartDate>
<HistogramStopTime>13:29:37</HistogramStopTime>
<HistogramStopDate>2025-12-08</HistogramStopDate>
<Channels>
<Channel>Tran</Channel>
<Channel>Vert</Channel>
<Channel>Long</Channel>
<Channel>MicL</Channel>
</Channels>
<NumberofIntervals>1.00</NumberofIntervals>
<IntervalSize>1 minute</IntervalSize>
<SampleRate>2048 sps</SampleRate>
<BatteryLevel>6.7 Volts</BatteryLevel>
<Calibration>June 13, 2025 by Instantel</Calibration>
<Units>in/s and dB(L)</Units>
<Project>I-80-North Fork-Area 3-462Richardsvilel</Project>
<Client>Fay Company</Client>
<UserName>Terra-Mechanics Inc.- Harrison</UserName>
<SeisLoc>Loc #8 - Area 3- 462 Richardsville Road</SeisLoc>
<GeoRange>
<Value>10.000</Value>
<Units>in/s</Units>
</GeoRange>
<TranPPV>
<Value>1.280</Value>
<Units>in/s</Units>
</TranPPV>
<VertPPV>
<Value>2.615</Value>
<Units>in/s</Units>
</VertPPV>
<LongPPV>
<Value>1.120</Value>
<Units>in/s</Units>
</LongPPV>
<TranZCFreq>
<Value>15.5</Value>
<Units>Hz</Units>
</TranZCFreq>
<VertZCFreq>
<Value>64</Value>
<Units>Hz</Units>
</VertZCFreq>
<LongZCFreq>
<Value>17.7</Value>
<Units>Hz</Units>
</LongZCFreq>
<TranPeakTime>13:29:37</TranPeakTime>
<TranPeakDate>2025-12-08</TranPeakDate>
<VertPeakTime>13:29:37</VertPeakTime>
<VertPeakDate>2025-12-08</VertPeakDate>
<LongPeakTime>13:29:37</LongPeakTime>
<LongPeakDate>2025-12-08</LongPeakDate>
<PeakVectorSum>
<Value>2.644</Value>
<Units>in/s</Units>
</PeakVectorSum>
<PeakVectorSumTime>13:29:37</PeakVectorSumTime>
<PeakVectorSumDate>2025-12-08</PeakVectorSumDate>
<Microphone>Linear Weighting</Microphone>
<MicLPSPL>
<Value>107.0</Value>
<Units>dB(L)</Units>
</MicLPSPL>
<MicLTime>13:29:37</MicLTime>
<MicLDate>2025-12-08</MicLDate>
<MicLZCFreq>
<Value>51</Value>
<Units>Hz</Units>
</MicLZCFreq>
<TranTestFreq>7.4 Hz.</TranTestFreq>
<TranTestRatio>4.2</TranTestRatio>
<TranTestResults>Passed</TranTestResults>
<VertTestFreq>7.6 Hz.</VertTestFreq>
<VertTestRatio>3.4</VertTestRatio>
<VertTestResults>Passed</VertTestResults>
<LongTestFreq>7.3 Hz.</LongTestFreq>
<LongTestRatio>3.7</LongTestRatio>
<LongTestResults>Passed</LongTestResults>
<MicLTestFreq>0.0 Hz.</MicLTestFreq>
<MicLTestAmplitude>0 mv</MicLTestAmplitude>
<MicLTestResults>Check</MicLTestResults>
<UsbSummaryChannels>
</UsbSummaryChannels>
<MonitorLog>2025-12-08 13:29:23 - 2025-12-08 13:29:37 &quot;Event Recorded Modem Exit&quot;</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>2025-12-08 13:29:37</Time>
<Row>
<Cell>1.280</Cell><Cell>15.5</Cell><Cell>2.615</Cell><Cell>64</Cell><Cell>1.120</Cell><Cell>17.7</Cell><Cell>2.644</Cell><Cell>0.001</Cell><Cell>107.0</Cell><Cell>51</Cell></Row>
</HistogramDataIntervals>
</HistogramData>
<HistogramDataUsbChannels>
</HistogramDataUsbChannels>
</Event>
Binary file not shown.
+116
View File
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<Event>
<FileVersion>8.0</FileVersion>
<EventType>Full Histogram</EventType>
<SerialNumber>BE18190</SerialNumber>
<Version>V 10.72-8.17 MiniMate Plus</Version>
<FileName>T190LD5Q.LD0H</FileName>
<HistogramStartTime>11:00:49</HistogramStartTime>
<HistogramStartDate>2025-12-09</HistogramStartDate>
<HistogramStopTime>11:00:59</HistogramStopTime>
<HistogramStopDate>2025-12-09</HistogramStopDate>
<Channels>
<Channel>Tran</Channel>
<Channel>Vert</Channel>
<Channel>Long</Channel>
<Channel>MicL</Channel>
</Channels>
<NumberofIntervals>1.00</NumberofIntervals>
<IntervalSize>1 minute</IntervalSize>
<SampleRate>1024 sps</SampleRate>
<BatteryLevel>6.9 Volts</BatteryLevel>
<Calibration>June 13, 2025 by Instantel</Calibration>
<Units>in/s and dB(L)</Units>
<Project>I-80-North Fork-Area 3-462Richardsvilel</Project>
<Client>Fay Company</Client>
<UserName>Terra-Mechanics Inc.- Harrison</UserName>
<SeisLoc>Loc #8 - Area 3- 462 Richardsville Road</SeisLoc>
<GeoRange>
<Value>10.000</Value>
<Units>in/s</Units>
</GeoRange>
<TranPPV>
<Value>2.140</Value>
<Units>in/s</Units>
</TranPPV>
<VertPPV>
<Value>OORANGE</Value>
<Units>in/s</Units>
</VertPPV>
<LongPPV>
<Value>2.830</Value>
<Units>in/s</Units>
</LongPPV>
<TranZCFreq>
<Value>&gt;100</Value>
<Units>Hz</Units>
</TranZCFreq>
<VertZCFreq>
<Value>85</Value>
<Units>Hz</Units>
</VertZCFreq>
<LongZCFreq>
<Value>34</Value>
<Units>Hz</Units>
</LongZCFreq>
<TranPeakTime>11:00:59</TranPeakTime>
<TranPeakDate>2025-12-09</TranPeakDate>
<VertPeakTime>11:00:59</VertPeakTime>
<VertPeakDate>2025-12-09</VertPeakDate>
<LongPeakTime>11:00:59</LongPeakTime>
<LongPeakDate>2025-12-09</LongPeakDate>
<PeakVectorSum>
<Value>OORANGE</Value>
<Units>in/s</Units>
</PeakVectorSum>
<PeakVectorSumTime>11:00:59</PeakVectorSumTime>
<PeakVectorSumDate>2025-12-09</PeakVectorSumDate>
<Microphone>Linear Weighting</Microphone>
<MicLPSPL>
<Value>106.0</Value>
<Units>dB(L)</Units>
</MicLPSPL>
<MicLTime>11:00:59</MicLTime>
<MicLDate>2025-12-09</MicLDate>
<MicLZCFreq>
<Value>85</Value>
<Units>Hz</Units>
</MicLZCFreq>
<TranTestFreq>7.4 Hz.</TranTestFreq>
<TranTestRatio>4.4</TranTestRatio>
<TranTestResults>Passed</TranTestResults>
<VertTestFreq>7.6 Hz.</VertTestFreq>
<VertTestRatio>3.5</VertTestRatio>
<VertTestResults>Passed</VertTestResults>
<LongTestFreq>7.3 Hz.</LongTestFreq>
<LongTestRatio>3.9</LongTestRatio>
<LongTestResults>Passed</LongTestResults>
<MicLTestFreq>20.5 Hz.</MicLTestFreq>
<MicLTestAmplitude>691 mv</MicLTestAmplitude>
<MicLTestResults>Passed</MicLTestResults>
<UsbSummaryChannels>
</UsbSummaryChannels>
<MonitorLog>2025-12-09 11:00:48 - 2025-12-09 11:00:59 &quot;Event Recorded Modem Exit&quot;</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>2025-12-09 11:00:59</Time>
<Row>
<Cell>2.140</Cell><Cell>&gt;100</Cell><Cell>OORANGE</Cell><Cell>85</Cell><Cell>2.830</Cell><Cell>34</Cell><Cell>OORANGE</Cell><Cell>0.001</Cell><Cell>106.0</Cell><Cell>85</Cell></Row>
</HistogramDataIntervals>
</HistogramData>
<HistogramDataUsbChannels>
</HistogramDataUsbChannels>
</Event>
Binary file not shown.
+116
View File
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<Event>
<FileVersion>8.0</FileVersion>
<EventType>Full Histogram</EventType>
<SerialNumber>BE9558</SerialNumber>
<Version>V 10.72-8.17 MiniMate Plus</Version>
<FileName>K558L4KY.440H</FileName>
<HistogramStartTime>17:04:52</HistogramStartTime>
<HistogramStartDate>2025-06-25</HistogramStartDate>
<HistogramStopTime>17:05:39</HistogramStopTime>
<HistogramStopDate>2025-06-25</HistogramStopDate>
<Channels>
<Channel>Tran</Channel>
<Channel>Vert</Channel>
<Channel>Long</Channel>
<Channel>MicL</Channel>
</Channels>
<NumberofIntervals>1.00</NumberofIntervals>
<IntervalSize>5 minutes</IntervalSize>
<SampleRate>1024 sps</SampleRate>
<BatteryLevel>6.3 Volts</BatteryLevel>
<Calibration>June 13, 2025 by Instantel</Calibration>
<Units>in/s and dB(L)</Units>
<Project>Fay - Locks &amp; Dam No3 -Loc 5 Synthomer</Project>
<Client>Fay Company</Client>
<UserName>Terra-Mechanics Inc - Harrison</UserName>
<Seis.Loc>Location #5 Sythomer Plant</Seis.Loc>
<GeoRange>
<Value>10.000</Value>
<Units>in/s</Units>
</GeoRange>
<TranPPV>
<Value>2.315</Value>
<Units>in/s</Units>
</TranPPV>
<VertPPV>
<Value>2.715</Value>
<Units>in/s</Units>
</VertPPV>
<LongPPV>
<Value>5.115</Value>
<Units>in/s</Units>
</LongPPV>
<TranZCFreq>
<Value>10</Value>
<Units>Hz</Units>
</TranZCFreq>
<VertZCFreq>
<Value>85</Value>
<Units>Hz</Units>
</VertZCFreq>
<LongZCFreq>
<Value>19</Value>
<Units>Hz</Units>
</LongZCFreq>
<TranPeakTime>17:05:39</TranPeakTime>
<TranPeakDate>2025-06-25</TranPeakDate>
<VertPeakTime>17:05:39</VertPeakTime>
<VertPeakDate>2025-06-25</VertPeakDate>
<LongPeakTime>17:05:39</LongPeakTime>
<LongPeakDate>2025-06-25</LongPeakDate>
<PeakVectorSum>
<Value>5.559</Value>
<Units>in/s</Units>
</PeakVectorSum>
<PeakVectorSumTime>17:05:39</PeakVectorSumTime>
<PeakVectorSumDate>2025-06-25</PeakVectorSumDate>
<Microphone>Linear Weighting</Microphone>
<MicLPSPL>
<Value>111.8</Value>
<Units>dB(L)</Units>
</MicLPSPL>
<MicLTime>17:05:39</MicLTime>
<MicLDate>2025-06-25</MicLDate>
<MicLZCFreq>
<Value>43</Value>
<Units>Hz</Units>
</MicLZCFreq>
<TranTestFreq>7.7 Hz.</TranTestFreq>
<TranTestRatio>3.9</TranTestRatio>
<TranTestResults>Passed</TranTestResults>
<VertTestFreq>7.5 Hz.</VertTestFreq>
<VertTestRatio>3.8</VertTestRatio>
<VertTestResults>Passed</VertTestResults>
<LongTestFreq>7.5 Hz.</LongTestFreq>
<LongTestRatio>3.7</LongTestRatio>
<LongTestResults>Passed</LongTestResults>
<MicLTestFreq>0.0 Hz.</MicLTestFreq>
<MicLTestAmplitude>0 mv</MicLTestAmplitude>
<MicLTestResults>Check</MicLTestResults>
<UsbSummaryChannels>
</UsbSummaryChannels>
<MonitorLog>2025-06-25 17:04:51 - 2025-06-25 17:05:39 &quot;Event Recorded Modem Exit&quot;</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>2025-06-25 17:05:39</Time>
<Row>
<Cell>2.315</Cell><Cell>10</Cell><Cell>2.715</Cell><Cell>85</Cell><Cell>5.115</Cell><Cell>19</Cell><Cell>5.559</Cell><Cell>0.001</Cell><Cell>111.8</Cell><Cell>43</Cell></Row>
</HistogramDataIntervals>
</HistogramData>
<HistogramDataUsbChannels>
</HistogramDataUsbChannels>
</Event>
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
Binary file not shown.
File diff suppressed because it is too large. Load diff
+36 -6
View File
@@ -141,10 +141,12 @@ def test_a_report_fills_in_when_the_record_is_missing():
assert (_dt(ev.timestamp), ev.timestamp_source) == (TRIGGER, "report")
def test_a_histogram_keeps_its_footer_start_for_now():
# Its record (marker fe f5) also holds Blastware's start -- that change is #51.
def test_a_histogram_takes_its_event_records_start():
# #51: its record (marker fe f5) holds Blastware's start; the footer's
# 19:04:50 is a second early.
ev = read_blastware_file(HISTOGRAM)
assert (_dt(ev.timestamp), ev.timestamp_source) == (datetime.datetime(2026, 5, 10, 19, 4, 50), "footer")
assert (_dt(ev.timestamp), ev.timestamp_source) == (datetime.datetime(2026, 5, 10, 19, 4, 51),
"event_record")
def test_the_sidecar_keeps_the_instruments_time_and_says_where_it_came_from():
@@ -173,13 +175,16 @@ def test_an_imported_event_with_only_an_estimate_does_not_overwrite_its_neighbou
from sfm.database import SeismoDb
from sfm.waveform_store import WaveformStore
store, db = WaveformStore(tmp_path / "waveforms"), SeismoDb(tmp_path / "seismo_relay.db")
other = Event(index=0) # a different event at 14:23:43
# A different waveform at 14:23:43. The key is unit + time + type (#51), so
# "its neighbour" is an event of the same type at the same second.
other = Event(index=0)
other.timestamp = Timestamp(raw=b"", flag=0x10, year=2026, unknown_byte=0, month=10, day=26,
hour=14, minute=23, second=43)
other._waveform_key = bytes.fromhex("01110000")
other.record_type = "Waveform"
other.peak_values = PeakValues(tran=0.01, vert=0.02, long=0.03, peak_vector_sum=0.04, micl=None)
db.insert_events([other], serial="BE9441", device_family="series3",
waveform_records={"01110000": {"filename": "K441LTOF.ZJ0H"}})
waveform_records={"01110000": {"filename": "K441LTOF.ZJ0W"}})
broken = bytes(_broken(lambda r, i: r.__setitem__(i + 1, 0x81))) # no validated record
ev, rec = store.save_imported_bw(broken, source_path=Path(ZI0.name))
@@ -189,6 +194,31 @@ def test_an_imported_event_with_only_an_estimate_does_not_overwrite_its_neighbou
waveform_records={ev._waveform_key.hex(): rec}) == (0, 1)
with sqlite3.connect(str(db.db_path)) as c:
assert c.execute("SELECT blastware_filename, peak_vector_sum FROM events").fetchall() == \
[("K441LTOF.ZJ0H", 0.04)]
[("K441LTOF.ZJ0W", 0.04)]
assert (tmp_path / "waveforms" / "BE9441" / "K441LTOF.ZI0").exists() # the data is kept
assert any("not merged" in r.message for r in caplog.records)
def test_an_estimate_beside_a_histogram_at_its_second_is_stored_alongside(tmp_path):
# A waveform and a histogram may share a second (#51): the estimate is its
# own row, and the histogram is untouched.
import sqlite3
from minimateplus.models import Event, PeakValues, Timestamp
from sfm.database import SeismoDb
from sfm.waveform_store import WaveformStore
store, db = WaveformStore(tmp_path / "waveforms"), SeismoDb(tmp_path / "seismo_relay.db")
hist = Event(index=0)
hist.timestamp = Timestamp(raw=b"", flag=0x10, year=2026, unknown_byte=0, month=10, day=26,
hour=14, minute=23, second=43)
hist._waveform_key = bytes.fromhex("01110000")
hist.record_type = "Histogram"
hist.peak_values = PeakValues(tran=0.01, vert=0.02, long=0.03, peak_vector_sum=0.04, micl=None)
db.insert_events([hist], serial="BE9441", device_family="series3",
waveform_records={"01110000": {"filename": "K441LTOF.ZJ0H"}})
broken = bytes(_broken(lambda r, i: r.__setitem__(i + 1, 0x81))) # no validated record
ev, rec = store.save_imported_bw(broken, source_path=Path(ZI0.name))
assert db.insert_events([ev], serial="BE9441", device_family="series3",
waveform_records={ev._waveform_key.hex(): rec}) == (1, 0)
with sqlite3.connect(str(db.db_path)) as c:
rows = c.execute("SELECT record_type, peak_vector_sum FROM events ORDER BY record_type").fetchall()
assert rows[0] == ("Histogram", 0.04) and rows[1][0] == "Waveform"
+130
View File
@@ -365,3 +365,133 @@ def test_a_waveform_with_the_early_record_is_timed_from_its_trigger():
# Blastware: 2019-09-26 11:14:08, record time 4 s (SFM read the stop, 11:14:12)
assert (ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second) == (2019, 9, 26, 11, 14, 8)
assert ev.timestamp_source in ("event_record", "estimate")
# ── Group A: identity, battery, trigger ─────────────────────────────────────
# The identity block before the setup name is what the live read gets from
# SUB FE (DeviceInfo): serial k-202, firmware k-147, DSP version k-138,
# calibration date k-132 and "by" k-128, manufacturer k-94, model k-72; the
# battery is a uint16 of hundredths of a volt at k-190. Measured against every
# DL2 report 2026-11-03 (serial, version, calibration 69,983 / 69,983).
import datetime as _dt # noqa: E402
_SF = "setup-fields-11-03-26"
def test_the_identity_block_is_read():
# Blastware: BE18189, "V 10.72-8.17 MiniMate Plus",
# "February 20, 2019 by Instantel", "6.8 Volts"
ev = read_blastware_file(_FIX / _SF / "T189HUD6.QE0W")
di = ev.device_info
assert (di.serial, di.firmware_version, di.dsp_version, di.manufacturer, di.model) == (
"BE18189", "S338.17", "10.72", "Instantel", "MiniMate Plus")
assert di.firmware_minor == 17
assert (di.calibration_date, di.calibrated_by) == (_dt.date(2019, 2, 20), "Instantel")
assert abs(ev.battery_volts - 6.8) <= 0.05 + 1e-9
def test_the_battery_is_kept_exact():
# Blastware prints "6.3 Volts" for a stored 6.25: it rounds half up.
assert read_blastware_file(_FIX / _SF / "K558L4KY.440H").battery_volts == 6.25
# (file, Blastware's Trigger as the event record's bitmask, geo level in/s,
# mic level psi or None, mic a trigger source)
@pytest.mark.parametrize("rel,by,geo,mic_psi,mic_src", [
(f"{_SF}/T189HUD6.QE0W", 0x0008, 0.050, 0.0072, True), # MicL, 128.0 dB(L)
(f"{_SF}/T438L713.RY0W", 0x0002, 0.500, 0.0100, True), # Vert, 130.8 dB(L)
(f"{_SF}/M529I6LG.3Y0W", 0x0004, 0.050, 0.005, True), # Long, 0.005 psi(L)
("bw-import-fields-10-29-26/R352HIUI.F40W", 0x0001, 0.400, None, False), # Tran
("decode-checker-10-29-26/T1905KDW.5F0W", 0x0200, None, None, None), # Manual
])
def test_the_trigger_comes_from_the_file(rel, by, geo, mic_psi, mic_src):
ev = read_blastware_file(_FIX / rel)
assert ev.triggered_by == by
if geo is not None:
assert abs(ev.trigger_level_geo - geo) <= 0.0005 + 1e-9
if mic_psi is not None:
assert abs(ev.trigger_level_mic_psi - mic_psi) <= 0.0005 + 1e-9 # psi to 3 places, as printed
if mic_src is not None:
assert bool(ev.trigger_sources & 0x08) == mic_src
assert (ev.record_stop_mode, ev.mic_type) == (0, 2) # Fixed, Linear Weighting
def test_the_h5_carries_the_setup_fields(tmp_path):
import h5py
from sfm import event_hdf5
ev = read_blastware_file(_FIX / _SF / "T189HUD6.QE0W")
event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE18189")
with h5py.File(tmp_path / "e.h5", "r") as f:
a = f.attrs
assert abs(float(a["battery_volts"]) - 6.8) <= 0.05 + 1e-9
assert (int(a["triggered_by"]), int(a["trigger_sources"])) == (0x0008, ev.trigger_sources)
assert abs(float(a["trigger_level_geo_ips"]) - 0.050) <= 0.0005 + 1e-9
assert abs(float(a["trigger_level_mic_psi"]) - ev.trigger_level_mic_psi) < 1e-9
assert (str(a["firmware_version"]), str(a["dsp_version"]), str(a["calibration_date"])) == (
"S338.17", "10.72", "2019-02-20")
# ── Group B: histogram interval detail ──────────────────────────────────────
# Interval size is the setup's uint16 seconds at k - 40 (Series IV [8:10]); the
# stop is the footer's. Each interval keeps its half-periods and its vector sum
# (PVS^2). Frequency = (sample rate / 2) / half-period: 527,915 / 527,915 cells
# at 1024 sps and 1,725 / 1,725 at 2048 (#50: the old fixed 512 halved every
# 2048-sps frequency). Measured 2026-11-03.
from minimateplus.histogram_codec import half_period_to_hz # noqa: E402
_HB = "histogram-intervals-11-03-26"
@pytest.mark.parametrize("rel,sr,freqs,pvs,stop", [
# Blastware: 1 minute; Tran 32, Vert 47, Long 14, MicL 47 Hz; PVS 1.358; stop 12:49:33
("decode-checker-10-29-26/T004JTRF.ME0H", 1024,
{"Tran": 32, "Vert": 47, "Long": 14, "MicL": 47}, 1.358, (2022, 12, 28, 12, 49, 33)),
# Blastware: 1 minute at 2048 sps; Tran 15.5, Vert 64, Long 17.7, MicL 51 Hz; PVS 2.644
(f"{_HB}/T190LD42.T00H", 2048,
{"Tran": 15.5, "Vert": 64, "Long": 17.7, "MicL": 51}, 2.644, (2025, 12, 8, 13, 29, 37)),
])
def test_histogram_interval_detail_comes_from_the_file(rel, sr, freqs, pvs, stop):
ev = read_blastware_file(_FIX / rel)
assert (ev.sample_rate, ev.histogram_interval_sec) == (sr, 60)
for ch, hz in freqs.items():
got = half_period_to_hz(ev.interval_half_periods[ch][0], ev.sample_rate)
d = 1 if isinstance(hz, float) else 0
assert abs(got - hz) <= 0.5 * 10 ** -d + 1e-9, (ch, got, hz)
assert abs(ev.interval_pvs[0] - pvs) <= 0.0005 + 1e-9
t = ev.stop_time
assert (t.year, t.month, t.day, t.hour, t.minute, t.second) == stop
def test_the_h5_carries_the_interval_detail(tmp_path):
import h5py
from sfm import event_hdf5
ev = read_blastware_file(_FIX / _HB / "T190LD42.T00H")
event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE18190")
with h5py.File(tmp_path / "e.h5", "r") as f:
assert int(f.attrs["histogram_interval_sec"]) == 60
assert list(f["intervals/half_period/Vert"][:]) == ev.interval_half_periods["Vert"]
assert abs(float(f["intervals/pvs_ips"][0]) - 2.644) <= 0.0005 + 1e-9
# ── #51: a histogram's start and stop from its own event record ─────────────
# The footer's start runs a second early on 97%. The histogram's event record
# (lead 00 28 05 00, source 04 00, marker fe f5) holds Blastware's start and
# stop: 63,490 / 63,490 DL2 histograms each (2026-11-03).
def test_a_histogram_starts_at_its_event_records_start():
ev = read_blastware_file(_FIX / "decode-checker-10-29-26/T004JTRF.ME0H")
t, s = ev.timestamp, ev.stop_time
# Blastware: start 2022-12-28 12:49:26, stop 12:49:33
assert (t.year, t.month, t.day, t.hour, t.minute, t.second) == (2022, 12, 28, 12, 49, 26)
assert (s.hour, s.minute, s.second) == (12, 49, 33)
assert ev.timestamp_source == "event_record"
def test_a_histogram_without_its_record_falls_back_to_the_footer_and_says_so():
raw = bytearray((_FIX / "decode-checker-10-29-26/T004JTRF.ME0H").read_bytes())
i = raw.find(b"\xfe\xf5")
raw[i] = 0x00 # break the record's marker
ev = decode_blastware_bytes(bytes(raw), name=None)
assert ev.timestamp_source == "footer"
assert ev.timestamp.second == 25 # the footer's start, a second early
assert any("histogram event record" in p for p in ev.decode_problems)
+6 -3
View File
@@ -83,9 +83,12 @@ def test_a_waveform_read_under_another_name_keeps_its_time(tmp_path):
datetime.datetime(2026, 10, 26, 14, 23, 42)
def test_a_histogram_keeps_the_binarys_window_start():
assert blastware_filename_time(HISTOGRAM.name) != datetime.datetime(2026, 5, 10, 19, 4, 50)
assert _dt(read_blastware_file(HISTOGRAM).timestamp) == datetime.datetime(2026, 5, 10, 19, 4, 50)
def test_a_histogram_now_agrees_with_its_filename():
# #51: the start comes from the histogram's own event record, which is
# Blastware's -- and so the filename's. The footer's window start (19:04:50)
# was a second early.
assert blastware_filename_time(HISTOGRAM.name) == datetime.datetime(2026, 5, 10, 19, 4, 51)
assert _dt(read_blastware_file(HISTOGRAM).timestamp) == datetime.datetime(2026, 5, 10, 19, 4, 51)
def test_an_import_no_longer_lands_a_waveform_on_its_histogram_twins_row(tmp_path):
+125 -3
View File
@@ -39,7 +39,8 @@ def test_event_type_comes_from_the_bytes():
def test_report_fields_stay_blank():
s = sfm_side((FIX / "T1905KDW.5F0W").read_bytes())
for tag in ("TranZCFreq", "TranPeakAcceleration", "BatteryLevel", "Calibration", "TranTestResults"):
# (BatteryLevel and Calibration are read since 2026-11-03: test_the_setup_fields_match_blastware)
for tag in ("TranZCFreq", "TranPeakAcceleration", "TranTestResults"):
assert s.values.get(tag) is None
@@ -66,7 +67,7 @@ def test_full_waveform_row_verdicts():
"notes", "samples.Tran", "samples.Vert", "samples.Long"):
assert res[f].verdict == "match", (f, res[f])
assert res["TranZCFreq"].verdict in ("sfm_blank", "no_reference")
assert res["BatteryLevel"].verdict == "sfm_blank"
assert res["BatteryLevel"].verdict == "match" # 6.72 V, printed "6.7 Volts"
assert "FileName" not in res
@@ -95,7 +96,7 @@ def test_zc_frequency_na_and_above_range():
def test_mic_units_pick_the_conversion():
res = _results("T004JTRF.ME0H") # psi(L)
assert res["intervals.MicL Peak dB(L)"].verdict in ("match", "mismatch")
assert res["intervals.Tran Freq Hz"].verdict == "sfm_blank"
assert res["intervals.Tran Freq Hz"].verdict == "match" # read since 2026-11-03
fields = set(_results("R352HFZ7.530H")) # no mic
assert not any(f.startswith(("samples.MicL", "intervals.MicL")) for f in fields)
@@ -221,3 +222,124 @@ def test_blastware_counting_the_monitoring_time_is_accepted():
def test_the_count_carveout_needs_blastwares_own_table_to_agree_with_sfm():
assert _count_case(30, drop_rows=1).verdict == "mismatch"
_GROUP_A = ("SerialNumber", "Version", "Calibration", "BatteryLevel", "Trigger",
"GeoTriggerLevel", "MicTriggerLevel", "RecordStopMode", "Microphone", "Units")
@pytest.mark.parametrize("stem,printed", [
("T189HUD6.QE0W", set(_GROUP_A)),
("T438L713.RY0W", set(_GROUP_A)), # 130.8 dB(L): 0.01 psi at 6895 Pa/psi
("K558L4KY.440H", {"SerialNumber", "Version", "Calibration", "BatteryLevel",
"Microphone", "Units"}), # histogram; battery 6.25 -> "6.3"
])
def test_the_setup_fields_match_blastware(stem, printed):
sf = FIX.parent / "setup-fields-11-03-26"
res = {r.field: r for r in compare(sfm_side((sf / stem).read_bytes()),
parse_xml_report_file(sf / (stem.replace(".", "_", 1) + "_XML.XML")),
CARVEOUTS)}
assert printed <= set(res)
for f in printed:
assert res[f].verdict == "match", (f, res[f])
def test_a_manual_trigger_matches():
res = _results("T1905KDW.5F0W", CARVEOUTS)
assert res["Trigger"].verdict == "match"
def _units_case(sfm_units):
sf = FIX.parent / "setup-fields-11-03-26"
ref = parse_xml_report_file(sf / "T189HUD6_QE0W_XML.XML")
ref.scalars["Units"] = "in/s and psi(L)"
side = sfm_side((sf / "T189HUD6.QE0W").read_bytes())
if sfm_units is not None:
side.values["Units"] = sfm_units
return {r.field: r for r in compare(side, ref, CARVEOUTS)}["Units"]
def test_dB_or_psi_is_blastwares_display_preference():
# Blastware writes its report in its PC's current preference; DL2's reports
# switch fleet-wide in 61 clean runs by write time, and no byte in the file
# tells them apart.
r = _units_case(None)
assert (r.verdict, r.carveout) == ("accepted", "units-is-a-display-preference")
def test_the_units_carveout_still_needs_the_mic():
assert _units_case("in/s").verdict == "mismatch"
def test_a_mic_trigger_level_is_read_in_the_unit_it_is_printed_in():
# K441LA17.IN0W: Units "in/s and psi(L)", yet MicTriggerLevel "125.0 dB(L)".
# The printed value states its own unit; that is the one to compare in.
sf = FIX.parent / "setup-fields-11-03-26"
ref = parse_xml_report_file(sf / "T189HUD6_QE0W_XML.XML") # 128.0 dB(L)
ref.event_units = "in/s and psi(L)"
res = {r.field: r for r in compare(sfm_side((sf / "T189HUD6.QE0W").read_bytes()), ref, CARVEOUTS)}
assert res["MicTriggerLevel"].verdict == "match", res["MicTriggerLevel"]
@pytest.mark.parametrize("path", [FIX / "T004JTRF.ME0H",
FIX.parent / "histogram-intervals-11-03-26" / "T190LD42.T00H"])
def test_histogram_interval_detail_matches_blastware(path):
ref = parse_xml_report_file(path.with_name(path.name.replace(".", "_", 1) + "_XML.XML"))
res = {r.field: r for r in compare(sfm_side(path.read_bytes()), ref, CARVEOUTS)}
for f in ("IntervalSize", "HistogramStopDate", "HistogramStopTime", "intervals.Tran Freq Hz",
"intervals.Vert Freq Hz", "intervals.Long Freq Hz", "intervals.MicL Freq Hz",
"intervals.Geo PVS in/s"):
assert res[f].verdict == "match", (f, res[f])
@pytest.mark.parametrize("halfp,sr,want", [
(0, 1024, "N/A"), (5, 1024, ">100"), (5, 2048, ">200"), (1024, 1024, "<1.0"),
])
def test_blastwares_interval_frequency_words(halfp, sr, want):
# N/A for a half-period of 0, ">100" / ">200" at 5 samples or fewer, "<1.0"
# below 1 Hz -- on ~3.1 M DL2 cells, 2026-11-03.
from minimateplus.decode_check import interval_frequency
assert interval_frequency(halfp, sr) == want
def _pvs_oorange(unclamp=False):
hb = FIX.parent / "histogram-intervals-11-03-26"
ref = parse_xml_report_file(hb / "T190LD5Q_LD0H_XML.XML") # Geo PVS OORANGE, Vert OORANGE
if unclamp:
cols = ref.interval_columns
t, row = ref.intervals[0]
row = list(row)
row[cols.index("Vert Peak in/s")] = "0.500"
ref.intervals[0] = (t, row)
res = {r.field: r for r in compare(sfm_side((hb / "T190LD5Q.LD0H").read_bytes()), ref, CARVEOUTS)}
return res["intervals.Geo PVS in/s"]
def test_an_oorange_interval_vector_sum_is_saturation():
# Blastware prints OORANGE for an interval's vector sum above the range when
# it clamped a channel in that interval: 17 / 17 DL2 cells, SFM's sum
# 10.01 .. 17.33 (= sqrt 3 x 10.005).
r = _pvs_oorange()
assert (r.verdict, r.carveout) == ("accepted", "saturation")
def test_an_oorange_vector_sum_needs_a_clamped_channel_in_that_interval():
assert _pvs_oorange(unclamp=True).verdict == "mismatch"
_PEAK_TIMES = ("TranPeakDate", "TranPeakTime", "VertPeakDate", "VertPeakTime", "LongPeakDate",
"LongPeakTime", "PeakVectorSumDate", "PeakVectorSumTime", "MicLDate", "MicLTime")
@pytest.mark.parametrize("path", [FIX / "T004JTRF.ME0H", # 1 interval
FIX.parent / "footer-11-03-26" / "T003LCYV.JD0H", # 145
FIX.parent / "histogram-decode-11-02-26" / "K440HA3C.JM0H"]) # 8 x 5 s
def test_histogram_times_match_blastware(path):
# #51: an interval's printed time is its end -- start + (n + 1) x interval,
# capped at the stop -- and each peak's date and time are its interval's:
# 2,308,524 / 2,308,524 rows and 2,000 / 2,000 peaks each on a DL2 sample.
ref = parse_xml_report_file(path.with_name(path.name.replace(".", "_", 1) + "_XML.XML"))
res = {r.field: r for r in compare(sfm_side(path.read_bytes()), ref, CARVEOUTS)}
for f in (("HistogramStartDate", "HistogramStartTime", "HistogramStopTime", "intervals.Time")
+ tuple(t for t in _PEAK_TIMES if t in ref.scalars)):
assert res[f].verdict == "match", (f, res[f])
+7 -6
View File
@@ -426,11 +426,12 @@ def test_the_units_range_reaches_the_store(tmp_path):
assert store.geo_range == 1
# Review finding (2026-10-29): a histogram's row is stored at its file's time,
# a second before the unit's 0C time on most histograms (#51) -- K441LTOK.QZ0
# decodes to 16:06:34, its 0C says 16:06:35 -- so a pre-check on the 0C time
# alone missed it, and a live download overwrote the watcher's row and sidecar.
# The Blastware name encodes the event's own second and does not miss.
# Review finding (2026-10-29): a histogram's row was stored at its file's time,
# a second before the unit's 0C time (#51) -- K441LTOK.QZ0 decoded to 16:06:34,
# its 0C says 16:06:35 -- so a pre-check on the 0C time alone missed it, and a
# live download overwrote the watcher's row and sidecar. Since #51 (dev,
# 2026-11-03) the file decodes the event's own second, so the time matches too;
# the Blastware name, which encodes that second, stays as the second guard.
@pytest.mark.parametrize("stored_as", ["K441LTOK.QZ0", "K441LTOK.QZ0H"]) # direct / call-in name
def test_a_live_histogram_the_watcher_already_stored_writes_nothing(sdm, stored_as):
@@ -442,7 +443,7 @@ def test_a_live_histogram_the_watcher_already_stored_writes_nothing(sdm, stored_
db.insert_events([ev], serial="BE9441", waveform_records={ev._waveform_key.hex(): rec},
device_family="series3") # as the import route (server.py) does
[row0] = db.query_events(serial="BE9441")
assert row0["timestamp"] != "2026-10-26T16:06:35" # the case: the row sits a second off
assert row0["timestamp"] == "2026-10-26T16:06:35" # #51: the event's own second
assert row0["blastware_filename"] == stored_as
out = persist_download(_hist_download("K441LTOK.QZ0", "01110000",
datetime.datetime(2026, 10, 26, 16, 6, 35)), store=store, db=db)
+123
View File
@@ -0,0 +1,123 @@
"""An event is identified by unit + time + type (#51).
The events table was unique on (serial, timestamp): one event per unit per
second. A unit records a waveform and a histogram in the same second
legitimately -- 209 times in prod's 2026-09-30 store once histograms carry
Blastware's start -- so the key is now (serial, timestamp, record_type).
Agreed with Brian 2026-11-03.
"""
from __future__ import annotations
import datetime
import os
import sqlite3
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from minimateplus.models import Event, PeakValues, Timestamp # noqa: E402
from sfm.database import SeismoDb # noqa: E402
T = "2026-08-25T10:33:29"
T_EARLY = "2026-08-25T10:33:28"
def _event(when: str, rtype: str, key: str = "0111646a", pvs: float = 0.5) -> Event:
t = datetime.datetime.fromisoformat(when)
ev = Event(index=0)
ev.timestamp = Timestamp(raw=b"", flag=0x10, year=t.year, unknown_byte=0, month=t.month,
day=t.day, hour=t.hour, minute=t.minute, second=t.second)
ev._waveform_key = bytes.fromhex(key)
ev.record_type = rtype
ev.peak_values = PeakValues(tran=0.1, vert=0.2, long=0.3, peak_vector_sum=pvs, micl=None)
return ev
def _store(db: SeismoDb, ev: Event, filename: str) -> tuple:
return db.insert_events([ev], serial="BE12844", device_family="series3",
waveform_records={ev._waveform_key.hex(): {"filename": filename}})
def _rows(db: SeismoDb) -> list:
with sqlite3.connect(str(db.db_path)) as c:
c.row_factory = sqlite3.Row
return [dict(r) for r in c.execute(
"SELECT * FROM events ORDER BY timestamp, record_type")]
def _key_sql(db: SeismoDb) -> str:
with sqlite3.connect(str(db.db_path)) as c:
return c.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name='events'"
).fetchone()[0]
def test_a_waveform_and_a_histogram_can_share_a_second(tmp_path):
db = SeismoDb(tmp_path / "seismo_relay.db")
assert _store(db, _event(T, "Waveform"), "N844LQHB.ZT0W") == (1, 0)
assert _store(db, _event(T, "Histogram", key="0111700a"), "N844LQHB.ZT0H") == (1, 0)
assert [(r["timestamp"], r["record_type"]) for r in _rows(db)] == [
(T, "Histogram"), (T, "Waveform")]
def test_the_same_event_twice_is_still_one_row(tmp_path):
db = SeismoDb(tmp_path / "seismo_relay.db")
_store(db, _event(T, "Histogram"), "N844LQHB.ZT0H")
assert _store(db, _event(T, "Histogram", pvs=0.8), "N844LQHB.ZT0H") == (0, 1)
(row,) = _rows(db)
assert row["peak_vector_sum"] == 0.8 # the upsert refreshed it
def test_a_histogram_moves_onto_its_waveforms_second(tmp_path):
# What the release backfill does: the histogram was stored a second early;
# its corrected start is the waveform's second. The row moves in place.
db = SeismoDb(tmp_path / "seismo_relay.db")
_store(db, _event(T, "Waveform"), "N844LQHB.ZT0W")
_store(db, _event(T_EARLY, "Histogram", key="0111700a"), "N844LQHB.ZS0H")
(before,) = [r for r in _rows(db) if r["record_type"] == "Histogram"]
assert _store(db, _event(T, "Histogram", key="0111700a"), "N844LQHB.ZS0H") == (0, 1)
rows = _rows(db)
assert [(r["timestamp"], r["record_type"]) for r in rows] == [(T, "Histogram"), (T, "Waveform")]
assert [r["id"] for r in rows if r["record_type"] == "Histogram"] == [before["id"]]
def test_a_re_typed_event_is_corrected_in_place(tmp_path):
# Before v0.33.0 the type came from the filename; a re-import with the
# file's own type must correct that row, not add a second one.
db = SeismoDb(tmp_path / "seismo_relay.db")
_store(db, _event(T, "Waveform"), "N844LQHB.ZT0H")
(before,) = _rows(db)
_store(db, _event(T, "Histogram"), "N844LQHB.ZT0H")
(row,) = _rows(db)
assert (row["id"], row["record_type"]) == (before["id"], "Histogram")
def test_an_old_database_is_migrated_keeping_every_row_and_id(tmp_path):
db = SeismoDb(tmp_path / "seismo_relay.db")
_store(db, _event(T, "Waveform"), "N844LQHB.ZT0W")
_store(db, _event(T_EARLY, "Histogram", key="0111700a"), "N844LQHB.ZS0H")
old_rows = _rows(db)
with sqlite3.connect(str(db.db_path)) as c: # put the old key back
sql = _key_sql(db).replace("UNIQUE(serial, timestamp, record_type)",
"UNIQUE(serial, timestamp)")
c.executescript(f"""
ALTER TABLE events RENAME TO events_new_key;
{sql};
INSERT INTO events SELECT * FROM events_new_key;
DROP TABLE events_new_key;
""")
assert "UNIQUE(serial, timestamp)" in _key_sql(db)
db = SeismoDb(tmp_path / "seismo_relay.db") # opening migrates
assert "UNIQUE(serial, timestamp, record_type)" in _key_sql(db)
assert _rows(db) == old_rows
assert _store(db, _event(T, "Histogram", key="0111700b"), "N844LQHC.ZT0H") == (1, 0)
with sqlite3.connect(str(db.db_path)) as c:
names = {r[0] for r in c.execute(
"SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='events'")}
assert {"idx_events_serial", "idx_events_timestamp"} <= names
def test_reopening_keeps_the_new_key(tmp_path):
SeismoDb(tmp_path / "seismo_relay.db")
db = SeismoDb(tmp_path / "seismo_relay.db")
assert "UNIQUE(serial, timestamp, record_type)" in _key_sql(db)
+5 -4
View File
@@ -22,7 +22,7 @@ from minimateplus.models import Event
FIX = Path(__file__).parent / "fixtures"
WAVEFORM = FIX / "fft-oracle-2026-09-14" / "N844LQHB.ZT0W" # footer ts2 = 2026-08-25 10:33:32
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H" # window start 2026-05-10 19:04:50
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H" # start 2026-05-10 19:04:51 (#51)
def _tuple(ts):
@@ -39,9 +39,10 @@ def test_waveform_timestamp_is_exact_trigger_from_binary():
def test_histogram_timestamp_is_window_start_unchanged():
ev = read_blastware_file(HISTOGRAM)
# Histogram event time = the window start (ts1); must NOT get the waveform
# ts2 treatment (that would land ~24 h off).
assert _tuple(ev.timestamp) == (2026, 5, 10, 19, 4, 50), _tuple(ev.timestamp)
# Histogram event time = the window start, from its own event record (#51;
# the footer's ts1 is a second earlier); must NOT get the waveform ts2
# treatment (that would land ~24 h off).
assert _tuple(ev.timestamp) == (2026, 5, 10, 19, 4, 51), _tuple(ev.timestamp)
def test_a_report_does_not_override_the_instruments_event_record():
+7
View File
@@ -695,3 +695,10 @@ def test_third_block_still_rejects_a_mismatched_counter():
+ _mk_multi_block(ivs, ctr=257)
+ _mk_multi_block(ivs, ctr=999)) # counter jumps — not consecutive
assert detect_multi_interval_stride(body) != 12 + 20 * 4
def test_half_period_to_hz_follows_the_sample_rate():
"""#50: (sample rate / 2) / half-period, measured on 1,725 / 1,725 cells at
2048 sps; the old fixed 512 halved them."""
assert half_period_to_hz(6, 2048) == pytest.approx(1024 / 6)
assert half_period_to_hz(6) == pytest.approx(512 / 6) # 1024 sps by default