66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# scripts/plot_temperature.py
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from datetime import timedelta
|
|
|
|
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
|
|
from meteo.dataset import load_raw_csv
|
|
|
|
|
|
CSV_PATH = Path("data/weather_minutely.csv")
|
|
OUTPUT_DIR = Path("figures")
|
|
|
|
|
|
def main() -> None:
|
|
if not CSV_PATH.exists():
|
|
print(f"⚠ Fichier introuvable : {CSV_PATH}")
|
|
print(" Assurez-vous d'avoir généré le dataset minuté.")
|
|
return
|
|
|
|
# Chargement du dataset minuté
|
|
df = load_raw_csv(CSV_PATH)
|
|
print(f"Dataset minuté chargé : {CSV_PATH}")
|
|
print(f" Lignes : {len(df)}")
|
|
print(f" Colonnes : {list(df.columns)}")
|
|
print(f" Période : {df.index[0]} → {df.index[-1]}")
|
|
print()
|
|
|
|
# On ne garde que les N derniers jours pour un premier graphique
|
|
last_n_days = 7
|
|
end = df.index.max()
|
|
start = end - pd.Timedelta(days=last_n_days)
|
|
df_slice = df.loc[start:end]
|
|
|
|
if df_slice.empty:
|
|
print("⚠ Aucun point dans l'intervalle choisi.")
|
|
return
|
|
|
|
# Moyenne horaire pour lisser un peu la courbe
|
|
df_hourly = df_slice.resample("1H").mean()
|
|
|
|
print(f"Intervalle tracé : {df_hourly.index[0]} → {df_hourly.index[-1]}")
|
|
print(f"Nombre de points (moyenne horaire) : {len(df_hourly)}")
|
|
|
|
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
output_path = OUTPUT_DIR / "temperature_last_7_days.png"
|
|
|
|
plt.figure()
|
|
plt.plot(df_hourly.index, df_hourly["temperature"])
|
|
plt.xlabel("Temps (UTC)")
|
|
plt.ylabel("Température (°C)")
|
|
plt.title("Température - Moyenne horaire sur les 7 derniers jours")
|
|
plt.grid(True)
|
|
plt.tight_layout()
|
|
plt.savefig(output_path, dpi=150)
|
|
print(f"✔ Figure sauvegardée dans : {output_path.resolve()}")
|
|
|
|
# Optionnel : afficher la fenêtre graphique si vous lancez ça depuis un environnement graphique
|
|
# plt.show()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|