"""Weak thermal labels: per target (all but CTR02-04), deviation from the end-of-night level (3 h before the start), in noises, over the whole label outside the nested Visibility/Obstruction/No data labels: the hourly median (the cycle) and the largest single point.""" import json, statistics, sys ids = sys.argv[1:]; sys.argv = sys.argv[:1] exec(open("labeling/auto/analyses/NORDEND_2026-08-10T0115_2026-08-23T0515/scripts/requalify.py").read().rsplit("\nfor line in open", 1)[0]) labels = [json.loads(l) for l in open(f"{D}/work/requalify_input.jsonl")] nested = [(T(l["start"]), T(l["end"])) for l in labels if l["family"] != "Thermal displacement"] for L in labels: if L["id"] not in ids: continue a, b = T(L["start"]), T(L["end"]); hr, pt = [], [] for (s, c), pts in data.items(): if s in REFS or (c, s) not in noise: continue pre = [v for t, v in pts if a - timedelta(hours=3) <= t < a] if len(pre) < 3: continue m = statistics.median(pre); n = noise[(c, s)]; hours = defaultdict(list); w = [] for t, v in pts: if a <= t <= b and not any(x <= t <= y for x, y in nested): hours[t.replace(minute=0)].append(v - m); w.append((t, v - m)) if not w: continue h, d = max(((h, statistics.median(v)) for h, v in hours.items() if len(v) >= 2), key=lambda x: abs(x[1]), default=(a, 0)) hr.append((abs(d) / n, f"{s} {c[-1]} {d/n:+.1f}@{h:%d %H}h")) t1, d1 = max(w, key=lambda x: abs(x[1])); pt.append((abs(d1) / n, f"{s} {c[-1]} {d1/n:+.1f}@{t1:%d %H:%M}")) hr.sort(reverse=True); pt.sort(reverse=True) print(f"{L['id']} hourly: " + "; ".join(x for _, x in hr[:5]) + "\n points: " + "; ".join(x for _, x in pt[:5]))