"""Validate synthetic radon & indoor radiation exposure dataset.""" from __future__ import annotations from pathlib import Path import matplotlib.pyplot as plt import pandas as pd SCENARIO_FILES = { "granite_geology_rural": "radon_granite_rural.csv", "urban_residential": "radon_urban_residential.csv", "occupational_underground": "radon_occupational.csv", } COLORS = {"granite_geology_rural": "#e6550d", "urban_residential": "#756bb1", "occupational_underground": "#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() for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[0].hist(subset["radon_bqm3"], bins=40, alpha=0.5, color=COLORS[s], label=s, range=(0, 800)) axes[0].axvline(100, color="red", ls="--", lw=1, label="WHO 100 Bq/m³") axes[0].axvline(300, color="orange", ls="--", lw=1, label="Action 300 Bq/m³") axes[0].set_title("Indoor Radon Distribution (Bq/m³)") axes[0].legend(fontsize=6) exc_cols = ["above_who_100", "above_action_300"] exc = df.groupby("scenario")[exc_cols].mean() * 100 exc.plot(kind="bar", ax=axes[1]) axes[1].set_title("WHO & Action Level Exceedance (%)") axes[1].legend(fontsize=7) health_cols = ["lung_cancer", "chronic_cough", "dyspnoea"] health = df.groupby("scenario")[health_cols].mean() * 100 health.plot(kind="bar", ax=axes[2]) axes[2].set_title("Health Outcomes (%)") axes[2].legend(fontsize=7) for s in SCENARIO_FILES: subset = df[df["scenario"] == s] axes[3].scatter(subset["radon_bqm3"], subset["lung_cancer"], s=4, alpha=0.05, color=COLORS[s], label=s) axes[3].set_title("Radon vs Lung Cancer") axes[3].legend(fontsize=7) bld = df.groupby(["scenario", "building_type"]).size().groupby(level=0).apply(lambda s: s / s.sum()) bld.unstack().plot(kind="bar", stacked=True, ax=axes[4]) axes[4].set_title("Building Type Distribution") axes[4].legend(fontsize=5) flr = df.groupby(["scenario", "floor_level"]).size().groupby(level=0).apply(lambda s: s / s.sum()) flr.unstack().plot(kind="bar", stacked=True, ax=axes[5]) axes[5].set_title("Floor Level Distribution") axes[5].legend(fontsize=7) risk_cols = ["ventilation_poor", "cracks_in_floor", "smoking", "uranium_geology"] risk = df.groupby("scenario")[risk_cols].mean() * 100 risk.plot(kind="bar", ax=axes[6]) axes[6].set_title("Risk Factors (%)") axes[6].legend(fontsize=6) mit_cols = ["radon_measured", "aware_of_radon", "mitigation_installed", "ventilation_improved"] mit = df.groupby("scenario")[mit_cols].mean() * 100 mit.plot(kind="bar", ax=axes[7]) axes[7].set_title("Measurement & Mitigation (%)") axes[7].legend(fontsize=6) 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()