"""Validate synthetic e-waste recycling & occupational health dataset.""" from __future__ import annotations from pathlib import Path import matplotlib.pyplot as plt import pandas as pd SCENARIO_FILES = { "mega_site_west_africa": "ewaste_mega_site.csv", "medium_site_urban": "ewaste_medium_urban.csv", "small_dispersed_sites": "ewaste_small_dispersed.csv", } COLORS = {"mega_site_west_africa": "#e6550d", "medium_site_urban": "#756bb1", "small_dispersed_sites": "#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: Blood Pb distribution for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[0].hist(subset["blood_pb_ugdL"], bins=40, alpha=0.5, color=COLORS[s], label=s) axes[0].set_title("Blood Lead Distribution (µg/dL)") axes[0].legend(fontsize=7) # Panel 2: Respiratory outcomes resp_cols = ["cough_chronic", "wheeze", "dyspnoea", "reduced_fev1"] resp = df.groupby("scenario")[resp_cols].mean() * 100 resp.plot(kind="bar", ax=axes[1]) axes[1].set_title("Respiratory Outcomes (%)") axes[1].legend(fontsize=6) # Panel 3: Elevated metal biomarkers bio_cols = ["elevated_pb", "elevated_cd"] bio = df.groupby("scenario")[bio_cols].mean() * 100 bio.plot(kind="bar", ax=axes[2]) axes[2].set_title("Elevated Biomarker Prevalence (%)") axes[2].legend(["Pb ≥10 µg/dL", "Cd ≥1.0 µg/L"], fontsize=7) # Panel 4: Role distribution role_dist = df.groupby(["scenario", "role"]).size().groupby(level=0).apply(lambda s: s / s.sum()) role_dist.unstack().plot(kind="bar", stacked=True, ax=axes[3]) axes[3].set_title("Worker Role Distribution") axes[3].legend(fontsize=5) # Panel 5: Processing method workers = df[df["is_worker"] == 1] proc_dist = workers.groupby(["scenario", "processing_method"]).size().groupby(level=0).apply(lambda s: s / s.sum()) proc_dist.unstack().plot(kind="bar", stacked=True, ax=axes[4]) axes[4].set_title("Processing Method (Workers)") axes[4].legend(fontsize=5) # Panel 6: PPE use & safety safety_cols = ["ppe_use", "gloves", "mask", "health_screening_access"] safety = df.groupby("scenario")[safety_cols].mean() * 100 safety.plot(kind="bar", ax=axes[5]) axes[5].set_title("Safety & Screening (%)") axes[5].legend(fontsize=6) # Panel 7: Skin, burns, eye outcomes skin_cols = ["skin_rash", "burns_injury", "eye_irritation"] skin = df.groupby("scenario")[skin_cols].mean() * 100 skin.plot(kind="bar", ax=axes[6]) axes[6].set_title("Dermal & Ocular Outcomes (%)") axes[6].legend(fontsize=7) # Panel 8: DNA damage & child developmental other_cols = ["dna_damage_risk", "child_developmental", "proteinuria"] other = df.groupby("scenario")[other_cols].mean() * 100 other.plot(kind="bar", ax=axes[7]) axes[7].set_title("Other Health Outcomes (%)") 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()