Release v0.35.0 — 80 of 88 report fields from the file, and monitor logs (.MLG) #60
No files matched your search
@@ -21,7 +21,7 @@ from typing import Callable, Optional, Sequence
|
|||||||
|
|
||||||
from .bw_xml_report import XmlReport
|
from .bw_xml_report import XmlReport
|
||||||
from .event_file_io import (interval_times, _GEO_FS_BY_RANGE, _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT,
|
from .event_file_io import (interval_times, _GEO_FS_BY_RANGE, _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT,
|
||||||
decode_blastware_bytes)
|
decode_blastware_bytes, mic_count_divisor)
|
||||||
from .histogram_codec import half_period_to_hz
|
from .histogram_codec import half_period_to_hz
|
||||||
from .models import Event
|
from .models import Event
|
||||||
from .waveform_codec import mic_count_to_db
|
from .waveform_codec import mic_count_to_db
|
||||||
@@ -87,6 +87,7 @@ class SfmSide:
|
|||||||
channels: list[str] # channels with decoded data, in Tran/Vert/Long/MicL order
|
channels: list[str] # channels with decoded data, in Tran/Vert/Long/MicL order
|
||||||
counts: dict[str, list[int]] # waveform samples or histogram interval peaks
|
counts: dict[str, list[int]] # waveform samples or histogram interval peaks
|
||||||
geo_ips_per_count: float = GEO_IPS_PER_COUNT # at the event's range, as SFM read it
|
geo_ips_per_count: float = GEO_IPS_PER_COUNT # at the event's range, as SFM read it
|
||||||
|
mic_divisor: int = 1 # mic counts per 0.25 Pa, at the mic's range
|
||||||
# interval column -> SFM's value per interval (a number, or Blastware's word)
|
# interval column -> SFM's value per interval (a number, or Blastware's word)
|
||||||
interval_values: dict[str, list[object]] = field(default_factory=dict)
|
interval_values: dict[str, list[object]] = field(default_factory=dict)
|
||||||
interval_times: Optional[list[str]] = None # each interval's printed time
|
interval_times: Optional[list[str]] = None # each interval's printed time
|
||||||
@@ -174,7 +175,8 @@ def sfm_side(raw: bytes) -> SfmSide:
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
values[f"{ch}{tag}"] = value
|
values[f"{ch}{tag}"] = value
|
||||||
if counts["MicL"]:
|
if counts["MicL"]:
|
||||||
values["MicLPSPL dB(L)"] = mic_count_to_db(max(abs(c) for c in counts["MicL"]))
|
values["MicLPSPL dB(L)"] = mic_count_to_db(max(abs(c) for c in counts["MicL"])
|
||||||
|
/ mic_count_divisor(ev.mic_range))
|
||||||
values["MicLPSPL psi(L)"] = pv.micl if pv is not None else None
|
values["MicLPSPL psi(L)"] = pv.micl if pv is not None else None
|
||||||
values.update(_setup_values(ev))
|
values.update(_setup_values(ev))
|
||||||
if ev.stop_time is not None:
|
if ev.stop_time is not None:
|
||||||
@@ -212,6 +214,7 @@ def sfm_side(raw: bytes) -> SfmSide:
|
|||||||
channels=[ch for ch in _CHANNELS if counts[ch]],
|
channels=[ch for ch in _CHANNELS if counts[ch]],
|
||||||
counts=counts,
|
counts=counts,
|
||||||
geo_ips_per_count=_GEO_FS_BY_RANGE.get(ev.geo_range, _GEO_NORMAL_FS_INS) / _GEO_INT16_FS,
|
geo_ips_per_count=_GEO_FS_BY_RANGE.get(ev.geo_range, _GEO_NORMAL_FS_INS) / _GEO_INT16_FS,
|
||||||
|
mic_divisor=mic_count_divisor(ev.mic_range),
|
||||||
interval_values=interval_values,
|
interval_values=interval_values,
|
||||||
interval_times=times,
|
interval_times=times,
|
||||||
)
|
)
|
||||||
@@ -264,12 +267,13 @@ def _same_text(a: object, b: str) -> bool:
|
|||||||
return " ".join(str(a).split()) == " ".join(b.split())
|
return " ".join(str(a).split()) == " ".join(b.split())
|
||||||
|
|
||||||
|
|
||||||
def _mic_converter(ref: XmlReport) -> Optional[Callable[[int], float]]:
|
def _mic_converter(ref: XmlReport, sfm: SfmSide) -> Optional[Callable[[int], float]]:
|
||||||
units = ref.event_units or ""
|
units = ref.event_units or ""
|
||||||
|
d = sfm.mic_divisor
|
||||||
if "dB(L)" in units:
|
if "dB(L)" in units:
|
||||||
return mic_count_to_db
|
return lambda c: mic_count_to_db(c / d)
|
||||||
if "psi(L)" in units:
|
if "psi(L)" in units:
|
||||||
return lambda c: c * _MIC_PSI_PER_COUNT
|
return lambda c: c * _MIC_PSI_PER_COUNT / d
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -339,7 +343,7 @@ def _series_result(field: str, n_bw: int, n_sfm: int, diffs: list[tuple[int, flo
|
|||||||
def _sample_converters(sfm: SfmSide, ref: XmlReport) -> dict[str, Callable[[int], float]]:
|
def _sample_converters(sfm: SfmSide, ref: XmlReport) -> dict[str, Callable[[int], float]]:
|
||||||
k = sfm.geo_ips_per_count
|
k = sfm.geo_ips_per_count
|
||||||
convert: dict[str, Callable[[int], float]] = {ch: (lambda c: c * k) for ch in _GEO}
|
convert: dict[str, Callable[[int], float]] = {ch: (lambda c: c * k) for ch in _GEO}
|
||||||
mic = _mic_converter(ref)
|
mic = _mic_converter(ref, sfm)
|
||||||
if mic is not None:
|
if mic is not None:
|
||||||
convert["MicL"] = mic
|
convert["MicL"] = mic
|
||||||
return convert
|
return convert
|
||||||
@@ -350,10 +354,11 @@ def _interval_converter(title: str, sfm: SfmSide) -> Optional[Callable[[int], fl
|
|||||||
ch, _, rest = title.partition(" ")
|
ch, _, rest = title.partition(" ")
|
||||||
if rest.startswith("Peak") and ch in _GEO:
|
if rest.startswith("Peak") and ch in _GEO:
|
||||||
return lambda c: c * sfm.geo_ips_per_count
|
return lambda c: c * sfm.geo_ips_per_count
|
||||||
|
d = sfm.mic_divisor
|
||||||
if ch == "MicL" and rest == "Peak dB(L)":
|
if ch == "MicL" and rest == "Peak dB(L)":
|
||||||
return mic_count_to_db
|
return lambda c: mic_count_to_db(c / d)
|
||||||
if ch == "MicL" and rest == "Peak psi(L)":
|
if ch == "MicL" and rest == "Peak psi(L)":
|
||||||
return lambda c: c * _MIC_PSI_PER_COUNT
|
return lambda c: c * _MIC_PSI_PER_COUNT / d
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -719,6 +719,15 @@ _HIST_GEO_COUNTS_PER_UNIT = 16
|
|||||||
# 0.0125 / 32768, that read every mic peak ~95x low (2026-10-31).
|
# 0.0125 / 32768, that read every mic peak ~95x low (2026-10-31).
|
||||||
_PA_PER_PSI = 6894.757
|
_PA_PER_PSI = 6894.757
|
||||||
_MIC_PSI_PER_COUNT = _wc.MIC_PA_PER_COUNT / _PA_PER_PSI
|
_MIC_PSI_PER_COUNT = _wc.MIC_PA_PER_COUNT / _PA_PER_PSI
|
||||||
|
# The mic's own range byte (its channel block, label + 29, as the geophones'):
|
||||||
|
# at 1 each count is an eighth. Set on 7 DL2 events, all of them Blastware's
|
||||||
|
# values divided by 8, and on none of the other 70,026 (2026-11-09).
|
||||||
|
_MIC_COUNTS_PER_UNIT_BY_RANGE = {0: 1, 1: 8}
|
||||||
|
|
||||||
|
|
||||||
|
def mic_count_divisor(mic_range: Optional[int]) -> int:
|
||||||
|
"""How many of a mic's counts make one 0.25 Pa unit at its range."""
|
||||||
|
return _MIC_COUNTS_PER_UNIT_BY_RANGE.get(mic_range, 1)
|
||||||
|
|
||||||
|
|
||||||
def _decode_strt(strt: bytes) -> dict:
|
def _decode_strt(strt: bytes) -> dict:
|
||||||
@@ -755,7 +764,8 @@ def _decode_samples_4ch_int16_le(stream: bytes) -> dict[str, list[int]]:
|
|||||||
|
|
||||||
|
|
||||||
def _peaks_from_samples(samples: dict[str, list[int]],
|
def _peaks_from_samples(samples: dict[str, list[int]],
|
||||||
geo_fs_ins: float = _GEO_NORMAL_FS_INS) -> PeakValues:
|
geo_fs_ins: float = _GEO_NORMAL_FS_INS,
|
||||||
|
mic_divisor: int = 1) -> PeakValues:
|
||||||
"""
|
"""
|
||||||
Compute peaks from raw int16 samples at the given geophone full scale
|
Compute peaks from raw int16 samples at the given geophone full scale
|
||||||
(Normal, 10 in/s, unless the file's range says otherwise). Used by the
|
(Normal, 10 in/s, unless the file's range says otherwise). Used by the
|
||||||
@@ -772,9 +782,9 @@ def _peaks_from_samples(samples: dict[str, list[int]],
|
|||||||
vert = _peak_ins(samples.get("Vert", []))
|
vert = _peak_ins(samples.get("Vert", []))
|
||||||
long_ = _peak_ins(samples.get("Long", []))
|
long_ = _peak_ins(samples.get("Long", []))
|
||||||
|
|
||||||
# Mic in psi: one count = 0.25 Pa
|
# Mic in psi: one count = 0.25 Pa, an eighth of that on a range-1 mic
|
||||||
mic_ch = samples.get("MicL", []) or []
|
mic_ch = samples.get("MicL", []) or []
|
||||||
mic = max((abs(int(v)) for v in mic_ch), default=0) * _MIC_PSI_PER_COUNT
|
mic = max((abs(int(v)) for v in mic_ch), default=0) * _MIC_PSI_PER_COUNT / mic_divisor
|
||||||
|
|
||||||
# Peak vector sum: max over time of sqrt(T^2 + V^2 + L^2)
|
# Peak vector sum: max over time of sqrt(T^2 + V^2 + L^2)
|
||||||
pvs = 0.0
|
pvs = 0.0
|
||||||
@@ -1396,6 +1406,7 @@ def _setup_trigger(raw: bytes, k: int) -> dict:
|
|||||||
if m >= 0:
|
if m >= 0:
|
||||||
out["trigger_level_mic_psi"] = struct.unpack_from(">f", raw, m + _TRIGGER_LEVEL_AFTER_LABEL)[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")
|
out["mic_type"] = int.from_bytes(raw[m + _MIC_TYPE_AFTER_LABEL:m + _MIC_TYPE_AFTER_LABEL + 4], "big")
|
||||||
|
out["mic_range"] = raw[m + _RANGE_AFTER_LABEL]
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
@@ -1703,7 +1714,8 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
|||||||
has_samples = any(samples.get(ch) for ch in ("Tran", "Vert", "Long", "MicL"))
|
has_samples = any(samples.get(ch) for ch in ("Tran", "Vert", "Long", "MicL"))
|
||||||
# The geophone full scale is the file's range; Normal when it wasn't read.
|
# 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)
|
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
|
ev.peak_values = (_peaks_from_samples(samples, geo_fs, mic_count_divisor(ev.mic_range))
|
||||||
|
if has_samples else None)
|
||||||
if (is_waveform_body and ev.peak_values is not None and ev.sample_rate
|
if (is_waveform_body and ev.peak_values is not None and ev.sample_rate
|
||||||
and ev.pretrig_samples is not None):
|
and ev.pretrig_samples is not None):
|
||||||
_waveform_peak_detail(ev.peak_values, samples, geo_fs, ev.sample_rate, ev.pretrig_samples)
|
_waveform_peak_detail(ev.peak_values, samples, geo_fs, ev.sample_rate, ev.pretrig_samples)
|
||||||
|
|||||||
@@ -608,6 +608,7 @@ class Event:
|
|||||||
trigger_level_mic_psi: Optional[float] = None
|
trigger_level_mic_psi: Optional[float] = None
|
||||||
record_stop_mode: Optional[int] = None # 0 = Fixed
|
record_stop_mode: Optional[int] = None # 0 = Fixed
|
||||||
mic_type: Optional[int] = None # 2 = Linear Weighting (as Series IV)
|
mic_type: Optional[int] = None # 2 = Linear Weighting (as Series IV)
|
||||||
|
mic_range: Optional[int] = None # 0; 1 = each mic count is an eighth (2026-11-09)
|
||||||
stop_time: Optional[datetime.datetime] = None # the footer's stop
|
stop_time: Optional[datetime.datetime] = None # the footer's stop
|
||||||
# A histogram's per-interval detail (2026-11-03); None for a waveform.
|
# A histogram's per-interval detail (2026-11-03); None for a waveform.
|
||||||
histogram_interval_sec: Optional[int] = None # as ComplianceConfig.histogram_interval_sec
|
histogram_interval_sec: Optional[int] = None # as ComplianceConfig.histogram_interval_sec
|
||||||
|
|||||||
BIN
Binary file not shown.
+3204
File diff suppressed because it is too large.
Load diff
@@ -737,3 +737,25 @@ def test_over_range_is_the_units_peak_beyond_full_scale(rel, over):
|
|||||||
pv = read_blastware_file(_FIX / rel).peak_values
|
pv = read_blastware_file(_FIX / rel).peak_values
|
||||||
assert (pv.tran_over_range, pv.vert_over_range, pv.long_over_range,
|
assert (pv.tran_over_range, pv.vert_over_range, pv.long_over_range,
|
||||||
pv.mic_over_range, pv.pvs_over_range) == over
|
pv.mic_over_range, pv.pvs_over_range) == over
|
||||||
|
|
||||||
|
|
||||||
|
# ── The mic's own range ─────────────────────────────────────────────────────
|
||||||
|
# The mic's channel block carries a range byte at the geophones' offset (label
|
||||||
|
# + 29, D.6.4): 1 makes each count an eighth -- 0.25 / 8 Pa. It is set on 7 DL2
|
||||||
|
# events, all of them Blastware's ÷8 values, and on none of the 70,026 others,
|
||||||
|
# independently of the geophone range (28 events have Sensitive geophones and
|
||||||
|
# a range-0 mic). SFM read those 7 mics 8x high (2026-11-09).
|
||||||
|
|
||||||
|
def test_a_range_1_mic_reads_an_eighth():
|
||||||
|
ev = read_blastware_file(_FIX / f"{_OR}/K557J1XQ.GF0W")
|
||||||
|
assert ev.mic_range == 1
|
||||||
|
peak = max(abs(c) for c in ev.raw_samples["MicL"]) # 6 counts
|
||||||
|
# Blastware: 79.4 dB(L) = 6 / 8 counts; as a range-0 mic it would be 97.5
|
||||||
|
assert ev.peak_values.micl == pytest.approx(peak * 0.25 / 8 / 6894.757, rel=1e-6)
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_range_0_mic_is_unchanged():
|
||||||
|
ev = read_blastware_file(_FIX / f"{_US}/I145L6UJ.3Y0W")
|
||||||
|
assert ev.mic_range == 0
|
||||||
|
peak = max(abs(c) for c in ev.raw_samples["MicL"])
|
||||||
|
assert ev.peak_values.micl == pytest.approx(peak * 0.25 / 6894.757, rel=1e-6)
|
||||||
@@ -473,3 +473,13 @@ def test_an_over_range_flag_against_a_printed_number_is_a_mismatch():
|
|||||||
sfm.event.peak_values.pvs_over_range = True # SFM would print OORANGE; Blastware printed 14.49
|
sfm.event.peak_values.pvs_over_range = True # SFM would print OORANGE; Blastware printed 14.49
|
||||||
res = {r.field: r for r in compare(sfm, ref, CARVEOUTS)}
|
res = {r.field: r for r in compare(sfm, ref, CARVEOUTS)}
|
||||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_range_1_mic_matches_blastware():
|
||||||
|
# Its mic range byte is 1: every count is an eighth (79.4 dB(L), not 97.5).
|
||||||
|
path = _OR / "K557J1XQ.GF0W"
|
||||||
|
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 ("MicLPSPL", "samples.MicL"):
|
||||||
|
assert res[f].verdict == "match", (f, res[f])
|
||||||
Reference in new issue
Block a user