| """Validate synthetic disability rights & social protection dataset.""" |
|
|
| from __future__ import annotations |
|
|
| from pathlib import Path |
|
|
| import matplotlib.pyplot as plt |
| import pandas as pd |
|
|
| SCENARIO_FILES = { |
| "urban_formal_sector": "drsp_urban.csv", |
| "periurban_informal": "drsp_periurban.csv", |
| "rural_subsistence": "drsp_rural.csv", |
| } |
|
|
|
|
| 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() |
|
|
| sp_cols = ["cash_transfer", "health_insurance", "disability_registered", "disability_card"] |
| sp = df.groupby("scenario")[sp_cols].mean() * 100 |
| sp.plot(kind="bar", ax=axes[0]) |
| axes[0].set_title("Social Protection (%)") |
| axes[0].legend(fontsize=6) |
|
|
| edu_cols = ["ever_attended_school", "school_completed", "out_of_school"] |
| edu = df.groupby("scenario")[edu_cols].mean() * 100 |
| edu.plot(kind="bar", ax=axes[1]) |
| axes[1].set_title("Education (%)") |
| axes[1].legend(fontsize=7) |
|
|
| emp_cols = ["employed", "formal_employment", "self_employed", "income_below_poverty"] |
| emp = df.groupby("scenario")[emp_cols].mean() * 100 |
| emp.plot(kind="bar", ax=axes[2]) |
| axes[2].set_title("Employment & Poverty (%)") |
| axes[2].legend(fontsize=6) |
|
|
| rts_cols = ["crpd_aware", "dpo_member", "voted_last_election"] |
| rts = df.groupby("scenario")[rts_cols].mean() * 100 |
| rts.plot(kind="bar", ax=axes[3]) |
| axes[3].set_title("Rights & Participation (%)") |
| axes[3].legend(fontsize=7) |
|
|
| disc_cols = ["discrimination_experienced", "abuse_experienced", "reported_discrimination"] |
| disc = df.groupby("scenario")[disc_cols].mean() * 100 |
| disc.plot(kind="bar", ax=axes[4]) |
| axes[4].set_title("Discrimination & Abuse (%)") |
| axes[4].legend(fontsize=7) |
|
|
| bar_cols = ["stigma", "transport_barrier"] |
| bar = df.groupby("scenario")[bar_cols].mean() * 100 |
| bar.plot(kind="bar", ax=axes[5]) |
| axes[5].set_title("Barriers (%)") |
| axes[5].legend(fontsize=7) |
|
|
| wb = df.groupby(["scenario", "wellbeing"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| wb.unstack().plot(kind="bar", stacked=True, ax=axes[6]) |
| axes[6].set_title("Wellbeing Distribution") |
| axes[6].legend(fontsize=7) |
|
|
| dis = df.groupby(["scenario", "disability_type"]).size().groupby(level=0).apply(lambda s: s / s.sum()) |
| dis.unstack().plot(kind="bar", stacked=True, ax=axes[7]) |
| axes[7].set_title("Disability Type Distribution") |
| axes[7].legend(fontsize=5) |
|
|
| 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() |
|
|