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

21 lines
1.1 KiB
Python
Raw Normal View History

# Prints, for some sensors of a station over [FROM, TO), each error_value with its MAD score and whether visibility.py counts it high (K_MAD and FACTOR). Args: <station folder> <from ISO> <to ISO> SENSOR...
import sys
from datetime import datetime
sys.path[:0] = ["/home/maxime/aimsight-detectors/scripts", "/home/maxime/aimsight-tools/scripts"]
from data import load # noqa: E402
from episodes import level # noqa: E402
import visibility as v # noqa: E402
folder, a, b, *sensors = sys.argv[1:]
a, b = (datetime.fromisoformat(x.replace("Z", "+00:00")) for x in (a, b))
ms = load(folder)
for s in sensors:
e = [m["error_value"] for m in ms[s] if m["error_value"] is not None]
med, mad = level(e)
print(s, f"median {med:.3g} MAD {mad:.3g} threshold {ms[s][0]['error_threshold']}")
for m in ms[s]:
if a <= m["t"] < b and m["error_value"] is not None:
x = m["error_value"]
high = x > med + v.K_MAD * mad and x > v.FACTOR * med
print(" ", m["t"].strftime("%m-%d %H:%M"), f"{x:.3g}", f"{(x - med) / mad:5.1f} MAD", "HIGH" if high else "")