| """Validate synthetic asbestos exposure & mesothelioma dataset.""" |
|
|
| from __future__ import annotations |
|
|
| from pathlib import Path |
|
|
| import matplotlib.pyplot as plt |
| import pandas as pd |
|
|
| SCENARIO_FILES = { |
| "former_mining_community": "asbestos_mining_community.csv", |
| "urban_construction": "asbestos_urban_construction.csv", |
| "rural_asbestos_roofing": "asbestos_rural_roofing.csv", |
| } |
|
|
| COLORS = {"former_mining_community": "#e6550d", "urban_construction": "#756bb1", "rural_asbestos_roofing": "#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["cumulative_exposure"], bins=40, alpha=0.5, color=COLORS[s], label=s, range=(0, 100)) |
| axes[0].set_title("Cumulative Exposure Distribution (f/mL·yr)") |
| axes[0].legend(fontsize=7) |
|
|
| disease_cols = ["mesothelioma", "asbestosis", "lung_cancer", "pleural_plaques"] |
| dis = df.groupby("scenario")[disease_cols].mean() * 100 |
| dis.plot(kind="bar", ax=axes[1]) |
| axes[1].set_title("Asbestos-Related Disease (%)") |
| axes[1].legend(fontsize=6) |
|
|
| ft = df.groupby(["scenario", "fibre_type"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| ft.unstack().plot(kind="bar", stacked=True, ax=axes[2]) |
| axes[2].set_title("Fibre Type Distribution") |
| axes[2].legend(fontsize=7) |
|
|
| exp = df.groupby(["scenario", "exposure_type"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| exp.unstack().plot(kind="bar", stacked=True, ax=axes[3]) |
| axes[3].set_title("Exposure Type Distribution") |
| axes[3].legend(fontsize=5) |
|
|
| for s in SCENARIO_FILES: |
| subset = df[df["scenario"] == s] |
| axes[4].scatter(subset["cumulative_exposure"], subset["any_asbestos_disease"], |
| s=4, alpha=0.05, color=COLORS[s], label=s) |
| axes[4].set_title("Cumulative Exposure vs Disease") |
| axes[4].legend(fontsize=7) |
|
|
| resp_cols = ["dyspnoea", "cough_chronic", "reduced_fvc"] |
| resp = df.groupby("scenario")[resp_cols].mean() * 100 |
| resp.plot(kind="bar", ax=axes[5]) |
| axes[5].set_title("Respiratory Symptoms (%)") |
| axes[5].legend(fontsize=7) |
|
|
| reg_cols = ["ban_in_place", "medical_surveillance", "ppe_use", "chest_xray_done"] |
| reg = df.groupby("scenario")[reg_cols].mean() * 100 |
| reg.plot(kind="bar", ax=axes[6]) |
| axes[6].set_title("Regulation & Surveillance (%)") |
| axes[6].legend(fontsize=6) |
|
|
| mort_cols = ["died", "hiv_positive", "compensation_claimed"] |
| mort = df.groupby("scenario")[mort_cols].mean() * 100 |
| mort.plot(kind="bar", ax=axes[7]) |
| axes[7].set_title("Mortality, HIV & Compensation (%)") |
| 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() |
|
|