35 lines
1.7 KiB
Python
35 lines
1.7 KiB
Python
"""Per instant, sensors whose corr deviates from their level in a reference window by more than K noises (r: rejected).
|
|||
|
|
Usage: python3 dev.py data/NIEDERHORN START END REF_START REF_END [K] [sensors,comma]"""
|
||
|
|
import sys, statistics
|
||
|
|
sys.path.insert(0, "tools/scripts")
|
||
|
|
import data
|
||
|
|
f, a, b, ra, rb = sys.argv[1], *map(data.parse_time, sys.argv[2:6])
|
||
|
|
K = float(sys.argv[6]) if len(sys.argv) > 6 else 5
|
||
|
|
only = set(sys.argv[7].split(",")) if len(sys.argv) > 7 else None
|
||
|
|
PERM = {"e03", "e04", "e05", "e07", "e08", "e11", "e12"}
|
||
|
|
M = data.load(f)
|
||
|
|
for v in M.values():
|
||
|
|
for m in v: m["t"] = m["t"].replace(second=0, microsecond=0)
|
||
|
|
lvl, noise = {}, {}
|
||
|
|
for s, v in M.items():
|
||
|
|
for c in ("corr_x", "corr_y"):
|
||
|
|
r = [m[c] for m in v if ra <= m["t"] <= rb and m[c] is not None]
|
||
|
|
allv = [m[c] for m in v if m[c] is not None]
|
||
|
|
d = [abs(y - x) for x, y in zip(allv, allv[1:])]
|
||
|
|
lvl[s, c] = statistics.median(r) if r else None
|
||
|
|
noise[s, c] = statistics.median(d) if d else 0
|
||
|
|
times = sorted({m["t"] for v in M.values() for m in v if a <= m["t"] <= b})
|
||
|
|
by = {s: {m["t"]: m for m in v} for s, v in M.items()}
|
||
|
|
short = lambda s: s.replace("PWD_", "").replace("_C09", "")
|
||
|
|
for t in times:
|
||
|
|
out = []
|
||
|
|
for s in sorted(M):
|
||
|
|
if s in PERM or (only and s not in only): continue
|
||
|
|
m = by[s].get(t)
|
||
|
|
if m is None: continue
|
||
|
|
if data.rejected(m): out.append(f"{short(s)}:r"); continue
|
||
|
|
for c in ("corr_x", "corr_y"):
|
||
|
|
if lvl[s, c] is None or not noise[s, c]: continue
|
||
|
|
d = (m[c] - lvl[s, c]) / noise[s, c]
|
||
|
|
if abs(d) >= K: out.append(f"{short(s)}:{c[-1]}{d:+.0f}")
|
||
|
|
print(data.iso(t), len(out), " ".join(out))
|