Kossisoroyce's picture
Upload folder using huggingface_hub
f21233b verified
raw
history blame contribute delete
8.19 kB
"""Generate synthetic One Health climate surveillance dataset for SSA."""
from __future__ import annotations
from pathlib import Path
import numpy as np
import pandas as pd
SEED = 42
N_PER_SCENARIO = 10_000
YEAR_RANGE = np.arange(2010, 2025)
YEAR_WEIGHTS = np.linspace(0.85, 1.3, len(YEAR_RANGE))
YEAR_WEIGHTS = YEAR_WEIGHTS / YEAR_WEIGHTS.sum()
SCENARIOS = {
"zoonotic_hotspot_forest": {
"setting_probs": {"rural_forest": 0.45, "peri_urban": 0.30, "urban": 0.25},
"deforestation_rate_mean": 0.03,
"temp_mean": 27, "temp_sd": 2,
"rainfall_mean": 1600, "rainfall_sd": 350,
"wildlife_contact_pct": 0.35,
"livestock_density_mean": 120,
"zoonotic_spillover_rate": 0.08,
"rvf_risk": 0.05,
"ebola_risk": 0.02,
"lassa_risk": 0.04,
"rabies_rate_per100k": 3.5,
"amr_livestock_pct": 0.30,
"surveillance_coverage_pct": 0.20,
"lab_capacity_score_mean": 0.25,
"one_health_platform_pct": 0.15,
},
"pastoral_livestock_interface": {
"setting_probs": {"rural": 0.60, "peri_urban": 0.25, "urban": 0.15},
"deforestation_rate_mean": 0.01,
"temp_mean": 32, "temp_sd": 3,
"rainfall_mean": 600, "rainfall_sd": 200,
"wildlife_contact_pct": 0.25,
"livestock_density_mean": 250,
"zoonotic_spillover_rate": 0.06,
"rvf_risk": 0.10,
"ebola_risk": 0.005,
"lassa_risk": 0.01,
"rabies_rate_per100k": 5.0,
"amr_livestock_pct": 0.35,
"surveillance_coverage_pct": 0.15,
"lab_capacity_score_mean": 0.20,
"one_health_platform_pct": 0.10,
},
"urban_periurban_market": {
"setting_probs": {"urban": 0.50, "peri_urban": 0.35, "rural": 0.15},
"deforestation_rate_mean": 0.005,
"temp_mean": 29, "temp_sd": 2.5,
"rainfall_mean": 1100, "rainfall_sd": 300,
"wildlife_contact_pct": 0.15,
"livestock_density_mean": 80,
"zoonotic_spillover_rate": 0.04,
"rvf_risk": 0.03,
"ebola_risk": 0.01,
"lassa_risk": 0.02,
"rabies_rate_per100k": 2.0,
"amr_livestock_pct": 0.25,
"surveillance_coverage_pct": 0.35,
"lab_capacity_score_mean": 0.45,
"one_health_platform_pct": 0.25,
},
}
SCENARIO_FILES = {
"zoonotic_hotspot_forest": "onehealth_zoonotic_forest.csv",
"pastoral_livestock_interface": "onehealth_pastoral_livestock.csv",
"urban_periurban_market": "onehealth_urban_market.csv",
}
ANIMAL_RESERVOIRS = {"rodent": 0.25, "bat": 0.20, "primate": 0.15, "livestock": 0.25, "poultry": 0.10, "dog": 0.05}
def _choice(rng, prob_map):
keys = list(prob_map.keys())
weights = np.array(list(prob_map.values()), dtype=float)
weights = weights / weights.sum()
return rng.choice(keys, p=weights)
def _simulate_scenario(name, params, seed):
rng = np.random.default_rng(seed)
records = []
for idx in range(N_PER_SCENARIO):
year = int(rng.choice(YEAR_RANGE, p=YEAR_WEIGHTS))
month = int(rng.choice(range(1, 13)))
setting = _choice(rng, params["setting_probs"])
temp = float(np.clip(rng.normal(params["temp_mean"], params["temp_sd"]), 15, 42))
rainfall = float(np.clip(rng.normal(params["rainfall_mean"], params["rainfall_sd"]), 50, 3000))
deforestation_rate = float(np.clip(
rng.normal(params["deforestation_rate_mean"], 0.01) + 0.001 * (year - 2010),
0, 0.10,
))
land_use_change = rng.choice(
["forest_intact", "deforested", "agricultural_expansion", "urban_expansion"],
p=[0.30, 0.20, 0.30, 0.20],
)
wildlife_contact = int(rng.random() < params["wildlife_contact_pct"])
bushmeat_consumption = int(wildlife_contact and rng.random() < 0.40)
livestock_density = float(np.clip(rng.normal(params["livestock_density_mean"], 50), 10, 500))
animal_reservoir = _choice(rng, ANIMAL_RESERVOIRS)
climate_anomaly = float(np.clip(rng.normal(0, 1), -3, 3))
enso_phase = rng.choice(["neutral", "el_nino", "la_nina"], p=[0.50, 0.25, 0.25])
flood_event = int(rainfall > params["rainfall_mean"] + params["rainfall_sd"] * 1.5)
risk_mult = (
1.0
+ deforestation_rate * 5
+ wildlife_contact * 0.3
+ flood_event * 0.25
+ (enso_phase == "el_nino") * 0.15
+ (temp > 35) * 0.1
)
zoonotic_event = int(rng.random() < np.clip(params["zoonotic_spillover_rate"] * risk_mult, 0, 0.5))
rvf_case = int(rng.random() < params["rvf_risk"] * (1 + flood_event * 1.5))
ebola_signal = int(rng.random() < params["ebola_risk"] * (1 + deforestation_rate * 10))
lassa_case = int(rng.random() < params["lassa_risk"] * risk_mult)
rabies_case = int(rng.random() < params["rabies_rate_per100k"] / 100_000 * 50)
any_zoonotic = int(zoonotic_event or rvf_case or ebola_signal or lassa_case or rabies_case)
amr_detected = int(rng.random() < params["amr_livestock_pct"])
antibiotic_livestock_use = int(rng.random() < 0.45)
surveillance_active = int(rng.random() < params["surveillance_coverage_pct"])
event_detected = int(any_zoonotic and surveillance_active and rng.random() < 0.60)
detection_delay_days = int(np.clip(rng.exponential(14 if not surveillance_active else 5), 1, 90))
lab_confirmed = int(event_detected and rng.random() < params["lab_capacity_score_mean"] * 1.5)
one_health_platform = int(rng.random() < params["one_health_platform_pct"])
joint_investigation = int(event_detected and one_health_platform and rng.random() < 0.40)
response_initiated = int(event_detected and rng.random() < 0.50)
human_cases = int(np.clip(rng.poisson(2) if any_zoonotic else 0, 0, 50))
animal_cases = int(np.clip(rng.poisson(5) if any_zoonotic else 0, 0, 100))
cfr = float(np.clip(rng.normal(0.10, 0.05) if any_zoonotic else 0, 0, 0.5))
human_deaths = int(human_cases * cfr)
record = {
"record_id": f"{name[:3].upper()}-{idx:05d}",
"scenario": name,
"year": year,
"month": month,
"setting": setting,
"temp_c": round(temp, 1),
"rainfall_mm": round(rainfall, 0),
"deforestation_rate": round(deforestation_rate, 3),
"land_use_change": land_use_change,
"climate_anomaly": round(climate_anomaly, 1),
"enso_phase": enso_phase,
"flood_event": flood_event,
"wildlife_contact": wildlife_contact,
"bushmeat_consumption": bushmeat_consumption,
"livestock_density_per_km2": round(livestock_density, 0),
"animal_reservoir": animal_reservoir,
"zoonotic_spillover_event": zoonotic_event,
"rvf_case": rvf_case,
"ebola_signal": ebola_signal,
"lassa_case": lassa_case,
"rabies_case": rabies_case,
"any_zoonotic_event": any_zoonotic,
"amr_detected_livestock": amr_detected,
"antibiotic_livestock_use": antibiotic_livestock_use,
"surveillance_active": surveillance_active,
"event_detected": event_detected,
"detection_delay_days": detection_delay_days,
"lab_confirmed": lab_confirmed,
"one_health_platform": one_health_platform,
"joint_investigation": joint_investigation,
"response_initiated": response_initiated,
"human_cases": human_cases,
"animal_cases": animal_cases,
"human_deaths": human_deaths,
}
records.append(record)
return pd.DataFrame(records)
def main():
output_dir = Path("data")
output_dir.mkdir(parents=True, exist_ok=True)
for idx, (name, params) in enumerate(SCENARIOS.items()):
df = _simulate_scenario(name, params, SEED + idx * 211)
df.to_csv(output_dir / SCENARIO_FILES[name], index=False)
print(f"Saved {name} -> {SCENARIO_FILES[name]}")
if __name__ == "__main__":
main()