Files
Support-Agent/labeling/auto/etiqueteur/JUNGFRAU_2026-10-06/outils/vue.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

104 lines
3.8 KiB
Python

"""Vue du lot : médiane des cibles corr_x/corr_y, cibles une à une, température, pose.
usage : .venv/bin/python vue.py DEBUT FIN SORTIE [--table]"""
import csv, glob, sys, statistics as st
from datetime import datetime, timedelta, timezone
import matplotlib; matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.dates as md
D = "data/JUNGFRAU"
deb = datetime.fromisoformat(sys.argv[1].replace("Z", "+00:00"))
fin = datetime.fromisoformat(sys.argv[2].replace("Z", "+00:00"))
out = sys.argv[3]
def t15(s):
t = datetime.fromisoformat(s)
return t.replace(second=0, microsecond=0, minute=t.minute // 15 * 15)
def jours(a, b):
d = a.date() - timedelta(days=1)
while d <= b.date():
yield d.strftime("%Y%m%d"), d.strftime("%Y_%m_%d")
d += timedelta(days=1)
rows = {} # (t, capteur) -> dict
for j, _ in jours(deb, fin):
for f in glob.glob(f"{D}/displacement/JUNGFRAU_advanced_{j}.csv"):
for r in csv.DictReader(open(f)):
t = t15(r["time_utc"])
if deb <= t <= fin:
rows[(t, r["sensor_name"])] = r
temps = sorted({t for t, _ in rows})
caps = sorted({c for _, c in rows})
cibles = [c for c in caps if not c.startswith("REF") and c != "PM_G"]
def val(t, c, k):
r = rows.get((t, c))
if not r or r[k] == "":
return None
return float(r[k])
# niveau de chaque cible sur le lot
niv = {}
for c in caps:
for k in ("corr_x", "corr_y"):
v = [val(t, c, k) for t in temps]
v = [x for x in v if x is not None]
niv[(c, k)] = st.median(v) if v else 0
def med(t, k):
v = [val(t, c, k) for c in cibles]
v = [x - niv[(c, k)] for x, c in zip(v, cibles) if x is not None]
return st.median(v) if v else None
temp = {}
for _, j in jours(deb, fin):
for f in glob.glob(f"{D}/metrics/JUNGFRAU_sensor_thermal_deg_c_{j}_*"):
for r in csv.DictReader(open(f)):
t = datetime.fromisoformat(r["time_utc"])
if r["metric"] and deb - timedelta(hours=1) <= t <= fin:
temp[t] = float(r["metric"])
cam = {}
for j, _ in jours(deb, fin):
for f in glob.glob(f"{D}/camera/JUNGFRAU_camera_{j}.csv"):
for r in csv.DictReader(open(f)):
t = t15(r["time_utc"])
if deb <= t <= fin:
cam[t] = (float(r["median_pan"]), float(r["median_tilt"]), float(r["median_scale"]))
fig, ax = plt.subplots(6, 1, figsize=(22, 20), sharex=True)
for k, a in zip(("corr_x", "corr_y"), ax[:2]):
a.plot(temps, [med(t, k) for t in temps], "k-", lw=1)
a.set_ylabel(f"médiane cibles {k}")
for k, a in zip(("corr_x", "corr_y"), ax[2:4]):
for c in cibles:
a.plot(temps, [(val(t, c, k) - niv[(c, k)]) if val(t, c, k) is not None else None for t in temps], lw=0.7, label=c)
a.set_ylabel(k + " par cible")
a.legend(ncol=6, fontsize=7)
ts = sorted(temp)
ax[4].plot(ts, [temp[t] for t in ts], "r.-")
ax[4].set_ylabel("sensor_thermal °C")
tc = sorted(cam)
ax[5].plot(tc, [cam[t][1] for t in tc], "g.-", ms=2)
ax[5].set_ylabel("tilt caméra")
for a in ax:
a.grid(alpha=.4)
a.xaxis.set_major_locator(md.HourLocator(byhour=[0, 6, 12, 18]))
a.xaxis.set_major_formatter(md.DateFormatter("%d/%m\n%Hh"))
fig.tight_layout()
nom = f"{out}/vue_{deb:%m%d%H%M}_{fin:%m%d%H%M}.png"
fig.savefig(nom, dpi=70)
print(nom)
if "--table" in sys.argv:
print("heure medX medY temp tilt n_cibles_corr")
for t in temps:
if t.minute % 30 and "--pas15" not in sys.argv:
continue
mx, my = med(t, "corr_x"), med(t, "corr_y")
tt = temp.get(t.replace(minute=0))
n = sum(val(t, c, "corr_y") is not None for c in cibles)
f = lambda x: " - " if x is None else f"{x:+.3f}"
print(t.strftime("%d/%m %H:%M"), f(mx), f(my), tt if tt is not None else "-",
f"{cam[t][1]:.4f}" if t in cam else "-", n)