Copie des agents de Support-Agent/API (sortie mail)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cbaab49d3f
commit
5e3faa47b4
49 files changed
+6662
No files matched your search
@@ -0,0 +1,80 @@
|
||||
"""Figure de présentation : panneaux caméra (tilt, pan, rotation), température, puis corr_y des cibles.
|
||||
|
||||
Usage : .venv/bin/python .claude/skills/presentation/figure-y.py data/STATION sortie.png DEBUT FIN --cam tilt,pan --temp --cibles A,B
|
||||
[--zone D/F ...] [--ligne T] [--toutes] (--toutes : corr_y de toutes les cibles, pour explorer)
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "agent-tools"))
|
||||
import matplotlib
|
||||
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.dates as mdates # noqa: E402
|
||||
import matplotlib.pyplot as plt # noqa: E402
|
||||
|
||||
from donnees import charger, charger_camera, charger_temperature, est_reference, filtrer, instant # noqa: E402
|
||||
|
||||
NOMS = {"tilt": "Tilt de la caméra (°)", "pan": "Pan de la caméra (°)", "rotation": "Rotation de la caméra (°)"}
|
||||
|
||||
|
||||
def coupee(points, trou_h=6):
|
||||
"""[(t, v)] -> listes x, y avec None aux trous de plus de trou_h heures (le trait ne relie pas le trou)."""
|
||||
xs, ys, prec = [], [], None
|
||||
for t, v in points:
|
||||
if prec and (t - prec).total_seconds() > trou_h * 3600:
|
||||
xs.append(prec)
|
||||
ys.append(None)
|
||||
xs.append(t)
|
||||
ys.append(v)
|
||||
prec = t
|
||||
return xs, [float("nan") if v is None else v for v in ys]
|
||||
|
||||
|
||||
a = argparse.ArgumentParser()
|
||||
a.add_argument("dossier")
|
||||
a.add_argument("sortie")
|
||||
a.add_argument("debut", type=instant)
|
||||
a.add_argument("fin", type=instant)
|
||||
a.add_argument("--cam", default="")
|
||||
a.add_argument("--temp", action="store_true")
|
||||
a.add_argument("--cibles", default="")
|
||||
a.add_argument("--toutes", action="store_true")
|
||||
a.add_argument("--zone", action="append", default=[])
|
||||
a.add_argument("--ligne", action="append", default=[])
|
||||
a.add_argument("--hauteur", type=float, default=6.4)
|
||||
o = a.parse_args()
|
||||
|
||||
mes = charger(o.dossier)
|
||||
cibles = [c for c in mes if not est_reference(mes[c])] if o.toutes else [c for c in o.cibles.split(",") if c]
|
||||
panneaux = [c for c in o.cam.split(",") if c] + (["temp"] if o.temp else []) + (["y"] if cibles else [])
|
||||
fig, axes = plt.subplots(len(panneaux), 1, figsize=(12.5, o.hauteur), sharex=True, squeeze=False,
|
||||
gridspec_kw={"height_ratios": [1] * (len(panneaux) - 1) + [2 if cibles else 1]})
|
||||
axes = axes[:, 0]
|
||||
cam = [p for p in charger_camera(o.dossier) if o.debut <= p["t"] <= o.fin]
|
||||
for ax, p in zip(axes, panneaux):
|
||||
if p in NOMS:
|
||||
ax.plot(*coupee([(q["t"], q[p]) for q in cam if q[p] is not None]), color="#444", lw=1.2)
|
||||
ax.set_ylabel(NOMS[p].replace(" (", "\n("), fontsize=10)
|
||||
elif p == "temp":
|
||||
ax.plot(*coupee([(t, v) for t, v in charger_temperature(o.dossier) if o.debut <= t <= o.fin]), color="#c0392b", lw=1.2)
|
||||
ax.set_ylabel("Température de\nla station (°C)", fontsize=10)
|
||||
else:
|
||||
for c in cibles:
|
||||
pts = [(m["t"], m["corr_y"]) for m in filtrer(mes[c], o.debut, o.fin) if m["corr_y"] is not None]
|
||||
ax.plot(*coupee(pts), lw=1.3, label=f"{c} (corr_y)")
|
||||
ax.set_ylabel("Déplacement vertical\ncorr_y (px)", fontsize=10)
|
||||
ax.legend(fontsize=8 if o.toutes else 10, ncol=4 if o.toutes else len(cibles), loc="best")
|
||||
for z in o.zone:
|
||||
d, f = z.split("/")
|
||||
ax.axvspan(instant(d), instant(f), color="#bbb", alpha=0.45, lw=0)
|
||||
for t in o.ligne:
|
||||
ax.axvline(instant(t), color="#333", ls="--", lw=1)
|
||||
ax.grid(alpha=0.3)
|
||||
axes[-1].set_xlim(o.debut, o.fin)
|
||||
axes[-1].xaxis.set_major_locator(mdates.DayLocator(interval=max(1, (o.fin - o.debut).days // 8)))
|
||||
axes[-1].xaxis.set_major_formatter(mdates.DateFormatter("%d.%m"))
|
||||
fig.tight_layout()
|
||||
fig.savefig(o.sortie, dpi=110)
|
||||
print(o.sortie)
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Montrer la cause qui se voit dans l'image (véhicule, obstacle, phares) : recadrages côte à côte,
|
||||
éclaircis, autour d'une cible marquée d'un cercle rouge.
|
||||
|
||||
.venv/bin/python .claude/skills/presentation/image-de-la-cause.py data/<STATION> <x> <y> <sortie.png> \
|
||||
<AAAAMMJJTHHMMZ>="<légende>" [<AAAAMMJJTHHMMZ>="<légende>" ...] [--demi 350]
|
||||
|
||||
x, y : pixel de la cible dans l'image entière (« centre du cadre » d'une vignette de vignettes.py).
|
||||
Une image par instant, prise dans <dossier>/images/<instant>_*.jpg ; mettre d'abord un instant sans la cause.
|
||||
"""
|
||||
import glob, os, sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import matplotlib; matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt, matplotlib.image as mi
|
||||
|
||||
args = sys.argv[1:]
|
||||
nommees = None # --cibles A,B : seulement ces noms écrits (les autres encombrent l'image) ; sans : tous
|
||||
if "--cibles" in args:
|
||||
i = args.index("--cibles"); nommees = set(args[i + 1].split(",")); del args[i:i + 2]
|
||||
demi = 350
|
||||
if "--demi" in args:
|
||||
i = args.index("--demi"); demi = int(args[i + 1]); del args[i:i + 2]
|
||||
dossier, x, y, sortie, *instants = args
|
||||
x, y = int(x), int(y)
|
||||
station = dossier.rstrip("/").split("/")[-1]
|
||||
|
||||
# le nom de chaque cible à sa position dans l'image (x, y de l'export, à la mesure la plus proche du premier instant)
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "agent-tools"))
|
||||
from donnees import charger # noqa: E402
|
||||
t0 = datetime.strptime(instants[0].partition("=")[0], "%Y%m%dT%H%MZ").replace(tzinfo=timezone.utc)
|
||||
positions = {}
|
||||
for capteur, ms in charger(dossier).items():
|
||||
if nommees is not None and capteur not in nommees:
|
||||
continue
|
||||
proches = [m for m in ms if m.get("x") is not None and m.get("y") is not None and abs(m["t"] - t0) <= timedelta(hours=2)]
|
||||
if proches:
|
||||
m = min(proches, key=lambda m: abs(m["t"] - t0))
|
||||
positions[capteur] = (m["x"], m["y"])
|
||||
|
||||
fig, axs = plt.subplots(1, len(instants), figsize=(4 * len(instants), 4.3), squeeze=False)
|
||||
for ax, inst in zip(axs[0], instants):
|
||||
k, _, lab = inst.partition("=")
|
||||
img = mi.imread(glob.glob(f"{dossier}/images/{k}_*.jpg")[0]).astype(float)
|
||||
y0, x0 = max(y - demi, 0), max(x - demi, 0)
|
||||
img = img[y0:y + demi, x0:x + demi]
|
||||
img = (img / img.max()) ** 0.45 # éclaircir les ombres, les scènes de nuit sont sombres
|
||||
ax.imshow(img, cmap="gray", vmin=0, vmax=1)
|
||||
ax.add_patch(plt.Circle((x - x0, y - y0), 28, fill=False, color="red", lw=1.5))
|
||||
for capteur, (cx, cy) in positions.items():
|
||||
if x0 <= cx < x0 + img.shape[1] and y0 <= cy < y0 + img.shape[0]:
|
||||
ax.text(cx - x0, cy - y0 - 22, capteur, color="yellow", fontsize=8, ha="center", va="bottom",
|
||||
bbox={"facecolor": "black", "alpha": 0.5, "pad": 1, "edgecolor": "none"})
|
||||
ax.set_title(lab, fontsize=11); ax.axis("off")
|
||||
fig.suptitle("Image éclaircie ; en jaune, le nom des cibles", fontsize=12) # pas de nom de station : il va au client
|
||||
fig.tight_layout(); fig.savefig(sortie, dpi=100); print(sortie)
|
||||
Reference in new issue
Block a user