28 lines
1.8 KiB
Python
28 lines
1.8 KiB
Python
"""Every Slow drift episode on the benchmark: station, sensor, axis, kind (whole/piece), drift/ampl, steps, share of its instants in a Displacement label. Args: detectors_dir labels_dir data_dir"""
|
|||
|
|
import sys
|
||
|
|
from datetime import timedelta
|
||
|
|
from pathlib import Path
|
||
|
|
det, labdir, datadir = sys.argv[1:4]
|
||
|
|
sys.path.insert(0, str(Path(det) / "bench")); sys.path.insert(0, str(Path(det) / "scripts"))
|
||
|
|
import score, regression, displacement as D
|
||
|
|
from data import load, parse_time, iso
|
||
|
|
for path in sorted(Path(labdir).glob("*.jsonl")):
|
||
|
|
folder = Path(datadir) / path.stem
|
||
|
|
if not folder.is_dir(): continue
|
||
|
|
start, end = regression.label_range(path)
|
||
|
|
labels = score.read_labels(str(path), start, end)
|
||
|
|
h, b = parse_time(start) - score.HISTORY, parse_time(end)
|
||
|
|
ms = {s: k for s, v in load(str(folder)).items() if (k := [m for m in v if h <= m["t"] < b])}
|
||
|
|
for s, sm in sorted(ms.items()):
|
||
|
|
for col in ("corr_x", "corr_y"):
|
||
|
|
a = D._days(sm, col)
|
||
|
|
if len(a[0]) < 2: continue
|
||
|
|
ds, lv, ampl, sp = a
|
||
|
|
for kind, found in (("whole", D._whole(*a)), ("piece", D._pieces(*a) if not D._whole(*a) else [])):
|
||
|
|
for d, i, j in found:
|
||
|
|
st, en = iso(sp[i][0]), iso(sp[j][1])
|
||
|
|
steps = [round(abs(lv[k + 1] - lv[k]) / abs(d), 2) for k in range(i, j)]
|
||
|
|
gaps = [(ds[k + 1] - ds[k]).days for k in range(i, j)]
|
||
|
|
inst = sorted({iso(m["t"]) for m in sm if st <= iso(m["t"]) <= en and iso(m["t"]) >= start})
|
||
|
|
ok = sum(any(e["family"] == "Displacement" and e["start"] < t < e["end"] for e in labels) for t in inst)
|
||
|
|
print(f"{path.stem:11} {s:8} {col} {kind} {st[:10]}→{en[:10]} d/ampl={abs(d)/ampl:.1f} n={j-i+1} maxstep={max(steps)} steps={steps} gaps={gaps} disp={ok}/{len(inst)}")
|