| """Validate synthetic visual impairment & low vision services dataset.""" |
|
|
| from __future__ import annotations |
|
|
| from pathlib import Path |
|
|
| import matplotlib.pyplot as plt |
| import pandas as pd |
|
|
| SCENARIO_FILES = { |
| "urban_eye_clinic": "vision_urban.csv", |
| "district_outreach": "vision_district.csv", |
| "rural_community": "vision_rural.csv", |
| } |
|
|
| COLORS = {"urban_eye_clinic": "#e6550d", "district_outreach": "#756bb1", "rural_community": "#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() |
|
|
| acc_cols = ["screened", "referred", "referral_completed", "ophthalmologist_seen"] |
| acc = df.groupby("scenario")[acc_cols].mean() * 100 |
| acc.plot(kind="bar", ax=axes[0]) |
| axes[0].set_title("Service Access Cascade (%)") |
| axes[0].legend(fontsize=6) |
|
|
| cau = df.groupby(["scenario", "cause"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| cau.unstack().plot(kind="bar", stacked=True, ax=axes[1]) |
| axes[1].set_title("Cause of Visual Impairment") |
| axes[1].legend(fontsize=5) |
|
|
| int_cols = ["spectacles_received", "cataract_surgery_done", "low_vision_device"] |
| intv = df.groupby("scenario")[int_cols].mean() * 100 |
| intv.plot(kind="bar", ax=axes[2]) |
| axes[2].set_title("Interventions Received (%)") |
| axes[2].legend(fontsize=7) |
|
|
| bar_cols = ["cost_barrier", "distance_barrier", "awareness_barrier"] |
| bar = df.groupby("scenario")[bar_cols].mean() * 100 |
| bar.plot(kind="bar", ax=axes[3]) |
| axes[3].set_title("Barriers (%)") |
| axes[3].legend(fontsize=7) |
|
|
| sev = df.groupby(["scenario", "severity"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| sev.unstack().plot(kind="bar", stacked=True, ax=axes[4]) |
| axes[4].set_title("Severity Distribution") |
| axes[4].legend(fontsize=7) |
|
|
| out_cols = ["vision_improved", "quality_of_life_improved", "employment_impacted"] |
| out = df.groupby("scenario")[out_cols].mean() * 100 |
| out.plot(kind="bar", ax=axes[5]) |
| axes[5].set_title("Outcomes (%)") |
| axes[5].legend(fontsize=7) |
|
|
| need_cols = ["spectacles_needed", "cataract_surgery_needed", "unmet_need"] |
| need = df.groupby("scenario")[need_cols].mean() * 100 |
| need.plot(kind="bar", ax=axes[6]) |
| axes[6].set_title("Need & Unmet Need (%)") |
| axes[6].legend(fontsize=7) |
|
|
| avd = df.groupby("scenario")["avoidable"].mean() * 100 |
| avd.plot(kind="bar", ax=axes[7], color="#e6550d") |
| axes[7].set_title("Avoidable Blindness (%)") |
|
|
| 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() |
|
|