"""Validate synthetic stroke rehabilitation & recovery dataset.""" from __future__ import annotations from pathlib import Path import matplotlib.pyplot as plt import pandas as pd SCENARIO_FILES = { "urban_stroke_unit": "stroke_urban.csv", "district_hospital": "stroke_district.csv", "rural_community": "stroke_rural.csv", } COLORS = {"urban_stroke_unit": "#e6550d", "district_hospital": "#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() surv_cols = ["survived", "one_year_mortality", "recurrent_stroke"] surv = df.groupby("scenario")[surv_cols].mean() * 100 surv.plot(kind="bar", ax=axes[0]) axes[0].set_title("Survival & Recurrence (%)") axes[0].legend(fontsize=7) dis_cols = ["hemiplegia", "aphasia", "dysphagia", "depression_post"] dis = df.groupby("scenario")[dis_cols].mean() * 100 dis.plot(kind="bar", ax=axes[1]) axes[1].set_title("Post-Stroke Disability (%)") axes[1].legend(fontsize=7) rehab_cols = ["rehab_received", "physiotherapy", "speech_therapy", "early_mobilisation"] rehab = df.groupby("scenario")[rehab_cols].mean() * 100 rehab.plot(kind="bar", ax=axes[2]) axes[2].set_title("Rehabilitation Access (%)") axes[2].legend(fontsize=6) out_cols = ["functional_recovery", "independent_adl", "walking_ability", "return_to_work"] out = df.groupby("scenario")[out_cols].mean() * 100 out.plot(kind="bar", ax=axes[3]) axes[3].set_title("Functional Outcomes (%)") axes[3].legend(fontsize=6) st = df.groupby(["scenario", "stroke_type"]).size().groupby(level=0).apply(lambda s: s / s.sum()) st.unstack().plot(kind="bar", stacked=True, ax=axes[4]) axes[4].set_title("Stroke Type Distribution") axes[4].legend(fontsize=7) rf_cols = ["hypertension", "diabetes", "hiv_positive"] rf = df.groupby("scenario")[rf_cols].mean() * 100 rf.plot(kind="bar", ax=axes[5]) axes[5].set_title("Risk Factors (%)") axes[5].legend(fontsize=7) prev_cols = ["antihypertensive", "bp_controlled"] prev = df.groupby("scenario")[prev_cols].mean() * 100 prev.plot(kind="bar", ax=axes[6]) axes[6].set_title("Secondary Prevention (%)") axes[6].legend(fontsize=7) diag_cols = ["ct_scan", "thrombolysis"] diag = df.groupby("scenario")[diag_cols].mean() * 100 diag.plot(kind="bar", ax=axes[7]) axes[7].set_title("Acute Diagnostics & Treatment (%)") 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()