"""Bornes du cycle thermique de la caméra, jour par jour, lues sur le pan (creux du matin) et le corr_x de PR18. Lancer depuis la racine : python3 labeling/auto/etiqueteur/NORDEND_2026-10-01/outils/bornes_thermiques.py""" import csv, glob, statistics as st from datetime import datetime, timedelta D = "data/NORDEND" P = lambda s: datetime.fromisoformat(s[:19]).replace(second=0) cam = sorted((P(r["time_utc"]), float(r["median_pan"])) for f in glob.glob(f"{D}/camera/NORDEND_camera_2026*.csv") for r in csv.DictReader(open(f))) pr = {} for f in glob.glob(f"{D}/displacement/NORDEND_advanced_2026*.csv"): for r in csv.DictReader(open(f)): if r["sensor_name"] == "PR18" and r["corr_x"]: pr[P(r["time_utc"])] = float(r["corr_x"]) def niveau(L, d, h0=1, h1=5): v = [p for t, p in L if d + timedelta(hours=h0) <= t < d + timedelta(hours=h1)] return st.median(v) if v else None for k in range(1, 32): d = datetime(2026, 10, k) N, N2 = niveau(cam, d), niveau(cam, d + timedelta(days=1)) jour = [(t, p) for t, p in cam if d + timedelta(hours=5) <= t <= d + timedelta(hours=16)] if N is None or not jour: print(d.date(), "-"); continue tm, pm = min(jour, key=lambda a: a[1]) amp = N - pm avant = [t for t, p in cam if d + timedelta(hours=4) <= t < tm and p > N - 0.1 * amp] deb = max(avant) if avant else None N2 = N2 if N2 is not None else N apres = [t for t, p in cam if tm < t <= d + timedelta(hours=36) and p > N2 - 0.1 * (N2 - pm)] fin = min(apres) if apres else None # PR18 : creux de jour face à la nuit L = sorted(pr.items()) n18 = niveau(L, d) j18 = [(t, p) for t, p in L if d + timedelta(hours=5) <= t <= d + timedelta(hours=20)] s = "-" if n18 is not None and j18: t18, p18 = min(j18, key=lambda a: a[1]) a18 = p18 - n18 dd = [t for t, p in j18 if t <= t18 and p - n18 > 0.2 * a18] ff = [t for t, p in j18 if t > t18 and p - n18 > 0.2 * a18] s = f"PR18 {a18:+.3f} à {t18:%H:%M}, {max(dd):%H:%M}→{min(ff):%H:%M}" if dd and ff else f"PR18 {a18:+.3f}" print(f"{d.date()} pan nuit {N:+.4f} creux {amp:+.4f} à {tm:%H:%M} ; début {deb:%d %H:%M} fin {fin:%d %H:%M} ; {s}" if deb and fin else f"{d.date()} pan creux {amp:+.4f} à {tm:%H:%M} deb {deb} fin {fin} ; {s}")