Files
aimsight-optimizer/sessions/CLARIDEN_2026-10-01T0000_2026-11-01T0000_20261118T1219Z/tools/drift_all.py
T

24 lines
1.2 KiB
Python

# Per labelled station (benchmark range): the Slow drift episodes of displacement.drift (with 3 days of history) and the Displacement labels, to compare. Args: <detectors dir> <labels folder> <data folder> [STATION,...]
import sys, json
from datetime import timedelta
from pathlib import Path
det = Path(sys.argv[1]).resolve()
sys.path[:0] = [str(det / "bench"), str(det / "scripts")]
import score, regression, displacement as D
from data import load, parse_time
only = sys.argv[4].split(",") if len(sys.argv) > 4 else None
for path in sorted(Path(sys.argv[2]).glob("*.jsonl")):
st = path.stem
if only and st not in only:
continue
start, end = regression.label_range(path)
ms = load(str(Path(sys.argv[3]) / st))
h, b = parse_time(start) - timedelta(days=3), parse_time(end)
chunk = {s: k for s, v in ms.items() if (k := [m for m in v if h <= m["t"] < b])}
print(f"== {st} {start} → {end}")
for e in score.read_labels(str(path), start, end):
if e["family"] == "Displacement":
print(" LABEL", e["id"], e["start"], e["end"], e["description"][:90])
for e in D.drift(chunk):
print(" drift", e["start"], e["end"], e["sensors"][0], e["text"].split(": ")[1][:30])