"""Per label: max deviation of each target's corr_x/corr_y (px and mm) from its level before the label, in its own noise. Level = median of the non-empty values in the LEVEL hours before start (night level for a thermal label). Noise = median |diff| of consecutive non-empty measurements over the whole range (as ranges.py).""" import sys, json, statistics as st from datetime import timedelta sys.path.insert(0, "tools/scripts") import data D = sys.argv[1]; LEVEL = float(sys.argv[2]) if len(sys.argv) > 2 else 3 S = data.load("data/FLORIDA/") T0, T1 = data.parse_time("2026-10-11T09:45Z"), data.parse_time("2026-10-22T03:15Z") targets = ["Sellette 4", "Sellette 5", "Massif 2", "Sellette 6"] noise = {} for s in targets: ms = data.filter_window(S[s], T0, T1) for c in ("corr_x", "corr_y", "corr_x_mm", "corr_y_mm"): v = [m[c] for m in ms if m[c] is not None] noise[s, c] = st.median(abs(a - b) for a, b in zip(v, v[1:])) if len(v) > 2 else None for line in open(D + "/work/requalify_input.jsonl"): L = json.loads(line); a, b = data.parse_time(L["start"]), data.parse_time(L["end"]) out = [] for s in targets: before = data.filter_window(S[s], a - timedelta(hours=LEVEL), a - timedelta(minutes=1)) inside = data.filter_window(S[s], a + timedelta(minutes=1), b - timedelta(minutes=1)) or data.filter_window(S[s], a, b) for c in ("corr_x", "corr_y"): lv = [m[c] for m in before if m[c] is not None] iv = [(m[c], m[c + "_mm"], m["t"]) for m in inside if m[c] is not None] if not lv or not iv or not noise[s, c]: continue l = st.median(lv); lmm = st.median([m[c + "_mm"] for m in before if m[c + "_mm"] is not None] or [0]) v, vmm, t = max(iv, key=lambda x: abs(x[0] - l)) k = (v - l) / noise[s, c] out.append((abs(k), f"{s} {c[-1]} {k:+.1f}n ({vmm - lmm if vmm is not None else float('nan'):+.1f}mm) @{data.iso(t)[11:16]}")) out.sort(reverse=True) print(L["id"], L["start"][5:16], L["end"][5:16], L["family"][:10], "|", "; ".join(x[1] for x in out[:4]))