"""Validate synthetic sea-level rise & coastal health infrastructure dataset.""" from __future__ import annotations from pathlib import Path import matplotlib.pyplot as plt import pandas as pd SCENARIO_FILES = { "west_africa_delta": "slr_west_africa_delta.csv", "east_africa_island": "slr_east_africa_island.csv", "southern_coastal_city": "slr_southern_coastal_city.csv", } COLORS = { "west_africa_delta": "#e6550d", "east_africa_island": "#3182bd", "southern_coastal_city": "#31a354", } 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() # Panel 1: Flood risk by scenario for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[0].hist(subset["flood_risk"], bins=25, alpha=0.5, color=COLORS[s], label=s) axes[0].set_title("Flood Risk Distribution by Scenario") axes[0].set_xlabel("Flood risk") axes[0].legend(fontsize=7) # Panel 2: Health impacts health_cols = ["waterborne_disease", "malaria_case", "cholera_outbreak", "mental_health_impact"] rates = df.groupby("scenario")[health_cols].mean() * 100 rates.plot(kind="bar", ax=axes[1]) axes[1].set_title("Health Impact Rates (%)") axes[1].set_ylabel("Percent") axes[1].legend(fontsize=7) # Panel 3: Facility damage & inaccessibility fac_cols = ["facility_at_risk", "facility_damaged", "facility_inaccessible"] fac_rates = df.groupby("scenario")[fac_cols].mean() * 100 fac_rates.plot(kind="bar", ax=axes[2]) axes[2].set_title("Health Facility Risk (%)") axes[2].set_ylabel("Percent") axes[2].legend(fontsize=7) # Panel 4: Elevation vs flood risk for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[3].scatter(subset["elevation_m"], subset["flood_risk"], s=6, alpha=0.15, color=COLORS[s], label=s) axes[3].set_title("Elevation vs Flood Risk") axes[3].set_xlabel("Elevation (m)") axes[3].set_ylabel("Flood risk") axes[3].legend(fontsize=7) # Panel 5: Supply chain disruption sc_cols = ["supply_chain_disrupted", "essential_medicine_stockout"] sc_rates = df.groupby("scenario")[sc_cols].mean() * 100 sc_rates.plot(kind="bar", ax=axes[4]) axes[4].set_title("Supply Chain Disruption (%)") axes[4].set_ylabel("Percent") axes[4].legend(fontsize=7) # Panel 6: Health system resilience res_data = [df[df["scenario"] == s]["health_system_resilience"] for s in SCENARIO_FILES] bp = axes[5].boxplot(res_data, tick_labels=SCENARIO_FILES.keys(), patch_artist=True) for patch, s in zip(bp["boxes"], SCENARIO_FILES.keys()): patch.set_facecolor(COLORS[s]) patch.set_alpha(0.6) axes[5].set_title("Health System Resilience Score") axes[5].set_ylabel("Score") # Panel 7: Cumulative SLR trend yearly = df.groupby(["scenario", "year"])["cumulative_slr_cm"].mean().reset_index() for s in SCENARIO_FILES: sub = yearly[yearly["scenario"] == s] axes[6].plot(sub["year"], sub["cumulative_slr_cm"], marker="o", color=COLORS[s], label=s) axes[6].set_title("Cumulative Sea-Level Rise Trend") axes[6].set_xlabel("Year") axes[6].set_ylabel("Cumulative SLR (cm)") axes[6].legend(fontsize=7) # Panel 8: Adaptation score adapt_data = [df[df["scenario"] == s]["adaptation_score"] for s in SCENARIO_FILES] bp2 = axes[7].boxplot(adapt_data, tick_labels=SCENARIO_FILES.keys(), patch_artist=True) for patch, s in zip(bp2["boxes"], SCENARIO_FILES.keys()): patch.set_facecolor(COLORS[s]) patch.set_alpha(0.6) axes[7].set_title("Adaptation Score by Scenario") axes[7].set_ylabel("Score") 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()