diff --git a/minimateplus/event_file_io.py b/minimateplus/event_file_io.py index f2a6dfa..0dbc16c 100644 --- a/minimateplus/event_file_io.py +++ b/minimateplus/event_file_io.py @@ -1098,22 +1098,34 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event: # Footer: locate the 0e 08 marker, validating the year is in a sane range. body_start = _bw._WAVEFORM_HEADER_SIZE + 21 - # The 0e 08 + plausible-year footer signature can occur inside the sample - # stream. Collect every candidate and prefer the first whose body yields a - # waveform record chain terminating on the 0x06 marker; fall back to the - # first candidate otherwise. Blast radius measured 2026-08-25: changes the - # chosen footer on exactly 1 of 1,388 series-3 waveform files - # (BE17353/S353L4O5.OX0W, false positive at 3800, real footer at 8576). - footer_candidates = [] - pos = body_start - while True: - pos = raw.find(b"\x0e\x08", pos) - if pos < 0 or pos + 26 > len(raw): - break - yr = (raw[pos + 4] << 8) | raw[pos + 5] - if 2015 <= yr <= 2050: - footer_candidates.append(pos) - pos += 1 + # The footer is the file's last 26 bytes whenever they are one -- 0e 08 and + # two valid times: 70,041 / 70,041 DL2 files (measured 2026-11-03). Taking + # the first "0e 08 + plausible year" instead found, on 14 of them, an + # earlier record ~1.1 KB before the end holding the stop time and zeros: a + # histogram then started at its own stop (a day late on BE9558's daily + # histograms) and a waveform lost its stop, so its trigger time too. + # + # Otherwise the search below stands. The signature can occur inside the + # sample stream, so it prefers the first candidate whose body yields a + # waveform record chain terminating on the 0x06 marker, then the first + # candidate (2026-08-25: BE17353/S353L4O5.OX0W, false positive at 3800, + # real footer at 8576). + end = len(raw) - 26 + if (end >= body_start and raw[end:end + 2] == b"\x0e\x08" + and _bw._decode_ts_be(raw[end + 2:end + 10]) is not None + and _bw._decode_ts_be(raw[end + 10:end + 18]) is not None): + footer_candidates = [end] + else: + footer_candidates = [] + pos = body_start + while True: + pos = raw.find(b"\x0e\x08", pos) + if pos < 0 or pos + 26 > len(raw): + break + yr = (raw[pos + 4] << 8) | raw[pos + 5] + if 2015 <= yr <= 2050: + footer_candidates.append(pos) + pos += 1 footer_pos = -1 for cand in footer_candidates: diff --git a/tests/fixtures/footer-11-03-26/K440I4LG.JK0W b/tests/fixtures/footer-11-03-26/K440I4LG.JK0W new file mode 100755 index 0000000..7537a4b Binary files /dev/null and b/tests/fixtures/footer-11-03-26/K440I4LG.JK0W differ diff --git a/tests/fixtures/footer-11-03-26/K558L9XP.FK0H b/tests/fixtures/footer-11-03-26/K558L9XP.FK0H new file mode 100755 index 0000000..e9d1aeb Binary files /dev/null and b/tests/fixtures/footer-11-03-26/K558L9XP.FK0H differ diff --git a/tests/fixtures/footer-11-03-26/T003LCYV.JD0H b/tests/fixtures/footer-11-03-26/T003LCYV.JD0H new file mode 100755 index 0000000..6d00185 Binary files /dev/null and b/tests/fixtures/footer-11-03-26/T003LCYV.JD0H differ diff --git a/tests/fixtures/footer-11-03-26/T003LCYV_JD0H_XML.XML b/tests/fixtures/footer-11-03-26/T003LCYV_JD0H_XML.XML new file mode 100755 index 0000000..4501047 --- /dev/null +++ b/tests/fixtures/footer-11-03-26/T003LCYV_JD0H_XML.XML @@ -0,0 +1,548 @@ + + +8.0 +Full Histogram +BE18003 +V 10.72-8.17 MiniMate Plus +T003LCYV.JD0H +18:04:25 +2025-12-05 +20:30:00 +2025-12-05 + +Tran +Vert +Long +MicL + +145.00 +1 minute +1024 sps +7.0 Volts +March 14, 2025 by Instantel +in/s and dB(L) +I-80-North Fork Bridges-I80 E. Abutment +Fay Company +Terra-Mechanics, Inc - Harrison +Area 2 - Loc 3 - I-80 - East Abutment + +10.000 +in/s + + +0.035 +in/s + + +0.090 +in/s + + +0.045 +in/s + + +11 +Hz + + +43 +Hz + + +37 +Hz + +20:10:25 +2025-12-05 +19:09:25 +2025-12-05 +20:09:25 +2025-12-05 + +0.099 +in/s + +19:09:25 +2025-12-05 +Linear Weighting + +124.7 +dB(L) + +18:19:25 +2025-12-05 + +2.4 +Hz + +7.7 Hz. +3.5 +Passed +7.6 Hz. +3.1 +Passed +7.4 Hz. +3.9 +Passed +20.1 Hz. +767 mv +Passed + + +2025-12-05 18:04:24 - 2025-12-05 20:30:00 "Event Recorded Timer Stop" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.020130.070230.030170.0750.003121.51.9 + + +0.0207.60.070470.025470.0740.003119.1>100 + + +0.020140.080340.030340.0840.002118.33.6 + + +0.0207.80.060470.025210.0640.003121.01.9 + + +0.0205.30.055470.020180.0590.004122.82.1 + + +0.030430.080430.035430.0880.003121.04.2 + + +0.025120.085430.035470.0920.003119.82.1 + + +0.0203.20.055470.025200.0610.003119.4>100 + + +0.0205.50.055730.025370.0620.002117.6>100 + + +0.025110.065430.035430.0720.004121.818 + + +0.025130.075470.030510.0810.002118.63.5 + + +0.025120.065470.030510.0720.003120.0>100 + + +0.025110.060470.025390.0650.003119.92.6 + + +0.020130.070470.030430.0770.003119.712 + + +0.025280.065430.030340.0730.005124.72.4 + + +0.025120.060470.025430.0660.003119.41.9 + + +0.0259.80.065470.025390.0700.003121.05.1 + + +0.025200.075430.030510.0790.003119.02.5 + + +0.025170.060470.020510.0630.004122.12.0 + + +0.0207.60.060470.020390.0640.003120.64.4 + + +0.0207.50.075370.030300.0820.002118.25.0 + + +0.025160.060260.025240.0640.003121.43.6 + + +0.025210.080370.030430.0840.003120.13.4 + + +0.025200.045240.020200.0480.002118.12.6 + + +0.025200.060430.025230.0650.003120.12.1 + + +0.0206.30.045220.020300.0510.002115.92.6 + + +0.030240.070390.030390.0730.004122.82.3 + + +0.0205.40.065470.025430.0700.003120.93.1 + + +0.025110.050470.025170.0570.003121.313 + + +0.020220.060470.030300.0660.004122.03.0 + + +0.025200.070470.035180.0770.003120.64.8 + + +0.0205.10.045220.020300.0510.002116.7>100 + + +0.025160.065470.025430.0700.003120.2>100 + + +0.020130.065470.025230.0700.003119.32.3 + + +0.0203.70.055470.020430.0590.003121.32.2 + + +0.020190.065470.030370.0680.004123.111 + + +0.025220.065470.025430.0700.002118.117 + + +0.025270.055470.025390.0620.002118.6>100 + + +0.0206.30.060430.025430.0650.002116.96.3 + + +0.025120.065430.030430.0720.004122.54.1 + + +0.0202.60.060430.025430.0660.004122.05.7 + + +0.0206.20.060470.025110.0640.004121.91.7 + + +0.025140.070430.030430.0760.004122.11.9 + + +0.025340.070430.030180.0760.003120.115 + + +0.0203.50.065470.025570.0700.004121.81.9 + + +0.025180.065430.025240.0690.002117.62.5 + + +0.025100.065430.030470.0700.004122.02.5 + + +0.0204.20.050220.020140.0560.003119.12.7 + + +0.0201.90.055470.020340.0590.004122.14.3 + + +0.020<1.00.065470.025470.0700.002117.22.1 + + +0.020170.065470.025430.0700.003121.1>100 + + +0.020<1.00.060470.025570.0650.003119.81.9 + + +0.025150.070430.025430.0740.003120.94.7 + + +0.0205.90.050220.020280.0510.002117.1>100 + + +0.025130.070470.030510.0770.002117.41.9 + + +0.025270.055850.030170.0580.003120.21.8 + + +0.020170.055430.020430.0590.004123.13.7 + + +0.020<1.00.065430.030430.0700.003120.4>100 + + +0.0206.60.065430.025430.0700.003119.6>100 + + +0.030170.085430.035570.0920.004122.82.2 + + +0.025240.055470.025390.0620.002117.8>100 + + +0.025120.050230.025260.0580.002116.451 + + +0.025140.055430.025260.0590.003119.02.2 + + +0.025110.070470.035300.0780.002117.21.9 + + +0.025150.090430.040470.0990.003120.24.7 + + +0.025170.065470.030430.0720.003119.63.6 + + +0.0203.60.060570.030280.0620.003119.8>100 + + +0.025320.065470.035270.0740.003120.24.0 + + +0.025160.065430.025240.0690.003119.6>100 + + +0.020160.040240.020220.0470.002117.4>100 + + +0.020190.065470.025430.0700.002116.72.0 + + +0.025160.070390.035510.0800.004121.92.0 + + +0.025120.080430.035270.0870.003119.72.7 + + +0.025200.070470.030510.0760.003119.46.7 + + +0.030200.065430.030510.0720.003121.64.7 + + +0.020<1.00.065390.025260.0690.003119.94.1 + + +0.0254.70.060470.030220.0650.002117.91.5 + + +0.025230.065470.030370.0700.002118.22.2 + + +0.020160.065470.025390.0710.003120.02.9 + + +0.0204.00.045340.020180.0500.003118.7>100 + + +0.0202.90.055230.025170.0620.002118.5>100 + + +0.025470.070470.030470.0750.004122.72.7 + + +0.0259.70.065430.035280.0740.003121.12.0 + + +0.025570.090470.040510.0970.003121.31.9 + + +0.025110.050220.020340.0560.002114.82.3 + + +0.025200.065470.030470.0720.003119.151 + + +0.025130.055430.025430.0610.004122.02.6 + + +0.015<1.00.015180.015120.0260.001108.0>100 + + +0.0202.90.050210.025220.0580.002117.2>100 + + +0.0208.30.060470.030240.0660.003121.51.9 + + +0.0205.80.040230.020230.0470.002114.4>100 + + +0.020120.055430.020390.0590.003121.02.8 + + +0.025130.055220.030200.0660.002117.63.1 + + +0.0207.30.050390.020320.0560.004122.22.5 + + +0.030230.070430.035470.0770.003120.3>100 + + +0.025180.065430.025510.0700.004121.82.0 + + +0.020320.065430.035170.0700.003120.114 + + +0.025170.060260.025230.0650.002116.1>100 + + +0.025200.060230.030240.0700.002116.9>100 + + +0.025130.075470.035510.0810.003121.56.0 + + +0.025180.050210.025220.0560.002117.2>100 + + +0.025220.055430.025180.0590.003119.63.0 + + +0.020<1.00.070470.030470.0770.002118.3>100 + + +0.0208.10.030390.020230.0370.002116.6>100 + + +0.025170.070470.025240.0740.002118.63.3 + + +0.0206.20.065430.030510.0720.003118.82.6 + + +0.020130.035210.020200.0410.001112.8>100 + + +0.025140.075470.030470.0810.004121.71.9 + + +0.025120.065430.030370.0720.004121.92.0 + + +0.025160.065430.025470.0700.003120.615 + + +0.025220.060430.030510.0650.003120.72.0 + + +0.025210.060470.025370.0660.003121.12.1 + + +0.0203.60.065470.030470.0720.004121.9>100 + + +0.030180.075470.030510.0790.003121.5>100 + + +0.025120.075430.035300.0810.003119.41.8 + + +0.025200.050220.025230.0570.002115.0>100 + + +0.025110.060470.025180.0660.003119.12.4 + + +0.025220.065470.030390.0730.003119.02.4 + + +0.025150.070470.030430.0760.003119.72.1 + + +0.025160.050340.025390.0550.002115.9>100 + + +0.0206.20.045340.020300.0490.002117.62.3 + + +0.025270.055240.025160.0610.002115.44.9 + + +0.0253.50.090470.040570.0970.004123.12.1 + + +0.025170.060430.025510.0660.003119.92.3 + + +0.025320.090430.045370.0980.002118.61.9 + + +0.035110.070470.030510.0770.003120.33.7 + + +0.025130.065430.025200.0700.002117.4>100 + + +0.0205.30.050240.025260.0590.002118.2>100 + + +0.025130.055470.025430.0610.002117.1>100 + + +0.020130.060470.025510.0640.002118.34.0 + + +0.020120.035240.020190.0430.002115.7>100 + + +0.020100.065430.030510.0720.002117.8>100 + + +0.025320.065430.025430.0690.004123.32.1 + + +0.020130.065470.030370.0700.003119.64.1 + + +0.0203.80.055230.025240.0620.003120.0>100 + + +0.0207.20.050390.025390.0570.002117.8>100 + + +0.0203.20.050230.025260.0590.002116.62.5 + + +0.0206.20.055230.025370.0620.002118.3>100 + + +0.025130.065470.030240.0720.003120.21.8 + + +0.025180.050320.025340.0570.002116.9>100 + + +0.025130.080470.035510.0870.002118.51.9 + + +0.0206.60.040230.020300.0460.002117.6>100 + + +0.020170.040210.020230.0470.002115.2>100 + + +0.025180.090730.040510.0930.003119.3>100 + + +0.025280.075430.030570.0810.004122.22.2 + + + + + + diff --git a/tests/test_bw_file_fields.py b/tests/test_bw_file_fields.py index eb9f843..f3a39d2 100644 --- a/tests/test_bw_file_fields.py +++ b/tests/test_bw_file_fields.py @@ -335,3 +335,33 @@ def test_a_loud_interval_does_not_hide_a_short_histogram(name, n): # which the old "first word is 0000" test rejected. ev = read_blastware_file(_FIX / _HD / name) assert len(ev.raw_samples["Tran"]) == n + + +# ── The footer is the file's last 26 bytes ────────────────────────────────── +# Every DL2 file ends in a valid footer (70,041 / 70,041: 0e 08 and two valid +# times). A few also hold an earlier "0e 08 + date" record, ~1.1 KB before +# the end: the stop time followed by zeros. The first-match footer search took +# it, so a histogram started at its own stop -- a day late on BE9558's daily +# histograms -- and a waveform lost its stop and its trigger time. +_FT = "footer-11-03-26" + + +def test_a_histogram_starts_at_its_footer_not_at_an_earlier_stop_record(): + ts = read_blastware_file(_FIX / _FT / "K558L9XP.FK0H").timestamp + # Blastware: 2025-10-07 19:14:08 (SFM read 2025-10-08 19:10:01) + assert (ts.year, ts.month, ts.day, ts.hour, ts.minute) == (2025, 10, 7, 19, 14) + + +def test_a_histogram_with_the_early_record_gets_its_time(): + ts = read_blastware_file(_FIX / _FT / "T003LCYV.JD0H").timestamp + # Blastware: 2025-12-05 18:04:25 (SFM had no time at all) + assert ts is not None + assert (ts.year, ts.month, ts.day, ts.hour, ts.minute) == (2025, 12, 5, 18, 4) + + +def test_a_waveform_with_the_early_record_is_timed_from_its_trigger(): + ev = read_blastware_file(_FIX / _FT / "K440I4LG.JK0W") + ts = ev.timestamp + # 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")