Files
T

45 lines
2.0 KiB
Python
Raw Normal View History

# Prints, for given UTC instants (and the measurement before and after), per sensor: error_value/threshold (r if rejected), and corr_x/corr_y deviation in noises from the median of the 4 measurements before.
# Usage: python3 instants.py <detectors dir> <station folder> 2026-09-25T12:15 [...]
import statistics
import sys
from pathlib import Path
det = Path(sys.argv[1]).resolve()
sys.path[:0] = [str(det / "scripts")]
import categories # noqa: E402,F401
from data import is_reference, iso, load # noqa: E402
from episodes import level, noise # noqa: E402
ms = load(sys.argv[2])
info = {}
for s, v in ms.items():
e = [m["error_value"] for m in v if m["error_value"] is not None]
med, mad = level(e) if len(e) >= 10 else (0, 1)
nz = {c: noise([m[c] for m in v if m[c] is not None]) for c in ("corr_x", "corr_y")}
info[s] = (v, med, mad, nz, is_reference(v))
times = sorted({m["t"] for v in ms.values() for m in v})
for want in sys.argv[3:]:
i = next(k for k, t in enumerate(times) if iso(t) >= want)
print(f"== {want}")
for t in times[max(0, i - 1):i + 2]:
row = []
for s in sorted(ms):
v, med, mad, nz, ref = info[s]
k = next((j for j, m in enumerate(v) if m["t"] == t), None)
if k is None:
row.append(f"{s}:-")
continue
m = v[k]
ev = m["error_value"]
r = "r" if ev is not None and m["error_threshold"] and ev > m["error_threshold"] else ""
z = f"{(ev - med) / mad:.0f}" if ev is not None else "?"
dv = ""
if not ref:
for c in ("corr_x", "corr_y"):
prev = [w[c] for w in v[max(0, k - 4):k] if w[c] is not None]
if m[c] is not None and prev and nz[c]:
dv += f"{(m[c] - statistics.median(prev)) / nz[c]:+.0f}"
else:
dv += "/."
row.append(f"{s}{'*' if ref else ''}:{z}{r}{('|' + dv) if dv else ''}")
print(iso(t)[5:16], " ".join(row))