"""Per instant: pose, temperature, rejected sensors (outside the permanent ones), one-measurement spikes of corr. Usage: python3 instants.py data/NIEDERHORN START END [K]""" import sys, statistics sys.path.insert(0, "tools/scripts") import data from datetime import timedelta folder, start, end = sys.argv[1], data.parse_time(sys.argv[2]), data.parse_time(sys.argv[3]) K = float(sys.argv[4]) if len(sys.argv) > 4 else 5 PERM = {"e03", "e04", "e05", "e07", "e08", "e11", "e12"} M = data.load(folder) for v in M.values(): for m in v: m["t"] = m["t"].replace(second=0, microsecond=0) lo, hi = start - timedelta(hours=24), end + timedelta(hours=24) M = {s: [m for m in v if lo <= m["t"] <= hi] for s, v in M.items()} refs = {s for s, v in M.items() if data.is_reference(v)} cam = {p["t"]: p for p in data.load_camera(folder)} temp = dict(data.load_temperature(folder)) noise = {} for s, v in M.items(): for c in ("corr_x", "corr_y"): vals = [m[c] for m in v if m[c] is not None] d = [abs(b - a) for a, b in zip(vals, vals[1:])] noise[s, c] = statistics.median(d) if d else 0 times = sorted({m["t"] for v in M.values() for m in v if start <= m["t"] <= end}) idx = {s: {m["t"]: i for i, m in enumerate(v)} for s, v in M.items()} prev = None for t in times: p = cam.get(t, {}) th = t.replace(minute=0) tc = temp.get(th) rej = [s for s in sorted(M) if s not in PERM and t in idx[s] and data.rejected(M[s][idx[s][t]])] spikes = [] for s in sorted(M): if s in PERM or t not in idx[s]: continue i = idx[s][t]; v = M[s] for c in ("corr_x", "corr_y"): x = v[i][c] if x is None or noise[s, c] == 0: continue nb = [v[j][c] for j in (i - 1, i + 1) if 0 <= j < len(v) and v[j][c] is not None] if not nb: continue dev = (x - statistics.mean(nb)) / noise[s, c] if abs(dev) >= K: spikes.append(f"{s.replace('PWD_','').replace('_C09','')}:{c[-1]}{dev:+.0f}") gap = "" if prev is None or t - prev <= timedelta(minutes=61) else f" GAP({int((t-prev).total_seconds()//3600)-1})" prev = t f = lambda k, n: "" if p.get(k) is None else f"{p[k]:.{n}f}" print(f"{data.iso(t)}{gap} T={tc if tc is None else round(tc,1)} pan={f('pan',4)} tilt={f('tilt',4)} rot={f('rotation',4)} sc={f('scale',5)} s0={f('sigma0',4)}" f" | rej[{len(rej)}]: {','.join(r.replace('PWD_','').replace('_C09','') for r in rej)} | spikes: {' '.join(spikes)}")