Files
Support-Agent/labeling/auto/etiqueteur/WILDSTRUBEL_2026-09-01/outils/instants.py
T
maximeandClaude Opus 5.5 6fbd7510b7 Etiqueteur: October labels for 8 stations; its folder moves to labeling/auto/etiqueteur/, analyses and scripts versioned (D-126)
Labels for CLARIDEN, FLORIDA, JUNGFRAU (gaps 06-20.10, 26.10-01.11), LENZSPITZE,
NIEDERHORN, NORDEND, SNCF01, WILDSTRUBEL. Figures and tool outputs stay out of git.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 16:33:41 +01:00

55 lines
1.9 KiB
Python

"""Par instant du lot : cibles rejetées, cibles dont corr sort de > K bruits de leur niveau, références hors (rejetées).
Usage : python3 instants.py data/WILDSTRUBEL 2026-09-01 2026-09-06 [K]
"""
import csv, glob, sys, statistics as st
from collections import defaultdict
d, j0, j1 = sys.argv[1], sys.argv[2], sys.argv[3]
K = float(sys.argv[4]) if len(sys.argv) > 4 else 5
rows = []
for f in sorted(glob.glob(f"{d}/displacement/*_advanced_*.csv")):
day = f[-12:-4]
if not (j0.replace('-', '') <= day <= j1.replace('-', '')):
continue
rows += list(csv.DictReader(open(f)))
def q(t): # quart d'heure
h, m = t[11:13], int(t[14:16])
return f"{t[:10]}T{h}:{m - m % 15:02d}Z"
ser = defaultdict(list)
for r in rows:
ser[r['sensor_name']].append(r)
lvl = {}
for s, rs in ser.items():
for c in ('corr_x', 'corr_y'):
v = [float(r[c]) for r in rs if r[c] and float(r['error_value']) <= float(r['error_threshold'])]
if len(v) < 10:
continue
med = st.median(v)
noise = st.median(abs(a - b) for a, b in zip(v, v[1:])) or 1e-9
lvl[s, c] = (med, noise)
by_t = defaultdict(lambda: {'rej_c': [], 'rej_r': [], 'out': []})
for s, rs in ser.items():
for r in rs:
t = q(r['time_utc'])
rej = float(r['error_value']) > float(r['error_threshold'])
ref = r['pattern_type'] == 'global_ref'
if rej:
by_t[t]['rej_r' if ref else 'rej_c'].append(s)
continue
if ref:
continue
for c in ('corr_x', 'corr_y'):
if r[c] and (s, c) in lvl:
med, n = lvl[s, c]
z = (float(r[c]) - med) / n
if abs(z) > K:
by_t[t]['out'].append(f"{s}.{c[-1]}{z:+.0f}")
for t in sorted(by_t):
b = by_t[t]
if b['rej_c'] or b['out']:
print(t, '| cibles rej:', ','.join(b['rej_c']) or '-', '| corr:', ' '.join(b['out']) or '-', '| réf rej:', ','.join(b['rej_r']) or '-')