You've already forked donnees_meteo
Réorganisation
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# scripts/plot_lagged_correlations.py
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
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.variables import VARIABLES_BY_KEY
|
||||
from meteo.analysis import compute_lagged_correlation
|
||||
from meteo.plots import plot_lagged_correlation
|
||||
from meteo.correlation_presets import DEFAULT_LAGGED_PAIRS
|
||||
|
||||
|
||||
CSV_PATH = Path("data/weather_minutely.csv")
|
||||
DOC_DIR = Path(__file__).resolve().parent.parent
|
||||
OUTPUT_DIR = DOC_DIR / "figures" / "lagged_correlations"
|
||||
|
||||
|
||||
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()
|
||||
|
||||
for key_x, key_y in DEFAULT_LAGGED_PAIRS:
|
||||
var_x = VARIABLES_BY_KEY[key_x]
|
||||
var_y = VARIABLES_BY_KEY[key_y]
|
||||
|
||||
print(f"→ Corrélation décalée : {var_x.key} → {var_y.key}")
|
||||
|
||||
lag_df = compute_lagged_correlation(
|
||||
df=df,
|
||||
var_x=var_x,
|
||||
var_y=var_y,
|
||||
max_lag_minutes=360, # ± 6 heures
|
||||
step_minutes=10, # pas de 10 minutes
|
||||
method="pearson",
|
||||
)
|
||||
|
||||
filename = f"lagcorr_{var_x.key}_to_{var_y.key}.png"
|
||||
output_path = OUTPUT_DIR / filename
|
||||
|
||||
plot_lagged_correlation(
|
||||
lag_df=lag_df,
|
||||
var_x=var_x,
|
||||
var_y=var_y,
|
||||
output_path=output_path,
|
||||
)
|
||||
|
||||
print("✔ Graphiques de corrélation décalée générés.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,65 @@
|
||||
# scripts/plot_rolling_correlation_heatmap.py
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
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.variables import VARIABLES_BY_KEY
|
||||
from meteo.analysis import compute_rolling_correlations_for_pairs
|
||||
from meteo.plots import plot_rolling_correlation_heatmap
|
||||
from meteo.correlation_presets import DEFAULT_ROLLING_PAIRS
|
||||
|
||||
|
||||
CSV_PATH = Path("data/weather_minutely.csv")
|
||||
DOC_DIR = Path(__file__).resolve().parent.parent
|
||||
OUTPUT_PATH = DOC_DIR / "figures" / "rolling_correlations" / "rolling_correlation_heatmap.png"
|
||||
|
||||
WINDOW_MINUTES = 180 # 3 heures pour observer les tendances synoptiques
|
||||
STEP_MINUTES = 30 # on n'échantillonne qu'un point sur 30 minutes
|
||||
|
||||
|
||||
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()
|
||||
|
||||
pairs = [(VARIABLES_BY_KEY[a], VARIABLES_BY_KEY[b]) for a, b in DEFAULT_ROLLING_PAIRS]
|
||||
|
||||
rolling_df = compute_rolling_correlations_for_pairs(
|
||||
df=df,
|
||||
pairs=pairs,
|
||||
window_minutes=WINDOW_MINUTES,
|
||||
min_valid_fraction=0.7,
|
||||
step_minutes=STEP_MINUTES,
|
||||
method="pearson",
|
||||
)
|
||||
|
||||
if rolling_df.empty:
|
||||
print("⚠ Impossible de calculer les corrélations glissantes (données insuffisantes).")
|
||||
return
|
||||
|
||||
output_path = plot_rolling_correlation_heatmap(
|
||||
rolling_corr=rolling_df,
|
||||
output_path=OUTPUT_PATH,
|
||||
cmap="coolwarm",
|
||||
vmin=-1.0,
|
||||
vmax=1.0,
|
||||
)
|
||||
|
||||
print(f"✔ Heatmap de corrélations glissantes enregistrée : {output_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user