29 lines
1.5 KiB
Python
29 lines
1.5 KiB
Python
"""Brief deviations of corr_x/corr_y against a rolling local median (+-N measurements), per instant,
|
|
with the labels (non-thermal) covering it. Usage: brief.py K N [labels.jsonl]"""
|
|
import sys, json, statistics
|
|
sys.path.insert(0, 'tools/scripts')
|
|
import data
|
|
K, N = float(sys.argv[1]), int(sys.argv[2])
|
|
lab = sys.argv[3] if len(sys.argv) > 3 else 'labeling/auto/analyses/NORDEND_2026-09-04T0615_2026-09-17T0545/work/existing.jsonl'
|
|
S, E = data.parse_time('2026-09-04T06:15Z'), data.parse_time('2026-09-17T05:45Z')
|
|
labels = [json.loads(l) for l in open(lab)]
|
|
nt = [(data.parse_time(l['start']), data.parse_time(l['end']), l.get('id', '?'), l['family']) for l in labels if l['family'] != 'Thermal displacement']
|
|
by = data.load('data/NORDEND')
|
|
hits = {}
|
|
for s, ms in by.items():
|
|
if s == 'PR04':
|
|
continue
|
|
ms = data.filter_window(ms, S, E)
|
|
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) < 20: continue
|
|
noise = statistics.median(abs(v[i+1][1]-v[i][1]) for i in range(len(v)-1)) or 1e-9
|
|
for i, (t, x) in enumerate(v):
|
|
nb = [w for _, w in v[max(0, i-N):i] + v[i+1:i+1+N]]
|
|
d = (x - statistics.median(nb)) / noise
|
|
if abs(d) >= K:
|
|
hits.setdefault(t, []).append(f"{s}:{c[-1]}{d:+.0f}")
|
|
for t in sorted(hits):
|
|
cov = [f"{i}" for a, b, i, f in nt if a <= t <= b]
|
|
print(data.iso(t), len(hits[t]), ' '.join(hits[t][:10]), '| covered:', ','.join(cov) or 'NONE')
|