Support: LENZSPITZE, métrique de qualité des points
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b1a20c40be
commit
d656d57650
27 files changed
+737
No files matched your search
@@ -0,0 +1,65 @@
|
||||
"""Métrique de qualité des points (error_value / error_threshold), médiane horaire, une ligne par point.
|
||||
Usage : .venv/bin/python support/2026-11-12_LENZSPITZE_metrique-qualite/figure.py"""
|
||||
import csv, glob, statistics
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
import matplotlib
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.dates as mdates
|
||||
from matplotlib.colors import ListedColormap, BoundaryNorm
|
||||
from matplotlib.patches import Patch
|
||||
import numpy as np
|
||||
|
||||
ICI = Path(__file__).parent
|
||||
REFS = {"ref", "global_ref"}
|
||||
val, kind = defaultdict(list), {}
|
||||
for f in sorted(glob.glob("data/LENZSPITZE/displacement/*.csv")):
|
||||
for r in csv.DictReader(open(f)):
|
||||
t = datetime.fromisoformat(r["time_utc"]).replace(minute=0, second=0, tzinfo=None)
|
||||
val[(r["sensor_name"], t)].append(float(r["error_value"]) / float(r["error_threshold"]))
|
||||
kind[r["sensor_name"]] = r["pattern_type"]
|
||||
|
||||
heures = sorted({t for _, t in val})
|
||||
h0, h1 = heures[0], heures[-1]
|
||||
grille = [h0 + timedelta(hours=i) for i in range(int((h1 - h0).total_seconds() // 3600) + 1)]
|
||||
cibles = sorted(s for s in kind if kind[s] not in REFS)
|
||||
refs = sorted(s for s in kind if kind[s] in REFS)
|
||||
lignes = cibles + refs
|
||||
M = np.full((len(lignes), len(grille)), np.nan)
|
||||
for i, s in enumerate(lignes):
|
||||
for j, t in enumerate(grille):
|
||||
if (s, t) in val:
|
||||
M[i, j] = statistics.median(val[(s, t)])
|
||||
|
||||
# ramp bleu (clair = bonne qualité) jusqu'au seuil, rouge au-dessus
|
||||
bleus = ["#cde2fb", "#9ec5f4", "#6da7ec", "#3987e5", "#256abf", "#104281"]
|
||||
cmap = ListedColormap(bleus); cmap.set_over("#d03b3b"); cmap.set_bad("#e6e6e6")
|
||||
norm = BoundaryNorm(np.linspace(0, 1, len(bleus) + 1), cmap.N)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(16, 10), dpi=150)
|
||||
x0, x1 = mdates.date2num(grille[0]), mdates.date2num(grille[-1] + timedelta(hours=1))
|
||||
im = ax.imshow(M, aspect="auto", interpolation="nearest", cmap=cmap, norm=norm,
|
||||
extent=[x0, x1, len(lignes) - 0.5, -0.5])
|
||||
ax.set_yticks(range(len(lignes)), lignes, fontsize=7)
|
||||
ax.axhline(len(cibles) - 0.5, color="black", lw=1.5)
|
||||
ax.text(x1, len(cibles) / 2, " cibles", va="center", rotation=90, fontsize=9)
|
||||
ax.text(x1, len(cibles) + len(refs) / 2, " références", va="center", rotation=90, fontsize=9)
|
||||
ax.xaxis.set_major_locator(mdates.DayLocator())
|
||||
ax.xaxis.set_major_formatter(mdates.DateFormatter("%d.%m"))
|
||||
ax.tick_params(axis="x", labelsize=8)
|
||||
ax.set_xlabel("Date (UTC)")
|
||||
ax.set_title("LENZSPITZE (Crissier), qualité de mesure des points : error_value / seuil, médiane horaire\n"
|
||||
f"{grille[0]:%d.%m.%Y %H:%M} au {grille[-1] + timedelta(hours=1):%d.%m.%Y %H:%M} UTC", fontsize=11)
|
||||
cb = fig.colorbar(im, ax=ax, extend="max", fraction=0.025, pad=0.03, ticks=[0, 0.25, 0.5, 0.75, 1])
|
||||
cb.set_label("error_value / seuil (au-dessus de 1, mesure jugée peu fiable)", fontsize=8)
|
||||
ax.legend(handles=[Patch(color="#d03b3b", label="au-dessus du seuil"), Patch(color="#e6e6e6", label="pas de mesure")],
|
||||
loc="upper left", bbox_to_anchor=(0, -0.06), ncol=2, fontsize=8, frameon=False)
|
||||
fig.tight_layout()
|
||||
fig.savefig(ICI / "metrique-qualite_LENZSPITZE.png")
|
||||
|
||||
# chiffres pour l'analyse : part des heures au-dessus du seuil, par point
|
||||
for s, row in zip(lignes, M):
|
||||
ok = row[~np.isnan(row)]
|
||||
print(f"{s:6} {kind[s] or '-':10} médiane {np.median(ok):.2f} heures>seuil {int((ok > 1).sum()):3}/{ok.size}")
|
||||
Reference in new issue
Block a user