fix(decode): the mic's own range -- a range-1 mic reads an eighth
The mic's channel block carries a range byte at the geophones' offset (label + 29, reference D.6.4). At 1 each count is an eighth, 0.25 / 8 Pa: set on 7 DL2 events, all of them Blastware's values divided by 8, and on none of the other 70,026 -- independently of the geophone range (28 events have Sensitive geophones and a range-0 mic). SFM read those 7 mics 8x high: K557J1XQ.GF0W is 79.4 dB(L), not 97.5. Event.mic_range; the decoded mic peak (and so the .h5 mic samples, whose scale is the peak's) and the checker's mic conversions follow it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
1 parent
af8dde5114
commit
836c9e864b
7 files changed
+3266
-12
No files matched your search
@@ -21,7 +21,7 @@ from typing import Callable, Optional, Sequence
|
||||
|
||||
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,
|
||||
decode_blastware_bytes)
|
||||
decode_blastware_bytes, mic_count_divisor)
|
||||
from .histogram_codec import half_period_to_hz
|
||||
from .models import Event
|
||||
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
|
||||
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
|
||||
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_values: dict[str, list[object]] = field(default_factory=dict)
|
||||
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:
|
||||
values[f"{ch}{tag}"] = value
|
||||
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.update(_setup_values(ev))
|
||||
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]],
|
||||
counts=counts,
|
||||
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_times=times,
|
||||
)
|
||||
@@ -264,12 +267,13 @@ def _same_text(a: object, b: str) -> bool:
|
||||
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 ""
|
||||
d = sfm.mic_divisor
|
||||
if "dB(L)" in units:
|
||||
return mic_count_to_db
|
||||
return lambda c: mic_count_to_db(c / d)
|
||||
if "psi(L)" in units:
|
||||
return lambda c: c * _MIC_PSI_PER_COUNT
|
||||
return lambda c: c * _MIC_PSI_PER_COUNT / d
|
||||
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]]:
|
||||
k = sfm.geo_ips_per_count
|
||||
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:
|
||||
convert["MicL"] = mic
|
||||
return convert
|
||||
@@ -350,10 +354,11 @@ def _interval_converter(title: str, sfm: SfmSide) -> Optional[Callable[[int], fl
|
||||
ch, _, rest = title.partition(" ")
|
||||
if rest.startswith("Peak") and ch in _GEO:
|
||||
return lambda c: c * sfm.geo_ips_per_count
|
||||
d = sfm.mic_divisor
|
||||
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)":
|
||||
return lambda c: c * _MIC_PSI_PER_COUNT
|
||||
return lambda c: c * _MIC_PSI_PER_COUNT / d
|
||||
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).
|
||||
_PA_PER_PSI = 6894.757
|
||||
_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:
|
||||
@@ -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]],
|
||||
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
|
||||
(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", []))
|
||||
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 = 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)
|
||||
pvs = 0.0
|
||||
@@ -1396,6 +1406,7 @@ def _setup_trigger(raw: bytes, k: int) -> dict:
|
||||
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")
|
||||
out["mic_range"] = raw[m + _RANGE_AFTER_LABEL]
|
||||
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"))
|
||||
# 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
|
||||
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
|
||||
and ev.pretrig_samples is not None):
|
||||
_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
|
||||
record_stop_mode: Optional[int] = None # 0 = Fixed
|
||||
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
|
||||
# A histogram's per-interval detail (2026-11-03); None for a waveform.
|
||||
histogram_interval_sec: Optional[int] = None # as ComplianceConfig.histogram_interval_sec
|
||||
|
||||
Reference in new issue
Block a user