merge: dev into feat/series4-sfm-parity -- v0.32.0, #42, #47/#49, #44/#45, the S3 decode checker
Brings the branch up to dev (41 commits) before the 1c bench fixes, which touch code dev changed: the histogram reader (#47/#49, bench finding #2), the v0.32.0 event-time rules, the Blastware file's setup-block fields (#44/#45), and the decode checker for verifying stored S3 downloads. One conflict: the top of the Series-III reference's change table -- both sides added rows; kept all, in date order, CRLF preserved. CLAUDE.md, README, blastware_file.py, models.py and database.py merged cleanly. Suite: the known 16 failures only (15 test_bw_ascii_report, test_save_imported_bw_without_report_ works_unchanged, which also fails on dev); 1237 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
commit
342c69602d
54 files changed
+22279
-264
No files matched your search
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+3292
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+113
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Event>
|
||||
<FileVersion>8.0</FileVersion>
|
||||
<EventType>Full Histogram</EventType>
|
||||
<SerialNumber>BE11529</SerialNumber>
|
||||
<Version>V 10.72-8.17 MiniMate Plus</Version>
|
||||
<FileName>M529L4XQ.R30H</FileName>
|
||||
<HistogramStartTime>14:54:39</HistogramStartTime>
|
||||
<HistogramStartDate>2025-07-02</HistogramStartDate>
|
||||
<HistogramStopTime>14:55:08</HistogramStopTime>
|
||||
<HistogramStopDate>2025-07-02</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.3 Volts</BatteryLevel>
|
||||
<Calibration>April 29, 2025 by Instantel</Calibration>
|
||||
<Units>in/s and dB(L)</Units>
|
||||
<Location>Test Loc</Location>
|
||||
<GeoRange>
|
||||
<Value>10.000</Value>
|
||||
<Units>in/s</Units>
|
||||
</GeoRange>
|
||||
<TranPPV>
|
||||
<Value>2.430</Value>
|
||||
<Units>in/s</Units>
|
||||
</TranPPV>
|
||||
<VertPPV>
|
||||
<Value>0.940</Value>
|
||||
<Units>in/s</Units>
|
||||
</VertPPV>
|
||||
<LongPPV>
|
||||
<Value>1.900</Value>
|
||||
<Units>in/s</Units>
|
||||
</LongPPV>
|
||||
<TranZCFreq>
|
||||
<Value>13</Value>
|
||||
<Units>Hz</Units>
|
||||
</TranZCFreq>
|
||||
<VertZCFreq>
|
||||
<Value>>100</Value>
|
||||
<Units>Hz</Units>
|
||||
</VertZCFreq>
|
||||
<LongZCFreq>
|
||||
<Value>5.8</Value>
|
||||
<Units>Hz</Units>
|
||||
</LongZCFreq>
|
||||
<TranPeakTime>14:55:08</TranPeakTime>
|
||||
<TranPeakDate>2025-07-02</TranPeakDate>
|
||||
<VertPeakTime>14:55:08</VertPeakTime>
|
||||
<VertPeakDate>2025-07-02</VertPeakDate>
|
||||
<LongPeakTime>14:55:08</LongPeakTime>
|
||||
<LongPeakDate>2025-07-02</LongPeakDate>
|
||||
<PeakVectorSum>
|
||||
<Value>3.095</Value>
|
||||
<Units>in/s</Units>
|
||||
</PeakVectorSum>
|
||||
<PeakVectorSumTime>14:55:08</PeakVectorSumTime>
|
||||
<PeakVectorSumDate>2025-07-02</PeakVectorSumDate>
|
||||
<Microphone>Linear Weighting</Microphone>
|
||||
<MicLPSPL>
|
||||
<Value>106.0</Value>
|
||||
<Units>dB(L)</Units>
|
||||
</MicLPSPL>
|
||||
<MicLTime>14:55:08</MicLTime>
|
||||
<MicLDate>2025-07-02</MicLDate>
|
||||
<MicLZCFreq>
|
||||
<Value>51</Value>
|
||||
<Units>Hz</Units>
|
||||
</MicLZCFreq>
|
||||
<TranTestFreq>7.5 Hz.</TranTestFreq>
|
||||
<TranTestRatio>4.0</TranTestRatio>
|
||||
<TranTestResults>Passed</TranTestResults>
|
||||
<VertTestFreq>7.6 Hz.</VertTestFreq>
|
||||
<VertTestRatio>3.7</VertTestRatio>
|
||||
<VertTestResults>Passed</VertTestResults>
|
||||
<LongTestFreq>7.2 Hz.</LongTestFreq>
|
||||
<LongTestRatio>4.0</LongTestRatio>
|
||||
<LongTestResults>Passed</LongTestResults>
|
||||
<MicLTestFreq>0.0 Hz.</MicLTestFreq>
|
||||
<MicLTestAmplitude>0 mv</MicLTestAmplitude>
|
||||
<MicLTestResults>Check</MicLTestResults>
|
||||
<UsbSummaryChannels>
|
||||
</UsbSummaryChannels>
|
||||
<MonitorLog>2025-07-02 14:54:39 - 2025-07-02 14:55:08 "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>2025-07-02 14:55:08</Time>
|
||||
<Row>
|
||||
<Cell>2.430</Cell><Cell>13</Cell><Cell>0.940</Cell><Cell>>100</Cell><Cell>1.900</Cell><Cell>5.8</Cell><Cell>3.095</Cell><Cell>0.001</Cell><Cell>106.0</Cell><Cell>51</Cell></Row>
|
||||
</HistogramDataIntervals>
|
||||
</HistogramData>
|
||||
<HistogramDataUsbChannels>
|
||||
</HistogramDataUsbChannels>
|
||||
|
||||
</Event>
|
||||
BIN
Binary file not shown.
+98
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Event>
|
||||
<FileVersion>8.0</FileVersion>
|
||||
<EventType>Full Histogram</EventType>
|
||||
<SerialNumber>BE16352</SerialNumber>
|
||||
<Version>V 10.72-8.17 MiniMate Plus</Version>
|
||||
<FileName>R352HFZ7.530H</FileName>
|
||||
<HistogramStartTime>21:17:27</HistogramStartTime>
|
||||
<HistogramStartDate>2018-06-04</HistogramStartDate>
|
||||
<HistogramStopTime>21:17:39</HistogramStopTime>
|
||||
<HistogramStopDate>2018-06-04</HistogramStopDate>
|
||||
<Channels>
|
||||
<Channel>Tran</Channel>
|
||||
<Channel>Vert</Channel>
|
||||
<Channel>Long</Channel>
|
||||
</Channels>
|
||||
<NumberofIntervals>1.00</NumberofIntervals>
|
||||
<IntervalSize>1 minute</IntervalSize>
|
||||
<SampleRate>1024 sps</SampleRate>
|
||||
<BatteryLevel>6.7 Volts</BatteryLevel>
|
||||
<Calibration>September 13, 2017 by Instantel</Calibration>
|
||||
<Units>in/s</Units>
|
||||
<Project>JV 241 - 1425 Spanlers Mill Rad</Project>
|
||||
<Client>Walsh Granite JV</Client>
|
||||
<UserName>Terra-Mechanics Inc- D. Harrison</UserName>
|
||||
<Seis.Loc>Loc #1 - 1425 Spanlers Mill Rd</Seis.Loc>
|
||||
<GeoRange>
|
||||
<Value>10.000</Value>
|
||||
<Units>in/s</Units>
|
||||
</GeoRange>
|
||||
<TranPPV>
|
||||
<Value>0.355</Value>
|
||||
<Units>in/s</Units>
|
||||
</TranPPV>
|
||||
<VertPPV>
|
||||
<Value>2.475</Value>
|
||||
<Units>in/s</Units>
|
||||
</VertPPV>
|
||||
<LongPPV>
|
||||
<Value>0.770</Value>
|
||||
<Units>in/s</Units>
|
||||
</LongPPV>
|
||||
<TranZCFreq>
|
||||
<Value>73</Value>
|
||||
<Units>Hz</Units>
|
||||
</TranZCFreq>
|
||||
<VertZCFreq>
|
||||
<Value>30</Value>
|
||||
<Units>Hz</Units>
|
||||
</VertZCFreq>
|
||||
<LongZCFreq>
|
||||
<Value>24</Value>
|
||||
<Units>Hz</Units>
|
||||
</LongZCFreq>
|
||||
<TranPeakTime>21:17:39</TranPeakTime>
|
||||
<TranPeakDate>2018-06-04</TranPeakDate>
|
||||
<VertPeakTime>21:17:39</VertPeakTime>
|
||||
<VertPeakDate>2018-06-04</VertPeakDate>
|
||||
<LongPeakTime>21:17:39</LongPeakTime>
|
||||
<LongPeakDate>2018-06-04</LongPeakDate>
|
||||
<PeakVectorSum>
|
||||
<Value>2.552</Value>
|
||||
<Units>in/s</Units>
|
||||
</PeakVectorSum>
|
||||
<PeakVectorSumTime>21:17:39</PeakVectorSumTime>
|
||||
<PeakVectorSumDate>2018-06-04</PeakVectorSumDate>
|
||||
<TranTestFreq>7.5 Hz.</TranTestFreq>
|
||||
<TranTestRatio>3.7</TranTestRatio>
|
||||
<TranTestResults>Passed</TranTestResults>
|
||||
<VertTestFreq>7.4 Hz.</VertTestFreq>
|
||||
<VertTestRatio>3.6</VertTestRatio>
|
||||
<VertTestResults>Passed</VertTestResults>
|
||||
<LongTestFreq>7.6 Hz.</LongTestFreq>
|
||||
<LongTestRatio>3.6</LongTestRatio>
|
||||
<LongTestResults>Passed</LongTestResults>
|
||||
<UsbSummaryChannels>
|
||||
</UsbSummaryChannels>
|
||||
<MonitorLog>2018-06-04 21:17:26 - 2018-06-04 21:17:39 "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>
|
||||
</HistogramDataColumnTitle>
|
||||
<HistogramDataIntervals>
|
||||
<Time>2018-06-04 21:17:39</Time>
|
||||
<Row>
|
||||
<Cell>0.355</Cell><Cell>73</Cell><Cell>2.475</Cell><Cell>30</Cell><Cell>0.770</Cell><Cell>24</Cell><Cell>2.552</Cell></Row>
|
||||
</HistogramDataIntervals>
|
||||
</HistogramData>
|
||||
<HistogramDataUsbChannels>
|
||||
</HistogramDataUsbChannels>
|
||||
|
||||
</Event>
|
||||
BIN
Binary file not shown.
+3968
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+116
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Event>
|
||||
<FileVersion>8.0</FileVersion>
|
||||
<EventType>Full Histogram</EventType>
|
||||
<SerialNumber>BE18004</SerialNumber>
|
||||
<Version>V 10.72-8.17 MiniMate Plus</Version>
|
||||
<FileName>T004JTRF.ME0H</FileName>
|
||||
<HistogramStartTime>12:49:26</HistogramStartTime>
|
||||
<HistogramStartDate>2022-12-28</HistogramStartDate>
|
||||
<HistogramStopTime>12:49:33</HistogramStopTime>
|
||||
<HistogramStopDate>2022-12-28</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.3 Volts</BatteryLevel>
|
||||
<Calibration>June 24, 2022 by Instantel</Calibration>
|
||||
<Units>in/s and psi(L)</Units>
|
||||
<Project>Robinson Run Bridge No 3-201 Marshall</Project>
|
||||
<Client>Mele & Mele & Sons, Inc.</Client>
|
||||
<UserName>Terra-Mechanics Inc. - D. Harrison</UserName>
|
||||
<SeisLoc>Location #1 - 201 Marshall Road</SeisLoc>
|
||||
<GeoRange>
|
||||
<Value>10.000</Value>
|
||||
<Units>in/s</Units>
|
||||
</GeoRange>
|
||||
<TranPPV>
|
||||
<Value>0.940</Value>
|
||||
<Units>in/s</Units>
|
||||
</TranPPV>
|
||||
<VertPPV>
|
||||
<Value>1.095</Value>
|
||||
<Units>in/s</Units>
|
||||
</VertPPV>
|
||||
<LongPPV>
|
||||
<Value>1.045</Value>
|
||||
<Units>in/s</Units>
|
||||
</LongPPV>
|
||||
<TranZCFreq>
|
||||
<Value>32</Value>
|
||||
<Units>Hz</Units>
|
||||
</TranZCFreq>
|
||||
<VertZCFreq>
|
||||
<Value>47</Value>
|
||||
<Units>Hz</Units>
|
||||
</VertZCFreq>
|
||||
<LongZCFreq>
|
||||
<Value>14</Value>
|
||||
<Units>Hz</Units>
|
||||
</LongZCFreq>
|
||||
<TranPeakTime>12:49:33</TranPeakTime>
|
||||
<TranPeakDate>2022-12-28</TranPeakDate>
|
||||
<VertPeakTime>12:49:33</VertPeakTime>
|
||||
<VertPeakDate>2022-12-28</VertPeakDate>
|
||||
<LongPeakTime>12:49:33</LongPeakTime>
|
||||
<LongPeakDate>2022-12-28</LongPeakDate>
|
||||
<PeakVectorSum>
|
||||
<Value>1.358</Value>
|
||||
<Units>in/s</Units>
|
||||
</PeakVectorSum>
|
||||
<PeakVectorSumTime>12:49:33</PeakVectorSumTime>
|
||||
<PeakVectorSumDate>2022-12-28</PeakVectorSumDate>
|
||||
<Microphone>Linear Weighting</Microphone>
|
||||
<MicLPSPL>
|
||||
<Value>0.0</Value>
|
||||
<Units>psi(L)</Units>
|
||||
</MicLPSPL>
|
||||
<MicLTime>12:49:33</MicLTime>
|
||||
<MicLDate>2022-12-28</MicLDate>
|
||||
<MicLZCFreq>
|
||||
<Value>47</Value>
|
||||
<Units>Hz</Units>
|
||||
</MicLZCFreq>
|
||||
<TranTestFreq>7.4 Hz.</TranTestFreq>
|
||||
<TranTestRatio>3.7</TranTestRatio>
|
||||
<TranTestResults>Passed</TranTestResults>
|
||||
<VertTestFreq>7.5 Hz.</VertTestFreq>
|
||||
<VertTestRatio>3.6</VertTestRatio>
|
||||
<VertTestResults>Passed</VertTestResults>
|
||||
<LongTestFreq>7.5 Hz.</LongTestFreq>
|
||||
<LongTestRatio>4.1</LongTestRatio>
|
||||
<LongTestResults>Passed</LongTestResults>
|
||||
<MicLTestFreq>0.0 Hz.</MicLTestFreq>
|
||||
<MicLTestAmplitude>0 mv</MicLTestAmplitude>
|
||||
<MicLTestResults>Check</MicLTestResults>
|
||||
<UsbSummaryChannels>
|
||||
</UsbSummaryChannels>
|
||||
<MonitorLog>2022-12-28 12:49:25 - 2022-12-28 12:49:33 "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>2022-12-28 12:49:33</Time>
|
||||
<Row>
|
||||
<Cell>0.940</Cell><Cell>32</Cell><Cell>1.095</Cell><Cell>47</Cell><Cell>1.045</Cell><Cell>14</Cell><Cell>1.358</Cell><Cell>0.001</Cell><Cell>104.9</Cell><Cell>47</Cell></Row>
|
||||
</HistogramDataIntervals>
|
||||
</HistogramData>
|
||||
<HistogramDataUsbChannels>
|
||||
</HistogramDataUsbChannels>
|
||||
|
||||
</Event>
|
||||
BIN
Binary file not shown.
+3204
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+7049
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -0,0 +1,72 @@
|
||||
"Event Type : Full Histogram"
|
||||
"Serial Number : BE9441"
|
||||
"Version : V 10.72-8.17 MiniMate Plus"
|
||||
"File Name : K441LTOK.QZ0"
|
||||
"Histogram Start Time : 16:06:35"
|
||||
"Histogram Start Date : October 26, 2026"
|
||||
"Histogram Stop Time : 16:07:21"
|
||||
"Histogram Stop Date : October 26, 2026"
|
||||
"Number of Intervals : 22.00"
|
||||
"Interval Size : 2 seconds "
|
||||
"Sample Rate : 2048 sps"
|
||||
"Battery Level : 6.8 Volts"
|
||||
"Calibration : October 6, 2026 by Instantel"
|
||||
"Units : in/s and "
|
||||
"Project: : TestUnit-Minimate"
|
||||
"Client: : Terra-Mechanics"
|
||||
"User Name: : Terra-Mechanics Inc. - Harrison"
|
||||
"Seis. Loc: : Test unit 1"
|
||||
"Geo Range : 10.000 in/s"
|
||||
"Tran PPV : 0.250 in/s"
|
||||
"Vert PPV : 1.080 in/s"
|
||||
"Long PPV : 0.195 in/s"
|
||||
"Tran ZC Freq : 16.8 Hz"
|
||||
"Vert ZC Freq : 22 Hz"
|
||||
"Long ZC Freq : 19.3 Hz"
|
||||
"Tran Peak Time : 16:06:45"
|
||||
"Tran Peak Date : October 26, 2026"
|
||||
"Vert Peak Time : 16:06:49"
|
||||
"Vert Peak Date : October 26, 2026"
|
||||
"Long Peak Time : 16:06:43"
|
||||
"Long Peak Date : October 26, 2026"
|
||||
"Peak Vector Sum : 1.083 in/s"
|
||||
"Peak Vector Sum Time : 16:06:49"
|
||||
"Peak Vector Sum Date : October 26, 2026"
|
||||
"Tran Test Freq : 7.3 Hz"
|
||||
"Tran Test Ratio : 4.5"
|
||||
"Tran Test Results : Passed"
|
||||
"Vert Test Freq : 7.4 Hz"
|
||||
"Vert Test Ratio : 3.5"
|
||||
"Vert Test Results : Passed"
|
||||
"Long Test Freq : 7.3 Hz"
|
||||
"Long Test Ratio : 4.2"
|
||||
"Long Test Results : Passed"
|
||||
"Monitor Log(s)"
|
||||
"Oct 26 /26 16:06:34 Oct 26 /26 16:07:21 Event recorded. (Keyboard Exit)"
|
||||
"PC SW Version : V 10.74"
|
||||
Tran Tran Vert Vert Long Long Geo
|
||||
PPV Freq PPV Freq PPV Freq PVS
|
||||
Time in/s Hz in/s Hz in/s Hz in/s
|
||||
October 26, 2026
|
||||
16:06:37 0.040 21 0.060 21 0.025 21 0.065
|
||||
16:06:39 0.030 12.8 0.030 16.5 0.015 73 0.034
|
||||
16:06:41 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:06:43 0.230 26 0.400 17.4 0.195 19.3 0.461
|
||||
16:06:45 0.250 16.8 0.120 24 0.135 20 0.255
|
||||
16:06:47 0.015 20 0.020 10.7 0.015 39 0.022
|
||||
16:06:49 0.235 33 1.080 22 0.165 20 1.083
|
||||
16:06:51 0.015 19.7 0.040 19.0 0.020 25 0.043
|
||||
16:06:53 0.085 4.3 0.140 3.0 0.115 3.4 0.185
|
||||
16:06:55 0.045 2.9 0.140 2.9 0.120 2.8 0.181
|
||||
16:06:57 0.015 31 0.010 >200 0.010 >200 0.015
|
||||
16:06:59 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:01 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:03 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:05 0.015 114 0.010 >200 0.010 >200 0.016
|
||||
16:07:07 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:09 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:11 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:13 0.045 4.0 0.055 3.4 0.055 5.7 0.066
|
||||
16:07:15 0.055 5.0 0.070 3.0 0.075 2.2 0.111
|
||||
16:07:17 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
16:07:19 0.010 >200 0.010 >200 0.010 >200 0.015
|
||||
@@ -0,0 +1,194 @@
|
||||
"""A Series-3 waveform's time comes from the instrument's own event record, not a filename.
|
||||
|
||||
A Blastware waveform file carries a copy of the unit's event record:
|
||||
`00 28 05 00 ?? ?? | fe 80 | trigger | stop`, each time `dd mm yyyy(BE) 00 hh mm ss`.
|
||||
Measured 2026-10-26:
|
||||
|
||||
* it is the instrument's data: in all 8 of BE9441's events Blastware downloaded,
|
||||
the record occurs exactly once in the unit's own 5A replies, and the trigger
|
||||
equals the unit's separate 0C record; SFM-only downloads carry it too;
|
||||
* on 7,935 waveforms (DL2 + prod store) exactly one candidate validates, its
|
||||
trigger equals Blastware's report (1,320/1,320) and filename (7,935/7,935);
|
||||
* the footer-only estimate (stop minus record time) is a second off on ~19%.
|
||||
|
||||
A filename is never a time source -- an event SFM receives itself has none --
|
||||
only a cross-check, logged when it disagrees.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from minimateplus.blastware_file import blastware_filename_time # noqa: E402
|
||||
from minimateplus.bw_ascii_report import BwAsciiReport # noqa: E402
|
||||
from minimateplus.event_file_io import (apply_report_to_event, # noqa: E402
|
||||
decode_blastware_bytes, read_blastware_file)
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures"
|
||||
ZI0 = FIX / "minimate-bench-10-26-26-blastware" / "blastware" / "K441LTOF.ZI0"
|
||||
ORACLE = sorted((FIX / "fft-oracle-2026-09-14").glob("N844*W"))
|
||||
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H"
|
||||
TRIGGER = datetime.datetime(2026, 10, 26, 14, 23, 42) # the unit's 0C record; the record
|
||||
ESTIMATE = datetime.datetime(2026, 10, 26, 14, 23, 43) # footer stop minus record time
|
||||
|
||||
|
||||
def _dt(ts):
|
||||
return datetime.datetime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second)
|
||||
|
||||
|
||||
def _record_at(raw: bytes) -> int:
|
||||
return raw.rfind(b"\xfe\x80")
|
||||
|
||||
|
||||
def _decode(raw: bytes, **kw):
|
||||
ev = decode_blastware_bytes(bytes(raw), **kw)
|
||||
return _dt(ev.timestamp), ev.timestamp_source, ev.decode_problems
|
||||
|
||||
|
||||
# -- no filename at all --------------------------------------------------------
|
||||
|
||||
def test_raw_bytes_with_no_name_give_the_instruments_trigger():
|
||||
assert _decode(ZI0.read_bytes()) == (TRIGGER, "event_record", [])
|
||||
|
||||
|
||||
def test_the_name_changes_nothing():
|
||||
assert _dt(read_blastware_file(ZI0).timestamp) == TRIGGER
|
||||
assert _decode(ZI0.read_bytes(), name="upload.bw")[:2] == (TRIGGER, "event_record")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ORACLE, ids=lambda p: p.name)
|
||||
def test_every_oracle_waveform_decodes_from_bytes_alone_to_blastwares_time(path):
|
||||
# BE12844's seven, Blastware's exact times (the fft-oracle reports)
|
||||
t, source, problems = _decode(path.read_bytes())
|
||||
assert (t, source, problems) == (blastware_filename_time(path.name), "event_record", [])
|
||||
|
||||
|
||||
# -- the filename is a cross-check ---------------------------------------------
|
||||
|
||||
def test_a_disagreeing_filename_is_logged_and_the_record_wins(caplog):
|
||||
# K441LTOF.ZJ0 is a valid Blastware name one second later
|
||||
with caplog.at_level(logging.WARNING):
|
||||
t, source, _ = _decode(ZI0.read_bytes(), name="K441LTOF.ZJ0")
|
||||
assert (t, source) == (TRIGGER, "event_record")
|
||||
assert any("14:23:42" in r.message and "14:23:43" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
def test_an_agreeing_filename_logs_nothing(caplog):
|
||||
with caplog.at_level(logging.WARNING):
|
||||
_decode(ZI0.read_bytes(), name=ZI0.name)
|
||||
assert not [r for r in caplog.records if "filename" in r.message]
|
||||
|
||||
|
||||
# -- validation: anything less than one clean candidate is a decode problem ---
|
||||
|
||||
def _session_starts_after_trigger(raw: bytearray, i: int) -> None:
|
||||
# only this rule breaks: the footer's ts1 becomes the record's trigger + 1 s
|
||||
f = len(raw) - 26
|
||||
raw[f + 2:f + 10] = raw[i + 2:i + 10]
|
||||
raw[f + 9] += 1
|
||||
|
||||
|
||||
def _broken(edit) -> bytearray:
|
||||
raw = bytearray(ZI0.read_bytes())
|
||||
edit(raw, _record_at(raw))
|
||||
return raw
|
||||
|
||||
|
||||
@pytest.mark.parametrize("why,edit", [
|
||||
("lead bytes", lambda r, i: r.__setitem__(i - 5, 0x29)), # 00 28 05 00 -> 00 29 ..
|
||||
("marker", lambda r, i: r.__setitem__(i + 1, 0x81)),
|
||||
("trigger zero byte", lambda r, i: r.__setitem__(i + 6, 0x01)),
|
||||
("impossible date", lambda r, i: r.__setitem__(i + 3, 13)), # month 13
|
||||
("stop far from the footer's", lambda r, i: r.__setitem__(i + 17, r[i + 17] - 5)),
|
||||
("trigger before the session start", lambda r, i: _session_starts_after_trigger(r, i)),
|
||||
], ids=lambda x: x if isinstance(x, str) else "")
|
||||
def test_a_record_that_fails_validation_is_a_decode_problem_not_a_filename(why, edit, caplog):
|
||||
with caplog.at_level(logging.WARNING):
|
||||
t, source, problems = _decode(_broken(edit), name=ZI0.name) # a valid name is right there
|
||||
assert (t, source) == (ESTIMATE, "estimate") # never the name's time
|
||||
assert problems and "event record" in problems[0]
|
||||
assert any("event record" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
def test_two_records_that_both_validate_are_not_guessed_between():
|
||||
def dup(raw, i):
|
||||
footer = len(raw) - 26
|
||||
raw[footer - 24:footer] = raw[i - 6:i + 18] # a second, identical candidate
|
||||
t, source, problems = _decode(_broken(dup))
|
||||
assert source == "estimate" and "2 candidates" in problems[0]
|
||||
|
||||
|
||||
# -- reports and histograms ----------------------------------------------------
|
||||
|
||||
def test_a_report_does_not_override_the_instruments_record(caplog):
|
||||
ev = decode_blastware_bytes(ZI0.read_bytes())
|
||||
with caplog.at_level(logging.WARNING):
|
||||
apply_report_to_event(ev, BwAsciiReport(event_datetime=datetime.datetime(2026, 10, 26, 14, 23, 40)))
|
||||
assert (_dt(ev.timestamp), ev.timestamp_source) == (TRIGGER, "event_record")
|
||||
assert any("14:23:40" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
def test_a_report_fills_in_when_the_record_is_missing():
|
||||
ev = decode_blastware_bytes(bytes(_broken(lambda r, i: r.__setitem__(i + 1, 0x81))))
|
||||
apply_report_to_event(ev, BwAsciiReport(event_datetime=TRIGGER))
|
||||
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.
|
||||
ev = read_blastware_file(HISTOGRAM)
|
||||
assert (_dt(ev.timestamp), ev.timestamp_source) == (datetime.datetime(2026, 5, 10, 19, 4, 50), "footer")
|
||||
|
||||
|
||||
def test_the_sidecar_keeps_the_instruments_time_and_says_where_it_came_from():
|
||||
from minimateplus.event_file_io import event_to_sidecar_dict
|
||||
ev = decode_blastware_bytes(ZI0.read_bytes())
|
||||
car = event_to_sidecar_dict(ev, serial="BE9441", blastware_filename="K441LTOF.ZI0",
|
||||
blastware_filesize=0, blastware_sha256="", source_kind="bw-import",
|
||||
bw_report=BwAsciiReport(event_datetime=datetime.datetime(2026, 10, 26, 14, 23, 40)))
|
||||
assert (car["event"]["timestamp"], car["event"]["timestamp_source"]) == \
|
||||
("2026-10-26T14:23:42", "event_record")
|
||||
assert "decode_problems" not in car["event"]
|
||||
|
||||
|
||||
def test_a_sidecar_carries_the_decode_problem():
|
||||
from minimateplus.event_file_io import event_to_sidecar_dict
|
||||
ev = decode_blastware_bytes(bytes(_broken(lambda r, i: r.__setitem__(i + 1, 0x81))))
|
||||
car = event_to_sidecar_dict(ev, serial="BE9441", blastware_filename="K441LTOF.ZI0",
|
||||
blastware_filesize=0, blastware_sha256="", source_kind="bw-import")
|
||||
assert car["event"]["timestamp_source"] == "estimate"
|
||||
assert "event record" in car["event"]["decode_problems"][0]
|
||||
|
||||
|
||||
def test_an_imported_event_with_only_an_estimate_does_not_overwrite_its_neighbour(tmp_path, caplog):
|
||||
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")
|
||||
other = Event(index=0) # a different event at 14:23:43
|
||||
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.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"}})
|
||||
|
||||
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 (_dt(ev.timestamp), ev.timestamp_source) == (ESTIMATE, "estimate")
|
||||
with caplog.at_level(logging.WARNING):
|
||||
assert db.insert_events([ev], serial="BE9441", device_family="series3",
|
||||
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)]
|
||||
assert (tmp_path / "waveforms" / "BE9441" / "K441LTOF.ZI0").exists() # the data is kept
|
||||
assert any("not merged" in r.message for r in caplog.records)
|
||||
@@ -0,0 +1,113 @@
|
||||
"""
|
||||
Setup and note fields read from a Blastware event file alone (#44, #45).
|
||||
|
||||
Every expected value below comes from Blastware's own output for the same
|
||||
file -- its ASCII report or its `_XML.XML` event report -- or, for the bench
|
||||
file with neither, from the record length and the MiniMate Plus spec, as
|
||||
written up in #44/#45. None is derived from the decoder under test.
|
||||
|
||||
The STRT record's bytes are not these fields: STRT[18] is the record-type
|
||||
marker (0x46 waveform, 0x0A histogram), which is why every waveform used to
|
||||
read "70 s".
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from minimateplus.event_file_io import read_blastware_file
|
||||
|
||||
_FIX = Path(__file__).resolve().parent / "fixtures"
|
||||
|
||||
# (file, sample rate, record time s, pre-trigger samples, total samples)
|
||||
_WAVEFORMS = [
|
||||
# ASCII report: 1024 sps, 3.0 s, -0.25 s; 3328 samples per channel.
|
||||
("5-11-26/M529LL1A.SP0", 1024, 3.0, 256, 3328),
|
||||
# ASCII report: 1024 sps, 1.0 s, -0.25 s.
|
||||
("decode-re-5-8-26/event-c/M529LK44.AB0", 1024, 1.0, 256, 1280),
|
||||
# #44/#45: BE9441 bench at 4096 sps, 5 s, 0.25 s -> 21,504 samples.
|
||||
("minimate-bench-10-26-26-blastware/blastware/K441LTOF.ZI0", 4096, 5.0, 1024, 21504),
|
||||
# XML: setup "BE16352.set", 1024 sps, 1.0 s, -0.247 s, 1277 sample rows.
|
||||
("bw-import-fields-10-29-26/R352HIUI.F40W", 1024, 1.0, 253, 1277),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,sr,rt,pretrig,total", _WAVEFORMS)
|
||||
def test_waveform_setup_fields_come_from_the_file(rel, sr, rt, pretrig, total):
|
||||
ev = read_blastware_file(_FIX / rel)
|
||||
assert ev.sample_rate == sr
|
||||
assert ev.rectime_seconds == pytest.approx(rt)
|
||||
assert ev.pretrig_samples == pretrig
|
||||
assert ev.total_samples == total
|
||||
|
||||
|
||||
# (file, sample rate) -- ASCII report / XML
|
||||
_HISTOGRAMS = [
|
||||
("histogram-mic-off-10-26-26/K441LTOK.QZ0", 2048),
|
||||
("ts-fix/K441LKZU.C30H", 1024),
|
||||
("bw-import-fields-10-29-26/M529L4XQ.R30H", 1024),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,sr", _HISTOGRAMS)
|
||||
def test_histogram_sample_rate_comes_from_the_file(rel, sr):
|
||||
ev = read_blastware_file(_FIX / rel)
|
||||
assert ev.sample_rate == sr
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,sr", _HISTOGRAMS)
|
||||
def test_histogram_has_no_record_time_or_pretrigger(rel, sr):
|
||||
# Blastware reports neither for a histogram; the STRT record-type byte
|
||||
# (0x0A = 10) is not a record time.
|
||||
ev = read_blastware_file(_FIX / rel)
|
||||
assert ev.rectime_seconds is None
|
||||
assert ev.pretrig_samples is None
|
||||
|
||||
|
||||
# (file, setup name, project, client, operator, sensor location)
|
||||
_NOTES = [
|
||||
# ASCII report; default labels, location spelled "Seis Loc:".
|
||||
("5-11-26/M529LL1A.SP0", "Standard Recording Setup",
|
||||
"Test-5-8-26", "New Client", "Terra-Mechanics - Harrison", "Still Catbed."),
|
||||
# ASCII report; location spelled "Seis. Loc:". BE9441's bench setup is
|
||||
# saved as "Standard Recording Setup.set" (#45).
|
||||
("histogram-mic-off-10-26-26/K441LTOK.QZ0", "Standard Recording Setup.set",
|
||||
"TestUnit-Minimate", "Terra-Mechanics", "Terra-Mechanics Inc. - Harrison", "Test unit 1"),
|
||||
# XML; a setup not named "Standard Recording Setup".
|
||||
("bw-import-fields-10-29-26/R352HIUI.F40W", "BE16352.set",
|
||||
"JV 241 - 1425 Spanlers Mill Rad", "Walsh Granite JV",
|
||||
"Terra-Mechanics Inc- D. Harrison", "Loc #1 - 1425 Spanlers Mill Rd"),
|
||||
# XML (<Location>Test Loc</Location> only); the operator relabelled the
|
||||
# four note slots "Location:", "Client:", "User Name:", "General:" and
|
||||
# filled in only the first. Slots are positional, as in the ASCII parser.
|
||||
("bw-import-fields-10-29-26/M529L4XQ.R30H", "Standard Recording Setup",
|
||||
"Test Loc", None, None, None),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,setup,project,client,operator,location", _NOTES)
|
||||
def test_notes_come_from_the_file_by_position(rel, setup, project, client, operator, location):
|
||||
pi = read_blastware_file(_FIX / rel).project_info
|
||||
assert pi.setup_name == setup
|
||||
assert pi.project == project
|
||||
assert pi.client == client
|
||||
assert pi.operator == operator
|
||||
assert pi.sensor_location == location
|
||||
|
||||
|
||||
def test_import_without_a_report_stores_the_file_fields(tmp_path: Path):
|
||||
"""The watcher path with no ASCII report: the sidecar carries what the
|
||||
file holds, not blanks and not the STRT bytes."""
|
||||
from sfm.waveform_store import WaveformStore
|
||||
|
||||
src = _FIX / "bw-import-fields-10-29-26/R352HIUI.F40W"
|
||||
store = WaveformStore(tmp_path / "waveforms")
|
||||
store.save_imported_bw(src.read_bytes(), source_path=src)
|
||||
|
||||
sc = store.load_sidecar("BE16352", src.name)
|
||||
assert sc["event"]["sample_rate"] == 1024
|
||||
assert sc["event"]["rectime_seconds"] == pytest.approx(1.0)
|
||||
assert sc["event"]["pretrig_samples"] == 253
|
||||
assert sc["project_info"]["project"] == "JV 241 - 1425 Spanlers Mill Rad"
|
||||
assert sc["project_info"]["sensor_location"] == "Loc #1 - 1425 Spanlers Mill Rd"
|
||||
@@ -0,0 +1,109 @@
|
||||
"""The Blastware filename's time: a cross-check on the decoded time, never its source.
|
||||
|
||||
A Blastware name encodes the event time to the second (stem + AB, see
|
||||
`blastware_filename`) -- Blastware's own copy of the unit's trigger. The decoder
|
||||
reads the time from the instrument's embedded event record instead (see
|
||||
test_bw_event_record_time.py); an event SFM receives itself has no name.
|
||||
Measured 2026-10-26:
|
||||
|
||||
* name == the report's Event Time on 81/81 prod-snapshot and 1,249/1,249 DL2
|
||||
report-paired waveforms;
|
||||
* the binary's trigger (ts2 - record time) is a second off on 260 of prod's
|
||||
1,394 waveforms (199 late, 61 early). On BE9558 the 61 early ones land on
|
||||
their histogram twin's second, and events is unique on (serial, timestamp):
|
||||
a fresh import wrote each waveform over its histogram's row.
|
||||
|
||||
Histograms keep the binary's ts1. Their name is Blastware's start time too (13,089/13,089),
|
||||
and ts1 runs a second early on 97% of them -- but in Blastware's timing a
|
||||
waveform and its histogram share a second 209 times in prod's store, which a
|
||||
(serial, timestamp) key cannot hold. That correction needs the key changed.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from minimateplus.blastware_file import blastware_filename, blastware_filename_time # noqa: E402
|
||||
from minimateplus.event_file_io import read_blastware_file # noqa: E402
|
||||
from minimateplus.models import Event, PeakValues, Timestamp # noqa: E402
|
||||
from sfm.database import SeismoDb # noqa: E402
|
||||
from sfm.waveform_store import WaveformStore # noqa: E402
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures"
|
||||
ZI0 = FIX / "minimate-bench-10-26-26-blastware" / "blastware" / "K441LTOF.ZI0"
|
||||
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H"
|
||||
|
||||
|
||||
def _dt(ts):
|
||||
return datetime.datetime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second)
|
||||
|
||||
|
||||
def test_names_decode_to_the_documented_times():
|
||||
# the three S353L4H0 events the encoder was verified against, plus an H
|
||||
assert blastware_filename_time("S353L4H0.3M0W") == datetime.datetime(2025, 6, 23, 13, 57, 22)
|
||||
assert blastware_filename_time("S353L4H0.8S0H") == datetime.datetime(2025, 6, 23, 14, 0, 28)
|
||||
assert blastware_filename_time("S353L4H0.9X0W") == datetime.datetime(2025, 6, 23, 14, 1, 9)
|
||||
assert blastware_filename_time("P036L318.C80H") == datetime.datetime(2025, 5, 26, 15, 0, 8)
|
||||
assert blastware_filename_time("K441LTOF.ZI0") == datetime.datetime(2026, 10, 26, 14, 23, 42)
|
||||
assert blastware_filename_time("k441ltof.zi0") == datetime.datetime(2026, 10, 26, 14, 23, 42)
|
||||
|
||||
|
||||
def test_the_decoder_inverts_the_encoder():
|
||||
for t in (datetime.datetime(2018, 1, 2, 3, 4, 5), datetime.datetime(2026, 10, 26, 23, 59, 59),
|
||||
datetime.datetime(2026, 2, 28, 0, 0, 0)):
|
||||
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)
|
||||
assert blastware_filename_time(blastware_filename(ev, "BE9441")) == t
|
||||
assert blastware_filename_time(blastware_filename(ev, "BE9441", ach=True)) == t
|
||||
|
||||
|
||||
def test_other_names_give_nothing():
|
||||
for name in ("imported.bw", "UM12947_20260406130113.IDFW", "K441LTOF.ZI1", "K441LTOF.ZI0X",
|
||||
"K441LTO.ZI0", "K441LTOF.Z!0", "", "BE9441.MLG"):
|
||||
assert blastware_filename_time(name) is None, name
|
||||
|
||||
|
||||
def test_a_waveform_decodes_to_the_time_its_name_encodes():
|
||||
# BE9441, 2026-10-26: the footer estimate says 14:23:43; the event record, the
|
||||
# unit's 0C record and the name all say 14:23:42
|
||||
assert _dt(read_blastware_file(ZI0).timestamp) == datetime.datetime(2026, 10, 26, 14, 23, 42)
|
||||
|
||||
|
||||
def test_a_waveform_read_under_another_name_keeps_its_time(tmp_path):
|
||||
tmp = tmp_path / "upload.bw"
|
||||
tmp.write_bytes(ZI0.read_bytes())
|
||||
assert _dt(read_blastware_file(tmp).timestamp) == datetime.datetime(2026, 10, 26, 14, 23, 42)
|
||||
assert _dt(read_blastware_file(tmp, name=ZI0.name).timestamp) == \
|
||||
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_an_import_no_longer_lands_a_waveform_on_its_histogram_twins_row(tmp_path):
|
||||
"""BE9558's 61: the binary's second was the histogram twin's. Built here from
|
||||
BE9441's ZI0: a histogram row at the binary's 14:23:43, then the waveform."""
|
||||
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.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"}})
|
||||
|
||||
ev, rec = store.save_imported_bw(ZI0.read_bytes(), source_path=Path(ZI0.name))
|
||||
db.insert_events([ev], serial="BE9441", device_family="series3",
|
||||
waveform_records={ev._waveform_key.hex(): rec})
|
||||
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
rows = c.execute("SELECT blastware_filename, timestamp FROM events ORDER BY timestamp").fetchall()
|
||||
assert rows == [("K441LTOF.ZI0", "2026-10-26T14:23:42"), ("K441LTOF.ZJ0H", "2026-10-26T14:23:43")]
|
||||
@@ -0,0 +1,83 @@
|
||||
"""
|
||||
Blastware's `_XML.XML` event report, parsed (decode checker, Task 1).
|
||||
|
||||
Expected values are copied from the fixture XML files themselves.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from minimateplus.bw_xml_report import parse_xml_report, parse_xml_report_file
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures/decode-checker-10-29-26"
|
||||
|
||||
|
||||
def test_scalars_units_and_special_text():
|
||||
r = parse_xml_report_file(FIX / "T1905KDW_5F0W_XML.XML")
|
||||
assert r.scalars["SampleRate"] == "1024 sps"
|
||||
assert r.scalars["RecordTime"] == "1.0 sec."
|
||||
assert r.scalars["TranPPV"] == "0.005" and r.units["TranPPV"] == "in/s"
|
||||
assert r.scalars["VertZCFreq"] == ">100" # entity unescaped
|
||||
assert r.scalars["TranZCFreq"] == "N/A"
|
||||
assert r.scalars["TranTestResults"] == "Check"
|
||||
assert r.scalars["BatteryLevel"] == "6.7 Volts"
|
||||
assert r.job_number == "1" and r.notes == []
|
||||
assert r.channels == ["Tran", "Vert", "Long", "MicL"]
|
||||
|
||||
|
||||
def test_waveform_sample_rows():
|
||||
r = parse_xml_report_file(FIX / "T1905KDW_5F0W_XML.XML")
|
||||
assert len(r.sample_rows) == 1024
|
||||
assert r.sample_rows[0] == ["-0.005", "0.000", "0.000", "81.94"]
|
||||
assert r.intervals is None
|
||||
|
||||
|
||||
def test_ragged_rows_are_kept_as_printed():
|
||||
r = parse_xml_report_file(FIX / "T438HGTZ_B30W_XML.XML")
|
||||
assert len(r.sample_rows) == 2304
|
||||
assert r.sample_rows[-4] == ["-0.185", "0.235", "-0.255", "-87.96"]
|
||||
assert r.sample_rows[-1] == ["-0.245"] # only Long still running
|
||||
|
||||
|
||||
def test_relabelled_notes_keep_their_tags_in_order():
|
||||
r = parse_xml_report_file(FIX / "M529L4XQ_R30H_XML.XML")
|
||||
assert r.notes == [("Location", "Test Loc")]
|
||||
r = parse_xml_report_file(FIX / "T004JTRF_ME0H_XML.XML")
|
||||
assert r.notes[1] == ("Client", "Mele & Mele & Sons, Inc.")
|
||||
assert r.event_units == "in/s and psi(L)"
|
||||
|
||||
|
||||
def test_notes_and_job_number_are_not_scalars():
|
||||
r = parse_xml_report_file(FIX / "T004JTRF_ME0H_XML.XML")
|
||||
assert "Project" not in r.scalars and "SeisLoc" not in r.scalars
|
||||
r = parse_xml_report_file(FIX / "T1905KDW_5F0W_XML.XML")
|
||||
assert "JobNumber" not in r.scalars
|
||||
|
||||
|
||||
def test_histogram_intervals_and_columns():
|
||||
r = parse_xml_report_file(FIX / "M529L4XQ_R30H_XML.XML")
|
||||
assert r.interval_columns[0] == "Tran Peak in/s" and len(r.interval_columns) == 10
|
||||
assert r.intervals == [("2025-07-02 14:55:08",
|
||||
["2.430", "13", "0.940", ">100", "1.900", "5.8", "3.095", "0.001", "106.0", "51"])]
|
||||
assert r.sample_rows is None
|
||||
|
||||
|
||||
def test_no_mic_histogram_has_seven_columns():
|
||||
r = parse_xml_report_file(FIX / "R352HFZ7_530H_XML.XML")
|
||||
assert r.event_units == "in/s"
|
||||
assert r.channels == ["Tran", "Vert", "Long"]
|
||||
assert len(r.interval_columns) == 7 and len(r.intervals[0][1]) == 7
|
||||
|
||||
|
||||
def test_oorange_and_range_values():
|
||||
r = parse_xml_report_file(FIX / "M007HVWF_K30W_XML.XML")
|
||||
assert r.scalars["TranPPV"] == "OORANGE"
|
||||
assert r.scalars["GeoRange"] == "1.250" and r.units["GeoRange"] == "in/s"
|
||||
|
||||
|
||||
def test_truncated_xml_raises_valueerror():
|
||||
data = (FIX / "M529L4XQ_R30H_XML.XML").read_bytes()
|
||||
with pytest.raises(ValueError):
|
||||
parse_xml_report(data[: len(data) // 2])
|
||||
@@ -0,0 +1,173 @@
|
||||
"""
|
||||
The decode checker's runner and reports (decode checker, Tasks 5-7).
|
||||
|
||||
Runs on the fixture folder, which holds the binaries and their XML reports
|
||||
side by side.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import gzip
|
||||
import importlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
run = importlib.import_module("scratch.check_s3_decode")
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures/decode-checker-10-29-26"
|
||||
|
||||
|
||||
def test_find_pairs_dedupes_and_pairs(tmp_path):
|
||||
(tmp_path / "Sent").mkdir()
|
||||
for n in ("R352HIUI.F40W", "Sent/R352HIUI.F40W", "UM11719_20240404193109.IDFH"):
|
||||
(tmp_path / n).write_bytes(b"x")
|
||||
pairs = run.find_pairs(tmp_path, FIX)
|
||||
assert [p[0] for p in pairs] == ["R352HIUI.F40W"]
|
||||
assert pairs[0][2].name == "R352HIUI_F40W_XML.XML"
|
||||
|
||||
|
||||
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"
|
||||
assert any(r[0] == "TranPPV" and r[1] == "mismatch" for r in out["results"])
|
||||
|
||||
|
||||
def test_bad_input_is_one_error_row(tmp_path):
|
||||
bad = tmp_path / "R352HIUI.F40W"
|
||||
bad.write_bytes(b"not a blastware file")
|
||||
out = run.check_event(bad.name, str(bad), str(FIX / "R352HIUI_F40W_XML.XML"))
|
||||
assert out["results"] == [["event", "error", None, None, out["results"][0][4], None]]
|
||||
|
||||
|
||||
def test_missing_reference_is_one_no_reference_row():
|
||||
out = run.check_event("R352HIUI.F40W", str(FIX / "R352HIUI.F40W"), None)
|
||||
assert [r[:2] for r in out["results"]] == [["event", "no_reference"]]
|
||||
|
||||
|
||||
def test_cli_writes_results(tmp_path):
|
||||
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "run"), "--jobs", "1"]) == 0
|
||||
lines = gzip.open(tmp_path / "run/results.jsonl.gz", "rt").read().splitlines()
|
||||
assert len(lines) == 7
|
||||
assert json.loads((tmp_path / "run/run.json").read_text())["events"] == 7
|
||||
|
||||
|
||||
def test_field_filter_keeps_only_matching_rows(tmp_path):
|
||||
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "run"), "--jobs", "1",
|
||||
"--field", "samples."]) == 0
|
||||
for line in gzip.open(tmp_path / "run/results.jsonl.gz", "rt"):
|
||||
assert all(r[0].startswith("samples.") for r in json.loads(line)["results"])
|
||||
|
||||
|
||||
# ── Task 6: summary and detailed report ─────────────────────────────────────
|
||||
|
||||
report = importlib.import_module("scratch.decode_check_report")
|
||||
|
||||
|
||||
def _write_results(path, events):
|
||||
with gzip.open(path, "wt") as fh:
|
||||
for ev in events:
|
||||
fh.write(json.dumps(ev) + "\n")
|
||||
|
||||
|
||||
def _ev(name, sr, verdict):
|
||||
return {"file": name, "attrs": {"sample_rate": sr, "year": "2024"},
|
||||
"results": [["SampleRate", verdict, sr + " sps", "1024", "", None]]}
|
||||
|
||||
|
||||
def test_details_group_failures_by_what_they_share(tmp_path):
|
||||
res = tmp_path / "results.jsonl.gz"
|
||||
_write_results(res, [_ev("A.W", "2048", "mismatch"), _ev("B.W", "2048", "mismatch"),
|
||||
_ev("C.W", "1024", "match")])
|
||||
agg = report.aggregate(res)
|
||||
report.write_details(agg, tmp_path / "details.json")
|
||||
d = json.loads((tmp_path / "details.json").read_text())["SampleRate|mismatch"]
|
||||
assert d["total"] == 2
|
||||
assert d["groups"]["sample_rate"] == [
|
||||
{"value": "2048", "failing": 2, "compared": 2, "rate": 1.0, "concentrated": True}]
|
||||
assert d["examples"] and all("--file" in e["rerun"] for e in d["examples"])
|
||||
|
||||
|
||||
def test_summary_counts_fields_fully_matching(tmp_path):
|
||||
res = tmp_path / "results.jsonl.gz"
|
||||
_write_results(res, [_ev("A.W", "2048", "mismatch"), _ev("C.W", "1024", "match")])
|
||||
report.write_summary(report.aggregate(res), tmp_path / "summary.md")
|
||||
text = (tmp_path / "summary.md").read_text()
|
||||
assert "0 of 1 fields fully matching" in text and "| SampleRate |" in text
|
||||
|
||||
|
||||
def test_a_run_writes_both_reports(tmp_path):
|
||||
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "run"), "--jobs", "1"]) == 0
|
||||
assert (tmp_path / "run/summary.md").exists() and (tmp_path / "run/details.json").exists()
|
||||
|
||||
|
||||
# ── Task 7: run-to-run changes and the one-event view ───────────────────────
|
||||
|
||||
def _one(name, field, verdict):
|
||||
return {"file": name, "attrs": {}, "results": [[field, verdict, "x", "y", "", None]]}
|
||||
|
||||
|
||||
def test_compare_runs_finds_regressions_and_fixes(tmp_path):
|
||||
prev, cur = tmp_path / "prev.jsonl.gz", tmp_path / "cur.jsonl.gz"
|
||||
_write_results(prev, [_one("A.W", "SampleRate", "match"), _one("B.W", "notes", "sfm_blank")])
|
||||
_write_results(cur, [_one("A.W", "SampleRate", "mismatch"), _one("B.W", "notes", "match")])
|
||||
chg = report.compare_runs(prev, cur)
|
||||
assert chg["regressions"] == [{"file": "A.W", "field": "SampleRate",
|
||||
"before": "match", "after": "mismatch"}]
|
||||
assert chg["fixed"] == 1
|
||||
report.write_changes(chg, tmp_path / "changes.md")
|
||||
assert "A.W" in (tmp_path / "changes.md").read_text()
|
||||
|
||||
|
||||
def test_compare_to_marks_the_summary(tmp_path):
|
||||
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "a"), "--jobs", "1"]) == 0
|
||||
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "b"), "--jobs", "1",
|
||||
"--compare-to", str(tmp_path / "a")]) == 0
|
||||
assert "**0 regressions**" in (tmp_path / "b/summary.md").read_text()
|
||||
assert (tmp_path / "b/changes.md").exists()
|
||||
|
||||
|
||||
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 "mismatch" in line for line in out.splitlines())
|
||||
|
||||
|
||||
# ── Final review fixes ──────────────────────────────────────────────────────
|
||||
|
||||
def test_a_matching_event_that_now_errors_is_a_regression(tmp_path):
|
||||
prev, cur = tmp_path / "prev.jsonl.gz", tmp_path / "cur.jsonl.gz"
|
||||
_write_results(prev, [_one("A.W", "SampleRate", "match"), _one("B.W", "notes", "match")])
|
||||
_write_results(cur, [_one("A.W", "event", "error"), _one("B.W", "notes", "match")])
|
||||
chg = report.compare_runs(prev, cur)
|
||||
assert chg["regressions"] == [{"file": "A.W", "field": "SampleRate",
|
||||
"before": "match", "after": "error"}]
|
||||
|
||||
|
||||
def test_counts_moved_cover_only_shared_events(tmp_path):
|
||||
prev, cur = tmp_path / "prev.jsonl.gz", tmp_path / "cur.jsonl.gz"
|
||||
_write_results(prev, [_one("A.W", "SampleRate", "match")])
|
||||
_write_results(cur, [_one("A.W", "SampleRate", "match"), _one("B.W", "SampleRate", "match")])
|
||||
assert report.compare_runs(prev, cur)["fields"]["SampleRate"]["match"] == [1, 1]
|
||||
|
||||
|
||||
def test_default_comparison_is_the_newest_completed_run_of_the_same_scope(tmp_path, monkeypatch):
|
||||
runs = tmp_path / "runs"
|
||||
monkeypatch.setattr(run, "RUNS_DIR", runs)
|
||||
base = [str(FIX), str(FIX), "--jobs", "1"]
|
||||
assert run.main(base + ["--out", str(runs / "20990101-000001")]) == 0 # same scope
|
||||
assert run.main(base + ["--out", str(runs / "20990101-000002"), "--type", "W"]) == 0 # narrower
|
||||
(runs / "20990101-000003").mkdir() # never finished
|
||||
assert run.main(base + ["--out", str(runs / "20990101-000004")]) == 0
|
||||
assert "20990101-000001" in (runs / "20990101-000004/changes.md").read_text().splitlines()[0]
|
||||
|
||||
|
||||
def test_fields_fully_matching_need_a_match_and_skip_the_event_row(tmp_path):
|
||||
res = tmp_path / "results.jsonl.gz"
|
||||
_write_results(res, [
|
||||
{"file": "A.W", "attrs": {}, "results": [["SampleRate", "match", "1", "1", "", None],
|
||||
["UsbSummaryChannels", "no_reference", "", None, "", None]]},
|
||||
{"file": "B.W", "attrs": {}, "results": [["event", "no_reference", None, None, "no XML report", None]]},
|
||||
])
|
||||
report.write_summary(report.aggregate(res), tmp_path / "summary.md")
|
||||
text = (tmp_path / "summary.md").read_text()
|
||||
assert "1 of 2 fields fully matching" in text
|
||||
assert "1 event without a report" in text and "| event |" not in text
|
||||
@@ -0,0 +1,145 @@
|
||||
"""
|
||||
The decode checker's SFM side and comparison (decode checker, Tasks 2-4).
|
||||
|
||||
Expected values come from the fixtures' Blastware XML reports. SFM's side is
|
||||
built from the event bytes alone -- no filename, no report.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from minimateplus.decode_check import sfm_side
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures/decode-checker-10-29-26"
|
||||
|
||||
|
||||
def test_waveform_side_from_bytes():
|
||||
s = sfm_side((FIX / "R352HIUI.F40W").read_bytes())
|
||||
assert s.values["SampleRate"] == 1024 and s.values["RecordTime"] == pytest.approx(1.0)
|
||||
assert s.values["Pre-triggerLength"] == pytest.approx(-253 / 1024)
|
||||
assert (s.values["EventDate"], s.values["EventTime"]) == ("2018-07-30", "16:13:52")
|
||||
assert s.notes == ["JV 241 - 1425 Spanlers Mill Rad", "Walsh Granite JV",
|
||||
"Terra-Mechanics Inc- D. Harrison", "Loc #1 - 1425 Spanlers Mill Rd"]
|
||||
assert len(s.counts["Tran"]) == 1277 and s.job_number is None
|
||||
|
||||
|
||||
def test_histogram_interval_peak_in_counts():
|
||||
s = sfm_side((FIX / "M529L4XQ.R30H").read_bytes())
|
||||
# Blastware: Tran interval peak 2.430 in/s = 7776 counts at 10/32000 in/s per count
|
||||
assert s.counts["Tran"] == [7776] and s.values["NumberofIntervals"] == 1
|
||||
|
||||
|
||||
def test_no_filename_reaches_the_decoder():
|
||||
# The type must come from the bytes; today they can't tell it (#41), so this
|
||||
# histogram reads as a waveform. Update to "Full Histogram" when #41 lands.
|
||||
s = sfm_side((FIX / "M529L4XQ.R30H").read_bytes())
|
||||
assert s.values["EventType"] == "Full Waveform"
|
||||
|
||||
|
||||
def test_report_fields_stay_blank():
|
||||
s = sfm_side((FIX / "T1905KDW.5F0W").read_bytes())
|
||||
for tag in ("TranZCFreq", "TranPeakAcceleration", "BatteryLevel", "Calibration", "TranTestResults"):
|
||||
assert s.values.get(tag) is None
|
||||
|
||||
|
||||
# ── Task 3: the comparison ──────────────────────────────────────────────────
|
||||
|
||||
from minimateplus.bw_xml_report import parse_xml_report_file # noqa: E402
|
||||
from minimateplus.decode_check import compare, matches_printed # noqa: E402
|
||||
|
||||
|
||||
def _results(stem, carveouts=()):
|
||||
raw = (FIX / stem).read_bytes()
|
||||
ref = parse_xml_report_file(FIX / (stem.replace(".", "_") + "_XML.XML"))
|
||||
return {r.field: r for r in compare(sfm_side(raw), ref, carveouts)}
|
||||
|
||||
|
||||
def test_matches_printed_rounds_half_away():
|
||||
assert matches_printed(-0.0625, "-0.063") and matches_printed(0.0015, "0.002")
|
||||
assert not matches_printed(0.0026, "0.002")
|
||||
|
||||
|
||||
def test_full_waveform_row_verdicts():
|
||||
res = _results("R352HIUI.F40W")
|
||||
for f in ("SampleRate", "RecordTime", "Pre-triggerLength", "EventDate", "EventTime",
|
||||
"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 "FileName" not in res
|
||||
|
||||
|
||||
def test_ragged_rows_match_by_running_channels():
|
||||
# Tran/Vert/MicL end 3 samples before Long, in SFM and in Blastware's table alike
|
||||
res = _results("T438HGTZ.B30W")
|
||||
for ch in ("Tran", "Vert", "Long"):
|
||||
assert res[f"samples.{ch}"].verdict == "match", res[f"samples.{ch}"]
|
||||
|
||||
|
||||
def test_an_extra_reference_row_is_a_mismatch_with_detail():
|
||||
raw = (FIX / "T1905KDW.5F0W").read_bytes()
|
||||
ref = parse_xml_report_file(FIX / "T1905KDW_5F0W_XML.XML")
|
||||
ref.sample_rows.append(["0.000", "0.000", "0.000", "0.000"])
|
||||
res = {r.field: r for r in compare(sfm_side(raw), ref)}
|
||||
assert res["samples.Tran"].verdict == "mismatch"
|
||||
assert "row_length_disagreements=1" in res["samples.Tran"].detail
|
||||
|
||||
|
||||
def test_job_number_na_and_above_range():
|
||||
res = _results("T1905KDW.5F0W")
|
||||
assert res["JobNumber"].verdict == "sfm_blank"
|
||||
assert res["TranZCFreq"].verdict == "no_reference" # N/A
|
||||
assert res["VertZCFreq"].verdict == "sfm_blank" # >100, SFM has no flag yet
|
||||
|
||||
|
||||
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"
|
||||
fields = set(_results("R352HFZ7.530H")) # no mic
|
||||
assert not any(f.startswith(("samples.MicL", "intervals.MicL")) for f in fields)
|
||||
|
||||
|
||||
# ── Task 4: carve-outs ──────────────────────────────────────────────────────
|
||||
|
||||
from minimateplus.decode_check_carveouts import CARVEOUTS # noqa: E402
|
||||
|
||||
|
||||
def test_clipped_normal_range_is_accepted():
|
||||
# Blastware: Tran 5.445, Vert 6.310, Long OORANGE, PVS OORANGE; SFM Long 10.005, PVS 11.55
|
||||
res = _results("T438HGTZ.B30W", CARVEOUTS)
|
||||
assert res["TranPPV"].verdict == "match" and res["VertPPV"].verdict == "match"
|
||||
for f in ("LongPPV", "PeakVectorSum"):
|
||||
assert (res[f].verdict, res[f].carveout) == ("accepted", "saturation")
|
||||
|
||||
|
||||
def test_sensitive_range_8x_stays_a_mismatch():
|
||||
res = _results("M007HVWF.K30W", CARVEOUTS)
|
||||
assert res["TranPPV"].verdict == "mismatch" and res["samples.Tran"].verdict == "mismatch"
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
|
||||
def test_every_carveout_has_evidence():
|
||||
assert all(c.id and c.fields and len(c.evidence) > 40 for c in CARVEOUTS)
|
||||
|
||||
|
||||
def test_pvs_carveout_needs_oorange_from_blastware():
|
||||
raw = (FIX / "T438HGTZ.B30W").read_bytes()
|
||||
ref = parse_xml_report_file(FIX / "T438HGTZ_B30W_XML.XML")
|
||||
ref.scalars["PeakVectorSum"] = "10.392" # a vector sum may exceed the range unclipped
|
||||
res = {r.field: r for r in compare(sfm_side(raw), ref, CARVEOUTS)}
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
|
||||
def test_pvs_carveout_needs_the_clipped_channel_at_the_ceiling():
|
||||
# 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["TranPPV"] = "0.157"
|
||||
side = sfm_side(raw)
|
||||
side.values["TranPPV"] = 1.256
|
||||
res = {r.field: r for r in compare(side, ref, CARVEOUTS)}
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
@@ -269,7 +269,7 @@ def test_seismodb_persists_sidecar_filename_and_review_sync(tmp_path: Path):
|
||||
|
||||
|
||||
def test_read_blastware_file_round_trip(tmp_path: Path):
|
||||
"""write → read → key/timestamp/rectime survive."""
|
||||
"""write → read → key/timestamp survive."""
|
||||
from minimateplus.blastware_file import write_blastware_file, blastware_filename
|
||||
|
||||
ev, frames = _make_synthetic_event()
|
||||
@@ -278,7 +278,10 @@ def test_read_blastware_file_round_trip(tmp_path: Path):
|
||||
|
||||
parsed = event_file_io.read_blastware_file(bw_path)
|
||||
assert parsed._waveform_key == ev._waveform_key
|
||||
assert parsed.rectime_seconds == ev.rectime_seconds
|
||||
# The synthetic file has no recording-setup block, so its record time is
|
||||
# unknown. STRT[18], where the helper puts it, is the record-type marker
|
||||
# and is not read as a record time (#44/#45).
|
||||
assert parsed.rectime_seconds is None
|
||||
# Timestamp lands via the footer; year/month/day/hour/min/sec all survive.
|
||||
assert parsed.timestamp is not None
|
||||
assert parsed.timestamp.year == ev.timestamp.year
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
"""A re-stored event whose decoded time changed must correct its row, not duplicate it.
|
||||
|
||||
The waveform event-time fix (a84a46e / 1e76d08) changed what time a Series-3
|
||||
waveform decodes to: the trigger, where v0.31.0 stamped the monitoring-session
|
||||
start -- hours off. The events table is unique on (serial, timestamp), so every
|
||||
store path that re-saves an old event (the release backfill, a watcher
|
||||
re-forward) found no row at the corrected time and inserted a second one: the
|
||||
event twice, once at each time, its review state on the old copy only.
|
||||
Measured 2026-10-26 by storing real files with v0.31.0 and backfilling with dev.
|
||||
|
||||
A row is the same event when it holds the same stored file (serial +
|
||||
blastware_filename -- a Blastware name encodes the serial and the time to the
|
||||
second). insert_events now moves that row to the corrected time in place.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
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
|
||||
from sfm.waveform_store import WaveformStore # noqa: E402
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures"
|
||||
WAVEFORM = FIX / "fft-oracle-2026-09-14" / "N844LQHB.ZT0W"
|
||||
OLD_TIME = "2026-08-25T06:00:13" # what v0.31.0 stored: the session start
|
||||
NEW_TIME = "2026-08-25T10:33:29" # the trigger, which the decoder now gives
|
||||
|
||||
|
||||
def _event(when: 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.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 = "N844LQHB.ZT0W") -> 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 blastware_filename, timestamp")]
|
||||
|
||||
|
||||
def test_a_restored_event_at_a_corrected_time_moves_its_row(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(OLD_TIME))
|
||||
(old,) = _rows(db)
|
||||
db.set_false_trigger(old["id"], True) # an operator's review
|
||||
|
||||
assert _store(db, _event(NEW_TIME, pvs=0.7)) == (0, 1) # nothing new inserted
|
||||
|
||||
(row,) = _rows(db)
|
||||
assert row["timestamp"] == NEW_TIME
|
||||
assert row["id"] == old["id"] # the same row ...
|
||||
assert row["false_trigger"] == 1 # ... its review kept
|
||||
assert row["peak_vector_sum"] == 0.7 # and refreshed as before
|
||||
|
||||
|
||||
def test_a_different_file_is_still_a_different_event(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(OLD_TIME))
|
||||
_store(db, _event(NEW_TIME, key="01118a2c"), filename="N844LQHC.000W")
|
||||
assert [(r["blastware_filename"], r["timestamp"]) for r in _rows(db)] == [
|
||||
("N844LQHB.ZT0W", OLD_TIME), ("N844LQHC.000W", NEW_TIME)]
|
||||
|
||||
|
||||
def test_an_event_without_a_stored_file_is_matched_on_time_alone_as_before(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
ev = _event(OLD_TIME)
|
||||
db.insert_events([ev], serial="BE12844", device_family="series3")
|
||||
db.insert_events([_event(NEW_TIME)], serial="BE12844", device_family="series3")
|
||||
assert [r["timestamp"] for r in _rows(db)] == [OLD_TIME, NEW_TIME]
|
||||
|
||||
|
||||
def test_a_corrected_time_held_by_another_file_moves_nothing_and_overwrites_nothing(tmp_path):
|
||||
# Another stored file already holds the corrected second. Moving onto it
|
||||
# would break the unique key, and the old upsert wrote this event's file and
|
||||
# peaks over THAT row. Now neither row changes.
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(OLD_TIME))
|
||||
_store(db, _event(NEW_TIME, key="01118a2c", pvs=0.9), filename="N844LQHC.000W")
|
||||
assert _store(db, _event(NEW_TIME)) == (0, 1)
|
||||
assert [(r["blastware_filename"], r["timestamp"], r["peak_vector_sum"]) for r in _rows(db)] == [
|
||||
("N844LQHB.ZT0W", OLD_TIME, 0.5), ("N844LQHC.000W", NEW_TIME, 0.9)]
|
||||
|
||||
|
||||
def test_a_duplicate_already_at_the_corrected_time_is_refreshed_as_before(tmp_path):
|
||||
# A box that already ran the new decoder holds the event twice; the row at
|
||||
# the corrected time is this file's own, so the usual refresh lands on it.
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(OLD_TIME))
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
c.execute("UPDATE events SET blastware_filename = 'x'")
|
||||
_store(db, _event(NEW_TIME))
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
c.execute("UPDATE events SET blastware_filename = 'N844LQHB.ZT0W'")
|
||||
assert _store(db, _event(NEW_TIME, pvs=0.8)) == (0, 1)
|
||||
assert [(r["timestamp"], r["peak_vector_sum"]) for r in _rows(db)] == [
|
||||
(OLD_TIME, 0.5), (NEW_TIME, 0.8)]
|
||||
|
||||
|
||||
def test_the_release_backfill_corrects_a_v031_row_in_place(tmp_path):
|
||||
"""The deploy step itself: a row as v0.31.0 stored it, then backfill_sidecars."""
|
||||
import scripts.backfill_sidecars as backfill
|
||||
|
||||
store, db = WaveformStore(tmp_path / "waveforms"), SeismoDb(tmp_path / "seismo_relay.db")
|
||||
ev, rec = store.save_imported_bw(WAVEFORM.read_bytes(), source_path=Path(WAVEFORM.name))
|
||||
db.insert_events([ev], serial=rec["serial"], device_family="series3",
|
||||
waveform_records={ev._waveform_key.hex(): rec})
|
||||
with sqlite3.connect(str(db.db_path)) as c: # as prod holds it today
|
||||
c.execute("UPDATE events SET timestamp = ?", (OLD_TIME,))
|
||||
(old,) = _rows(db)
|
||||
db.set_false_trigger(old["id"], True)
|
||||
|
||||
assert backfill.main(["--store-root", str(tmp_path / "waveforms"),
|
||||
"--db-path", str(db.db_path), "--force"]) == 0
|
||||
|
||||
(row,) = _rows(db)
|
||||
assert (row["id"], row["timestamp"], row["false_trigger"]) == (old["id"], NEW_TIME, 1)
|
||||
|
||||
|
||||
def test_a_generic_upload_name_is_not_one_event(tmp_path):
|
||||
# Unnamed uploads are all stored as "imported.bw": two different events can
|
||||
# share it. Only a Blastware name says which event a row is.
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(OLD_TIME), filename="imported.bw")
|
||||
_store(db, _event(NEW_TIME, key="01118a2c"), filename="imported.bw")
|
||||
assert [r["timestamp"] for r in _rows(db)] == [OLD_TIME, NEW_TIME]
|
||||
|
||||
|
||||
def test_of_two_copies_the_reviewed_one_with_a_time_is_the_one_moved(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
db.insert_events([_event(OLD_TIME)], serial="BE12844", device_family="series3",
|
||||
waveform_records={"0111646a": {"filename": "N844LQHB.ZT0W"}})
|
||||
with sqlite3.connect(str(db.db_path)) as c: # an older copy with no time
|
||||
c.execute("INSERT INTO events (id, serial, waveform_key, timestamp, blastware_filename) "
|
||||
"VALUES ('untimed', 'BE12844', '0111646a', NULL, 'N844LQHB.ZT0W')")
|
||||
c.execute("UPDATE events SET rowid = 0 WHERE id = 'untimed'")
|
||||
reviewed = next(r["id"] for r in _rows(db) if r["timestamp"] == OLD_TIME)
|
||||
db.set_false_trigger(reviewed, True)
|
||||
|
||||
_store(db, _event(NEW_TIME))
|
||||
|
||||
moved = {r["id"]: r["timestamp"] for r in _rows(db)}
|
||||
assert moved[reviewed] == NEW_TIME and moved["untimed"] is None
|
||||
|
||||
|
||||
# -- an estimated time (no validated event record) never overwrites, merges or
|
||||
# duplicates; the event is still stored when its second is free --------------
|
||||
|
||||
def _estimated(when: str, key: str = "0111646a", pvs: float = 0.5) -> Event:
|
||||
ev = _event(when, key, pvs)
|
||||
ev.timestamp_source = "estimate"
|
||||
return ev
|
||||
|
||||
|
||||
def test_an_estimate_on_a_free_second_is_stored(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
assert _store(db, _estimated(NEW_TIME)) == (1, 0)
|
||||
assert [r["timestamp"] for r in _rows(db)] == [NEW_TIME]
|
||||
|
||||
|
||||
def test_an_estimate_never_merges_into_another_events_row(tmp_path, caplog):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(NEW_TIME, key="01118a2c", pvs=0.9), filename="N844LQHC.000W")
|
||||
with caplog.at_level(logging.WARNING):
|
||||
assert _store(db, _estimated(NEW_TIME)) == (0, 1)
|
||||
assert [(r["blastware_filename"], r["peak_vector_sum"]) for r in _rows(db)] == [("N844LQHC.000W", 0.9)]
|
||||
assert any("N844LQHC.000W" in r.message and "estimated" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
def test_an_estimate_never_moves_or_duplicates_its_own_stored_event(tmp_path, caplog):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(NEW_TIME)) # stored at a validated time
|
||||
with caplog.at_level(logging.WARNING):
|
||||
assert _store(db, _estimated(OLD_TIME, pvs=0.7)) == (0, 1)
|
||||
assert [(r["timestamp"], r["peak_vector_sum"]) for r in _rows(db)] == [(NEW_TIME, 0.5)]
|
||||
assert any(NEW_TIME in r.message and "estimated" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
def test_an_estimate_on_its_own_rows_second_refreshes_it_as_before(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _event(NEW_TIME))
|
||||
assert _store(db, _estimated(NEW_TIME, pvs=0.7)) == (0, 1)
|
||||
assert [(r["timestamp"], r["peak_vector_sum"]) for r in _rows(db)] == [(NEW_TIME, 0.7)]
|
||||
|
||||
|
||||
def test_a_generic_upload_name_does_not_make_two_estimates_one_event(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
_store(db, _estimated(OLD_TIME), filename="imported.bw")
|
||||
assert _store(db, _estimated(NEW_TIME, key="01118a2c"), filename="imported.bw") == (1, 0)
|
||||
assert len(_rows(db)) == 2
|
||||
@@ -44,11 +44,12 @@ def test_histogram_timestamp_is_window_start_unchanged():
|
||||
assert _tuple(ev.timestamp) == (2026, 5, 10, 19, 4, 50), _tuple(ev.timestamp)
|
||||
|
||||
|
||||
def test_report_event_datetime_is_authoritative_over_binary():
|
||||
# The binary already yields the exact trigger, but a paired report stays
|
||||
# authoritative (e.g. if the unit clock had drifted) — applying it wins.
|
||||
def test_a_report_does_not_override_the_instruments_event_record():
|
||||
# Superseded 2026-10-26: the exact trigger is the instrument's embedded event
|
||||
# record, and a paired report (Blastware's copy of the same unit time) is a
|
||||
# cross-check -- they agree on 1,320/1,320. A disagreement is logged.
|
||||
ev = read_blastware_file(WAVEFORM)
|
||||
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 33, 29) # exact, from binary
|
||||
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 33, 29) # exact, from the record
|
||||
apply_report_to_event(ev, BwAsciiReport(
|
||||
event_datetime=datetime.datetime(2026, 8, 25, 10, 35, 0)))
|
||||
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 35, 0) # report wins
|
||||
assert _tuple(ev.timestamp) == (2026, 8, 25, 10, 33, 29) # the record stands
|
||||
@@ -509,8 +509,10 @@ def test_marker_is_single_byte_not_uint16():
|
||||
# followed by 2 words (first is 0x0000)
|
||||
# [-6:] 6-byte block trailer
|
||||
#
|
||||
# NOTE the endianness flip: the standard 32-byte block is big-endian, this
|
||||
# variant is little-endian.
|
||||
# ⚠ RETRACTED 2026-10-26 (#49): "the standard block is big-endian, this variant
|
||||
# little-endian" -- both are big-endian from byte 5 (histogram_codec.py). The
|
||||
# builder below writes little-endian from byte 6, which reads identically while
|
||||
# every value is under 256.
|
||||
#
|
||||
# Ground truth: BE9440/K440L3AQ.T70H (15 s intervals, 5,710 of them) decodes
|
||||
# with 17,130/17,130 geo peak counts, 22,840/22,840 frequencies and
|
||||
@@ -556,14 +558,19 @@ def test_multi_interval_block_decodes_all_four_channels():
|
||||
assert recs[1]["t_peak"] == 5 and recs[1]["m_halfp"] == 12
|
||||
|
||||
|
||||
def test_multi_interval_values_are_little_endian():
|
||||
"""The standard 32-byte block is big-endian; this variant is not.
|
||||
def test_multi_interval_values_are_not_little_endian_from_byte_6():
|
||||
"""RETRACTED 2026-10-26 (#49): the records are BIG-endian from byte 5.
|
||||
|
||||
A peak of 0x0100 must decode as 256, not 1.
|
||||
This test once pinned "a peak of 0x0100 written little-endian from byte 6
|
||||
decodes as 256". Those bytes (``00 | 00 01``) read big-endian from byte 5
|
||||
are a Tran peak of 0 and a half-period of 1 -- the right reading, per
|
||||
Blastware. The two models agree whenever the high bytes are zero, which
|
||||
is why this builder's other tests pass under both; see
|
||||
tests/test_histogram_multi_interval.py for the measured cases.
|
||||
"""
|
||||
ivs = [(0x0100, 1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1, 1, 1)]
|
||||
body = _mk_multi_block(ivs) + _mk_multi_block(ivs, ctr=257)
|
||||
assert walk_multi_interval_blocks(body)[0]["t_peak"] == 0x0100
|
||||
assert walk_multi_interval_blocks(body)[0]["t_peak"] != 0x0100
|
||||
|
||||
|
||||
def test_decode_histogram_body_falls_back_to_the_variant():
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
"""Multi-interval histogram blocks, mic on and mic off (issues #47, #49).
|
||||
|
||||
Measured 2026-10-26:
|
||||
|
||||
* A sub-minute histogram packs one minute of intervals per block:
|
||||
``[00][segment][ctr LE][0a]`` (5 bytes), then one record per interval of
|
||||
BIG-endian peak / half-period pairs per channel, then ``0000`` and one more
|
||||
word, then a 7-byte trailer. A record is 20 bytes with the mic and 16
|
||||
without (``4 * channels + 4``); the standard 32-byte block is the same thing
|
||||
with one record.
|
||||
* The last block is SHORT, not padded: it holds only the intervals recorded and
|
||||
ends in ``9c 06 00 42`` (K440L3AQ: 1,427 x 4 + 2 = 5,710, Blastware's count).
|
||||
* #47: BE9441's mic-off 2-second histogram (fixture) decoded to nothing. Read
|
||||
as above, its 22 intervals match Blastware's export: 66/66 peaks, 66/66
|
||||
frequencies.
|
||||
* #49: the old reader took the mic-on records as little-endian from byte 6 --
|
||||
the same bytes shifted by one, identical whenever the high bytes are zero.
|
||||
Across the 770 archive histograms with an export it disagreed with Blastware
|
||||
on exactly 1 of 10,715,315 intervals (K440KZP4.560H #4764).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from minimateplus.histogram_codec import ( # noqa: E402
|
||||
decode_histogram_body,
|
||||
decode_histogram_body_full,
|
||||
walk_multi_interval_blocks,
|
||||
)
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures" / "histogram-mic-off-10-26-26"
|
||||
TERMINAL = b"\x9c\x06\x00\x42"
|
||||
|
||||
|
||||
def _body(path: Path) -> bytes:
|
||||
raw = path.read_bytes()
|
||||
return raw[raw.find(b"STRT") + 21:]
|
||||
|
||||
|
||||
def _ascii_rows(path: Path) -> list:
|
||||
return [line.split() for line in path.read_text(errors="replace").splitlines()
|
||||
if re.match(r"^\d\d:\d\d:\d\d\s", line)]
|
||||
|
||||
|
||||
def _block(records, *, ctr=0x0100, seg=0, mic=True, last=False) -> bytes:
|
||||
"""One block: records are (T, Tf, V, Vf, L, Lf[, M, Mf]) tuples, BIG-endian."""
|
||||
b = bytearray([0x00, seg, ctr & 0xFF, ctr >> 8, 0x0A])
|
||||
for r in records:
|
||||
assert len(r) == (8 if mic else 6)
|
||||
for v in r:
|
||||
b += int(v).to_bytes(2, "big")
|
||||
b += b"\x00\x00" + b"\x00\x2d" # the zero word, then one more
|
||||
b += b"\xfc\xf3\x00" + (TERMINAL if last else b"\x5a\x0a\x00\x00")
|
||||
return bytes(b)
|
||||
|
||||
|
||||
# -- #47: mic off -------------------------------------------------------------
|
||||
|
||||
def test_the_mic_off_histogram_matches_blastwares_export():
|
||||
recs = decode_histogram_body_full(_body(FIX / "K441LTOK.QZ0"))
|
||||
rows = _ascii_rows(FIX / "K441LTOK_QZ0_ASCII.TXT")
|
||||
assert recs is not None and len(recs) == len(rows) == 22
|
||||
num = 2048 / 2 # "Sample Rate : 2048 sps"
|
||||
for r, row in zip(recs, rows):
|
||||
for c, ch in enumerate("tvl"):
|
||||
assert r[f"{ch}_peak"] * 0.005 == pytest.approx(float(row[1 + 2 * c]), abs=1e-9)
|
||||
f, want = num / r[f"{ch}_halfp"], row[2 + 2 * c]
|
||||
if want.startswith(">"):
|
||||
assert f > 200
|
||||
else:
|
||||
assert f == pytest.approx(float(want), rel=0.051)
|
||||
assert r["m_peak"] is None and r["m_halfp"] is None
|
||||
|
||||
|
||||
def test_a_mic_off_histogram_has_no_mic_channel():
|
||||
ch = decode_histogram_body(_body(FIX / "K441LTOK.QZ0"))
|
||||
assert ch is not None
|
||||
assert [len(ch[c]) for c in ("Tran", "Vert", "Long", "MicL")] == [22, 22, 22, 0]
|
||||
assert max(ch["Vert"]) * 0.005 == pytest.approx(1.080) # Blastware's Vert PPV
|
||||
|
||||
|
||||
def test_mic_off_blocks_walk_in_sixteen_byte_records():
|
||||
a = [(1, 2, 3, 4, 5, 6)] * 30
|
||||
body = _block(a, mic=False) + _block([(7, 8, 9, 10, 11, 12)] * 3, ctr=0x0101, mic=False,
|
||||
last=True) + b"setup block follows"
|
||||
recs = walk_multi_interval_blocks(body)
|
||||
assert len(recs) == 33
|
||||
assert (recs[30]["t_peak"], recs[30]["l_halfp"]) == (7, 12)
|
||||
|
||||
|
||||
# -- #49: mic on, big-endian from byte 5 ---------------------------------------
|
||||
|
||||
def test_mic_on_records_are_big_endian():
|
||||
# K440KZP4.560H #4764's shape: a mic peak >= 256 next to a Long half-period of 1.
|
||||
# Read little-endian from byte 6, that half-period came out 257 (~2 Hz, not >100).
|
||||
iv = [(10, 2, 11, 1, 10, 1, 0x0123, 4)] * 4
|
||||
body = _block(iv) + _block(iv, ctr=0x0101, last=True)
|
||||
r = walk_multi_interval_blocks(body)[0]
|
||||
assert (r["l_halfp"], r["m_peak"], r["m_halfp"]) == (1, 0x0123, 4)
|
||||
|
||||
|
||||
def test_a_loud_first_interval_does_not_end_the_walk():
|
||||
# byte 5 is the first record's Tran peak high byte, not a constant 0
|
||||
iv = [(0x0150, 9, 1, 1, 1, 1, 1, 1)] + [(1, 1, 1, 1, 1, 1, 1, 1)] * 3
|
||||
body = _block(iv) + _block(iv, ctr=0x0101) + _block(iv, ctr=0x0102, last=True)
|
||||
recs = walk_multi_interval_blocks(body)
|
||||
assert len(recs) == 12 and recs[8]["t_peak"] == 0x0150
|
||||
|
||||
|
||||
# -- the last block is short, bounded by its terminal tail ---------------------
|
||||
|
||||
def test_the_last_block_holds_only_its_intervals():
|
||||
iv = [(1, 1, 2, 2, 3, 3, 4, 4)]
|
||||
tail = [(5, 5, 6, 6, 7, 7, 8, 8)] * 2
|
||||
body = (_block(iv * 4) + _block(tail, ctr=0x0101, last=True)
|
||||
+ bytes([0x00, 0x00, 0x01, 0x01, 0x0A]) + b"\x07" * 60) # setup data after it
|
||||
recs = walk_multi_interval_blocks(body)
|
||||
assert len(recs) == 6
|
||||
assert recs[-1]["t_peak"] == 5
|
||||
|
||||
|
||||
def test_a_single_short_block_decodes():
|
||||
body = _block([(4, 9, 4, 9, 4, 9, 2, 2)] * 7, last=True) + b"\x00" * 40
|
||||
recs = walk_multi_interval_blocks(body)
|
||||
assert len(recs) == 7 and recs[0]["m_peak"] == 2
|
||||
|
||||
|
||||
def test_the_walk_crosses_a_segment_boundary():
|
||||
# 256 blocks per segment: block_ctr restarts at 0x0100 and segment_id steps.
|
||||
iv = [(1, 1, 2, 2, 3, 3, 4, 4)] * 4
|
||||
body = (_block(iv, ctr=0x01FE) + _block(iv, ctr=0x01FF)
|
||||
+ _block(iv, ctr=0x0100, seg=1) + _block(iv, ctr=0x0101, seg=1, last=True))
|
||||
recs = walk_multi_interval_blocks(body)
|
||||
assert len(recs) == 16 and recs[-1]["segment_id"] == 1
|
||||
@@ -0,0 +1,78 @@
|
||||
"""Thor (Micromate) .h5 samples are scaled with Thor's own LSB (issue #42).
|
||||
|
||||
A Thor geo count is 0.000310308 in/s (``micromate.idf_file._GEO_LSB_IPS``).
|
||||
The .h5 writer used to convert Thor counts with the MiniMate body-codec scale
|
||||
instead -- 10/32768 until 2026-08-25 (samples -1.65%), 10/32000 after
|
||||
(+0.71%). Stored peaks were right; every float sample disagreed with them
|
||||
by that constant, so waveform plots, FFT magnitudes and the offset detector
|
||||
all read off-scale for Series-4 events.
|
||||
|
||||
The invariant tested: for an idf-import .h5, max|float32 sample| equals the
|
||||
event's peak to float32 precision, and every sample is count x Thor LSB.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from micromate.idf_file import _GEO_LSB_IPS
|
||||
from sfm.waveform_store import WaveformStore
|
||||
|
||||
_FIXDIR = Path(__file__).parent / "fixtures"
|
||||
_IDFW = sorted((_FIXDIR / "thor-idf-sc").glob("*.IDFW")) # tracked
|
||||
_IDFH = sorted((_FIXDIR / "thor-idf").glob("*.IDFH")) # untracked on dev
|
||||
_GEO = ("Tran", "Vert", "Long")
|
||||
|
||||
|
||||
def _ingest(tmp_path: Path, src: Path) -> tuple[WaveformStore, Path]:
|
||||
store = WaveformStore(tmp_path / "waveforms")
|
||||
store.save_imported_idf(src.read_bytes(), src)
|
||||
serial = src.name.split("_")[0]
|
||||
return store, store.hdf5_path_for(serial, src.name)
|
||||
|
||||
|
||||
def _assert_thor_scaled(h5_path: Path) -> None:
|
||||
with h5py.File(h5_path, "r") as f:
|
||||
for ch in _GEO:
|
||||
counts = f["samples_int16"][ch][()]
|
||||
v = f["samples"][ch][()]
|
||||
np.testing.assert_allclose(v, counts * _GEO_LSB_IPS, rtol=1e-6)
|
||||
peak = float(f.attrs[f"peak_{ch.lower()}_ips"])
|
||||
assert float(np.max(np.abs(v))) == pytest.approx(peak, rel=1e-6), ch
|
||||
|
||||
|
||||
def test_fixtures_present():
|
||||
# Guards the parametrised tests below from silently collecting nothing.
|
||||
assert len(_IDFW) == 4
|
||||
|
||||
|
||||
@pytest.mark.parametrize("src", _IDFW, ids=lambda p: p.name)
|
||||
def test_idfw_ingest_samples_use_thor_lsb(tmp_path, src):
|
||||
_, h5_path = _ingest(tmp_path, src)
|
||||
_assert_thor_scaled(h5_path)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _IDFH, reason="tests/fixtures/thor-idf/*.IDFH not present")
|
||||
@pytest.mark.parametrize("src", _IDFH, ids=lambda p: p.name)
|
||||
def test_idfh_ingest_interval_peaks_use_thor_lsb(tmp_path, src):
|
||||
_, h5_path = _ingest(tmp_path, src)
|
||||
_assert_thor_scaled(h5_path)
|
||||
|
||||
|
||||
def test_backfill_thor_events_regenerates_with_thor_lsb(tmp_path):
|
||||
# The backfill replays save_imported_idf's bridge with its own
|
||||
# write_event_hdf5 call, so it has to be held to the same scale.
|
||||
from scripts.backfill_thor_events import main as backfill_main
|
||||
|
||||
src = _IDFW[0]
|
||||
store, h5_path = _ingest(tmp_path, src)
|
||||
h5_path.unlink()
|
||||
|
||||
rc = backfill_main(["--store-root", str(store.root), "--force"])
|
||||
|
||||
assert rc == 0
|
||||
assert h5_path.exists()
|
||||
_assert_thor_scaled(h5_path)
|
||||
@@ -0,0 +1,100 @@
|
||||
"""A paired Blastware report's event time must win, in every date format and through a backfill.
|
||||
|
||||
The event-time fix makes a report's Event Time + Event Date authoritative (the
|
||||
binary gives the trigger only to within a second). On prod's own data it never
|
||||
applied (measured on the 2026-09-30 store snapshot, 81 report-paired waveforms):
|
||||
|
||||
* every one of those reports writes the date as ISO ("2026-08-14") -- the
|
||||
parser read only "August 14, 2026", so event_datetime was always None;
|
||||
* the sidecar's bw_report block never stored the event time, so a backfill had
|
||||
nothing to re-apply -- and its overlay ignored the time anyway.
|
||||
|
||||
The binary's trigger matched Blastware's event time on 66 of the 81 and was one
|
||||
second late on 15.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from minimateplus.bw_ascii_report import parse_report # noqa: E402
|
||||
from minimateplus.event_file_io import (_bw_report_to_dict, # noqa: E402
|
||||
apply_bw_report_dict_to_event, read_blastware_file)
|
||||
from minimateplus.models import Event # noqa: E402
|
||||
from sfm.database import SeismoDb # noqa: E402
|
||||
from sfm.waveform_store import WaveformStore # noqa: E402
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures"
|
||||
WAVEFORM = FIX / "fft-oracle-2026-09-14" / "N844LQHB.ZT0W" # the binary's trigger: 10:33:29
|
||||
REPORT_TIME = datetime.datetime(2026, 8, 25, 10, 33, 28) # a report a second earlier
|
||||
|
||||
|
||||
def _report(date_line: str) -> str:
|
||||
return ('"Event Type : Full Waveform"\n"Serial Number : BE12844"\n'
|
||||
'"Event Time : 10:33:28"\n' + date_line + '\n"Record Time : 3.0 sec."\n')
|
||||
|
||||
|
||||
def _tuple(ts):
|
||||
return datetime.datetime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second)
|
||||
|
||||
|
||||
def test_an_iso_dated_report_gives_its_event_time():
|
||||
# The form all 81 of prod's saved waveform reports use.
|
||||
assert parse_report(_report('"Event Date : 2026-08-25"')).event_datetime == REPORT_TIME
|
||||
|
||||
|
||||
def test_a_long_form_dated_report_still_gives_its_event_time():
|
||||
assert parse_report(_report('"Event Date : August 25, 2026"')).event_datetime == REPORT_TIME
|
||||
|
||||
|
||||
def test_the_saved_report_block_carries_the_event_time_back_onto_the_event():
|
||||
# It fills in when the instrument's event record gave no time ...
|
||||
block = json.loads(json.dumps(_bw_report_to_dict(parse_report(_report('"Event Date : 2026-08-25"')))))
|
||||
ev = Event(index=0)
|
||||
apply_bw_report_dict_to_event(ev, block) # as a sidecar holds it
|
||||
assert (_tuple(ev.timestamp), ev.timestamp_source) == (REPORT_TIME, "report")
|
||||
# ... and is only a cross-check against a validated one
|
||||
ev = read_blastware_file(WAVEFORM)
|
||||
apply_bw_report_dict_to_event(ev, block)
|
||||
assert (_tuple(ev.timestamp), ev.timestamp_source) == \
|
||||
(datetime.datetime(2026, 8, 25, 10, 33, 29), "event_record")
|
||||
|
||||
|
||||
def test_a_saved_report_block_without_an_event_time_leaves_the_time_alone():
|
||||
ev = Event(index=0)
|
||||
apply_bw_report_dict_to_event(ev, {"available": True, "peaks": {}})
|
||||
assert ev.timestamp is None
|
||||
|
||||
|
||||
def test_the_backfill_with_reparse_puts_a_v031_row_on_the_instruments_time(tmp_path):
|
||||
"""prod's shape: a session-start row, a saved ISO-dated .TXT, a sidecar whose
|
||||
report block has no event time (written by the old parser). The report here
|
||||
disagrees by a second: the instrument's event record is kept."""
|
||||
import scripts.backfill_sidecars as backfill
|
||||
|
||||
store, db = WaveformStore(tmp_path / "waveforms"), SeismoDb(tmp_path / "seismo_relay.db")
|
||||
ev, rec = store.save_imported_bw(WAVEFORM.read_bytes(), source_path=Path(WAVEFORM.name),
|
||||
bw_report_text=_report('"Event Date : 2026-08-25"'))
|
||||
db.insert_events([ev], serial=rec["serial"], device_family="series3",
|
||||
waveform_records={ev._waveform_key.hex(): rec})
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
c.execute("UPDATE events SET timestamp = '2026-08-25T06:00:13'")
|
||||
car = next((tmp_path / "waveforms").rglob("*.sfm.json"))
|
||||
d = json.loads(car.read_text())
|
||||
assert d["source"].get("txt_filename") # the report is on disk
|
||||
d["bw_report"].pop("event_datetime", None) # as the old parser left it
|
||||
car.write_text(json.dumps(d))
|
||||
|
||||
assert backfill.main(["--store-root", str(tmp_path / "waveforms"),
|
||||
"--db-path", str(db.db_path), "--force", "--reparse-txt"]) == 0
|
||||
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
assert c.execute("SELECT timestamp FROM events").fetchall() == [("2026-08-25T10:33:29",)]
|
||||
assert json.loads(car.read_text())["event"]["timestamp"] == "2026-08-25T10:33:29"
|
||||
assert json.loads(car.read_text())["bw_report"]["event_datetime"] == REPORT_TIME.isoformat()
|
||||
Reference in new issue
Block a user