71 lines
4.0 KiB
Python
71 lines
4.0 KiB
Python
"""L'analyse Temperature, pour la vérifier (D-016) : le panneau DAILY_GPU_TEMPERATURE_LIMIT, puis la série du GPU.
|
|||
|
|
|
||
|
|
Usage : python3 src/temperature/all_analyses.py [CSV ou dossiers...] (défaut : data/WEISSHORN/ et data/NORDEND/)
|
||
|
|
Écrit out/<STATION>_temperature.html et l'ouvre. Documentation : docs/temperature/analyses/daily_gpu_temperature_limit.md
|
||
|
|
"""
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # src/ : paquets common, energy et temperature
|
||
|
|
from common.page import AUTOSCALE_Y_JS, ROOT, open_html # noqa: E402 (bascule seule sur .venv si plotly manque)
|
||
|
|
from common.stations import gaps, load_stations # noqa: E402
|
||
|
|
from plotly.subplots import make_subplots # noqa: E402
|
||
|
|
from energy.final import noon # noqa: E402 (points journaliers à midi UTC, D-019)
|
||
|
|
from temperature import day_color as dc, gpu_temperature_limit as gl # noqa: E402
|
||
|
|
|
||
|
|
METRIC = "sensor_GPU_deg_c"
|
||
|
|
STYLE = {"GREEN": ("#008300", "circle"), "RED": ("#d03b3b", "x"), None: ("#8c8c8c", "circle-open")} # couleurs d'Energy
|
||
|
|
|
||
|
|
|
||
|
|
def figure(station, series):
|
||
|
|
title = f"Analysis {gl.RULE['id']}"
|
||
|
|
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.08, subplot_titles=[title, METRIC])
|
||
|
|
group = dict(legendgroup=gl.RULE["id"], legendgrouptitle_text=title)
|
||
|
|
pts = dc.run(series)["points"]
|
||
|
|
x = [noon(p["t"].date()) for p in pts]
|
||
|
|
fig.add_scatter(x=x, y=[p["facts"].get("max_deg_c") for p in pts], name="max of the last 24 h", mode="lines",
|
||
|
|
line=dict(color="#52514e", width=1.5), hoverinfo="skip", row=1, col=1, **group)
|
||
|
|
# Limite tracée comme une courbe (un point par jour) : AUTOSCALE_Y_JS la garde visible au zoom (D-013).
|
||
|
|
fig.add_scatter(x=x, y=[gl.GPU_LIMIT_DEG_C] * len(x), name=f"limit {gl.GPU_LIMIT_DEG_C} °C", mode="lines",
|
||
|
|
hoverinfo="skip", line=dict(color=STYLE["RED"][0], dash="dash", width=1), row=1, col=1, **group)
|
||
|
|
for color, (c, symbol) in STYLE.items():
|
||
|
|
sel = [p for p in pts if p["facts"]["color"] == color]
|
||
|
|
if sel:
|
||
|
|
fig.add_scatter(x=[noon(p["t"].date()) for p in sel], y=[p["facts"].get("max_deg_c", 0) for p in sel],
|
||
|
|
name=color or "unknown", mode="markers", hovertemplate="%{text}<extra></extra>",
|
||
|
|
text=[f"{p['t']:%Y-%m-%d}<br>" + "<br>".join(f"{k}={v}" for k, v in p["facts"].items())
|
||
|
|
for p in sel],
|
||
|
|
marker=dict(color=c, symbol=symbol, size=9, line=dict(color="white", width=1)),
|
||
|
|
row=1, col=1, **group)
|
||
|
|
|
||
|
|
s = series[METRIC]
|
||
|
|
fig.add_scatter(x=sorted(s), y=[s[t] for t in sorted(s)], name=METRIC, line=dict(width=1), row=2, col=1,
|
||
|
|
legendgroup="mesures", legendgrouptitle_text="Mesures")
|
||
|
|
for a, b in gaps(s):
|
||
|
|
fig.add_vrect(x0=a, x1=b, fillcolor="gray", opacity=0.3, line_width=0, row=2, col=1)
|
||
|
|
fig.update_yaxes(title_text="°C")
|
||
|
|
fig.update_xaxes(showticklabels=True) # dates sous chaque graphique, pas seulement le dernier
|
||
|
|
fig.update_yaxes(fixedrange=True) # zoom horizontal seulement : l'ordonnée est recalée par AUTOSCALE_Y_JS
|
||
|
|
fig.update_layout(title=f"{station} : analysis {gl.RULE['id']}", height=700, legend=dict(groupclick="toggleitem"))
|
||
|
|
return fig
|
||
|
|
|
||
|
|
|
||
|
|
def main(paths):
|
||
|
|
"""Pour chaque station qui a la température du GPU : out/<STATION>_temperature.html. -> chemins écrits."""
|
||
|
|
(ROOT / "out").mkdir(exist_ok=True)
|
||
|
|
written = []
|
||
|
|
for station, series in sorted(load_stations(paths).items()):
|
||
|
|
if METRIC not in series:
|
||
|
|
print(f"{station} : ignorée, pas de {METRIC}")
|
||
|
|
continue
|
||
|
|
path = ROOT / "out" / f"{station}_temperature.html"
|
||
|
|
figure(station, series).write_html(
|
||
|
|
path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
|
||
|
|
print(path)
|
||
|
|
written.append(path)
|
||
|
|
return written
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
for p in main(sys.argv[1:] or [str(ROOT / "data" / d) for d in ("WEISSHORN", "NORDEND")]):
|
||
|
|
open_html(p)
|