49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""End-to-end IDFH ingest verification."""
|
|
from __future__ import annotations
|
|
import sys
|
|
import tempfile
|
|
import json
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(REPO))
|
|
|
|
from sfm.waveform_store import WaveformStore
|
|
|
|
|
|
def main():
|
|
idfh = REPO / "tests/fixtures/THORDATA_example/THORDATA_example/UPMC Presby/UM13981/UM13981_20220805075441.IDFH"
|
|
txt = idfh.parent / "TXT" / f"{idfh.name}.txt"
|
|
|
|
with tempfile.TemporaryDirectory() as td:
|
|
store = WaveformStore(Path(td))
|
|
ev, rec = store.save_imported_idf(
|
|
idfh.read_bytes(),
|
|
idfh,
|
|
idf_report_text=txt.read_text(errors="replace"),
|
|
)
|
|
print("=== save_imported_idf (IDFH) ===")
|
|
print(f" serial: {rec['serial']}")
|
|
print(f" filename: {rec['filename']}")
|
|
print(f" filesize: {rec['filesize']}")
|
|
print(f" h5: {rec['hdf5_filename']}") # expect None for histogram
|
|
print(f" sidecar: {rec['sidecar_filename']}")
|
|
print()
|
|
print("=== Event ===")
|
|
print(f" timestamp: {ev.timestamp}")
|
|
print(f" record_type: {ev.record_type}")
|
|
print(f" sample_rate: {ev.sample_rate}")
|
|
print()
|
|
# Inspect sidecar to confirm intervals were stashed
|
|
sc_path = Path(td) / "UM13981" / f"{idfh.name}.sfm.json"
|
|
sc = json.loads(sc_path.read_text())
|
|
intervals = sc.get("extensions", {}).get("idf_intervals", [])
|
|
print(f" sidecar intervals: {len(intervals)}")
|
|
if intervals:
|
|
print(f" first interval: {intervals[0]}")
|
|
print(f" last interval: {intervals[-1]}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|