diff --git a/minimateplus/decode_check.py b/minimateplus/decode_check.py index 6133d77..0c19fdd 100644 --- a/minimateplus/decode_check.py +++ b/minimateplus/decode_check.py @@ -36,7 +36,7 @@ class SfmSide: event: Event values: dict[str, object] # reference tag -> SFM's value; absent or None = blank notes: list[str] # non-empty user-note slots, in order - job_number: Optional[str] # None until the decoder reads it + job_number: Optional[str] # only when the file says Blastware shows 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 @@ -78,7 +78,7 @@ def sfm_side(raw: bytes) -> SfmSide: values=values, notes=[v for v in (pi.project, pi.client, pi.operator, pi.sensor_location) if v] if pi is not None else [], - job_number=None, + job_number=str(pi.job_number) if pi is not None and pi.job_number_enabled else 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, @@ -289,6 +289,9 @@ def compare(sfm: SfmSide, ref: XmlReport, carveouts: Sequence["Carveout"] = ()) if sfm.job_number is None else FieldResult("JobNumber", "match" if _same_text(sfm.job_number, ref.job_number) else "mismatch", ref.job_number, sfm.job_number)) + elif sfm.job_number is not None: + # SFM says the job number is shown; Blastware printed none. + out.append(FieldResult("JobNumber", "mismatch", None, sfm.job_number)) out.append(FieldResult("Channels", "match" if ref.channels == sfm.channels else "mismatch", " ".join(ref.channels), " ".join(sfm.channels))) if ref.sample_rows is not None: diff --git a/minimateplus/event_file_io.py b/minimateplus/event_file_io.py index 7907e29..dd486b3 100644 --- a/minimateplus/event_file_io.py +++ b/minimateplus/event_file_io.py @@ -996,8 +996,29 @@ def _setup_notes(raw: bytes) -> ProjectInfo: text = [p.decode("ascii", errors="replace").strip() or None for p in parts] text += [None] * (2 + 2 * _NOTE_SLOTS - len(text)) project, client, operator, location = text[2:2 + 2 * _NOTE_SLOTS:2] + enabled, number = _setup_job_number(raw, k) return ProjectInfo(setup_name=text[0], project=project, client=client, - operator=operator, sensor_location=location) + operator=operator, sensor_location=location, + job_number_enabled=enabled, job_number=number) + + +# The job number, in Series IV's 0x1A layout ([39] report flags, [40:42] the +# number): flags at k - 9, bit 0x02 = shown; the number, uint16 BE, at k - 8, +# kept while switched off. The flag matches Blastware's JobNumber on 2,997 / +# 2,997 DL2 events that print one and 66,986 / 66,986 that don't, and every +# printed value matches (all are 1; measured 2026-11-02). +_REPORT_FLAGS_BEFORE_NAME = 9 +_JOB_NUMBER_BEFORE_NAME = 8 +_JOB_NUMBER_ON = 0x02 + + +def _setup_job_number(raw: bytes, k: int) -> tuple[Optional[bool], Optional[int]]: + """(shown, number) from the setup block whose name starts at k.""" + if k < _REPORT_FLAGS_BEFORE_NAME: + return None, None + flags = raw[k - _REPORT_FLAGS_BEFORE_NAME] + j = k - _JOB_NUMBER_BEFORE_NAME + return bool(flags & _JOB_NUMBER_ON), int.from_bytes(raw[j:j + 2], "big") # The geophone range sits in the setup's channel blocks, which follow the diff --git a/minimateplus/models.py b/minimateplus/models.py index 81eb9ea..6096342 100644 --- a/minimateplus/models.py +++ b/minimateplus/models.py @@ -379,6 +379,8 @@ class ProjectInfo: operator: Optional[str] = None # operator / user name sensor_location: Optional[str] = None # sensor location string notes: Optional[str] = None # extended notes + job_number_enabled: Optional[bool] = None # Blastware prints the job number + job_number: Optional[int] = None # kept while switched off # ── Compliance Config ────────────────────────────────────────────────────────── diff --git a/sfm/event_hdf5.py b/sfm/event_hdf5.py index bde0e28..f8c3a4e 100644 --- a/sfm/event_hdf5.py +++ b/sfm/event_hdf5.py @@ -32,6 +32,8 @@ Layout written to `.h5`: client str operator str sensor_location str + job_number int (only when read; kept while not shown) + job_number_enabled bool (Blastware prints the job number) peak_tran_ips float (from 0C; authoritative) peak_vert_ips float peak_long_ips float @@ -257,6 +259,9 @@ def write_event_hdf5( attrs["client"] = (pi.client if pi else "") or "" attrs["operator"] = (pi.operator if pi else "") or "" attrs["sensor_location"] = (pi.sensor_location if pi else "") or "" + 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) 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) diff --git a/tests/fixtures/job-number-11-02-26/K557I55Y.I20H b/tests/fixtures/job-number-11-02-26/K557I55Y.I20H new file mode 100755 index 0000000..f56537a Binary files /dev/null and b/tests/fixtures/job-number-11-02-26/K557I55Y.I20H differ diff --git a/tests/fixtures/job-number-11-02-26/K557I55Y_I20H_XML.XML b/tests/fixtures/job-number-11-02-26/K557I55Y_I20H_XML.XML new file mode 100755 index 0000000..9d649bd --- /dev/null +++ b/tests/fixtures/job-number-11-02-26/K557I55Y_I20H_XML.XML @@ -0,0 +1,116 @@ + + +8.0 +Full Histogram +BE9557 +V 10.72-8.17 MiniMate Plus +K557I55Y.I20H +12:54:02 +2019-10-07 +12:54:28 +2019-10-07 + +Tran +Vert +Long +MicL + +1.00 +1 minute +1024 sps +6.4 Volts +January 18, 2019 by Instantel +in/s and dB(L) +Landmark - The Standard - Atherton Hotel +Landmark Constructors +Terra-Mechanics, Inc. - D. Bartholomae +Loc 2- Atherton Hotel - 125 S. Atherton + +10.000 +in/s + + +0.425 +in/s + + +0.010 +in/s + + +0.485 +in/s + + +>100 +Hz + + +>100 +Hz + + +>100 +Hz + +12:54:28 +2019-10-07 +12:54:28 +2019-10-07 +12:54:28 +2019-10-07 + +0.645 +in/s + +12:54:28 +2019-10-07 +Linear Weighting + +91.5 +dB(L) + +12:54:28 +2019-10-07 + +>100 +Hz + +7.9 Hz. +3.4 +Passed +7.4 Hz. +3.7 +Passed +7.7 Hz. +3.9 +Passed +20.1 Hz. +585 mv +Passed + + +2019-10-07 12:54:01 - 2019-10-07 12:54:28 "Event Recorded Modem Exit" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.425>1000.010>1000.485>1000.6450.00091.48>100 + + + + + + diff --git a/tests/fixtures/job-number-11-02-26/T438I4V5.DJ0H b/tests/fixtures/job-number-11-02-26/T438I4V5.DJ0H new file mode 100755 index 0000000..9b25a40 Binary files /dev/null and b/tests/fixtures/job-number-11-02-26/T438I4V5.DJ0H differ diff --git a/tests/fixtures/job-number-11-02-26/T438I4V5_DJ0H_XML.XML b/tests/fixtures/job-number-11-02-26/T438I4V5_DJ0H_XML.XML new file mode 100755 index 0000000..03c6b02 --- /dev/null +++ b/tests/fixtures/job-number-11-02-26/T438I4V5_DJ0H_XML.XML @@ -0,0 +1,117 @@ + + +8.0 +Full Histogram +BE18438 +V 10.72-8.17 MiniMate Plus +T438I4V5.DJ0H +16:48:55 +2019-10-01 +16:48:57 +2019-10-01 + +Tran +Vert +Long +MicL + +1.00 +1 minute +1024 sps +6.8 Volts +September 3, 2019 by Instantel +in/s and dB(L) +1 +Univ of Pitt - Scaife Hall-UPMC - Loc 2 +P J Dick, Inc. +Terra-Mechanics, Inc. - D. Harrison +Unit #2 - Station #2 - Loc 2 + +10.000 +in/s + + +0.550 +in/s + + +1.335 +in/s + + +0.270 +in/s + + +N/A +Hz + + +N/A +Hz + + +N/A +Hz + +16:48:57 +2019-10-01 +16:48:57 +2019-10-01 +16:48:57 +2019-10-01 + +1.394 +in/s + +16:48:57 +2019-10-01 +Linear Weighting + +114.4 +dB(L) + +16:48:57 +2019-10-01 + +51 +Hz + +7.5 Hz. +4.0 +Passed +7.5 Hz. +3.9 +Passed +7.6 Hz. +3.7 +Passed +0.0 Hz. +0 mv +Check + + +2019-10-01 16:48:54 - 2019-10-01 16:48:57 "Event Recorded Modem Exit" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.550N/A1.335N/A0.270N/A1.3940.002114.451 + + + + + + diff --git a/tests/test_bw_file_fields.py b/tests/test_bw_file_fields.py index fc57beb..1dc7b6a 100644 --- a/tests/test_bw_file_fields.py +++ b/tests/test_bw_file_fields.py @@ -276,3 +276,30 @@ def test_an_imported_file_and_the_backfill_store_its_range(tmp_path): "--db-path", str(tmp_path / "seismo_relay.db"), "--force"]) == 0 with h5py.File(h5, "r") as f: assert f.attrs["geo_range"] == "sensitive" + + +# ── The job number ────────────────────────────────────────────────────────── +# Series IV's 0x1A layout again: report flags at k - 9 (bit 0x02 = job number +# shown) and the number, uint16 BE, at k - 8, kept while switched off. The flag +# matches Blastware's JobNumber on 2,997 / 2,997 DL2 events that print one and +# 66,986 / 66,986 that don't (measured 2026-11-02). Every printed value is 1; +# hidden ones hold real numbers (802, 1012, 1013, 622). + +@pytest.mark.parametrize("rel,enabled,number", [ + ("decode-checker-10-29-26/T1905KDW.5F0W", True, 1), # XML JobNumber 1 + ("job-number-11-02-26/T438I4V5.DJ0H", True, 1), # histogram, XML JobNumber 1 + ("job-number-11-02-26/K557I55Y.I20H", False, 802), # no JobNumber in the XML + ("decode-checker-10-29-26/R352HFZ7.530H", False, 1), +]) +def test_job_number_comes_from_the_file(rel, enabled, number): + pi = read_blastware_file(_FIX / rel).project_info + assert (pi.job_number_enabled, pi.job_number) == (enabled, number) + + +def test_the_h5_carries_the_job_number(tmp_path): + import h5py + from sfm import event_hdf5 + ev = read_blastware_file(_FIX / "job-number-11-02-26/K557I55Y.I20H") + event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE9557") + with h5py.File(tmp_path / "e.h5", "r") as f: + assert (bool(f.attrs["job_number_enabled"]), int(f.attrs["job_number"])) == (False, 802) diff --git a/tests/test_decode_check.py b/tests/test_decode_check.py index d030611..b9848de 100644 --- a/tests/test_decode_check.py +++ b/tests/test_decode_check.py @@ -86,9 +86,8 @@ def test_an_extra_reference_row_is_a_mismatch_with_detail(): assert "row_length_disagreements=1" in res["samples.Tran"].detail -def test_job_number_na_and_above_range(): - res = _results("T1905KDW.5F0W") - assert res["JobNumber"].verdict == "sfm_blank" +def test_zc_frequency_na_and_above_range(): + res = _results("T1905KDW.5F0W") # its JobNumber: test_the_job_number_matches_blastware assert res["TranZCFreq"].verdict == "no_reference" # N/A assert res["VertZCFreq"].verdict == "sfm_blank" # >100, SFM has no flag yet @@ -172,3 +171,19 @@ def test_a_sensitive_range_event_now_matches(): for f in ("GeoRange", "TranPPV", "VertPPV", "LongPPV", "PeakVectorSum", "samples.Tran", "samples.Vert", "samples.Long"): assert res[f].verdict == "match", (f, res[f]) + + +def test_the_job_number_matches_blastware(): + assert _results("T1905KDW.5F0W", CARVEOUTS)["JobNumber"].verdict == "match" + + +def test_a_hidden_job_number_is_not_reported(): + # Flag off: Blastware prints no JobNumber, and SFM's side reports none either. + assert sfm_side((FIX / "R352HFZ7.530H").read_bytes()).job_number is None + + +def test_a_job_number_only_sfm_shows_is_a_mismatch(): + side = sfm_side((FIX / "R352HFZ7.530H").read_bytes()) + side.job_number = "1" + res = {r.field: r for r in compare(side, parse_xml_report_file(FIX / "R352HFZ7_530H_XML.XML"))} + assert res["JobNumber"].verdict == "mismatch"