merge: a Blastware file's identity, battery and trigger settings (group A)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-03 17:22:34 -05:00
commit 3ee9923f81
14 files changed
+8401 -16

No files matched your search

+52 -4
View File
@@ -13,6 +13,7 @@ Pure: no I/O, and no import from `sfm/`.
"""
from __future__ import annotations
import math
import re
from dataclasses import dataclass
from typing import Callable, Optional, Sequence
@@ -30,6 +31,50 @@ GEO_IPS_PER_COUNT: float = _GEO_NORMAL_FS_INS / _GEO_INT16_FS
_CHANNELS = ("Tran", "Vert", "Long", "MicL")
_EVENT_TYPE = {"Waveform": "Full Waveform", "Histogram": "Full Histogram"}
# How Blastware prints the setup fields SFM reads (measured 2026-11-03).
_MONTHS = ("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December")
_TRIGGERED_BY = {0x0001: "Tran", 0x0002: "Vert", 0x0004: "Long", 0x0008: "MicL", 0x0200: "Manual"}
_STOP_MODES = {0: "Fixed"}
_MIC_TYPES = {2: "Linear Weighting"}
_GEO_TRIGGERS, _MIC_TRIGGER = 0x07, 0x08
# Blastware turns the mic trigger level from psi to dB with 6895 Pa per psi, not
# 6894.757: 4,272 / 4,272 DL2 levels against 4,271 (the odd one 0.01 psi,
# printed 130.8 dB(L), is 130.7498 at the exact constant).
_TRIGGER_PA_PER_PSI = 6895.0
def _setup_values(ev: Event) -> dict[str, object]:
out: dict[str, object] = {}
di = ev.device_info
if di is not None:
out["SerialNumber"] = di.serial
fw = di.firmware_version or ""
if di.dsp_version and fw.startswith("S33") and di.model:
# "V 10.72-8.17 MiniMate Plus" from "10.72", "S338.17" and the model --
# the only version in DL2, so the rule is proven for it alone.
out["Version"] = f"V {di.dsp_version}-{fw[3:]} {di.model}"
if di.calibration_date and di.calibrated_by:
c = di.calibration_date
out["Calibration"] = f"{_MONTHS[c.month - 1]} {c.day}, {c.year} by {di.calibrated_by}"
out["BatteryLevel"] = ev.battery_volts
out["Trigger"] = _TRIGGERED_BY.get(ev.triggered_by)
out["RecordStopMode"] = _STOP_MODES.get(ev.record_stop_mode)
out["Microphone"] = _MIC_TYPES.get(ev.mic_type)
# dB or psi is Blastware's preference, not the unit's (carve-out
# units-is-a-display-preference); SFM reports dB, the default.
out["Units"] = "in/s and dB(L)" if ev.mic_type is not None else "in/s"
# Blastware prints a trigger level only for a channel that is a trigger
# source, and none for a Manual trigger.
src, manual = ev.trigger_sources or 0, ev.triggered_by == 0x0200
if src & _GEO_TRIGGERS and not manual:
out["GeoTriggerLevel"] = ev.trigger_level_geo
if src & _MIC_TRIGGER and not manual and ev.trigger_level_mic_psi:
psi = ev.trigger_level_mic_psi
out["MicTriggerLevel psi(L)"] = psi
out["MicTriggerLevel dB(L)"] = 20 * math.log10(psi * _TRIGGER_PA_PER_PSI / 2e-5)
return out
@dataclass
class SfmSide:
@@ -72,6 +117,7 @@ def sfm_side(raw: bytes) -> SfmSide:
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
values.update(_setup_values(ev))
return SfmSide(
event=ev,
@@ -144,10 +190,12 @@ def _mic_converter(ref: XmlReport) -> Optional[Callable[[int], float]]:
def _compare_scalar(tag: str, printed: str, sfm: SfmSide, ref: XmlReport) -> FieldResult:
if not printed.strip() or printed.strip() == "N/A":
return FieldResult(tag, "no_reference", printed, None)
if tag == "MicLPSPL":
units = ref.event_units or ""
key = ("MicLPSPL dB(L)" if "dB(L)" in units else
"MicLPSPL psi(L)" if "psi(L)" in units else None)
if tag in ("MicLPSPL", "MicTriggerLevel"):
# A printed value that states its unit is compared in that unit:
# K441LA17.IN0W's Units say psi(L), its MicTriggerLevel "125.0 dB(L)".
units = printed if ("dB(L)" in printed or "psi(L)" in printed) else (ref.event_units or "")
key = (f"{tag} dB(L)" if "dB(L)" in units else
f"{tag} psi(L)" if "psi(L)" in units else None)
value = sfm.values.get(key) if key else None
else:
value = sfm.values.get(tag)
+26 -1
View File
@@ -106,4 +106,29 @@ INTERVAL_COUNT_IS_DURATION = Carveout(
applies=_interval_count_is_duration,
)
CARVEOUTS: tuple[Carveout, ...] = (SATURATION, INTERVAL_COUNT_IS_DURATION)
_MIC_UNITS = ("in/s and dB(L)", "in/s and psi(L)")
def _units_is_a_display_preference(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool:
"""Both sides say the event has a mic; they differ only in dB against psi."""
return (" ".join((res.bw or "").split()) in _MIC_UNITS
and sfm.values.get("Units") in _MIC_UNITS)
UNITS_IS_A_DISPLAY_PREFERENCE = Carveout(
id="units-is-a-display-preference",
fields=("Units",),
evidence=("dB(L) or psi(L) is Blastware's display preference on the PC when it wrote the "
"report, not the unit's: in report-write order (the _XML.XML mtimes) DL2's 70,034 "
"reports switch fleet-wide in 61 clean runs, every unit at once, and no byte or "
"bit of the event file separates the two (k-240 .. k+520, nor the 1.2 KB before "
"the footer). Instantel documents both settings: the unit's own Microphone "
"Units (MiniMate Plus manual 716U0101 Rev 15 §3.9.7: psi(L), dB(L) or Pa(L), "
"keypad Right Arrow + Setups) and Blastware's report preference (Blastware "
"manual 714U0301 Rev 22 §4, Preferences > Units and Channel: Show Mic in dB / "
"in Linear Units). 2026-11-03."),
applies=_units_is_a_display_preference,
)
CARVEOUTS: tuple[Carveout, ...] = (SATURATION, INTERVAL_COUNT_IS_DURATION,
UNITS_IS_A_DISPLAY_PREFERENCE)
+96 -9
View File
@@ -25,7 +25,7 @@ import struct
from pathlib import Path
from typing import Optional, Union
from .models import Event, PeakValues, ProjectInfo, Timestamp
from .models import DeviceInfo, Event, PeakValues, ProjectInfo, Timestamp
from . import blastware_file as _bw # avoid circular reference at module load
from .bw_ascii_report import BwAsciiReport
from . import waveform_codec as _wc
@@ -895,17 +895,22 @@ def _ts8(b: bytes) -> Optional[datetime.datetime]:
def _embedded_event_record(
raw: bytes, end: int, start: Optional[datetime.datetime],
stop: Optional[datetime.datetime], record_time: Optional[float],
) -> tuple[Optional[datetime.datetime], str]:
"""The trigger time from the instrument's embedded event record, or (None, why).
) -> tuple[Optional[datetime.datetime], str, Optional[int]]:
"""The trigger time and trigger source from the instrument's embedded event
record, or (None, why, None).
Every `fe 80` before `end` (the footer) is a candidate. One counts only if
its lead bytes match, both its times are well formed, the footer's session
start <= trigger <= its stop, its stop is the footer's stop or a second
before it, and its length agrees with the record time. Exactly one may
pass: none, or more than one, is reported rather than guessed between.
The two bytes between the lead and `fe 80` are the trigger source, a uint16
BE bitmask: 0x01 Tran, 0x02 Vert, 0x04 Long, 0x08 MicL, 0x200 Manual --
Blastware's Trigger on 6,493 / 6,493 DL2 waveforms (2026-11-03).
"""
if start is None or stop is None:
return None, "the footer has no start and stop to check one against"
return None, "the footer has no start and stop to check one against", None
found, rejected = [], 0
i = raw.find(_EVENT_RECORD_MARKER, 6)
while 0 <= i and i + 18 <= end:
@@ -921,15 +926,15 @@ def _embedded_event_record(
<= _EVENT_RECORD_SLACK_S[1])
)
if valid:
found.append(trig)
found.append((trig, int.from_bytes(raw[i - 2:i], "big")))
else:
rejected += 1
i = raw.find(_EVENT_RECORD_MARKER, i + 1)
if len(found) == 1:
return found[0], ""
return found[0][0], "", found[0][1]
if found:
return None, f"{len(found)} candidates validate"
return None, (f"{rejected} candidate(s), none valid" if rejected else "no candidate")
return None, f"{len(found)} candidates validate", None
return None, (f"{rejected} candidate(s), none valid" if rejected else "no candidate"), None
def _parse_record_time_seconds(raw: bytes) -> Optional[float]:
@@ -1047,6 +1052,83 @@ def _setup_geo_range(raw: bytes) -> tuple[Optional[int], Optional[str]]:
return None, f"geophone range not read: channel range bytes {found}"
# The identity block before the setup: what the live read gets from SUB FE
# (DeviceInfo). Offsets back from k, the setup name; matched against every DL2
# report 2026-11-03 -- serial, version and calibration 69,983 / 69,983, the
# battery 69,729 plus 254 that Blastware rounds half up (6.25 -> "6.3 Volts").
_SERIAL_BEFORE_NAME = 202 # ASCII, NUL-terminated
_BATTERY_BEFORE_NAME = 190 # uint16 BE, hundredths of a volt
_FIRMWARE_MINOR_BEFORE_NAME = 193 # 0x11 = 17 for S338.17, as SUB EA
_FIRMWARE_BEFORE_NAME = 147 # "S338.17"
_DSP_BEFORE_NAME = 138 # "10.72"
_CALIBRATION_BEFORE_NAME = 132 # dd mm yyyy (BE)
_CALIBRATED_BY_BEFORE_NAME = 128 # "Instantel"
_MANUFACTURER_BEFORE_NAME = 94 # "Instantel"
_MODEL_BEFORE_NAME = 72 # "MiniMate Plus" / "BlastMate III"
def _cstr(raw: bytes, i: int, limit: int = 40) -> Optional[str]:
if i < 0:
return None
j = raw.find(b"\x00", i, i + limit)
s = raw[i:j if j >= 0 else i + limit].decode("ascii", errors="replace").strip()
return s or None
def _setup_identity(raw: bytes, k: int) -> tuple[Optional[DeviceInfo], Optional[float]]:
"""(the unit's identity, the battery in volts) from the block before the
setup name at k."""
if k < _SERIAL_BEFORE_NAME:
return None, None
serial = _cstr(raw, k - _SERIAL_BEFORE_NAME, 16)
if not serial:
return None, None
c = k - _CALIBRATION_BEFORE_NAME
try:
cal = datetime.date(int.from_bytes(raw[c + 2:c + 4], "big"), raw[c + 1], raw[c])
except ValueError:
cal = None
info = DeviceInfo(
serial=serial,
firmware_minor=raw[k - _FIRMWARE_MINOR_BEFORE_NAME],
firmware_version=_cstr(raw, k - _FIRMWARE_BEFORE_NAME, 9),
dsp_version=_cstr(raw, k - _DSP_BEFORE_NAME, 6),
manufacturer=_cstr(raw, k - _MANUFACTURER_BEFORE_NAME),
model=_cstr(raw, k - _MODEL_BEFORE_NAME),
calibration_date=cal,
calibrated_by=_cstr(raw, k - _CALIBRATED_BY_BEFORE_NAME, 32),
)
b = k - _BATTERY_BEFORE_NAME
return info, int.from_bytes(raw[b:b + 2], "big") / 100
# Trigger settings, in Series IV's 0x1A layout again: the trigger-source bitmask
# at k - 19 ([29]: 0x07 geophones, 0x08 mic), the stop mode at k - 31 ([17],
# 0 = Fixed), and each channel block's trigger level, a float32 at label + 30 --
# in/s for a geophone, psi for the mic. The mic block's type code at label + 4
# is Series IV's (2 = linear). Against every DL2 waveform (2026-11-03): the geo
# level 6,447 / 6,447, the mic level 4,403 / 4,403, and Blastware prints a level
# exactly when its channel is a trigger source and the event was not Manual.
_TRIGGER_SOURCES_BEFORE_NAME = 19
_STOP_MODE_BEFORE_NAME = 31
_TRIGGER_LEVEL_AFTER_LABEL = 30
_MIC_TYPE_AFTER_LABEL = 4
def _setup_trigger(raw: bytes, k: int) -> dict:
out = {"trigger_sources": raw[k - _TRIGGER_SOURCES_BEFORE_NAME],
"record_stop_mode": raw[k - _STOP_MODE_BEFORE_NAME]}
t = raw.find(b"\x00\x00\x01Tran", k, k + _CHANNEL_BLOCK_SPAN)
if t >= 0:
p = t + 3 + _TRIGGER_LEVEL_AFTER_LABEL
out["trigger_level_geo"] = struct.unpack_from(">f", raw, p)[0]
m = raw.find(b"MicL", k, k + _CHANNEL_BLOCK_SPAN)
if m >= 0:
out["trigger_level_mic_psi"] = struct.unpack_from(">f", raw, m + _TRIGGER_LEVEL_AFTER_LABEL)[0]
out["mic_type"] = int.from_bytes(raw[m + _MIC_TYPE_AFTER_LABEL:m + _MIC_TYPE_AFTER_LABEL + 4], "big")
return out
def read_blastware_file(path: Union[str, Path], *, name: Optional[str] = None) -> Event:
"""Parse a Blastware event file into an Event: `decode_blastware_bytes` on its
bytes, `name` defaulting to the file's own (see there -- never a time source)."""
@@ -1236,6 +1318,11 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
ev.geo_range, range_problem = _setup_geo_range(raw)
if range_problem:
ev.decode_problems.append(range_problem + "; peaks assume the Normal range")
k = _setup_name_at(raw)
if k is not None:
ev.device_info, ev.battery_volts = _setup_identity(raw, k)
for attr, value in _setup_trigger(raw, k).items():
setattr(ev, attr, value)
if is_waveform_body:
ev.rectime_seconds = _setup_record_time(raw)
ev.total_samples = len(samples["Tran"]) or None
@@ -1276,7 +1363,7 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
_rt = _parse_record_time_seconds(raw)
_start = (datetime.datetime(ts1.year, ts1.month, ts1.day, ts1.hour, ts1.minute, ts1.second)
if ts1 is not None else None)
_trig, _why = _embedded_event_record(raw, footer_pos, _start, _stop, _rt)
_trig, _why, ev.triggered_by = _embedded_event_record(raw, footer_pos, _start, _stop, _rt)
if _trig is not None:
ev.timestamp_source = "event_record"
else:
+13
View File
@@ -300,6 +300,10 @@ class DeviceInfo:
# ── From SUB 08 (EVENT_INDEX_RESPONSE) ────────────────────────────────────
event_count: Optional[int] = None # stored event count from F7 response 🔶
# ── From a Blastware event file's identity block (2026-11-03) ─────────────
calibration_date: Optional[datetime.date] = None # e.g. 2019-02-20 ✅
calibrated_by: Optional[str] = None # e.g. "Instantel" ✅
def __str__(self) -> str:
fw = self.firmware_version or f"?.{self.firmware_minor}"
mdl = self.model or "MiniMate Plus"
@@ -548,6 +552,15 @@ class Event:
# Geophone range from the recording setup, as ComplianceConfig.geo_range:
# 0 Normal (10 in/s full scale), 1 Sensitive (1.25 in/s). None: not read.
geo_range: Optional[int] = None
# From a Blastware event file (2026-11-03); None when not read.
device_info: Optional["DeviceInfo"] = None # the unit, as SUB FE reports it
battery_volts: Optional[float] = None # at the event
triggered_by: Optional[int] = None # 0x01 Tran 0x02 Vert 0x04 Long 0x08 MicL 0x200 Manual
trigger_sources: Optional[int] = None # setup bitmask: 0x07 geophones, 0x08 mic
trigger_level_geo: Optional[float] = None # in/s, as ComplianceConfig.trigger_level_geo
trigger_level_mic_psi: Optional[float] = None
record_stop_mode: Optional[int] = None # 0 = Fixed
mic_type: Optional[int] = None # 2 = Linear Weighting (as Series IV)
# Sensor self-check traces keyed by channel label — the short diagnostic
# waveforms the unit records when it pulses each sensor before monitoring
+21
View File
@@ -34,6 +34,10 @@ Layout written to `<filename>.h5`:
sensor_location str
job_number int (only when read; kept while not shown)
job_number_enabled bool (Blastware prints the job number)
battery_volts, triggered_by, trigger_sources, trigger_level_geo_ips,
trigger_level_mic_psi, firmware_version, dsp_version, model,
calibration_date (ISO), calibrated_by
(each only when read from the event file)
peak_tran_ips float (from 0C; authoritative)
peak_vert_ips float
peak_long_ips float
@@ -262,6 +266,23 @@ def write_event_hdf5(
if pi is not None and getattr(pi, "job_number", None) is not None:
attrs["job_number"] = int(pi.job_number)
attrs["job_number_enabled"] = bool(pi.job_number_enabled)
# Read from a Blastware file's identity and setup blocks; absent when not read.
for attr, value in (
("battery_volts", getattr(event, "battery_volts", None)),
("triggered_by", getattr(event, "triggered_by", None)),
("trigger_sources", getattr(event, "trigger_sources", None)),
("trigger_level_geo_ips", getattr(event, "trigger_level_geo", None)),
("trigger_level_mic_psi", getattr(event, "trigger_level_mic_psi", None)),
):
if value is not None:
attrs[attr] = value
di = getattr(event, "device_info", None)
if di is not None:
for attr in ("firmware_version", "dsp_version", "model", "calibrated_by"):
if getattr(di, attr, None):
attrs[attr] = getattr(di, attr)
if getattr(di, "calibration_date", None) is not None:
attrs["calibration_date"] = di.calibration_date.isoformat()
attrs["peak_tran_ips"] = float(pv.tran if pv and pv.tran is not None else 0.0)
attrs["peak_vert_ips"] = float(pv.vert if pv and pv.vert is not None else 0.0)
attrs["peak_long_ips"] = float(pv.long if pv and pv.long is not None else 0.0)
Binary file not shown.
+116
View File
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<Event>
<FileVersion>8.0</FileVersion>
<EventType>Full Histogram</EventType>
<SerialNumber>BE9558</SerialNumber>
<Version>V 10.72-8.17 MiniMate Plus</Version>
<FileName>K558L4KY.440H</FileName>
<HistogramStartTime>17:04:52</HistogramStartTime>
<HistogramStartDate>2025-06-25</HistogramStartDate>
<HistogramStopTime>17:05:39</HistogramStopTime>
<HistogramStopDate>2025-06-25</HistogramStopDate>
<Channels>
<Channel>Tran</Channel>
<Channel>Vert</Channel>
<Channel>Long</Channel>
<Channel>MicL</Channel>
</Channels>
<NumberofIntervals>1.00</NumberofIntervals>
<IntervalSize>5 minutes</IntervalSize>
<SampleRate>1024 sps</SampleRate>
<BatteryLevel>6.3 Volts</BatteryLevel>
<Calibration>June 13, 2025 by Instantel</Calibration>
<Units>in/s and dB(L)</Units>
<Project>Fay - Locks &amp; Dam No3 -Loc 5 Synthomer</Project>
<Client>Fay Company</Client>
<UserName>Terra-Mechanics Inc - Harrison</UserName>
<Seis.Loc>Location #5 Sythomer Plant</Seis.Loc>
<GeoRange>
<Value>10.000</Value>
<Units>in/s</Units>
</GeoRange>
<TranPPV>
<Value>2.315</Value>
<Units>in/s</Units>
</TranPPV>
<VertPPV>
<Value>2.715</Value>
<Units>in/s</Units>
</VertPPV>
<LongPPV>
<Value>5.115</Value>
<Units>in/s</Units>
</LongPPV>
<TranZCFreq>
<Value>10</Value>
<Units>Hz</Units>
</TranZCFreq>
<VertZCFreq>
<Value>85</Value>
<Units>Hz</Units>
</VertZCFreq>
<LongZCFreq>
<Value>19</Value>
<Units>Hz</Units>
</LongZCFreq>
<TranPeakTime>17:05:39</TranPeakTime>
<TranPeakDate>2025-06-25</TranPeakDate>
<VertPeakTime>17:05:39</VertPeakTime>
<VertPeakDate>2025-06-25</VertPeakDate>
<LongPeakTime>17:05:39</LongPeakTime>
<LongPeakDate>2025-06-25</LongPeakDate>
<PeakVectorSum>
<Value>5.559</Value>
<Units>in/s</Units>
</PeakVectorSum>
<PeakVectorSumTime>17:05:39</PeakVectorSumTime>
<PeakVectorSumDate>2025-06-25</PeakVectorSumDate>
<Microphone>Linear Weighting</Microphone>
<MicLPSPL>
<Value>111.8</Value>
<Units>dB(L)</Units>
</MicLPSPL>
<MicLTime>17:05:39</MicLTime>
<MicLDate>2025-06-25</MicLDate>
<MicLZCFreq>
<Value>43</Value>
<Units>Hz</Units>
</MicLZCFreq>
<TranTestFreq>7.7 Hz.</TranTestFreq>
<TranTestRatio>3.9</TranTestRatio>
<TranTestResults>Passed</TranTestResults>
<VertTestFreq>7.5 Hz.</VertTestFreq>
<VertTestRatio>3.8</VertTestRatio>
<VertTestResults>Passed</VertTestResults>
<LongTestFreq>7.5 Hz.</LongTestFreq>
<LongTestRatio>3.7</LongTestRatio>
<LongTestResults>Passed</LongTestResults>
<MicLTestFreq>0.0 Hz.</MicLTestFreq>
<MicLTestAmplitude>0 mv</MicLTestAmplitude>
<MicLTestResults>Check</MicLTestResults>
<UsbSummaryChannels>
</UsbSummaryChannels>
<MonitorLog>2025-06-25 17:04:51 - 2025-06-25 17:05:39 &quot;Event Recorded Modem Exit&quot;</MonitorLog>
<HistogramData>
<HistogramDataColumnTitle>
<ColumnTitle> Tran Peak in/s </ColumnTitle>
<ColumnTitle> Tran Freq Hz </ColumnTitle>
<ColumnTitle> Vert Peak in/s </ColumnTitle>
<ColumnTitle> Vert Freq Hz </ColumnTitle>
<ColumnTitle> Long Peak in/s </ColumnTitle>
<ColumnTitle> Long Freq Hz </ColumnTitle>
<ColumnTitle> Geo PVS in/s </ColumnTitle>
<ColumnTitle> MicL Peak psi(L) </ColumnTitle>
<ColumnTitle> MicL Peak dB(L) </ColumnTitle>
<ColumnTitle> MicL Freq Hz </ColumnTitle>
</HistogramDataColumnTitle>
<HistogramDataIntervals>
<Time>2025-06-25 17:05:39</Time>
<Row>
<Cell>2.315</Cell><Cell>10</Cell><Cell>2.715</Cell><Cell>85</Cell><Cell>5.115</Cell><Cell>19</Cell><Cell>5.559</Cell><Cell>0.001</Cell><Cell>111.8</Cell><Cell>43</Cell></Row>
</HistogramDataIntervals>
</HistogramData>
<HistogramDataUsbChannels>
</HistogramDataUsbChannels>
</Event>
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
Binary file not shown.
File diff suppressed because it is too large. Load diff
+64
View File
@@ -365,3 +365,67 @@ def test_a_waveform_with_the_early_record_is_timed_from_its_trigger():
# Blastware: 2019-09-26 11:14:08, record time 4 s (SFM read the stop, 11:14:12)
assert (ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second) == (2019, 9, 26, 11, 14, 8)
assert ev.timestamp_source in ("event_record", "estimate")
# ── Group A: identity, battery, trigger ─────────────────────────────────────
# The identity block before the setup name is what the live read gets from
# SUB FE (DeviceInfo): serial k-202, firmware k-147, DSP version k-138,
# calibration date k-132 and "by" k-128, manufacturer k-94, model k-72; the
# battery is a uint16 of hundredths of a volt at k-190. Measured against every
# DL2 report 2026-11-03 (serial, version, calibration 69,983 / 69,983).
import datetime as _dt # noqa: E402
_SF = "setup-fields-11-03-26"
def test_the_identity_block_is_read():
# Blastware: BE18189, "V 10.72-8.17 MiniMate Plus",
# "February 20, 2019 by Instantel", "6.8 Volts"
ev = read_blastware_file(_FIX / _SF / "T189HUD6.QE0W")
di = ev.device_info
assert (di.serial, di.firmware_version, di.dsp_version, di.manufacturer, di.model) == (
"BE18189", "S338.17", "10.72", "Instantel", "MiniMate Plus")
assert di.firmware_minor == 17
assert (di.calibration_date, di.calibrated_by) == (_dt.date(2019, 2, 20), "Instantel")
assert abs(ev.battery_volts - 6.8) <= 0.05 + 1e-9
def test_the_battery_is_kept_exact():
# Blastware prints "6.3 Volts" for a stored 6.25: it rounds half up.
assert read_blastware_file(_FIX / _SF / "K558L4KY.440H").battery_volts == 6.25
# (file, Blastware's Trigger as the event record's bitmask, geo level in/s,
# mic level psi or None, mic a trigger source)
@pytest.mark.parametrize("rel,by,geo,mic_psi,mic_src", [
(f"{_SF}/T189HUD6.QE0W", 0x0008, 0.050, 0.0072, True), # MicL, 128.0 dB(L)
(f"{_SF}/T438L713.RY0W", 0x0002, 0.500, 0.0100, True), # Vert, 130.8 dB(L)
(f"{_SF}/M529I6LG.3Y0W", 0x0004, 0.050, 0.005, True), # Long, 0.005 psi(L)
("bw-import-fields-10-29-26/R352HIUI.F40W", 0x0001, 0.400, None, False), # Tran
("decode-checker-10-29-26/T1905KDW.5F0W", 0x0200, None, None, None), # Manual
])
def test_the_trigger_comes_from_the_file(rel, by, geo, mic_psi, mic_src):
ev = read_blastware_file(_FIX / rel)
assert ev.triggered_by == by
if geo is not None:
assert abs(ev.trigger_level_geo - geo) <= 0.0005 + 1e-9
if mic_psi is not None:
assert abs(ev.trigger_level_mic_psi - mic_psi) <= 0.0005 + 1e-9 # psi to 3 places, as printed
if mic_src is not None:
assert bool(ev.trigger_sources & 0x08) == mic_src
assert (ev.record_stop_mode, ev.mic_type) == (0, 2) # Fixed, Linear Weighting
def test_the_h5_carries_the_setup_fields(tmp_path):
import h5py
from sfm import event_hdf5
ev = read_blastware_file(_FIX / _SF / "T189HUD6.QE0W")
event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE18189")
with h5py.File(tmp_path / "e.h5", "r") as f:
a = f.attrs
assert abs(float(a["battery_volts"]) - 6.8) <= 0.05 + 1e-9
assert (int(a["triggered_by"]), int(a["trigger_sources"])) == (0x0008, ev.trigger_sources)
assert abs(float(a["trigger_level_geo_ips"]) - 0.050) <= 0.0005 + 1e-9
assert abs(float(a["trigger_level_mic_psi"]) - ev.trigger_level_mic_psi) < 1e-9
assert (str(a["firmware_version"]), str(a["dsp_version"]), str(a["calibration_date"])) == (
"S338.17", "10.72", "2019-02-20")
+60 -2
View File
@@ -39,7 +39,8 @@ def test_event_type_comes_from_the_bytes():
def test_report_fields_stay_blank():
s = sfm_side((FIX / "T1905KDW.5F0W").read_bytes())
for tag in ("TranZCFreq", "TranPeakAcceleration", "BatteryLevel", "Calibration", "TranTestResults"):
# (BatteryLevel and Calibration are read since 2026-11-03: test_the_setup_fields_match_blastware)
for tag in ("TranZCFreq", "TranPeakAcceleration", "TranTestResults"):
assert s.values.get(tag) is None
@@ -66,7 +67,7 @@ def test_full_waveform_row_verdicts():
"notes", "samples.Tran", "samples.Vert", "samples.Long"):
assert res[f].verdict == "match", (f, res[f])
assert res["TranZCFreq"].verdict in ("sfm_blank", "no_reference")
assert res["BatteryLevel"].verdict == "sfm_blank"
assert res["BatteryLevel"].verdict == "match" # 6.72 V, printed "6.7 Volts"
assert "FileName" not in res
@@ -221,3 +222,60 @@ def test_blastware_counting_the_monitoring_time_is_accepted():
def test_the_count_carveout_needs_blastwares_own_table_to_agree_with_sfm():
assert _count_case(30, drop_rows=1).verdict == "mismatch"
_GROUP_A = ("SerialNumber", "Version", "Calibration", "BatteryLevel", "Trigger",
"GeoTriggerLevel", "MicTriggerLevel", "RecordStopMode", "Microphone", "Units")
@pytest.mark.parametrize("stem,printed", [
("T189HUD6.QE0W", set(_GROUP_A)),
("T438L713.RY0W", set(_GROUP_A)), # 130.8 dB(L): 0.01 psi at 6895 Pa/psi
("K558L4KY.440H", {"SerialNumber", "Version", "Calibration", "BatteryLevel",
"Microphone", "Units"}), # histogram; battery 6.25 -> "6.3"
])
def test_the_setup_fields_match_blastware(stem, printed):
sf = FIX.parent / "setup-fields-11-03-26"
res = {r.field: r for r in compare(sfm_side((sf / stem).read_bytes()),
parse_xml_report_file(sf / (stem.replace(".", "_", 1) + "_XML.XML")),
CARVEOUTS)}
assert printed <= set(res)
for f in printed:
assert res[f].verdict == "match", (f, res[f])
def test_a_manual_trigger_matches():
res = _results("T1905KDW.5F0W", CARVEOUTS)
assert res["Trigger"].verdict == "match"
def _units_case(sfm_units):
sf = FIX.parent / "setup-fields-11-03-26"
ref = parse_xml_report_file(sf / "T189HUD6_QE0W_XML.XML")
ref.scalars["Units"] = "in/s and psi(L)"
side = sfm_side((sf / "T189HUD6.QE0W").read_bytes())
if sfm_units is not None:
side.values["Units"] = sfm_units
return {r.field: r for r in compare(side, ref, CARVEOUTS)}["Units"]
def test_dB_or_psi_is_blastwares_display_preference():
# Blastware writes its report in its PC's current preference; DL2's reports
# switch fleet-wide in 61 clean runs by write time, and no byte in the file
# tells them apart.
r = _units_case(None)
assert (r.verdict, r.carveout) == ("accepted", "units-is-a-display-preference")
def test_the_units_carveout_still_needs_the_mic():
assert _units_case("in/s").verdict == "mismatch"
def test_a_mic_trigger_level_is_read_in_the_unit_it_is_printed_in():
# K441LA17.IN0W: Units "in/s and psi(L)", yet MicTriggerLevel "125.0 dB(L)".
# The printed value states its own unit; that is the one to compare in.
sf = FIX.parent / "setup-fields-11-03-26"
ref = parse_xml_report_file(sf / "T189HUD6_QE0W_XML.XML") # 128.0 dB(L)
ref.event_units = "in/s and psi(L)"
res = {r.field: r for r in compare(sfm_side((sf / "T189HUD6.QE0W").read_bytes()), ref, CARVEOUTS)}
assert res["MicTriggerLevel"].verdict == "match", res["MicTriggerLevel"]