# scripts/make_minutely_dataset.py from __future__ import annotations 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") OUTPUT_CSV_PATH = Path("data/weather_minutely.csv") def main() -> None: if not FORMATTED_CSV_PATH.exists(): print(f"⚠ Fichier formaté introuvable : {FORMATTED_CSV_PATH}") print(" Lancez d'abord : python -m scripts.format_raw_csv") return df_1s = load_raw_csv(FORMATTED_CSV_PATH) print(f"Fichier 1s chargé : {FORMATTED_CSV_PATH}") print(f" Lignes : {len(df_1s)}, colonnes : {list(df_1s.columns)}") 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: print(f"⚠ Coordonnées GPS invalides : {exc}") 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)..." ) add_solar_elevation_column( df_min, latitude=location.latitude, longitude=location.longitude, elevation_m=location.elevation_m, ) else: print( "ℹ 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") print(f"✔ Dataset minuté écrit dans : {OUTPUT_CSV_PATH.resolve()}") if __name__ == "__main__": main()