"""Thermal labels: hourly-median deviation of PR14-PR18 (the targets that carry the camera cycle) from their end-of-night level (3 h before the label start), in noises, over the first 12 h of the label, outside the nested Visibility/Obstruction labels.""" import json, statistics 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"] in ("Visibility", "Obstruction")] for L in labels: if L["family"] != "Thermal displacement": continue a, b = T(L["start"]), min(T(L["end"]), T(L["start"]) + timedelta(hours=12)) res = [] for s in ("PR14", "PR15", "PR16", "PR17", "PR18"): for c in ("corr_x", "corr_y"): pts = data[(s, c)] pre = [v for t, v in pts if a - timedelta(hours=3) <= t < a] if len(pre) < 3: continue m = statistics.median(pre); hours = defaultdict(list) 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) if not hours: continue h, d = max(((h, statistics.median(v)) for h, v in hours.items()), key=lambda x: abs(x[1])) res.append((abs(d) / noise[(c, s)], f"{s} {c[-1]} {d/noise[(c,s)]:+.1f}@{h:%d %H}h")) res.sort(reverse=True) print(f"{L['id']:12s} {L['start'][5:16]} " + "; ".join(x for _, x in res[:4]))