fix(decode): a Blastware file's geophone range comes from its setup -- Sensitive events no longer read 8x
In the setup's channel blocks, the byte 29 after each geophone label is the range: 0x00 Normal (10 in/s), 0x01 Sensitive (1.25 in/s). It matches Blastware's GeoRange on 70,042 / 70,042 DL2 events, all three channels agreeing on every one (35 Sensitive). SFM's live 1A has the same byte at label+33. SFM assumed Normal, so every Sensitive event's peaks, vector sum and .h5 samples read 8x high. - Event.geo_range (0 / 1, None when not read -- channels disagreeing, an unknown value or a missing block -- with a decode_problems entry). - decode_blastware_bytes scales peaks and the histogram vector sum by it. - event_hdf5.write_event_hdf5: geo_range defaults to None = the event's own, else Normal; an explicit argument still wins. - waveform_store.save_imported_bw and scripts/backfill_sidecars.py stop forcing 'normal', so imports and the backfill store the file's range. The waveform_store line was agreed with the parity session, which owns that file; its own branch keeps a geo_range parameter, defaulting to None at its next dev merge. - The checker's SFM side converts at the event's range and reports GeoRange; tests that pinned the old 8x gap now pin the fix, and the saturation carve-out is still tested against an 8x value. 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
6c7c6b0a15
commit
4844135f01
13 files changed
+3549
-32
No files matched your search
@@ -18,12 +18,13 @@ from dataclasses import dataclass
|
||||
from typing import Callable, Optional, Sequence
|
||||
|
||||
from .bw_xml_report import XmlReport
|
||||
from .event_file_io import _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT, decode_blastware_bytes
|
||||
from .event_file_io import (_GEO_FS_BY_RANGE, _GEO_INT16_FS, _GEO_NORMAL_FS_INS, _MIC_PSI_PER_COUNT,
|
||||
decode_blastware_bytes)
|
||||
from .models import Event
|
||||
from .waveform_codec import mic_count_to_db
|
||||
|
||||
# SFM's conversion: it cannot yet read the geophone range from the file, and
|
||||
# assumes Normal (10 in/s full scale = 32000 counts).
|
||||
# SFM's conversion at the Normal range (10 in/s full scale = 32000 counts),
|
||||
# which SFM assumes when it cannot read the event's range from the file.
|
||||
GEO_IPS_PER_COUNT: float = _GEO_NORMAL_FS_INS / _GEO_INT16_FS
|
||||
|
||||
_CHANNELS = ("Tran", "Vert", "Long", "MicL")
|
||||
@@ -38,6 +39,7 @@ class SfmSide:
|
||||
job_number: Optional[str] # None until the decoder reads it
|
||||
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
|
||||
|
||||
|
||||
def sfm_side(raw: bytes) -> SfmSide:
|
||||
@@ -55,6 +57,7 @@ def sfm_side(raw: bytes) -> SfmSide:
|
||||
# SFM's interval count is its decoded entry count; the reference
|
||||
# carries this field for histograms only.
|
||||
"NumberofIntervals": len(counts["Tran"]) or None,
|
||||
"GeoRange": _GEO_FS_BY_RANGE.get(ev.geo_range),
|
||||
}
|
||||
if ts is not None:
|
||||
date = f"{ts.year:04d}-{ts.month:02d}-{ts.day:02d}"
|
||||
@@ -78,6 +81,7 @@ def sfm_side(raw: bytes) -> SfmSide:
|
||||
job_number=None,
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
@@ -184,19 +188,20 @@ def _series_result(field: str, n_bw: int, n_sfm: int, diffs: list[tuple[int, flo
|
||||
)
|
||||
|
||||
|
||||
def _sample_converters(ref: XmlReport) -> dict[str, Callable[[int], float]]:
|
||||
convert: dict[str, Callable[[int], float]] = {ch: (lambda c: c * GEO_IPS_PER_COUNT) for ch in _GEO}
|
||||
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)
|
||||
if mic is not None:
|
||||
convert["MicL"] = mic
|
||||
return convert
|
||||
|
||||
|
||||
def _interval_converter(title: str) -> Optional[Callable[[int], float]]:
|
||||
def _interval_converter(title: str, sfm: SfmSide) -> Optional[Callable[[int], float]]:
|
||||
"""SFM keeps each interval's peaks; it drops their frequencies and geo PVS."""
|
||||
ch, _, rest = title.partition(" ")
|
||||
if rest.startswith("Peak") and ch in _GEO:
|
||||
return lambda c: c * GEO_IPS_PER_COUNT
|
||||
return lambda c: c * sfm.geo_ips_per_count
|
||||
if ch == "MicL" and rest == "Peak dB(L)":
|
||||
return mic_count_to_db
|
||||
if ch == "MicL" and rest == "Peak psi(L)":
|
||||
@@ -215,7 +220,7 @@ def series_pairs(sfm: SfmSide, ref: XmlReport,
|
||||
a row whose cell count differs is a disagreement for every channel."""
|
||||
if field.startswith("samples."):
|
||||
ch = field[len("samples."):]
|
||||
convert = _sample_converters(ref).get(ch)
|
||||
convert = _sample_converters(sfm, ref).get(ch)
|
||||
counts = sfm.counts.get(ch, [])
|
||||
if convert is None or not counts:
|
||||
return None
|
||||
@@ -232,7 +237,7 @@ def series_pairs(sfm: SfmSide, ref: XmlReport,
|
||||
if field.startswith("intervals."):
|
||||
title = field[len("intervals."):]
|
||||
columns = ref.interval_columns or []
|
||||
convert = _interval_converter(title)
|
||||
convert = _interval_converter(title, sfm)
|
||||
counts = sfm.counts.get(title.partition(" ")[0], [])
|
||||
if convert is None or not counts or title not in columns:
|
||||
return None
|
||||
|
||||
@@ -704,9 +704,11 @@ _INT16_FS = 32768.0
|
||||
# sfm.event_hdf5._GEO_INT16_FS or sidecar peaks disagree with the plotted
|
||||
# waveform by 2.3%. Confirmed 2026-08-25 against the BW ASCII corpus.
|
||||
_GEO_INT16_FS = 32000.0
|
||||
# A histogram's geo values are in decoder units of 16 counts = 0.005 in/s at
|
||||
# the Normal range (the same assumption as the samples above).
|
||||
_HIST_GEO_UNIT_INS = 16 * _GEO_NORMAL_FS_INS / _GEO_INT16_FS
|
||||
# Full scale per geo_range: 0 Normal, 1 Sensitive.
|
||||
_GEO_FS_BY_RANGE = {0: _GEO_NORMAL_FS_INS, 1: _GEO_SENSITIVE_FS_INS}
|
||||
# A histogram's geo values are decoder units of 16 counts: 0.005 in/s at the
|
||||
# Normal range, scaled by the range's full scale like the samples above.
|
||||
_HIST_GEO_COUNTS_PER_UNIT = 16
|
||||
|
||||
# Microphone scale factor, psi per MicL count: one count is 0.25 Pa
|
||||
# (waveform_codec.MIC_PA_PER_COUNT, measured against Blastware's psi(L) on
|
||||
@@ -749,17 +751,19 @@ def _decode_samples_4ch_int16_le(stream: bytes) -> dict[str, list[int]]:
|
||||
}
|
||||
|
||||
|
||||
def _peaks_from_samples(samples: dict[str, list[int]]) -> PeakValues:
|
||||
def _peaks_from_samples(samples: dict[str, list[int]],
|
||||
geo_fs_ins: float = _GEO_NORMAL_FS_INS) -> PeakValues:
|
||||
"""
|
||||
Compute approximate peaks from raw int16 samples assuming Normal-range
|
||||
geophone sensitivity. Used by the BW-importer when the 0C waveform
|
||||
record (the device's authoritative peaks) is unavailable.
|
||||
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
|
||||
BW-importer when the 0C waveform record (the device's authoritative peaks)
|
||||
is unavailable.
|
||||
"""
|
||||
def _peak_ins(ch: list[int]) -> float:
|
||||
if not ch:
|
||||
return 0.0
|
||||
m = max(abs(int(v)) for v in ch)
|
||||
return m / _GEO_INT16_FS * _GEO_NORMAL_FS_INS
|
||||
return m / _GEO_INT16_FS * geo_fs_ins
|
||||
|
||||
tran = _peak_ins(samples.get("Tran", []))
|
||||
vert = _peak_ins(samples.get("Vert", []))
|
||||
@@ -773,7 +777,7 @@ def _peaks_from_samples(samples: dict[str, list[int]]) -> PeakValues:
|
||||
pvs = 0.0
|
||||
n = min(len(samples.get("Tran", [])), len(samples.get("Vert", [])), len(samples.get("Long", [])))
|
||||
if n:
|
||||
scale = _GEO_NORMAL_FS_INS / _GEO_INT16_FS
|
||||
scale = geo_fs_ins / _GEO_INT16_FS
|
||||
T = samples["Tran"]; V = samples["Vert"]; L = samples["Long"]
|
||||
for i in range(n):
|
||||
t = T[i] * scale
|
||||
@@ -996,6 +1000,32 @@ def _setup_notes(raw: bytes) -> ProjectInfo:
|
||||
operator=operator, sensor_location=location)
|
||||
|
||||
|
||||
# The geophone range sits in the setup's channel blocks, which follow the
|
||||
# notes: the byte 29 after each geophone label (`00 00 01 Tran ...`). 0x00 is
|
||||
# Normal, 0x01 Sensitive -- Blastware's GeoRange on 70,042 / 70,042 DL2 events,
|
||||
# all three channels agreeing on every one (measured 2026-11-01). SFM's live
|
||||
# 1A read has the same byte at label+33.
|
||||
_RANGE_AFTER_LABEL = 29
|
||||
_CHANNEL_BLOCK_SPAN = 2000 # how far past the setup name the blocks may sit
|
||||
|
||||
|
||||
def _setup_geo_range(raw: bytes) -> tuple[Optional[int], Optional[str]]:
|
||||
"""(geo_range, problem): 0 Normal or 1 Sensitive when all three geophone
|
||||
channels say the same, else None and why."""
|
||||
k = _setup_name_at(raw)
|
||||
if k is None:
|
||||
return None, "no recording-setup block to read the geophone range from"
|
||||
found = {}
|
||||
for label in (b"Tran", b"Vert", b"Long"):
|
||||
i = raw.find(b"\x00\x00\x01" + label, k, k + _CHANNEL_BLOCK_SPAN)
|
||||
p = i + 3 + _RANGE_AFTER_LABEL
|
||||
found[label.decode()] = raw[p] if i >= 0 and p < len(raw) else None
|
||||
values = set(found.values())
|
||||
if len(values) == 1 and values <= {0, 1}:
|
||||
return values.pop(), None
|
||||
return None, f"geophone range not read: channel range bytes {found}"
|
||||
|
||||
|
||||
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)."""
|
||||
@@ -1156,6 +1186,9 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
# every waveform used to read "70 s". A histogram has no record time or
|
||||
# pre-trigger -- Blastware reports neither.
|
||||
ev.sample_rate = _setup_sample_rate(raw)
|
||||
ev.geo_range, range_problem = _setup_geo_range(raw)
|
||||
if range_problem:
|
||||
ev.decode_problems.append(range_problem + "; peaks assume the Normal range")
|
||||
if is_waveform_body:
|
||||
ev.rectime_seconds = _setup_record_time(raw)
|
||||
ev.total_samples = len(samples["Tran"]) or None
|
||||
@@ -1244,14 +1277,17 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
# None, and ``apply_report_to_event`` overlays from a paired ASCII
|
||||
# report when one is supplied.
|
||||
has_samples = any(samples.get(ch) for ch in ("Tran", "Vert", "Long", "MicL"))
|
||||
ev.peak_values = _peaks_from_samples(samples) if has_samples else None
|
||||
# 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 not is_waveform_body and ev.peak_values is not None:
|
||||
# A histogram stores each interval's vector sum (squared); the event's
|
||||
# is the largest. Combining the channel peaks instead read high on 86%
|
||||
# of DL2's histograms -- they can come from different moments.
|
||||
pvs = interval_pvs(body)
|
||||
if pvs:
|
||||
ev.peak_values.peak_vector_sum = max(pvs) * _HIST_GEO_UNIT_INS
|
||||
ev.peak_values.peak_vector_sum = (
|
||||
max(pvs) * _HIST_GEO_COUNTS_PER_UNIT * geo_fs / _GEO_INT16_FS)
|
||||
ev._a5_frames = None # not recoverable from BW file
|
||||
|
||||
return ev
|
||||
@@ -543,6 +543,9 @@ class Event:
|
||||
total_samples: Optional[int] = None # from STRT record: expected total sample-sets
|
||||
pretrig_samples: Optional[int] = None # from STRT record: pre-trigger sample count
|
||||
rectime_seconds: Optional[int] = None # from STRT record: record duration (seconds)
|
||||
# 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
|
||||
|
||||
# Sensor self-check traces keyed by channel label — the short diagnostic
|
||||
# waveforms the unit records when it pulses each sensor before monitoring
|
||||
|
||||
@@ -428,8 +428,7 @@ def main(argv=None) -> int:
|
||||
try:
|
||||
event_hdf5.write_event_hdf5(
|
||||
hdf5_path, ev,
|
||||
serial=serial,
|
||||
geo_range="normal",
|
||||
serial=serial, # range: the event's own, from its setup
|
||||
source_kind=source_kind,
|
||||
)
|
||||
hdf5_filename = hdf5_path.name
|
||||
|
||||
+6
-1
@@ -180,7 +180,7 @@ def write_event_hdf5(
|
||||
event: Event,
|
||||
*,
|
||||
serial: str,
|
||||
geo_range = "normal",
|
||||
geo_range = None,
|
||||
source_kind: str = "sfm-live",
|
||||
tool_version: Optional[str] = None,
|
||||
captured_at: Optional[datetime.datetime] = None,
|
||||
@@ -190,6 +190,9 @@ def write_event_hdf5(
|
||||
"""
|
||||
Persist a decoded Event as an HDF5 file with samples in physical units.
|
||||
|
||||
``geo_range`` left as None takes the event's own (``event.geo_range``,
|
||||
which a Blastware file's decode reads from its setup block), else Normal.
|
||||
|
||||
``geo_ips_per_count`` overrides the range-derived MiniMate count scale
|
||||
for sources whose counts differ — Thor IDF imports pass
|
||||
``micromate.idf_file._GEO_LSB_IPS`` (issue #42).
|
||||
@@ -202,6 +205,8 @@ def write_event_hdf5(
|
||||
pv = event.peak_values
|
||||
pi = event.project_info
|
||||
|
||||
if geo_range is None:
|
||||
geo_range = event.geo_range if getattr(event, "geo_range", None) is not None else "normal"
|
||||
geo_fs = _resolve_geo_full_scale(geo_range)
|
||||
geo_range_str = _normalise_range(geo_range)
|
||||
captured_at = captured_at or datetime.datetime.utcnow()
|
||||
|
||||
@@ -412,8 +412,7 @@ class WaveformStore:
|
||||
try:
|
||||
event_hdf5.write_event_hdf5(
|
||||
hdf5_path, ev,
|
||||
serial=serial,
|
||||
geo_range="normal", # BW file doesn't carry the range; assume Normal
|
||||
serial=serial, # range: the event's own, read from the file's setup
|
||||
source_kind="bw-import",
|
||||
)
|
||||
hdf5_filename = hdf5_path.name
|
||||
|
||||
BIN
Binary file not shown.
+3207
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+167
@@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Event>
|
||||
<FileVersion>8.0</FileVersion>
|
||||
<EventType>Full Histogram</EventType>
|
||||
<SerialNumber>BE11010</SerialNumber>
|
||||
<Version>V 10.72-8.17 MiniMate Plus</Version>
|
||||
<FileName>M010HR6K.OA0H</FileName>
|
||||
<HistogramStartTime>17:02:34</HistogramStartTime>
|
||||
<HistogramStartDate>2019-01-08</HistogramStartDate>
|
||||
<HistogramStopTime>17:20:00</HistogramStopTime>
|
||||
<HistogramStopDate>2019-01-08</HistogramStopDate>
|
||||
<Channels>
|
||||
<Channel>Tran</Channel>
|
||||
<Channel>Vert</Channel>
|
||||
<Channel>Long</Channel>
|
||||
<Channel>MicL</Channel>
|
||||
</Channels>
|
||||
<NumberofIntervals>18.00</NumberofIntervals>
|
||||
<IntervalSize>1 minute</IntervalSize>
|
||||
<SampleRate>1024 sps</SampleRate>
|
||||
<BatteryLevel>6.8 Volts</BatteryLevel>
|
||||
<Calibration>December 17, 2018 by Instantel</Calibration>
|
||||
<Units>in/s and dB(L)</Units>
|
||||
<Project>Wampum Ave-ECMS 29301-215 Joseph St</Project>
|
||||
<Client>Brayman Construction</Client>
|
||||
<UserName>Terra-Mechanics Inc - D. Bartholomae</UserName>
|
||||
<Seis.Loc>Loc, #1 - 215 Joseph Street</Seis.Loc>
|
||||
<GeoRange>
|
||||
<Value>1.250</Value>
|
||||
<Units>in/s</Units>
|
||||
</GeoRange>
|
||||
<TranPPV>
|
||||
<Value>0.008</Value>
|
||||
<Units>in/s</Units>
|
||||
</TranPPV>
|
||||
<VertPPV>
|
||||
<Value>0.009</Value>
|
||||
<Units>in/s</Units>
|
||||
</VertPPV>
|
||||
<LongPPV>
|
||||
<Value>0.005</Value>
|
||||
<Units>in/s</Units>
|
||||
</LongPPV>
|
||||
<TranZCFreq>
|
||||
<Value>11</Value>
|
||||
<Units>Hz</Units>
|
||||
</TranZCFreq>
|
||||
<VertZCFreq>
|
||||
<Value>73</Value>
|
||||
<Units>Hz</Units>
|
||||
</VertZCFreq>
|
||||
<LongZCFreq>
|
||||
<Value>16</Value>
|
||||
<Units>Hz</Units>
|
||||
</LongZCFreq>
|
||||
<TranPeakTime>17:11:34</TranPeakTime>
|
||||
<TranPeakDate>2019-01-08</TranPeakDate>
|
||||
<VertPeakTime>17:03:34</VertPeakTime>
|
||||
<VertPeakDate>2019-01-08</VertPeakDate>
|
||||
<LongPeakTime>17:11:34</LongPeakTime>
|
||||
<LongPeakDate>2019-01-08</LongPeakDate>
|
||||
<PeakVectorSum>
|
||||
<Value>0.009</Value>
|
||||
<Units>in/s</Units>
|
||||
</PeakVectorSum>
|
||||
<PeakVectorSumTime>17:11:34</PeakVectorSumTime>
|
||||
<PeakVectorSumDate>2019-01-08</PeakVectorSumDate>
|
||||
<Microphone>Linear Weighting</Microphone>
|
||||
<MicLPSPL>
|
||||
<Value>134.1</Value>
|
||||
<Units>dB(L)</Units>
|
||||
</MicLPSPL>
|
||||
<MicLTime>17:03:34</MicLTime>
|
||||
<MicLDate>2019-01-08</MicLDate>
|
||||
<MicLZCFreq>
|
||||
<Value>9.7</Value>
|
||||
<Units>Hz</Units>
|
||||
</MicLZCFreq>
|
||||
<TranTestFreq>7.2 Hz.</TranTestFreq>
|
||||
<TranTestRatio>4.3</TranTestRatio>
|
||||
<TranTestResults>Passed</TranTestResults>
|
||||
<VertTestFreq>7.6 Hz.</VertTestFreq>
|
||||
<VertTestRatio>3.4</VertTestRatio>
|
||||
<VertTestResults>Passed</VertTestResults>
|
||||
<LongTestFreq>7.2 Hz.</LongTestFreq>
|
||||
<LongTestRatio>3.8</LongTestRatio>
|
||||
<LongTestResults>Passed</LongTestResults>
|
||||
<MicLTestFreq>20.1 Hz.</MicLTestFreq>
|
||||
<MicLTestAmplitude>583 mv</MicLTestAmplitude>
|
||||
<MicLTestResults>Passed</MicLTestResults>
|
||||
<UsbSummaryChannels>
|
||||
</UsbSummaryChannels>
|
||||
<MonitorLog>2019-01-08 17:02:33 - 2019-01-08 17:20:00 "Event Recorded Modem Exit"</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>2019-01-08 17:03:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>47</Cell><Cell>0.009</Cell><Cell>73</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.009</Cell><Cell>0.015</Cell><Cell>134.1</Cell><Cell>9.7</Cell></Row>
|
||||
<Time>2019-01-08 17:04:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>21</Cell><Cell>0.007</Cell><Cell>27</Cell><Cell>0.002</Cell><Cell>85</Cell><Cell>0.007</Cell><Cell>0.000</Cell><Cell>87.96</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:05:34</Time>
|
||||
<Row>
|
||||
<Cell>0.004</Cell><Cell>20</Cell><Cell>0.004</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.005</Cell><Cell>0.003</Cell><Cell>119.1</Cell><Cell>7.5</Cell></Row>
|
||||
<Time>2019-01-08 17:06:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>34</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>51</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:07:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>51</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>39</Cell></Row>
|
||||
<Time>2019-01-08 17:08:34</Time>
|
||||
<Row>
|
||||
<Cell>0.004</Cell><Cell>12</Cell><Cell>0.004</Cell><Cell>16</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.005</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>13</Cell></Row>
|
||||
<Time>2019-01-08 17:09:34</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>51</Cell><Cell>0.002</Cell><Cell>64</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:10:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>12</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:11:34</Time>
|
||||
<Row>
|
||||
<Cell>0.008</Cell><Cell>11</Cell><Cell>0.005</Cell><Cell>13</Cell><Cell>0.005</Cell><Cell>16</Cell><Cell>0.009</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>19</Cell></Row>
|
||||
<Time>2019-01-08 17:12:34</Time>
|
||||
<Row>
|
||||
<Cell>0.006</Cell><Cell>13</Cell><Cell>0.004</Cell><Cell>14</Cell><Cell>0.004</Cell><Cell>51</Cell><Cell>0.007</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>20</Cell></Row>
|
||||
<Time>2019-01-08 17:13:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>57</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>87.96</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:14:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>47</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>13</Cell></Row>
|
||||
<Time>2019-01-08 17:15:34</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>95.92</Cell><Cell>2.5</Cell></Row>
|
||||
<Time>2019-01-08 17:16:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>13</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>85</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>93.98</Cell><Cell>9.1</Cell></Row>
|
||||
<Time>2019-01-08 17:17:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>17</Cell><Cell>0.002</Cell><Cell>85</Cell><Cell>0.002</Cell><Cell>73</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>81.94</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:18:34</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>87.96</Cell><Cell>>100</Cell></Row>
|
||||
<Time>2019-01-08 17:19:34</Time>
|
||||
<Row>
|
||||
<Cell>0.003</Cell><Cell>73</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>20</Cell><Cell>0.004</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>6.1</Cell></Row>
|
||||
<Time>2019-01-08 17:20:00</Time>
|
||||
<Row>
|
||||
<Cell>0.002</Cell><Cell>37</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.002</Cell><Cell>>100</Cell><Cell>0.003</Cell><Cell>0.000</Cell><Cell>91.48</Cell><Cell>18</Cell></Row>
|
||||
</HistogramDataIntervals>
|
||||
</HistogramData>
|
||||
<HistogramDataUsbChannels>
|
||||
</HistogramDataUsbChannels>
|
||||
|
||||
</Event>
|
||||
@@ -206,3 +206,73 @@ def test_mic_peak_in_psi():
|
||||
# Blastware: MicL PSPL 106.0 dB(L) = 20 uPa x 10^(106/20) = 3.990 Pa = 5.787e-4 psi.
|
||||
ev = read_blastware_file(_FIX / "decode-checker-10-29-26/M529L4XQ.R30H")
|
||||
assert ev.peak_values.micl == pytest.approx(5.787e-4, rel=0.01)
|
||||
|
||||
|
||||
# ── The geophone range: Normal or Sensitive ─────────────────────────────────
|
||||
# In the setup's channel blocks, the byte 29 after each geophone label is the
|
||||
# range: 0x00 Normal (10 in/s full scale), 0x01 Sensitive (1.25 in/s). It
|
||||
# matches Blastware's GeoRange on 70,042 / 70,042 DL2 events, all three
|
||||
# channels agreeing on every one (35 Sensitive), measured 2026-11-01. Until
|
||||
# now SFM assumed Normal, so a Sensitive event read 8x high.
|
||||
|
||||
from minimateplus.event_file_io import _setup_name_at # noqa: E402
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel,want", [
|
||||
("bw-import-fields-10-29-26/R352HIUI.F40W", 0),
|
||||
("geo-range-11-01-26/K557J1KB.RQ0W", 1), # waveform, XML GeoRange 1.250
|
||||
("geo-range-11-01-26/M010HR6K.OA0H", 1), # histogram, XML GeoRange 1.250
|
||||
])
|
||||
def test_geo_range_comes_from_the_file(rel, want):
|
||||
assert read_blastware_file(_FIX / rel).geo_range == want
|
||||
|
||||
|
||||
# (file, Blastware's Tran / Vert / Long PPV and Peak Vector Sum, from its XML)
|
||||
@pytest.mark.parametrize("rel,peaks", [
|
||||
("geo-range-11-01-26/K557J1KB.RQ0W", ("0.019", "0.055", "0.019", "0.061")),
|
||||
("geo-range-11-01-26/M010HR6K.OA0H", ("0.008", "0.009", "0.005", "0.009")),
|
||||
])
|
||||
def test_sensitive_range_peaks_are_not_8x(rel, peaks):
|
||||
pv = read_blastware_file(_FIX / rel).peak_values
|
||||
for got, want in zip((pv.tran, pv.vert, pv.long, pv.peak_vector_sum), peaks):
|
||||
assert abs(got - float(want)) <= 0.0005 + 1e-9, (got, want)
|
||||
|
||||
|
||||
def test_channels_that_disagree_give_no_range_and_a_problem():
|
||||
raw = bytearray((_FIX / "geo-range-11-01-26/K557J1KB.RQ0W").read_bytes())
|
||||
i = raw.find(b"\x00\x00\x01Vert", _setup_name_at(bytes(raw)))
|
||||
raw[i + 3 + 29] = 0x00 # Vert Normal, Tran / Long Sensitive
|
||||
ev = decode_blastware_bytes(bytes(raw), name=None)
|
||||
assert ev.geo_range is None
|
||||
assert any("range" in p for p in ev.decode_problems)
|
||||
|
||||
|
||||
def test_the_h5_takes_the_events_range(tmp_path):
|
||||
import h5py
|
||||
from sfm import event_hdf5
|
||||
ev = read_blastware_file(_FIX / "geo-range-11-01-26/K557J1KB.RQ0W")
|
||||
event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE9557")
|
||||
with h5py.File(tmp_path / "e.h5", "r") as f:
|
||||
assert f.attrs["geo_range"] == "sensitive"
|
||||
assert abs(float(abs(f["samples/Vert"][:]).max()) - 0.055) <= 0.0005 + 1e-9
|
||||
|
||||
|
||||
def test_an_imported_file_and_the_backfill_store_its_range(tmp_path):
|
||||
import h5py
|
||||
import scripts.backfill_sidecars as backfill
|
||||
from sfm import event_hdf5
|
||||
from sfm.waveform_store import WaveformStore
|
||||
|
||||
src = _FIX / "geo-range-11-01-26/K557J1KB.RQ0W"
|
||||
store = WaveformStore(tmp_path / "waveforms")
|
||||
ev, _ = store.save_imported_bw(src.read_bytes(), source_path=src)
|
||||
h5 = store.hdf5_path_for("BE9557", src.name)
|
||||
with h5py.File(h5, "r") as f:
|
||||
assert f.attrs["geo_range"] == "sensitive"
|
||||
|
||||
# A file stored before this fix carries "normal"; the backfill rewrites it.
|
||||
event_hdf5.write_event_hdf5(h5, ev, serial="BE9557", geo_range="normal")
|
||||
assert backfill.main(["--store-root", str(tmp_path / "waveforms"),
|
||||
"--db-path", str(tmp_path / "seismo_relay.db"), "--force"]) == 0
|
||||
with h5py.File(h5, "r") as f:
|
||||
assert f.attrs["geo_range"] == "sensitive"
|
||||
@@ -28,7 +28,8 @@ def test_find_pairs_dedupes_and_pairs(tmp_path):
|
||||
def test_check_event_rows_and_attrs():
|
||||
out = run.check_event("M007HVWF.K30W", str(FIX / "M007HVWF.K30W"), str(FIX / "M007HVWF_K30W_XML.XML"))
|
||||
assert out["attrs"]["range"] == "1.250" and out["attrs"]["model"] == "MiniMate Plus"
|
||||
assert any(r[0] == "TranPPV" and r[1] == "mismatch" for r in out["results"])
|
||||
# clipped at its own 1.250 ceiling: accepted under the saturation carve-out
|
||||
assert ["TranPPV", "accepted"] in [r[:2] for r in out["results"]]
|
||||
|
||||
|
||||
def test_bad_input_is_one_error_row(tmp_path):
|
||||
@@ -128,7 +129,7 @@ def test_compare_to_marks_the_summary(tmp_path):
|
||||
def test_file_prints_one_event(tmp_path, capsys):
|
||||
assert run.main([str(FIX), str(FIX), "--file", "M007HVWF.K30W"]) == 0
|
||||
out = capsys.readouterr().out
|
||||
assert any("TranPPV" in line and "mismatch" in line for line in out.splitlines())
|
||||
assert any("TranPPV" in line and "accepted" in line for line in out.splitlines())
|
||||
|
||||
|
||||
# ── Final review fixes ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -114,8 +114,23 @@ def test_clipped_normal_range_is_accepted():
|
||||
assert (res[f].verdict, res[f].carveout) == ("accepted", "saturation")
|
||||
|
||||
|
||||
def test_sensitive_range_8x_stays_a_mismatch():
|
||||
def test_a_clipped_sensitive_event_is_accepted_at_its_own_ceiling():
|
||||
# SFM reads the 1.250 range from the file; the clipped channels sit at 1.2506.
|
||||
res = _results("M007HVWF.K30W", CARVEOUTS)
|
||||
assert res["GeoRange"].verdict == "match" and res["samples.Tran"].verdict == "match"
|
||||
for f in ("TranPPV", "PeakVectorSum"):
|
||||
assert (res[f].verdict, res[f].carveout) == ("accepted", "saturation")
|
||||
|
||||
|
||||
def test_the_carveout_never_accepts_an_8x_value():
|
||||
# What SFM produced while it assumed Normal on a Sensitive unit: 8x high.
|
||||
# The saturation rule must leave it a mismatch.
|
||||
raw = (FIX / "M007HVWF.K30W").read_bytes()
|
||||
side = sfm_side(raw)
|
||||
side.values.update(TranPPV=10.005, VertPPV=10.005, LongPPV=10.005, PeakVectorSum=17.33)
|
||||
side.geo_ips_per_count = 10.0 / 32000
|
||||
res = {r.field: r for r in compare(side, parse_xml_report_file(FIX / "M007HVWF_K30W_XML.XML"),
|
||||
CARVEOUTS)}
|
||||
assert res["TranPPV"].verdict == "mismatch" and res["samples.Tran"].verdict == "mismatch"
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
@@ -133,13 +148,14 @@ def test_pvs_carveout_needs_oorange_from_blastware():
|
||||
|
||||
|
||||
def test_pvs_carveout_needs_the_clipped_channel_at_the_ceiling():
|
||||
# 1.250 range, Blastware PVS OORANGE; an UNclipped channel's 8x value happens to land
|
||||
# in the 1.250 band -- that must not let SFM's 8x vector sum through.
|
||||
# 1.250 range, Blastware PVS OORANGE, but no channel Blastware clamped: an
|
||||
# UNclipped channel's 8x value landing in the 1.250 band must not let a vector
|
||||
# sum through, even one inside the sqrt(3) bound.
|
||||
raw = (FIX / "M007HVWF.K30W").read_bytes()
|
||||
ref = parse_xml_report_file(FIX / "M007HVWF_K30W_XML.XML")
|
||||
ref.scalars["TranPPV"] = "0.157"
|
||||
ref.scalars.update(TranPPV="0.157", VertPPV="0.157", LongPPV="0.157")
|
||||
side = sfm_side(raw)
|
||||
side.values["TranPPV"] = 1.256
|
||||
side.values.update(TranPPV=1.256, PeakVectorSum=2.0)
|
||||
res = {r.field: r for r in compare(side, ref, CARVEOUTS)}
|
||||
assert res["PeakVectorSum"].verdict == "mismatch"
|
||||
|
||||
@@ -147,3 +163,12 @@ def test_pvs_carveout_needs_the_clipped_channel_at_the_ceiling():
|
||||
def test_interval_mic_psi_matches():
|
||||
# psi(L) report: every interval's "MicL Peak psi(L)" now converts right
|
||||
assert _results("T004JTRF.ME0H")["intervals.MicL Peak psi(L)"].verdict == "match"
|
||||
|
||||
|
||||
def test_a_sensitive_range_event_now_matches():
|
||||
gr = FIX.parent / "geo-range-11-01-26"
|
||||
raw = (gr / "K557J1KB.RQ0W").read_bytes()
|
||||
res = {r.field: r for r in compare(sfm_side(raw), parse_xml_report_file(gr / "K557J1KB_RQ0W_XML.XML"))}
|
||||
for f in ("GeoRange", "TranPPV", "VertPPV", "LongPPV", "PeakVectorSum",
|
||||
"samples.Tran", "samples.Vert", "samples.Long"):
|
||||
assert res[f].verdict == "match", (f, res[f])
|
||||
Reference in new issue
Block a user