fix(decode): histograms go to the histogram codec, and a loud interval no longer hides a short one
Three causes behind the histograms the checker found decoding wrongly: 1. The file decoder tried the waveform codec first, whatever the record type. It accepted BE9440 / BE9557 / BE17354's 2018 5 s histograms and returned ~5x too many 'samples' (K440HDXX.XH0H: SFM 44,504, Blastware 6,976). The codec now follows STRT[18] (0x46 / 0x0A on 70,041 / 70,041 DL2 files); only an unknown type falls back to trial order, and a chosen codec that fails is a decode problem rather than a silent switch. 2. The sub-minute layout check required each record's 'zero word' to be 0000. It is the high word of the interval's PVS squared, non-zero above 1.28 in/s, so a one-block histogram with a loud interval was not recognised (T193KR5M.X90H, K440HA3C.JM0H, R352HFZ7.530H decoded to nothing). The check is now the measured relation peak <= PVS <= sqrt(3) * peak, which holds on 34,502,955 / 34,502,955 DL2 sub-minute intervals. The no-terminal-tail trim uses the same test. Two test builders wrote PVS bytes no real record has (one still in the retracted little-endian layout); they now write peak^2 in the measured layout, and the retraction test keeps a legacy builder of its own. 3. Checker carve-out interval-count-is-duration: Blastware's Number of Intervals is (stop - start) / interval from the footer times, and its own interval table lists one block fewer when the unit never wrote the last minute. SFM matches the table (T193KSWP.FF0H: 2,880 vs 2,850). 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
99b6b315d6
commit
aec4a38473
12 files changed
+434
-29
No files matched your search
@@ -1170,18 +1170,37 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
# mode, synthetic test input), fall back to empty channels — the
|
||||
# rest of the event (timestamp, waveform_key, project strings) is
|
||||
# still recoverable and useful.
|
||||
decoded = decode_waveform_v2(body)
|
||||
# Discriminator for the timestamp logic below: a waveform (trigger) event
|
||||
# vs a histogram window. Keyed on the codec, not the filename — the
|
||||
# save_imported_bw path passes a tmp ".bw" name whose extension lies.
|
||||
is_waveform_body = decoded is not None
|
||||
if decoded is None:
|
||||
#
|
||||
# The record type comes from the bytes: STRT[18] (#41), 0x46 / 0x0A on
|
||||
# 70,041 / 70,041 DL2 files. It picks the codec. Trying the waveform codec
|
||||
# first handed it BE9440 / BE9557 / BE17354's 2018 5 s histograms, which it
|
||||
# accepted and returned ~5x too many "samples" for. Only an unknown type
|
||||
# falls back to the old trial order. The filename's last letter is only a
|
||||
# cross-check -- SFM's own downloads have no name, and a manual download's
|
||||
# (".QZ0") carries no type at all.
|
||||
type_byte = strt_raw[18]
|
||||
record_type = _RECORD_TYPE_BY_STRT.get(type_byte)
|
||||
problems = []
|
||||
if record_type is None:
|
||||
problems.append(f"unknown record type byte 0x{type_byte:02x} at STRT[18]")
|
||||
if record_type == "Histogram":
|
||||
decoded = decode_histogram_body(body)
|
||||
is_waveform_body = False
|
||||
elif record_type == "Waveform":
|
||||
decoded = decode_waveform_v2(body)
|
||||
is_waveform_body = True
|
||||
else:
|
||||
decoded = decode_waveform_v2(body)
|
||||
is_waveform_body = decoded is not None
|
||||
if decoded is None:
|
||||
decoded = decode_histogram_body(body)
|
||||
if decoded is None:
|
||||
log.warning(
|
||||
"%s: body codec failed to decode (body starts %s) — "
|
||||
"raw_samples will be empty", label, body[:8].hex(" "),
|
||||
)
|
||||
if record_type is not None:
|
||||
problems.append(f"the {record_type.lower()} codec could not decode the body")
|
||||
samples = {"Tran": [], "Vert": [], "Long": [], "MicL": []}
|
||||
else:
|
||||
samples = decoded_to_adc_counts(decoded)
|
||||
@@ -1190,13 +1209,8 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
ev = Event(index=-1)
|
||||
if strt_fields.get("waveform_key"):
|
||||
ev._waveform_key = bytes.fromhex(strt_fields["waveform_key"])
|
||||
# The record type comes from the bytes: STRT[18] (#41). The filename's
|
||||
# last letter is only a cross-check -- SFM's own downloads have no name,
|
||||
# and a manual download's (".QZ0") carries no type at all.
|
||||
type_byte = strt_raw[18]
|
||||
ev.record_type = _RECORD_TYPE_BY_STRT.get(type_byte)
|
||||
if ev.record_type is None:
|
||||
ev.decode_problems.append(f"unknown record type byte 0x{type_byte:02x} at STRT[18]")
|
||||
ev.record_type = record_type
|
||||
ev.decode_problems.extend(problems)
|
||||
named_type = derive_record_type_from_filename(name, default=None) if name else None
|
||||
if named_type is not None and ev.record_type is not None and named_type != ev.record_type:
|
||||
log.warning("%s: record type %s from the file disagrees with the filename's %s; "
|
||||
|
||||
Reference in new issue
Block a user