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>
112 lines
6.0 KiB
Python
112 lines
6.0 KiB
Python
"""Dérive des corr face à la pose de la caméra et à la température, BREITHORN, octobre 2026.
|
|
Lancer depuis la racine : .venv/bin/python labeling/auto/etiqueteur/BREITHORN_2026-10-01/outils/derive.py"""
|
|
import csv, glob, statistics as st
|
|
from datetime import datetime
|
|
import matplotlib
|
|
matplotlib.use("Agg")
|
|
import matplotlib.pyplot as plt
|
|
|
|
D = "data/BREITHORN"
|
|
OUT = "labeling/auto/etiqueteur/BREITHORN_2026-10-01"
|
|
T0, T1 = "2026-10-03", "2026-11-01T00:01"
|
|
|
|
def t(s):
|
|
return s[:16].replace(" ", "T")
|
|
|
|
mes = {} # capteur -> list of (t, x, y, err, thr, cx, cy, rx, ry)
|
|
for f in sorted(glob.glob(f"{D}/displacement/*.csv")):
|
|
for r in csv.DictReader(open(f)):
|
|
k = t(r["time_utc"])
|
|
if not (T0 <= k <= T1):
|
|
continue
|
|
fl = lambda c: float(r[c]) if r[c] not in ("", None) else None
|
|
err, thr = fl("error_value"), fl("error_threshold")
|
|
ok = err <= thr
|
|
mes.setdefault(r["sensor_name"], []).append(
|
|
(k, fl("x"), fl("y"), err, ok, fl("corr_x") if ok else None, fl("corr_y") if ok else None, fl("relative_x"), fl("relative_y")))
|
|
|
|
cam = {}
|
|
for f in sorted(glob.glob(f"{D}/camera/*.csv")):
|
|
for r in csv.DictReader(open(f)):
|
|
k = t(r["time_utc"])
|
|
if T0 <= k <= T1:
|
|
cam[k] = (float(r["median_pan"]), float(r["median_tilt"]), float(r["median_rotation"]), float(r["median_scale"]))
|
|
|
|
temp = {}
|
|
for f in sorted(glob.glob(f"{D}/metrics/*sensor_thermal_deg_c*.csv")):
|
|
for r in csv.DictReader(open(f)):
|
|
k = t(r["time_utc"])
|
|
if T0 <= k <= T1 and r["metric"]:
|
|
temp[k] = float(r["metric"])
|
|
|
|
def corr(a, b):
|
|
if len(a) < 10:
|
|
return float("nan")
|
|
ma, mb = st.mean(a), st.mean(b)
|
|
sa = sum((x - ma) ** 2 for x in a) ** .5
|
|
sb = sum((y - mb) ** 2 for y in b) ** .5
|
|
return sum((x - ma) * (y - mb) for x, y in zip(a, b)) / (sa * sb) if sa and sb else float("nan")
|
|
|
|
print("capteur x_img y_img | r(corr_x,tilt) r(corr_y,tilt) r(corr_x,rot) r(corr_y,rot) | corr_x début->fin corr_y début->fin (médianes 03-05/10 et 29-31/10)")
|
|
for s, L in sorted(mes.items()):
|
|
xs = [v for v in L if v[5] is not None and v[0] in cam]
|
|
tl = [cam[v[0]][1] for v in xs]
|
|
rt = [cam[v[0]][2] for v in xs]
|
|
cx = [v[5] for v in xs]; cy = [v[6] for v in xs]
|
|
deb = [v for v in xs if v[0] < "2026-10-06"]; fin = [v for v in xs if v[0] >= "2026-10-29"]
|
|
print(f"{s:9s} {st.median(v[1] for v in L):7.0f} {st.median(v[2] for v in L):7.0f} | {corr(cx,tl):6.2f} {corr(cy,tl):6.2f} {corr(cx,rt):6.2f} {corr(cy,rt):6.2f} | "
|
|
f"{st.median(v[5] for v in deb):+.3f}->{st.median(v[5] for v in fin):+.3f} {st.median(v[6] for v in deb):+.3f}->{st.median(v[6] for v in fin):+.3f}"
|
|
f" raw x {st.median(v[1] for v in deb):.2f}->{st.median(v[1] for v in fin):.2f} y {st.median(v[2] for v in deb):.2f}->{st.median(v[2] for v in fin):.2f}")
|
|
|
|
# température : médiane par jour, min, max
|
|
print("\njour T_thermal médiane min max ; tilt fin de jour ; rotation")
|
|
jours = sorted({k[:10] for k in temp})
|
|
for j in jours:
|
|
v = [temp[k] for k in temp if k.startswith(j)]
|
|
c = [cam[k] for k in cam if k.startswith(j)]
|
|
print(j, f"{st.median(v):5.1f} {min(v):5.1f} {max(v):5.1f}", f"{c[-1][1]:.4f} {c[-1][2]:.4f}" if c else "")
|
|
|
|
# figure : corr_x, corr_y des cibles qui dérivent et des autres, face à tilt, rotation, température
|
|
derivent = ["COLH20", "COLI20", "COLI21", "COLJ19", "POUI19", "POUI20"]
|
|
autres = ["POUH21", "COLI22", "COLH20'''", "COLI24", "POUI22", "POUI24"]
|
|
fig, ax = plt.subplots(6, 1, figsize=(14, 18), sharex=True)
|
|
tt = lambda ks: [datetime.fromisoformat(k) for k in ks]
|
|
for i, col in enumerate((5, 6)):
|
|
for grp, a in ((derivent, ax[i]), (autres, ax[2 + i])):
|
|
for s in grp:
|
|
L = [v for v in mes[s] if v[col] is not None]
|
|
m = st.median(v[col] for v in L)
|
|
a.plot(tt([v[0] for v in L]), [v[col] - m for v in L], ".-", ms=2, lw=.7, label=s)
|
|
a.set_ylabel(("corr_x", "corr_y")[i] + (" (dérivent)" if grp is derivent else " (autres)"))
|
|
a.legend(fontsize=7, ncol=6); a.grid(alpha=.3)
|
|
ks = sorted(cam)
|
|
ax[4].plot(tt(ks), [cam[k][1] for k in ks], "g.-", ms=2, label="tilt")
|
|
a2 = ax[4].twinx(); a2.plot(tt(ks), [cam[k][2] for k in ks], "r.-", ms=2, label="rotation"); a2.set_ylabel("rotation [deg]", color="r")
|
|
ax[4].set_ylabel("tilt [deg]", color="g"); ax[4].grid(alpha=.3)
|
|
kt = sorted(temp)
|
|
ax[5].plot(tt(kt), [temp[k] for k in kt], "k-", lw=.6); ax[5].set_ylabel("sensor_thermal [°C]"); ax[5].grid(alpha=.3)
|
|
fig.suptitle("BREITHORN : corr des cibles (moins leur médiane) face à la pose de la caméra et à la température")
|
|
fig.tight_layout(); p = f"{OUT}/derive-pose-temperature.png"; fig.savefig(p, dpi=80); print(p)
|
|
|
|
# Ajout après les précisions de l'expert : r avec pan, et nuages corr face à tilt, pan, rotation
|
|
print("\ncapteur r(corr_x,pan) r(corr_y,pan)")
|
|
for s in derivent + autres:
|
|
xs = [v for v in mes[s] if v[5] is not None and v[0] in cam]
|
|
print(f"{s:9s} {corr([v[5] for v in xs],[cam[v[0]][0] for v in xs]):6.2f} {corr([v[6] for v in xs],[cam[v[0]][0] for v in xs]):6.2f}")
|
|
fig, ax = plt.subplots(2, 3, figsize=(15, 8))
|
|
for i, col in enumerate((5, 6)):
|
|
for j, (pi, nom) in enumerate(((1, "tilt"), (0, "pan"), (2, "rotation"))):
|
|
a = ax[i][j]
|
|
for s in derivent:
|
|
L = [v for v in mes[s] if v[col] is not None and v[0] in cam]
|
|
m = st.median(v[col] for v in L)
|
|
a.plot([cam[v[0]][pi] for v in L], [v[col] - m for v in L], ".", ms=3, label=s)
|
|
L = [v for v in mes["POUH21"] if v[col] is not None and v[0] in cam]
|
|
m = st.median(v[col] for v in L)
|
|
a.plot([cam[v[0]][pi] for v in L], [v[col] - m for v in L], "k+", ms=4, label="POUH21 (témoin)")
|
|
a.set_xlabel(nom + " [deg]"); a.set_ylabel(("corr_x", "corr_y")[i]); a.grid(alpha=.3)
|
|
a.set_ylim(-0.3, 0.3)
|
|
ax[0][0].legend(fontsize=7)
|
|
fig.suptitle("BREITHORN 03-31/10 : corr des cibles qui dérivent (moins leur médiane) face à la pose de la caméra ; POUH21 en témoin")
|
|
fig.tight_layout(); p = f"{OUT}/derive-face-a-la-pose.png"; fig.savefig(p, dpi=75); print(p)
|