"""Validate synthetic arsenic in groundwater & health dataset.""" from __future__ import annotations from pathlib import Path import matplotlib.pyplot as plt import pandas as pd SCENARIO_FILES = { "geogenic_sahel_hotspot": "arsenic_sahel_geogenic.csv", "mining_affected_area": "arsenic_mining_affected.csv", "rift_valley_volcanic": "arsenic_rift_volcanic.csv", } COLORS = {"geogenic_sahel_hotspot": "#e6550d", "mining_affected_area": "#756bb1", "rift_valley_volcanic": "#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: Water As distribution for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[0].hist(subset["water_arsenic_ugL"], bins=40, alpha=0.5, color=COLORS[s], label=s, range=(0, 200)) axes[0].axvline(10, color="red", ls="--", lw=1, label="WHO 10 µg/L") axes[0].set_title("Water Arsenic Distribution (µg/L)") axes[0].legend(fontsize=6) # Panel 2: Exceedance rates exc_cols = ["above_who_10", "above_50"] exc = df.groupby("scenario")[exc_cols].mean() * 100 exc.plot(kind="bar", ax=axes[1]) axes[1].set_title("WHO Guideline Exceedance (%)") axes[1].legend([">10 µg/L", ">50 µg/L"], fontsize=7) # Panel 3: Skin effects skin_cols = ["melanosis", "keratosis", "skin_lesion"] skin = df.groupby("scenario")[skin_cols].mean() * 100 skin.plot(kind="bar", ax=axes[2]) axes[2].set_title("Skin Effects (%)") axes[2].legend(fontsize=7) # Panel 4: Water As vs skin lesion (dose-response) for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[3].scatter(subset["water_arsenic_ugL"], subset["skin_lesion"], s=4, alpha=0.05, color=COLORS[s], label=s) axes[3].set_title("Water As vs Skin Lesion") axes[3].set_xlabel("Water As (µg/L)") axes[3].legend(fontsize=7) # Panel 5: Cancer & chronic disease chronic_cols = ["any_cancer", "cardiovascular", "diabetes", "neuropathy"] chronic = df.groupby("scenario")[chronic_cols].mean() * 100 chronic.plot(kind="bar", ax=axes[4]) axes[4].set_title("Cancer & Chronic Disease (%)") axes[4].legend(fontsize=6) # Panel 6: Water source distribution ws = df.groupby(["scenario", "water_source"]).size().groupby(level=0).apply(lambda s: s / s.sum()) ws.unstack().plot(kind="bar", stacked=True, ax=axes[5]) axes[5].set_title("Water Source Distribution") axes[5].legend(fontsize=6) # Panel 7: Testing & mitigation mit_cols = ["water_tested", "safe_alternative_available", "uses_safe_alternative"] mit = df.groupby("scenario")[mit_cols].mean() * 100 mit.plot(kind="bar", ax=axes[6]) axes[6].set_title("Testing & Mitigation (%)") axes[6].legend(fontsize=7) # Panel 8: Urine As distribution for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[7].hist(subset["urine_arsenic_ugL"], bins=40, alpha=0.5, color=COLORS[s], label=s, range=(0, 200)) axes[7].set_title("Urine Arsenic Biomarker (µg/L)") 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()