Files
aimsight-labeling/auto/analyses/LENZSPITZE_2026-10-16T0235_2026-10-23T2355/scripts/neighbours.py
T

36 lines
1.7 KiB
Python
Raw Normal View History

"""Rolling deviation (median of 12 measurements each side, without the point) in own noises
(median |successive difference| over the window), at each instant of a window, for given sensors:
does the instant of a label stand out from its neighbours? Also counts, over the window, the
instants where |deviation| exceeds the value at the label instant.
Usage: .venv/bin/python neighbours.py START END LABEL_INSTANT SENSOR[,SENSOR...]|targets
"""
import sys, statistics
sys.path.insert(0, "tools/scripts")
import data
REFS = {"8002","8004","8011","8012","8013","8014","8017","8019","92H"}
s, e, at = (data.parse_time(x) for x in sys.argv[1:4])
d = data.load("data/LENZSPITZE")
names = [n for n in d if n not in REFS] if sys.argv[4] == "targets" else sys.argv[4].split(",")
rows = {}
for n in names:
for c in ("corr_x", "corr_y"):
ms = [(m["t"], m[c]) for m in d[n] if s <= m["t"] <= e and m[c] is not None]
if len(ms) < 30: continue
v = [x for _, x in ms]
noise = statistics.median(abs(a - b) for a, b in zip(v[1:], v[:-1]))
devs = []
for i, (t, x) in enumerate(ms):
nb = v[max(0, i-12):i] + v[i+1:i+13]
devs.append((t, (x - statistics.median(nb)) / noise))
k_at = [k for t, k in devs if t == at]
if not k_at: continue
k_at = k_at[0]
n_more = sum(1 for t, k in devs if t != at and abs(k) >= abs(k_at))
rows[(n, c)] = (k_at, n_more, len(devs))
top = sorted(rows.items(), key=lambda kv: -abs(kv[1][0]))[:10]
for (n, c), (k, nm, tot) in top:
print(f"{n:6s} {c}: {k:+.1f} noises at the label instant; {nm} other instants of {tot} at least as far")
# common-mode: number of targets beyond 5 at each instant
cnt = {}
for n in names:
pass