| """Validate synthetic wildfire smoke & respiratory outcomes dataset.""" |
|
|
| from __future__ import annotations |
|
|
| from pathlib import Path |
|
|
| import matplotlib.pyplot as plt |
| import pandas as pd |
|
|
| SCENARIO_FILES = { |
| "savanna_fire_belt": "wildfire_savanna_fire_belt.csv", |
| "forest_clearing_burn": "wildfire_forest_clearing_burn.csv", |
| "urban_peri_urban_haze": "wildfire_urban_peri_urban_haze.csv", |
| } |
|
|
| COLORS = { |
| "savanna_fire_belt": "#e6550d", |
| "forest_clearing_burn": "#31a354", |
| "urban_peri_urban_haze": "#756bb1", |
| } |
|
|
|
|
| def load_data() -> pd.DataFrame: |
| frames = [] |
| for scenario, filename in SCENARIO_FILES.items(): |
| df = pd.read_csv(Path("data") / filename) |
| frames.append(df) |
| return pd.concat(frames, ignore_index=True) |
|
|
|
|
| def plot_validation(df: pd.DataFrame, output_path: Path) -> None: |
| fig, axes = plt.subplots(4, 2, figsize=(14, 16)) |
| axes = axes.flatten() |
|
|
| |
| for s in SCENARIO_FILES: |
| subset = df[df["scenario"] == s] |
| axes[0].hist(subset["pm25_total_ugm3"], bins=40, alpha=0.5, color=COLORS[s], label=s) |
| axes[0].set_title("PM2.5 Total Distribution by Scenario") |
| axes[0].set_xlabel("PM2.5 (µg/m³)") |
| axes[0].legend(fontsize=7) |
|
|
| |
| for s in SCENARIO_FILES: |
| subset = df[df["scenario"] == s] |
| monthly = subset.groupby("month")["pm25_total_ugm3"].mean() |
| axes[1].plot(monthly.index, monthly.values, marker="o", color=COLORS[s], label=s) |
| axes[1].set_title("Monthly PM2.5 Trend") |
| axes[1].set_xlabel("Month") |
| axes[1].set_ylabel("Mean PM2.5") |
| axes[1].legend(fontsize=7) |
|
|
| |
| symptom_cols = ["cough", "wheeze", "dyspnoea", "eye_irritation"] |
| symptom_rates = df.groupby("scenario")[symptom_cols].mean() * 100 |
| symptom_rates.plot(kind="bar", ax=axes[2]) |
| axes[2].set_title("Respiratory Symptom Prevalence (%)") |
| axes[2].set_ylabel("Percent") |
| axes[2].legend(fontsize=7) |
|
|
| |
| for s in SCENARIO_FILES: |
| subset = df[df["scenario"] == s] |
| axes[3].scatter( |
| subset["exposure_risk_score"], subset["ari_episode"], |
| s=6, alpha=0.1, color=COLORS[s], label=s, |
| ) |
| axes[3].set_title("Exposure Risk Score vs ARI Episode") |
| axes[3].set_xlabel("Exposure risk score") |
| axes[3].set_ylabel("ARI episode") |
| axes[3].legend(fontsize=7) |
|
|
| |
| for s in SCENARIO_FILES: |
| subset = df[df["scenario"] == s] |
| axes[4].hist(subset["vulnerability_index"], bins=20, alpha=0.5, color=COLORS[s], label=s) |
| axes[4].set_title("Vulnerability Index Distribution") |
| axes[4].set_xlabel("Vulnerability index") |
| axes[4].legend(fontsize=7) |
|
|
| |
| cascade_cols = ["ari_episode", "er_visit", "hospitalised", "mortality"] |
| cascade = df.groupby("scenario")[cascade_cols].mean() * 100 |
| cascade.plot(kind="bar", ax=axes[5]) |
| axes[5].set_title("Health Outcomes Cascade (%)") |
| axes[5].set_ylabel("Percent") |
| axes[5].legend(fontsize=7) |
|
|
| |
| aqi_counts = df.groupby(["scenario", "aqi_category"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| aqi_counts.unstack().plot(kind="bar", stacked=True, ax=axes[6]) |
| axes[6].set_title("AQI Category Distribution") |
| axes[6].set_ylabel("Share") |
| axes[6].legend(fontsize=6) |
|
|
| |
| fire_season = df[df["in_fire_season"] == 1] |
| for s in SCENARIO_FILES: |
| subset = fire_season[fire_season["scenario"] == s] |
| axes[7].scatter( |
| subset["fire_proximity_km"], subset["pm25_smoke_ugm3"], |
| s=6, alpha=0.15, color=COLORS[s], label=s, |
| ) |
| axes[7].set_title("Fire Proximity vs Smoke PM2.5 (fire season)") |
| axes[7].set_xlabel("Fire proximity (km)") |
| axes[7].set_ylabel("PM2.5 smoke (µg/m³)") |
| axes[7].legend(fontsize=7) |
|
|
| plt.tight_layout() |
| fig.savefig(output_path, dpi=200) |
| plt.close(fig) |
|
|
|
|
| def main() -> None: |
| df = load_data() |
| output_path = Path("validation_report.png") |
| plot_validation(df, output_path) |
| print(f"Saved {output_path}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|