"""Validate synthetic One Health climate surveillance dataset.""" from __future__ import annotations from pathlib import Path import matplotlib.pyplot as plt import pandas as pd SCENARIO_FILES = { "zoonotic_hotspot_forest": "onehealth_zoonotic_forest.csv", "pastoral_livestock_interface": "onehealth_pastoral_livestock.csv", "urban_periurban_market": "onehealth_urban_market.csv", } COLORS = {"zoonotic_hotspot_forest": "#31a354", "pastoral_livestock_interface": "#d95f02", "urban_periurban_market": "#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() zoo_cols = ["zoonotic_spillover_event", "rvf_case", "ebola_signal", "lassa_case", "rabies_case"] rates = df.groupby("scenario")[zoo_cols].mean() * 100 rates.plot(kind="bar", ax=axes[0]) axes[0].set_title("Zoonotic Event Rates (%)") axes[0].legend(fontsize=6) surv_cols = ["surveillance_active", "event_detected", "lab_confirmed"] surv = df.groupby("scenario")[surv_cols].mean() * 100 surv.plot(kind="bar", ax=axes[1]) axes[1].set_title("Surveillance Cascade (%)") axes[1].legend(fontsize=7) res_counts = df.groupby(["scenario", "animal_reservoir"]).size().groupby(level=0).apply(lambda s: s / s.sum()) res_counts.unstack().plot(kind="bar", stacked=True, ax=axes[2]) axes[2].set_title("Animal Reservoir Distribution") axes[2].legend(fontsize=6) for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[3].hist(subset["detection_delay_days"], bins=30, alpha=0.5, color=COLORS[s], label=s) axes[3].set_title("Detection Delay (days)") axes[3].legend(fontsize=7) oh_cols = ["one_health_platform", "joint_investigation", "response_initiated"] oh = df.groupby("scenario")[oh_cols].mean() * 100 oh.plot(kind="bar", ax=axes[4]) axes[4].set_title("One Health Response (%)") axes[4].legend(fontsize=7) amr_cols = ["amr_detected_livestock", "antibiotic_livestock_use"] amr = df.groupby("scenario")[amr_cols].mean() * 100 amr.plot(kind="bar", ax=axes[5]) axes[5].set_title("AMR & Antibiotic Use in Livestock (%)") axes[5].legend(fontsize=7) for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[6].scatter(subset["deforestation_rate"], subset["any_zoonotic_event"], s=6, alpha=0.1, color=COLORS[s], label=s) axes[6].set_title("Deforestation vs Zoonotic Events") axes[6].legend(fontsize=7) cases = df.groupby("scenario")[["human_cases", "animal_cases", "human_deaths"]].sum() cases.plot(kind="bar", ax=axes[7]) axes[7].set_title("Total Cases & Deaths by Scenario") axes[7].legend(fontsize=7) plt.tight_layout() fig.savefig(output_path, dpi=200) plt.close(fig) def main() -> None: df = load_data() plot_validation(df, Path("validation_report.png")) print("Saved validation_report.png") if __name__ == "__main__": main()