Release v0.34.0 — Series-4 parity, and most of Blastware's report from the event file alone #59

Merged
serversdown merged 245 commits from dev into main 2026-11-04 18:19:24 -05:00
5 changed files with 103 additions and 2 deletions
Showing only changes of commit 401d83dc2c - Show all commits

No files matched your search

+11
View File
@@ -137,6 +137,17 @@ def sfm_side(raw: bytes) -> SfmSide:
if pv is not None:
values.update(TranPPV=pv.tran, VertPPV=pv.vert, LongPPV=pv.long,
PeakVectorSum=pv.peak_vector_sum)
# A waveform's peak detail (None on a histogram, so not reported).
for tag, value in (("TranTimeofPeak", pv.tran_time_of_peak),
("VertTimeofPeak", pv.vert_time_of_peak),
("LongTimeofPeak", pv.long_time_of_peak),
("MicLTimeofPeak", pv.micl_time_of_peak),
("PeakVectorSumTimeSum", pv.pvs_time),
("TranPeakAcceleration", pv.tran_peak_accel_g),
("VertPeakAcceleration", pv.vert_peak_accel_g),
("LongPeakAcceleration", pv.long_peak_accel_g)):
if value is not None:
values[tag] = value
if counts["MicL"]:
values["MicLPSPL dB(L)"] = mic_count_to_db(max(abs(c) for c in counts["MicL"]))
values["MicLPSPL psi(L)"] = pv.micl if pv is not None else None
+42
View File
@@ -794,6 +794,45 @@ def _peaks_from_samples(samples: dict[str, list[int]],
)
# Blastware's g for peak acceleration, fitted: every printed acceleration in
# DL2 bounds it, and together they leave [386.2236, 386.2240] in/s^2 -- 19,475 /
# 19,479 values fit (the other 4: one odd file, O117I1NK.R70W, and one sample
# mismatch). That is 9.81 m/s^2 (386.2205) plus an offset not explained, as
# with the mic's fitted dB offset; 9.81 gives 19,423, the standard 9.80665 gives
# 17,806 (2026-11-04).
_ACCEL_IPS2_PER_G = 386.2238
def _waveform_peak_detail(pv: PeakValues, samples: dict[str, list[int]], geo_fs_ins: float,
sample_rate: int, pretrig: int) -> None:
"""A waveform's time of peak per channel, the vector sum's time and each
geophone's peak acceleration, on `pv`. Measured on 400 DL2 waveforms
(2026-11-04):
* time of peak = (first peak sample - pre-trigger samples) / sample rate,
1,197 / 1,197; the vector-sum time is the same on sqrt(T^2 + V^2 + L^2),
398 / 399
* peak acceleration = the largest |v[i+1] - v[i]| x sample rate / g,
with Blastware's fitted g -- the manuals: "subtracts two velocity
readings and divides the result by the elapsed time between them"."""
scale = geo_fs_ins / _GEO_INT16_FS
geo = {}
for ch in ("Tran", "Vert", "Long", "MicL"):
c = samples.get(ch) or []
if not c:
continue
i = max(range(len(c)), key=lambda k: abs(c[k]))
setattr(pv, f"{ch.lower()}_time_of_peak", (i - pretrig) / sample_rate)
if ch != "MicL":
geo[ch] = c
step = max((abs(c[k + 1] - c[k]) for k in range(len(c) - 1)), default=0)
setattr(pv, f"{ch.lower()}_peak_accel_g", step * scale * sample_rate / _ACCEL_IPS2_PER_G)
if len(geo) == 3:
n = min(len(c) for c in geo.values())
t, v, l = geo["Tran"], geo["Vert"], geo["Long"]
j = max(range(n), key=lambda k: t[k] * t[k] + v[k] * v[k] + l[k] * l[k])
pv.pvs_time = (j - pretrig) / sample_rate
# STRT[18], the record-type byte (#41): 0x46 on every one of DL2's 6,577
# waveform files and 0x0A on every one of its 63,535 histograms (measured
# 2026-10-29). Manual / Event / Combo never occur there, so their bytes are
@@ -1480,6 +1519,9 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
# The geophone full scale is the file's range; Normal when it wasn't read.
geo_fs = _GEO_FS_BY_RANGE.get(ev.geo_range, _GEO_NORMAL_FS_INS)
ev.peak_values = _peaks_from_samples(samples, geo_fs) if has_samples else None
if (is_waveform_body and ev.peak_values is not None and ev.sample_rate
and ev.pretrig_samples is not None):
_waveform_peak_detail(ev.peak_values, samples, geo_fs, ev.sample_rate, ev.pretrig_samples)
if ev.stop_time is None: # a histogram's record stop, else the footer's
ev.stop_time = ts2
if hist_records:
+9
View File
@@ -364,6 +364,15 @@ class PeakValues:
vert_zc_above_range: bool = False
long_zc_above_range: bool = False
mic_zc_above_range: bool = False
# A waveform's peak detail, from its samples (2026-11-04); None for a histogram.
tran_time_of_peak: Optional[float] = None # s from the trigger; negative = pre-trigger
vert_time_of_peak: Optional[float] = None
long_time_of_peak: Optional[float] = None
micl_time_of_peak: Optional[float] = None
pvs_time: Optional[float] = None # s from the trigger, of the vector-sum peak
tran_peak_accel_g: Optional[float] = None
vert_peak_accel_g: Optional[float] = None
long_peak_accel_g: Optional[float] = None
# ── Project / operator metadata ───────────────────────────────────────────────
+27
View File
@@ -495,3 +495,30 @@ def test_a_histogram_without_its_record_falls_back_to_the_footer_and_says_so():
assert ev.timestamp_source == "footer"
assert ev.timestamp.second == 25 # the footer's start, a second early
assert any("histogram event record" in p for p in ev.decode_problems)
# ── Group D, part 1: time of peak, vector-sum time, peak acceleration ───────
# Measured on 400 DL2 waveforms (2026-11-04):
# time of peak = (peak sample - pre-trigger samples) / sample rate: 1,197 / 1,197
# vector-sum time, the same on sqrt(T^2 + V^2 + L^2): 398 / 399
# peak acceleration = largest |v[i+1] - v[i]| x rate / g, with Blastware's g
# fitted to [386.2236, 386.2240] in/s^2 by every DL2 value: 19,475 / 19,479
@pytest.mark.parametrize("rel,times,pvs_time,accel", [
(f"{_SF}/T189HUD6.QE0W",
{"tran": 0.004, "vert": 0.001, "long": 0.024, "micl": 0.003}, 0.016, (0.027, 0.013, 0.027)),
("decode-checker-10-29-26/R352HIUI.F40W",
{"tran": 0.000, "vert": 0.000, "long": 0.000, "micl": 0.005}, 0.000, (1.617, 0.278, 0.318)),
])
def test_waveform_peak_detail_comes_from_the_samples(rel, times, pvs_time, accel):
pv = read_blastware_file(_FIX / rel).peak_values
for ch, t in times.items():
assert abs(getattr(pv, f"{ch}_time_of_peak") - t) <= 0.0005 + 1e-9, (ch, getattr(pv, f"{ch}_time_of_peak"))
assert abs(pv.pvs_time - pvs_time) <= 0.0005 + 1e-9
for got, want in zip((pv.tran_peak_accel_g, pv.vert_peak_accel_g, pv.long_peak_accel_g), accel):
assert abs(got - want) <= 0.0005 + 1e-9, (got, want)
def test_a_histogram_has_no_waveform_peak_detail():
pv = read_blastware_file(_FIX / "decode-checker-10-29-26/T004JTRF.ME0H").peak_values
assert (pv.tran_time_of_peak, pv.pvs_time, pv.tran_peak_accel_g) == (None, None, None)
+14 -2
View File
@@ -39,8 +39,9 @@ def test_event_type_comes_from_the_bytes():
def test_report_fields_stay_blank():
s = sfm_side((FIX / "T1905KDW.5F0W").read_bytes())
# (BatteryLevel and Calibration are read since 2026-11-03: test_the_setup_fields_match_blastware)
for tag in ("TranZCFreq", "TranPeakAcceleration", "TranTestResults"):
# (BatteryLevel and Calibration are read since 2026-11-03, peak acceleration
# since 2026-11-04: test_the_setup_fields_match_blastware, test_waveform_peak_detail_*)
for tag in ("TranZCFreq", "TranPeakDisplacement", "TranTestResults"):
assert s.values.get(tag) is None
@@ -343,3 +344,14 @@ def test_histogram_times_match_blastware(path):
for f in (("HistogramStartDate", "HistogramStartTime", "HistogramStopTime", "intervals.Time")
+ tuple(t for t in _PEAK_TIMES if t in ref.scalars)):
assert res[f].verdict == "match", (f, res[f])
@pytest.mark.parametrize("path", [FIX / "R352HIUI.F40W",
FIX.parent / "setup-fields-11-03-26" / "T189HUD6.QE0W"])
def test_waveform_peak_detail_matches_blastware(path):
ref = parse_xml_report_file(path.with_name(path.name.replace(".", "_", 1) + "_XML.XML"))
res = {r.field: r for r in compare(sfm_side(path.read_bytes()), ref, CARVEOUTS)}
for f in ("TranTimeofPeak", "VertTimeofPeak", "LongTimeofPeak", "MicLTimeofPeak",
"PeakVectorSumTimeSum", "TranPeakAcceleration", "VertPeakAcceleration",
"LongPeakAcceleration"):
assert res[f].verdict == "match", (f, res[f])