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

29 lines
1.6 KiB
Python

"""Instants not covered by a label of LABELS (Thermal displacement ignored) where sensors jump: |corr - median of the
6 measurements before and 6 after| > K own noises, or rejected. Prints instants with >= N such sensors."""
import sys, json, statistics, datetime as dt
sys.path.insert(0, 'tools/scripts')
import data
L, K, N = sys.argv[1], float(sys.argv[2]), int(sys.argv[3])
P = lambda s: dt.datetime.strptime(s, '%Y-%m-%dT%H:%MZ').replace(tzinfo=dt.timezone.utc)
labs = [json.loads(l) for l in open(L)]
cov = [(P(d['start']), P(d['end'])) for d in labs if d['family'] != 'Thermal displacement']
A, B = P('2026-10-16T02:35Z'), P('2026-10-23T23:55Z')
S = data.load('data/LENZSPITZE')
hits = {}
for s, v in S.items():
v = [m for m in v if A - dt.timedelta(hours=2) <= m['t'] <= B + dt.timedelta(hours=2)]
for c in ('corr_x', 'corr_y'):
al = [m[c] for m in v if m[c] is not None]
nz = statistics.median([abs(al[i+1]-al[i]) for i in range(len(al)-1)])
for i, m in enumerate(v):
if not (A <= m['t'] <= B) or any(a < m['t'] < b for a, b in cov): continue
if data.rejected(m):
hits.setdefault(m['t'], set()).add(s + ':R'); continue
nb = [u[c] for u in v[max(0, i-6):i] + v[i+1:i+7] if u[c] is not None]
if m[c] is None or len(nb) < 6 or not nz: continue
d = (m[c] - statistics.median(nb)) / nz
if abs(d) > K: hits.setdefault(m['t'], set()).add('%s:%s%+.0f' % (s, c[-1], d))
for t in sorted(hits):
if len(hits[t]) >= N or any(h.endswith(':R') for h in hits[t]):
print(f"{t:%m-%d %H:%M}", ' '.join(sorted(hits[t])))