Agent tools: reading tools moved to agent-tools/ (D-081)
The reading tools leave agents/diagnostic/outils/ for a root folder of their own; paths updated in skills, agents, detectors, scripts, case fiches, support/, contexts and CLAUDE.md; graphique, vignettes and gif find the repo root one level up; history keeps old paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb98818712
commit
56b93e9b82
55 files changed
+135
-127
No files matched your search
@@ -0,0 +1,92 @@
|
||||
"""Graphique PNG des séries d'un export « advanced », pour que l'agent de diagnostic les regarde.
|
||||
|
||||
Usage : .venv/bin/python agent-tools/graphique.py data/PS_DES_COUDRES/
|
||||
[--capteurs CAPTEUR_A,CAPTEUR_B] [--colonnes error_value,corr_x,corr_y] [--debut ...] [--fin ...]
|
||||
[--zone DEBUT/FIN ...] [--sortie DOSSIER]
|
||||
Un panneau par colonne, une courbe par capteur, heures UTC ; chaque --zone est grisée.
|
||||
Imprime le chemin du PNG (out/diagnostic/, ou --sortie : le dossier du rapport, pour une figure de preuve).
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
import matplotlib
|
||||
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.dates as mdates # noqa: E402
|
||||
import matplotlib.pyplot as plt # noqa: E402
|
||||
|
||||
from donnees import charger, est_reference, filtrer, instant # noqa: E402
|
||||
|
||||
RACINE = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
||||
COLONNES = ("error_value", "corr_x", "corr_y", "relative_x", "relative_y", "x", "y", "sigma0", "reproj_err")
|
||||
|
||||
|
||||
def zone(texte):
|
||||
"""'2026-10-13T01:00Z/2026-10-13T03:00Z' -> (début, fin)."""
|
||||
debut, sep, fin = texte.partition("/")
|
||||
if not sep:
|
||||
raise argparse.ArgumentTypeError(f"zone invalide : {texte!r} (ex. 2026-10-13T01:00Z/2026-10-13T03:00Z)")
|
||||
return instant(debut), instant(fin)
|
||||
|
||||
|
||||
def borne(t, defaut):
|
||||
return t.strftime("%Y%m%dT%H%MZ") if t else defaut
|
||||
|
||||
|
||||
def main():
|
||||
a = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
a.add_argument("dossier")
|
||||
a.add_argument("--capteurs", help="liste séparée par des virgules (défaut : tous)")
|
||||
a.add_argument("--colonnes", default="error_value,corr_x,corr_y")
|
||||
a.add_argument("--debut", type=instant)
|
||||
a.add_argument("--fin", type=instant)
|
||||
a.add_argument("--zone", type=zone, action="append", default=[], help="fenêtre à griser, DEBUT/FIN (répétable)")
|
||||
a.add_argument("--sortie", default=os.path.join(RACINE, "out", "diagnostic"), help="dossier du PNG")
|
||||
o = a.parse_args()
|
||||
|
||||
par = charger(o.dossier)
|
||||
if not par:
|
||||
sys.exit(f"Aucun export « advanced » dans {o.dossier} (voir inventaire.py).")
|
||||
noms = o.capteurs.split(",") if o.capteurs else sorted(par, key=lambda s: (not est_reference(par[s]), s))
|
||||
colonnes = o.colonnes.split(",")
|
||||
for demandes, connus, quoi in ((noms, par, "Capteurs"), (colonnes, COLONNES, "Colonnes")):
|
||||
absents = [x for x in demandes if x not in connus]
|
||||
if absents:
|
||||
sys.exit(f"{quoi} inconnus : {', '.join(absents)}. Connus : {', '.join(sorted(connus))}.")
|
||||
series = {s: filtrer(par[s], o.debut, o.fin) for s in noms}
|
||||
if not any(series.values()):
|
||||
sys.exit("Aucune mesure dans la fenêtre demandée.")
|
||||
vides = [c for c in colonnes if all(m[c] is None for s in noms for m in series[s])]
|
||||
if len(vides) == len(colonnes):
|
||||
sys.exit(f"Rien à tracer : {', '.join(colonnes)} vide(s) pour ces capteurs dans la fenêtre.")
|
||||
if vides:
|
||||
print(f"Panneaux vides (aucune valeur pour ces capteurs) : {', '.join(vides)}")
|
||||
|
||||
fig, axes = plt.subplots(len(colonnes), 1, sharex=True, figsize=(14, 3.2 * len(colonnes)), squeeze=False)
|
||||
tab20 = plt.get_cmap("tab20").colors
|
||||
couleurs = tab20[::2] + tab20[1::2] # teintes foncées d'abord : deux capteurs voisins ne partagent pas une teinte
|
||||
for ax, col in zip(axes[:, 0], colonnes):
|
||||
for i, s in enumerate(noms):
|
||||
ms = series[s] # une valeur vide devient NaN : la courbe s'interrompt au lieu de relier le trou
|
||||
ax.plot([m["t"] for m in ms], [float("nan") if m[col] is None else m[col] for m in ms], ".-", ms=2, lw=0.7,
|
||||
color=couleurs[i % len(couleurs)], label=s)
|
||||
for debut, fin in o.zone:
|
||||
ax.axvspan(debut, fin, color="0.85", zorder=0)
|
||||
ax.set_ylabel(col)
|
||||
ax.grid(alpha=0.3)
|
||||
axes[0, 0].legend(loc="upper left", bbox_to_anchor=(1.0, 1.0), fontsize=8)
|
||||
axes[-1, 0].xaxis.set_major_formatter(mdates.DateFormatter("%d/%m\n%H:%MZ"))
|
||||
station = os.path.basename(os.path.normpath(o.dossier))
|
||||
fig.suptitle(f"{station} : {', '.join(colonnes)} (heures UTC)")
|
||||
|
||||
os.makedirs(o.sortie, exist_ok=True)
|
||||
qui = "-".join(noms) if o.capteurs else "tous"
|
||||
sortie = os.path.join(o.sortie, f"{station}_{'-'.join(colonnes)}_{qui}_"
|
||||
f"{borne(o.debut, 'debut')}_{borne(o.fin, 'fin')}.png")
|
||||
fig.savefig(sortie, dpi=100, bbox_inches="tight")
|
||||
print(sortie)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user