Files
aimsight-optimizer/sessions/SNCF01_2026-10-14T0645_2026-10-22T1030_20261118T1350Z/tools/shimmer_hours.py
T

25 lines
1.5 KiB
Python

# Prints, per hour, the heat-shimmer statistics of visibility.heat_shimmer: share of sensors agitated >= RATIO, median agitation and median error_value ratio. Args: <station folder> <from> <to> [detectors dir]
import sys, statistics
from datetime import datetime, timezone, timedelta
from pathlib import Path
det = Path(sys.argv[4] if len(sys.argv) > 4 else "/home/maxime/aimsight-detectors") / "scripts"
sys.path[:0] = [str(det), "/home/maxime/aimsight-tools/scripts"]
from data import load
import visibility as v
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
a, b = day(sys.argv[2]), day(sys.argv[3])
ms = {s: k for s, x in load(sys.argv[1]).items() if (k := [m for m in x if a - timedelta(days=3) <= m["t"] < b])}
hours = {}
for s, x in ms.items():
ag = v._ratios([(q["t"], abs(q["corr_x"] - p["corr_x"]) + abs(q["corr_y"] - p["corr_y"]))
for p, q in zip(x, x[1:]) if p["corr_x"] is not None and q["corr_x"] is not None])
er = v._ratios([(m["t"], m["error_value"]) for m in x if m["error_value"] is not None])
for h in ag.keys() & er.keys():
hours.setdefault(h, {})[s] = (ag[h], er[h])
for h, r in sorted(hours.items()):
if h < a:
continue
sh = sum(x >= v.RATIO for x, _ in r.values()) / len(r)
print(h.strftime("%m-%d %H"), f"n={len(r):2d} share={sh:.2f} agit={statistics.median(x for x,_ in r.values()):.2f} err={statistics.median(e for _,e in r.values()):.2f}",
"TURB" if sh >= v.SHARE and statistics.median(e for _, e in r.values()) >= v.RATIO else "")