Ajout des vues calendrier à l'étape 3
This commit is contained in:
parent
79603b7c3e
commit
6a78dbb50d
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 |
@ -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.
|
||||
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
|
||||
python "docs/03 - Premiers graphiques/scripts/plot_basic_variables.py"
|
||||
```
|
||||
@ -23,3 +25,24 @@ python "docs/03 - Premiers graphiques/scripts/plot_basic_variables.py"
|
||||

|
||||
|
||||

|
||||
|
||||
## 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"
|
||||
```
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Ces vues, bien que simples en principe, mettent déjà mieux en évidence les fluctuations au cours du temps.
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
# scripts/plot_calendar_overview.py
|
||||
# docs/03 - Premiers graphiques/scripts/plot_calendar_overview.py
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import calendar
|
||||
import numpy as np
|
||||
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.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
|
||||
|
||||
|
||||
CSV_PATH = Path("data/weather_minutely.csv")
|
||||
OUTPUT_DIR = Path("figures/calendar")
|
||||
DOC_DIR = Path(__file__).resolve().parent.parent
|
||||
CSV_PATH = PROJECT_ROOT / "data" / "weather_minutely.csv"
|
||||
OUTPUT_DIR = DOC_DIR / "figures" / "calendar"
|
||||
|
||||
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()
|
||||
|
||||
|
||||
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:
|
||||
if not CSV_PATH.exists():
|
||||
print(f"⚠ Fichier introuvable : {CSV_PATH}")
|
||||
@ -136,11 +105,6 @@ def main() -> None:
|
||||
)
|
||||
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:
|
||||
daily_pressure = compute_daily_mean(df, "pressure")
|
||||
pressure_matrix = _format_calendar_matrix(daily_pressure, latest_year, "Pression (hPa)")
|
||||
@ -155,7 +119,6 @@ def main() -> None:
|
||||
colorbar_label="hPa",
|
||||
)
|
||||
print(f"✔ Heatmap pression {latest_year} : {pressure_path}")
|
||||
matrices_for_combined["Pression (hPa)"] = pressure_matrix
|
||||
|
||||
if "illuminance" in df.columns:
|
||||
daily_lux = compute_daily_mean(df, "illuminance")
|
||||
@ -171,7 +134,6 @@ def main() -> None:
|
||||
colorbar_label="lux",
|
||||
)
|
||||
print(f"✔ Heatmap illuminance {latest_year} : {lux_path}")
|
||||
matrices_for_combined["Illuminance (lux)"] = lux_matrix
|
||||
|
||||
if "wind_speed" in df.columns:
|
||||
daily_wind = compute_daily_mean(df, "wind_speed")
|
||||
@ -187,15 +149,6 @@ def main() -> None:
|
||||
colorbar_label="km/h",
|
||||
)
|
||||
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()
|
||||
weekday_stats = hourly.groupby(hourly.index.dayofweek).mean()
|
||||
@ -29,7 +29,10 @@ PLOT_SCRIPTS: tuple[PlotScript, ...] = (
|
||||
"plot_basic_variables",
|
||||
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(
|
||||
"plot_all_pairwise_scatter",
|
||||
PROJECT_ROOT / "docs" / "04 - Corrélations binaires" / "scripts" / "plot_all_pairwise_scatter.py",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user