41 lines
2.0 KiB
Python
41 lines
2.0 KiB
Python
"""Per instant: targets whose corr_x / corr_y jump against their local level (median of the 3 measurements on each side,
|
|
without the point), rejected sensors outside the always-rejected ones, and the labels covering the instant.
|
|
Usage: python3 scan.py START END [K]"""
|
|
import json, statistics, sys
|
|
sys.path.insert(0, "tools/scripts")
|
|
import data
|
|
|
|
A = "labeling/auto/analyses/NIEDERHORN_2026-10-11T0500_2026-10-21T1200/work/"
|
|
start, end = data.parse_time(sys.argv[1]), data.parse_time(sys.argv[2])
|
|
K = float(sys.argv[3]) if len(sys.argv) > 3 else 5
|
|
ALWAYS = {"e03", "e04", "e05", "e07", "e08", "e11", "e12"}
|
|
by = data.load("data/NIEDERHORN")
|
|
labels = [json.loads(l) for f in ("existing.jsonl", "spanning.jsonl") for l in open(A + f)]
|
|
for l in labels:
|
|
l["s"], l["e"] = data.parse_time(l["start"]), data.parse_time(l["end"])
|
|
|
|
dev = {} # t -> list of strings
|
|
rej = {}
|
|
for s, ms in by.items():
|
|
if s in ALWAYS:
|
|
continue
|
|
ms = [m for m in ms if start - __import__("datetime").timedelta(hours=6) <= m["t"] <= end]
|
|
for c in ("corr_x", "corr_y"):
|
|
v = [(m["t"], m[c]) for m in ms if m[c] is not None]
|
|
if len(v) < 8:
|
|
continue
|
|
diffs = [abs(v[i + 1][1] - v[i][1]) for i in range(len(v) - 1)]
|
|
noise = statistics.median(diffs) or 1e-9
|
|
for i, (t, x) in enumerate(v):
|
|
nb = [y for _, y in v[max(0, i - 3):i] + v[i + 1:i + 4]]
|
|
d = (x - statistics.median(nb)) / noise
|
|
if abs(d) >= K and start <= t <= end:
|
|
dev.setdefault(t, []).append(f"{s.replace('PWD_','').replace('_C09','')}:{c[-1]}{d:+.0f}")
|
|
for m in ms:
|
|
if data.rejected(m) and start <= m["t"] <= end:
|
|
rej.setdefault(m["t"], []).append(s.replace("PWD_", "").replace("_C09", ""))
|
|
|
|
for t in sorted(set(dev) | set(rej)):
|
|
cov = [l["id"].split("-")[1] + l["family"][:3] for l in labels if l["s"] <= t <= l["e"]]
|
|
print(data.iso(t), "| rej:", ",".join(rej.get(t, [])), "| dev:", " ".join(dev.get(t, [])), "| lab:", ",".join(cov))
|