"""Instants where Sellette 4/5 corr deviate from a rolling local level (or a non-Target-issue sensor is rejected), not covered by an existing label.""" import csv, glob, json, statistics as st, sys D = 'labeling/auto/analyses/FLORIDA_2026-10-11T0945_2026-10-22T0315/work/existing.jsonl' labels = [json.loads(l) for l in open(D)] S, E = '2026-10-11T09:45Z', '2026-10-22T03:15Z' K = float(sys.argv[1]) if len(sys.argv) > 1 else 4 data = {} for f in sorted(glob.glob('data/FLORIDA/displacement/FLORIDA_advanced_*.csv')): for r in csv.DictReader(open(f)): t = r['time_utc'][:16].replace(' ', 'T') + 'Z' if not (S <= t <= E): continue data.setdefault(t, {})[r['sensor_name']] = r times = sorted(data) def cov(t, fam=None): return [l['id'] for l in labels if l['start'] < t < l['end'] or (l['start'] <= t <= l['end'])] flags = {} for s in ['Sellette 4', 'Sellette 5']: for c in ['corr_x', 'corr_y']: ser = [(t, float(data[t][s][c])) for t in times if s in data[t] and data[t][s][c] not in ('', None) and float(data[t][s]['error_value']) <= float(data[t][s]['error_threshold'])] vals = [v for _, v in ser] noise = st.median(abs(vals[i+1]-vals[i]) for i in range(len(vals)-1)) for i, (t, v) in enumerate(ser): nb = vals[max(0, i-8):i] + vals[i+1:i+9] d = (v - st.median(nb)) / noise if abs(d) > K: flags.setdefault(t, []).append(f"{s[-1]}{c[-1]}{d:+.0f}") for t in times: for s in ['p1_r', 'r1_r', 'Sellette 4', 'Sellette 5', 'Pont Ernen', 'Sellette 3']: r = data[t].get(s) if r and float(r['error_value']) > float(r['error_threshold']): flags.setdefault(t, []).append(f"{s}:REJ") for t in sorted(flags): c = [i for i in cov(t)] nonthermal = [i for i in c if next(l for l in labels if l['id']==i)['family'] != 'Thermal displacement'] print(t, ' '.join(flags[t]), '| covered by', ','.join(c) or 'NONE')