Kossisoroyce's picture
Upload folder using huggingface_hub
242cb7a verified
Raw History Blame Contribute Delete
3.32 kB
"""Validate synthetic climate & maternal-neonatal outcomes dataset."""
from __future__ import annotations
from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
SCENARIO_FILES = {
"heat_exposed_pregnancy": "maternal_heat_exposed.csv",
"drought_food_insecure_pregnancy": "maternal_drought_food_insecure.csv",
"flood_disrupted_services": "maternal_flood_disrupted.csv",
}
COLORS = {"heat_exposed_pregnancy": "#e6550d", "drought_food_insecure_pregnancy": "#d95f02", "flood_disrupted_services": "#3182bd"}
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()
outcome_cols = ["preterm", "low_birth_weight", "stillbirth", "preeclampsia"]
rates = df.groupby("scenario")[outcome_cols].mean() * 100
rates.plot(kind="bar", ax=axes[0])
axes[0].set_title("Adverse Pregnancy Outcomes (%)")
axes[0].legend(fontsize=7)
for s in SCENARIO_FILES:
subset = df[df["scenario"] == s]
axes[1].hist(subset["birth_weight_g"], bins=30, alpha=0.5, color=COLORS[s], label=s)
axes[1].set_title("Birth Weight Distribution")
axes[1].set_xlabel("Birth weight (g)")
axes[1].legend(fontsize=7)
svc_cols = ["anc_4plus", "skilled_birth_attendant", "facility_delivery", "facility_accessible"]
svc = df.groupby("scenario")[svc_cols].mean() * 100
svc.plot(kind="bar", ax=axes[2])
axes[2].set_title("Service Access (%)")
axes[2].legend(fontsize=7)
for s in SCENARIO_FILES:
subset = df[df["scenario"] == s]
axes[3].scatter(subset["heat_index"], subset["preterm"], s=6, alpha=0.1, color=COLORS[s], label=s)
axes[3].set_title("Heat Index vs Preterm Birth")
axes[3].set_xlabel("Heat index")
axes[3].legend(fontsize=7)
risk_cols = ["anaemia", "malaria_in_pregnancy", "food_insecure", "dehydration"]
risk = df.groupby("scenario")[risk_cols].mean() * 100
risk.plot(kind="bar", ax=axes[4])
axes[4].set_title("Risk Factors (%)")
axes[4].legend(fontsize=7)
mort_cols = ["neonatal_death", "maternal_death"]
mort = df.groupby("scenario")[mort_cols].mean() * 1000
mort.plot(kind="bar", ax=axes[5])
axes[5].set_title("Mortality (per 1000)")
axes[5].legend(fontsize=7)
for s in SCENARIO_FILES:
subset = df[df["scenario"] == s]
axes[6].hist(subset["gestational_age_weeks"], bins=25, alpha=0.5, color=COLORS[s], label=s)
axes[6].set_title("Gestational Age Distribution")
axes[6].set_xlabel("Weeks")
axes[6].legend(fontsize=7)
neo_cols = ["neonatal_sepsis", "birth_asphyxia", "pph"]
neo = df.groupby("scenario")[neo_cols].mean() * 100
neo.plot(kind="bar", ax=axes[7])
axes[7].set_title("Neonatal/Maternal Complications (%)")
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()