Files
aimsight-labeling/auto/analyses/NORDEND_2026-10-13T0745_2026-10-24T1630/scripts/uncovered.py
T

36 lines
1.9 KiB
Python

"""Instants of the range where a sensor is rejected or its corr leaves a rolling level (±8 measurements) by more than K
noises, and that no label (labels.jsonl + spanning Target issue / Obstruction of that sensor) covers."""
import sys, os, json, pickle, statistics
sys.path.insert(0, "tools/scripts")
import data
H = os.path.join(os.path.dirname(__file__), "..")
D, CAM = pickle.load(open(os.path.join(H, "work", "cache.pkl"), "rb"))
K = float(sys.argv[1]) if len(sys.argv) > 1 else 8
P = data.parse_time
labs = [(P(d["start"]), P(d["end"]), None) for d in map(json.loads, open(os.path.join(H, "labels.jsonl"))) if d["family"] != "Thermal displacement"]
span = {"NORDEND-152": "PR04", "NORDEND-169": "PR17", "NORDEND-195": "CTR01"}
for d in map(json.loads, open(os.path.join(H, "work", "spanning.jsonl"))):
labs.append((P(d["start"]), P(d["end"]), span[d["id"]]))
s0, s1 = P("2026-10-13T07:45Z"), P("2026-10-24T16:30Z")
def covered(t, s):
return any(a < t < b or (a <= t <= b and False) for a, b, who in labs if who in (None, s))
hits = {}
for s, ms in D.items():
ms = data.filter_window(ms, s0, s1)
for col in ("corr_x", "corr_y"):
v = [m[col] for m in ms]
diffs = [abs(b - a) for a, b in zip(v, v[1:]) if a is not None and b is not None]
noise = statistics.median(diffs) if diffs else 0
for i, m in enumerate(ms):
t = m["t"].replace(second=0, microsecond=0)
if data.rejected(m):
if not covered(t, s): hits.setdefault(t, set()).add(s + " rej")
continue
nb = [x for x in v[max(0, i - 8):i] + v[i + 1:i + 9] if x is not None]
if len(nb) < 4 or noise == 0: continue
dev = (v[i] - statistics.median(nb)) / noise
if abs(dev) > K and not covered(t, s):
hits.setdefault(t, set()).add("%s.%s%+.0f" % (s, col[-1], dev))
for t in sorted(hits):
print(data.iso(t), " ".join(sorted(hits[t])))