1

Ajout des vues calendrier à l'étape 3

This commit is contained in:
Richard Dern 2025-11-19 22:35:03 +01:00
parent 79603b7c3e
commit 6a78dbb50d
8 changed files with 36 additions and 57 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -4,6 +4,8 @@ On peut désormais tracer nos premiers graphiques simples et bruts.
S'ils ne sont pas très instructifs par rapport à ce que nous fournissent Home Assistant et InfluxDB, ils nous permettent au moins de nous assurer que tout fonctionne, et que les données semblent cohérentes. S'ils ne sont pas très instructifs par rapport à ce que nous fournissent Home Assistant et InfluxDB, ils nous permettent au moins de nous assurer que tout fonctionne, et que les données semblent cohérentes.
Les fichiers CSV correspondant à chaque figure sont conservés dans `data/` dans ce dossier. Les fichiers CSV correspondant à chaque figure sont conservés dans `data/` dans ce dossier.
On se limite dans un premier temps aux 7 derniers jours.
```shell ```shell
python "docs/03 - Premiers graphiques/scripts/plot_basic_variables.py" python "docs/03 - Premiers graphiques/scripts/plot_basic_variables.py"
``` ```
@ -23,3 +25,24 @@ python "docs/03 - Premiers graphiques/scripts/plot_basic_variables.py"
![](figures/wind_direction_last_7_days.png) ![](figures/wind_direction_last_7_days.png)
![](figures/sun_elevation_last_7_days.png) ![](figures/sun_elevation_last_7_days.png)
## Vues calendrier
Les vues calendrier permettent de visualiser, jour par jour, les cumuls ou moyennes quotidiennes sur la dernière année complète disponible.
Les images générées sont stockées dans `figures/calendar/` et les CSV correspondants dans `data/calendar/`.
```shell
python "docs/03 - Premiers graphiques/scripts/plot_calendar_overview.py"
```
![](figures/calendar/calendar_rain_2025.png)
![](figures/calendar/calendar_temperature_2025.png)
![](figures/calendar/calendar_pressure_2025.png)
![](figures/calendar/calendar_illuminance_2025.png)
![](figures/calendar/calendar_wind_2025.png)
Ces vues, bien que simples en principe, mettent déjà mieux en évidence les fluctuations au cours du temps.

View File

@ -1,12 +1,16 @@
# scripts/plot_calendar_overview.py # docs/03 - Premiers graphiques/scripts/plot_calendar_overview.py
from __future__ import annotations from __future__ import annotations
from pathlib import Path from pathlib import Path
import sys
import calendar import calendar
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt
PROJECT_ROOT = Path(__file__).resolve().parents[3]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from meteo.dataset import load_raw_csv from meteo.dataset import load_raw_csv
from meteo.analysis import compute_daily_rainfall_totals from meteo.analysis import compute_daily_rainfall_totals
@ -14,8 +18,9 @@ from meteo.plots import export_plot_dataset, plot_calendar_heatmap, plot_weekday
from meteo.variables import VARIABLES_BY_KEY from meteo.variables import VARIABLES_BY_KEY
CSV_PATH = Path("data/weather_minutely.csv") DOC_DIR = Path(__file__).resolve().parent.parent
OUTPUT_DIR = Path("figures/calendar") CSV_PATH = PROJECT_ROOT / "data" / "weather_minutely.csv"
OUTPUT_DIR = DOC_DIR / "figures" / "calendar"
WEEKDAY_VARIABLE_KEYS = ["temperature", "humidity", "wind_speed", "illuminance"] WEEKDAY_VARIABLE_KEYS = ["temperature", "humidity", "wind_speed", "illuminance"]
@ -47,42 +52,6 @@ def compute_daily_mean(df: pd.DataFrame, column: str) -> pd.Series:
return df[column].resample("1D").mean() return df[column].resample("1D").mean()
def plot_combined_calendar(
matrices: dict[str, pd.DataFrame],
output_path: Path,
*,
title: str,
) -> None:
if not matrices:
return
combined_dataset = pd.concat(matrices, axis=1)
export_plot_dataset(combined_dataset, output_path)
n = len(matrices)
fig, axes = plt.subplots(n, 1, figsize=(14, 4 * n), sharex=True)
if n == 1:
axes = [axes]
for ax, (label, matrix) in zip(axes, matrices.items()):
data = matrix.to_numpy(dtype=float)
im = ax.imshow(data, aspect="auto", interpolation="nearest", cmap=matrix.attrs.get("cmap", "viridis"))
ax.set_xticks(np.arange(matrix.shape[1]))
ax.set_xticklabels(matrix.columns, rotation=90)
ax.set_yticks(np.arange(matrix.shape[0]))
ax.set_yticklabels(matrix.index)
ax.set_ylabel(label)
cbar = fig.colorbar(im, ax=ax)
if matrix.attrs.get("colorbar_label"):
cbar.set_label(matrix.attrs["colorbar_label"])
axes[-1].set_xlabel("Jour du mois")
fig.suptitle(title)
fig.tight_layout(rect=[0, 0, 1, 0.97])
fig.savefig(output_path, dpi=150)
plt.close(fig)
def main() -> None: def main() -> None:
if not CSV_PATH.exists(): if not CSV_PATH.exists():
print(f"⚠ Fichier introuvable : {CSV_PATH}") print(f"⚠ Fichier introuvable : {CSV_PATH}")
@ -136,11 +105,6 @@ def main() -> None:
) )
print(f"✔ Heatmap température {latest_year} : {temp_path}") print(f"✔ Heatmap température {latest_year} : {temp_path}")
matrices_for_combined = {
"Pluie (mm)": rain_matrix,
"Température (°C)": temp_matrix,
}
if "pressure" in df.columns: if "pressure" in df.columns:
daily_pressure = compute_daily_mean(df, "pressure") daily_pressure = compute_daily_mean(df, "pressure")
pressure_matrix = _format_calendar_matrix(daily_pressure, latest_year, "Pression (hPa)") pressure_matrix = _format_calendar_matrix(daily_pressure, latest_year, "Pression (hPa)")
@ -155,7 +119,6 @@ def main() -> None:
colorbar_label="hPa", colorbar_label="hPa",
) )
print(f"✔ Heatmap pression {latest_year} : {pressure_path}") print(f"✔ Heatmap pression {latest_year} : {pressure_path}")
matrices_for_combined["Pression (hPa)"] = pressure_matrix
if "illuminance" in df.columns: if "illuminance" in df.columns:
daily_lux = compute_daily_mean(df, "illuminance") daily_lux = compute_daily_mean(df, "illuminance")
@ -171,7 +134,6 @@ def main() -> None:
colorbar_label="lux", colorbar_label="lux",
) )
print(f"✔ Heatmap illuminance {latest_year} : {lux_path}") print(f"✔ Heatmap illuminance {latest_year} : {lux_path}")
matrices_for_combined["Illuminance (lux)"] = lux_matrix
if "wind_speed" in df.columns: if "wind_speed" in df.columns:
daily_wind = compute_daily_mean(df, "wind_speed") daily_wind = compute_daily_mean(df, "wind_speed")
@ -187,15 +149,6 @@ def main() -> None:
colorbar_label="km/h", colorbar_label="km/h",
) )
print(f"✔ Heatmap vent {latest_year} : {wind_path}") print(f"✔ Heatmap vent {latest_year} : {wind_path}")
matrices_for_combined["Vent (km/h)"] = wind_matrix
combined_path = OUTPUT_DIR / f"calendar_combined_{latest_year}.png"
plot_combined_calendar(
matrices=matrices_for_combined,
output_path=combined_path,
title=f"Calendrier combiné {latest_year}",
)
print(f"✔ Calendrier combiné : {combined_path}")
hourly = df[WEEKDAY_VARIABLE_KEYS].resample("1h").mean() hourly = df[WEEKDAY_VARIABLE_KEYS].resample("1h").mean()
weekday_stats = hourly.groupby(hourly.index.dayofweek).mean() weekday_stats = hourly.groupby(hourly.index.dayofweek).mean()

View File

@ -29,7 +29,10 @@ PLOT_SCRIPTS: tuple[PlotScript, ...] = (
"plot_basic_variables", "plot_basic_variables",
PROJECT_ROOT / "docs" / "03 - Premiers graphiques" / "scripts" / "plot_basic_variables.py", PROJECT_ROOT / "docs" / "03 - Premiers graphiques" / "scripts" / "plot_basic_variables.py",
), ),
PlotScript("plot_calendar_overview", PROJECT_ROOT / "scripts" / "plot_calendar_overview.py"), PlotScript(
"plot_calendar_overview",
PROJECT_ROOT / "docs" / "03 - Premiers graphiques" / "scripts" / "plot_calendar_overview.py",
),
PlotScript( PlotScript(
"plot_all_pairwise_scatter", "plot_all_pairwise_scatter",
PROJECT_ROOT / "docs" / "04 - Corrélations binaires" / "scripts" / "plot_all_pairwise_scatter.py", PROJECT_ROOT / "docs" / "04 - Corrélations binaires" / "scripts" / "plot_all_pairwise_scatter.py",