You've already forked donnees_meteo
Visualisations saisonnières et cumul de pluie
This commit is contained in:
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
from meteo.dataset import load_raw_csv, resample_to_minutes
|
||||
from meteo.config import StationLocation
|
||||
from meteo.solar import add_solar_elevation_column
|
||||
from meteo.season import add_season_column
|
||||
|
||||
|
||||
FORMATTED_CSV_PATH = Path("data/weather_filled_1s.csv")
|
||||
@@ -25,6 +26,7 @@ def main() -> None:
|
||||
df_min = resample_to_minutes(df_1s)
|
||||
print(f"Après resampling 60s : {len(df_min)} lignes")
|
||||
|
||||
hemisphere = "north"
|
||||
try:
|
||||
location = StationLocation.from_env(optional=True)
|
||||
except RuntimeError as exc:
|
||||
@@ -32,6 +34,7 @@ def main() -> None:
|
||||
location = None
|
||||
|
||||
if location is not None:
|
||||
hemisphere = "south" if location.latitude < 0 else "north"
|
||||
print(
|
||||
f"Ajout de l'élévation solaire (lat={location.latitude}, lon={location.longitude}, "
|
||||
f"alt={location.elevation_m} m)..."
|
||||
@@ -47,6 +50,9 @@ def main() -> None:
|
||||
"ℹ Coordonnées GPS non définies (STATION_LATITUDE / STATION_LONGITUDE). "
|
||||
"La colonne sun_elevation ne sera pas ajoutée."
|
||||
)
|
||||
print("ℹ Saison : hypothèse par défaut = hémisphère nord. Définissez STATION_LATITUDE pour adapter.")
|
||||
|
||||
add_season_column(df_min, hemisphere=hemisphere)
|
||||
|
||||
OUTPUT_CSV_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
df_min.to_csv(OUTPUT_CSV_PATH, index_label="time")
|
||||
|
||||
66
scripts/plot_seasonal_overview.py
Normal file
66
scripts/plot_seasonal_overview.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# scripts/plot_seasonal_overview.py
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from meteo.dataset import load_raw_csv
|
||||
from meteo.variables import VARIABLES_BY_KEY
|
||||
from meteo.analysis import compute_rainfall_by_season
|
||||
from meteo.plots import plot_seasonal_boxplots, plot_rainfall_by_season
|
||||
from meteo.season import sort_season_labels, SEASON_LABELS
|
||||
|
||||
|
||||
CSV_PATH = Path("data/weather_minutely.csv")
|
||||
OUTPUT_DIR = Path("figures/seasonal")
|
||||
|
||||
BOXPLOT_VARIABLES = ["temperature", "humidity", "pressure", "wind_speed"]
|
||||
|
||||
|
||||
def infer_season_order(df) -> list[str]:
|
||||
seasons = df["season"].dropna().unique()
|
||||
order = sort_season_labels(seasons, order=SEASON_LABELS)
|
||||
if not order:
|
||||
order = list(SEASON_LABELS)
|
||||
return order
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if not CSV_PATH.exists():
|
||||
print(f"⚠ Fichier introuvable : {CSV_PATH}")
|
||||
return
|
||||
|
||||
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()
|
||||
|
||||
if "season" not in df.columns:
|
||||
print("⚠ La colonne 'season' est absente. Relancez scripts.make_minutely_dataset.")
|
||||
return
|
||||
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
season_order = infer_season_order(df)
|
||||
print(f"Saisons détectées : {season_order}")
|
||||
|
||||
variables = [VARIABLES_BY_KEY[key] for key in BOXPLOT_VARIABLES]
|
||||
boxplot_path = OUTPUT_DIR / "seasonal_boxplots.png"
|
||||
plot_seasonal_boxplots(
|
||||
df=df,
|
||||
variables=variables,
|
||||
output_path=boxplot_path,
|
||||
season_order=season_order,
|
||||
title="Distribution des mesures par saison",
|
||||
)
|
||||
print(f"✔ Boxplots saisonniers : {boxplot_path}")
|
||||
|
||||
rainfall = compute_rainfall_by_season(df=df, rate_column="rain_rate", season_column="season")
|
||||
rainfall_path = OUTPUT_DIR / "rainfall_by_season.png"
|
||||
plot_rainfall_by_season(rainfall_df=rainfall, output_path=rainfall_path)
|
||||
print(f"✔ Pluie saisonnière : {rainfall_path}")
|
||||
|
||||
print("✔ Tous les graphiques saisonniers ont été générés.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user