23 lines
1.4 KiB
Python
23 lines
1.4 KiB
Python
"""One-measurement spikes (both neighbours on the same side, the smaller step > K own noises) and isolated rejections,
|
|
at instants no label (except Target issue) covers. usage: spikes.py LABELS K"""
|
|
import json, sys, statistics as st
|
|
sys.path.insert(0, 'tools/scripts')
|
|
import data
|
|
D = 'labeling/auto/analyses/NIEDERHORN_2026-10-21T1200_2026-11-01T0000/'
|
|
labels = [json.loads(l) for f in (sys.argv[1], D + 'work/spanning.jsonl') for l in open(f)]
|
|
K = float(sys.argv[2])
|
|
for l in labels:
|
|
l['s'], l['e'] = data.parse_time(l['start'][:-1]), data.parse_time(l['end'][:-1])
|
|
a, b = data.parse_time('2026-10-21T12:00'), data.parse_time('2026-11-01T00:00')
|
|
cov = lambda t: [l.get('id', '?') for l in labels if l['s'] < t < l['e'] and l['family'] != 'Target issue']
|
|
for s, ms in data.load('data/NIEDERHORN').items():
|
|
for c in ('corr_x', 'corr_y'):
|
|
v = [(m['t'].replace(second=0, microsecond=0), m[c]) for m in ms if m[c] is not None]
|
|
if len(v) < 50: continue
|
|
noise = st.median(abs(v[i + 1][1] - v[i][1]) for i in range(len(v) - 1)) or 1e-9
|
|
for i in range(1, len(v) - 1):
|
|
t, x = v[i]
|
|
d1, d2 = x - v[i - 1][1], x - v[i + 1][1]
|
|
if d1 * d2 > 0 and min(abs(d1), abs(d2)) > K * noise and a < t < b and not cov(t):
|
|
print(data.iso(t), s, c, f'{min(abs(d1), abs(d2)) / noise:.1f}', 'sign', '+' if d1 > 0 else '-')
|