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>
65 lines
4.2 KiB
Python
65 lines
4.2 KiB
Python
"""Table par instant : médiane des cibles (corr - niveau propre), pose caméra, températures ; figure."""
|
|
import csv, glob, statistics as st, sys
|
|
from datetime import datetime
|
|
import matplotlib; matplotlib.use("Agg")
|
|
import matplotlib.pyplot as plt
|
|
|
|
D = "data/NEBRASKA"; OUT = "labeling/auto/etiqueteur/NEBRASKA_2026-10-01"
|
|
T0, T1 = "2026-10-03", "2026-11-01T00:01"
|
|
def t(s): return s[:16].replace(" ", "T")
|
|
|
|
rows = {} # instant -> capteur -> dict
|
|
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
|
|
rows.setdefault(k, {})[r["sensor_name"]] = r
|
|
cam = {}
|
|
for f in sorted(glob.glob(f"{D}/camera/*.csv")):
|
|
for r in csv.DictReader(open(f)):
|
|
cam[t(r["time_utc"])] = r
|
|
temp = {}
|
|
for s in ["A0", "CPU", "GPU", "PLL", "thermal"]:
|
|
for f in glob.glob(f"{D}/metrics/NEBRASKA_sensor_{s}_deg_c_*.csv"):
|
|
for r in csv.DictReader(open(f)):
|
|
if r["metric"]: temp.setdefault(t(r["time_utc"]), {})[s] = float(r["metric"])
|
|
|
|
inst = sorted(rows)
|
|
cibles = sorted({c for k in inst for c, r in rows[k].items() if r["pattern_type"] == "target"})
|
|
def val(r, c):
|
|
try: return float(r[c]) if float(r["error_value"]) <= float(r["error_threshold"]) and r[c] != "" else None
|
|
except ValueError: return None
|
|
niv = {(c, col): st.median([v for k in inst if c in rows[k] for v in [val(rows[k][c], col)] if v is not None])
|
|
for c in cibles for col in ("corr_x", "corr_y")}
|
|
# température : moyenne glissante 24 h centrée sur l'instant (heures disponibles)
|
|
def tmoy(k, s="A0", w=12):
|
|
h = datetime.fromisoformat(k)
|
|
vals = [v[s] for kk, v in temp.items() if s in v and abs((datetime.fromisoformat(kk) - h).total_seconds()) <= w * 3600]
|
|
return st.mean(vals) if vals else None
|
|
out = []
|
|
for k in inst:
|
|
mx = st.median([val(rows[k][c], "corr_x") - niv[(c, "corr_x")] for c in cibles if c in rows[k] and val(rows[k][c], "corr_x") is not None])
|
|
my = st.median([val(rows[k][c], "corr_y") - niv[(c, "corr_y")] for c in cibles if c in rows[k] and val(rows[k][c], "corr_y") is not None])
|
|
cm = cam.get(k, {})
|
|
out.append(dict(t=k, cx=mx, cy=my, pan=float(cm.get("median_pan") or "nan"), tilt=float(cm.get("median_tilt") or "nan"),
|
|
rot=float(cm.get("median_rotation") or "nan"), scale=float(cm.get("median_scale") or "nan"),
|
|
tA0=temp.get(k, {}).get("A0"), tA0_24=tmoy(k), tTh=temp.get(k, {}).get("thermal")))
|
|
with open(f"{OUT}/table.tsv", "w") as fo:
|
|
fo.write("t\tcx\tcy\tpan\ttilt\trot\tscale\tA0\tA0_24h\tthermal\n")
|
|
for o in out:
|
|
fo.write("\t".join(str(round(o[c], 5)) if isinstance(o[c], float) else str(o[c]) for c in ["t","cx","cy","pan","tilt","rot","scale","tA0","tA0_24","tTh"]) + "\n")
|
|
def corr(a, b):
|
|
p = [(x, y) for x, y in zip(a, b) if x is not None and y is not None and x == x and y == y]
|
|
return st.correlation([x for x, _ in p], [y for _, y in p]) if len(p) > 3 else None
|
|
for nom, sel in [("tout", out), ("avant 09.10 12h", [o for o in out if o["t"] < "2026-10-09T12"]), ("après", [o for o in out if o["t"] >= "2026-10-09T12"])]:
|
|
print(nom, {f"{a}~{b}": round(corr([o[a] for o in sel], [o[b] for o in sel]) or 0, 2)
|
|
for a in ("cx", "cy") for b in ("tilt", "pan", "rot", "scale", "tA0_24")}, "tilt~A0_24", round(corr([o["tilt"] for o in sel], [o["tA0_24"] for o in sel]), 2))
|
|
x = [datetime.fromisoformat(o["t"]) for o in out]
|
|
fig, ax = plt.subplots(6, 1, figsize=(14, 16), sharex=True)
|
|
for a, (c, lab) in zip(ax, [("cx", "médiane cibles corr_x"), ("cy", "médiane cibles corr_y"), ("tilt", "tilt"), ("pan", "pan"), ("rot", "rotation"), ("scale", "scale")]):
|
|
a.plot(x, [o[c] for o in out], ".-"); a.set_ylabel(lab); a.grid(alpha=.3)
|
|
a2 = ax[2].twinx(); a2.plot(x, [o["tA0_24"] for o in out], "r-"); a2.set_ylabel("A0 moy 24h (rouge)", color="r"); a2.invert_yaxis()
|
|
a3 = ax[0].twinx(); a3.plot(x, [o["tA0_24"] for o in out], "r-"); a3.invert_yaxis(); a3.set_ylabel("A0 24h inversée", color="r")
|
|
for a in ax: a.axvline(datetime.fromisoformat("2026-10-09T12:00"), color="k", ls=":")
|
|
fig.tight_layout(); fig.savefig(f"{OUT}/cibles_pose_temperature.png", dpi=80); print(f"{OUT}/cibles_pose_temperature.png")
|