40 lines
1.9 KiB
Python
40 lines
1.9 KiB
Python
"""Per-instant table of one column for chosen sensors, minus a level (median over --level T1/T2).
|
|||
|
|
usage: tab.py COL START END [--level T1/T2] [--sensors A,B] ; 'r' = rejected. Cache in work/."""
|
||
|
|
import sys, os, pickle, statistics
|
||
|
|
sys.path.insert(0, "tools/scripts")
|
||
|
|
import data
|
||
|
|
OUT = os.path.join(os.path.dirname(__file__), "..", "work", "cache.pkl")
|
||
|
|
if os.path.exists(OUT):
|
||
|
|
D, CAM = pickle.load(open(OUT, "rb"))
|
||
|
|
else:
|
||
|
|
allm = data.load("data/NORDEND")
|
||
|
|
s0, s1 = data.parse_time("2026-10-10T00:00Z"), data.parse_time("2026-10-28T00:00Z")
|
||
|
|
D = {s: data.filter_window(v, s0, s1) for s, v in allm.items()}
|
||
|
|
CAM = {p["t"].replace(second=0, microsecond=0): p for p in data.load_camera("data/NORDEND") if s0 <= p["t"] <= s1}
|
||
|
|
pickle.dump((D, CAM), open(OUT, "wb"))
|
||
|
|
a = sys.argv[1:]
|
||
|
|
col, st, en = a[0], data.parse_time(a[1]), data.parse_time(a[2])
|
||
|
|
opt = dict(zip(a[3::2], a[4::2]))
|
||
|
|
sens = opt.get("--sensors", ",".join(sorted(D, key=lambda s: (not s.startswith("CTR0") or s == "CTR01", s)))).split(",")
|
||
|
|
lv = {}
|
||
|
|
if "--level" in opt:
|
||
|
|
l0, l1 = map(data.parse_time, opt["--level"].split("/"))
|
||
|
|
for s in sens:
|
||
|
|
v = [m[col] for m in data.filter_window(D[s], l0, l1) if m[col] is not None and not data.rejected(m)]
|
||
|
|
lv[s] = statistics.median(v) if v else 0
|
||
|
|
rows = {}
|
||
|
|
for s in sens:
|
||
|
|
for m in data.filter_window(D[s], st, en):
|
||
|
|
t = m["t"].replace(second=0, microsecond=0)
|
||
|
|
if data.rejected(m) and col != "error_value":
|
||
|
|
c = "r"
|
||
|
|
elif m[col] is None:
|
||
|
|
c = "."
|
||
|
|
else:
|
||
|
|
c = "%.3f" % (m[col] - lv.get(s, 0)) + ("r" if data.rejected(m) else "")
|
||
|
|
rows.setdefault(t, {})[s] = c
|
||
|
|
print("time pan tilt " + " ".join("%6s" % s[-5:] for s in sens))
|
||
|
|
for t in sorted(rows):
|
||
|
|
p = CAM.get(t)
|
||
|
|
ps = "%6.3f %6.3f" % (p["pan"], p["tilt"]) if p and p["pan"] is not None else " - - "
|
||
|
|
print(t.strftime("%d %H:%M"), ps, " ".join("%6s" % rows[t].get(s, "") for s in sens))
|