| """Generate synthetic wildfire smoke & respiratory outcomes 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 = { |
| "savanna_fire_belt": { |
| "fire_season_months": [11, 12, 1, 2, 3], |
| "pm25_smoke_mean": 180, |
| "pm25_smoke_sd": 90, |
| "pm25_baseline": 25, |
| "fire_frequency_mean": 3.5, |
| "fire_proximity_km_mean": 12, |
| "fire_proximity_km_sd": 8, |
| "smoke_days_mean": 45, |
| "smoke_days_sd": 18, |
| "asthma_prev": 0.08, |
| "copd_prev": 0.04, |
| "ari_rate_per1k": 85, |
| "er_visit_rate": 0.12, |
| "mortality_rate_per100k": 4.5, |
| "setting_probs": {"rural": 0.60, "peri_urban": 0.25, "urban": 0.15}, |
| "mask_access": 0.05, |
| }, |
| "forest_clearing_burn": { |
| "fire_season_months": [6, 7, 8, 9], |
| "pm25_smoke_mean": 250, |
| "pm25_smoke_sd": 120, |
| "pm25_baseline": 20, |
| "fire_frequency_mean": 2.0, |
| "fire_proximity_km_mean": 8, |
| "fire_proximity_km_sd": 5, |
| "smoke_days_mean": 60, |
| "smoke_days_sd": 25, |
| "asthma_prev": 0.07, |
| "copd_prev": 0.03, |
| "ari_rate_per1k": 95, |
| "er_visit_rate": 0.10, |
| "mortality_rate_per100k": 5.0, |
| "setting_probs": {"rural": 0.70, "peri_urban": 0.20, "urban": 0.10}, |
| "mask_access": 0.03, |
| }, |
| "urban_peri_urban_haze": { |
| "fire_season_months": [12, 1, 2, 3], |
| "pm25_smoke_mean": 120, |
| "pm25_smoke_sd": 55, |
| "pm25_baseline": 40, |
| "fire_frequency_mean": 1.5, |
| "fire_proximity_km_mean": 25, |
| "fire_proximity_km_sd": 15, |
| "smoke_days_mean": 30, |
| "smoke_days_sd": 12, |
| "asthma_prev": 0.10, |
| "copd_prev": 0.05, |
| "ari_rate_per1k": 70, |
| "er_visit_rate": 0.18, |
| "mortality_rate_per100k": 3.5, |
| "setting_probs": {"urban": 0.50, "peri_urban": 0.35, "rural": 0.15}, |
| "mask_access": 0.15, |
| }, |
| } |
|
|
| SCENARIO_FILES = { |
| "savanna_fire_belt": "wildfire_savanna_fire_belt.csv", |
| "forest_clearing_burn": "wildfire_forest_clearing_burn.csv", |
| "urban_peri_urban_haze": "wildfire_urban_peri_urban_haze.csv", |
| } |
|
|
|
|
| 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)) |
| age = int(np.clip(rng.normal(32, 18), 1, 85)) |
| sex = rng.choice(["male", "female"], p=[0.48, 0.52]) |
| setting = _choice(rng, params["setting_probs"]) |
| is_child = int(age < 5) |
| is_elderly = int(age >= 60) |
|
|
| pre_existing_asthma = int(rng.random() < params["asthma_prev"]) |
| pre_existing_copd = int(age > 35 and rng.random() < params["copd_prev"]) |
| smoker = int(age > 15 and rng.random() < 0.12) |
|
|
| month = int(rng.choice(range(1, 13))) |
| in_fire_season = int(month in params["fire_season_months"]) |
|
|
| if in_fire_season: |
| pm25_smoke = float(np.clip(rng.normal(params["pm25_smoke_mean"], params["pm25_smoke_sd"]), 20, 800)) |
| else: |
| pm25_smoke = float(np.clip(rng.normal(params["pm25_baseline"], 10), 5, 60)) |
|
|
| pm25_total = float(pm25_smoke + rng.normal(params["pm25_baseline"], 8)) |
| pm25_total = float(np.clip(pm25_total, 10, 900)) |
|
|
| fire_proximity_km = float(np.clip( |
| rng.normal(params["fire_proximity_km_mean"], params["fire_proximity_km_sd"]), 0.5, 100 |
| )) |
|
|
| smoke_days = int(np.clip( |
| rng.normal(params["smoke_days_mean"], params["smoke_days_sd"]) * (1.2 if in_fire_season else 0.3), |
| 0, 120, |
| )) |
|
|
| fire_count = int(np.clip(rng.poisson(params["fire_frequency_mean"]), 0, 15)) |
|
|
| aqi_category = ( |
| "hazardous" if pm25_total > 250 else |
| "very_unhealthy" if pm25_total > 150 else |
| "unhealthy" if pm25_total > 55 else |
| "moderate" if pm25_total > 35 else |
| "good" |
| ) |
|
|
| mask_use = int(rng.random() < params["mask_access"] * (1.5 if in_fire_season else 0.5)) |
| stayed_indoors = int(in_fire_season and rng.random() < 0.20) |
|
|
| vulnerability = ( |
| 0.15 |
| + is_child * 0.25 |
| + is_elderly * 0.20 |
| + pre_existing_asthma * 0.15 |
| + pre_existing_copd * 0.15 |
| + smoker * 0.10 |
| ) |
| vulnerability = float(np.clip(vulnerability, 0, 1)) |
|
|
| exposure_risk = float(np.clip( |
| (pm25_total / 300) * (1 - mask_use * 0.3) * (1 - stayed_indoors * 0.4) * vulnerability * 2, |
| 0, 1, |
| )) |
|
|
| cough = int(rng.random() < 0.15 + exposure_risk * 0.35) |
| wheeze = int(rng.random() < 0.08 + exposure_risk * 0.25) |
| dyspnoea = int(rng.random() < 0.05 + exposure_risk * 0.20) |
| eye_irritation = int(in_fire_season and rng.random() < 0.20 + exposure_risk * 0.25) |
|
|
| ari_episode = int(rng.random() < params["ari_rate_per1k"] / 1000 * (1 + exposure_risk * 2)) |
| asthma_exacerbation = int(pre_existing_asthma and rng.random() < 0.15 + exposure_risk * 0.3) |
| copd_exacerbation = int(pre_existing_copd and rng.random() < 0.10 + exposure_risk * 0.25) |
|
|
| er_visit = int( |
| (ari_episode or asthma_exacerbation or copd_exacerbation) |
| and rng.random() < params["er_visit_rate"] |
| ) |
| hospitalised = int(er_visit and rng.random() < 0.25) |
|
|
| mortality = int( |
| hospitalised and rng.random() < params["mortality_rate_per100k"] / 100_000 * 500 |
| ) |
|
|
| climate_fire_trend = float(np.clip(0.015 * (year - 2010) + rng.normal(0, 0.005), -0.02, 0.1)) |
|
|
| record = { |
| "record_id": f"{name[:3].upper()}-{idx:05d}", |
| "scenario": name, |
| "year": year, |
| "month": month, |
| "in_fire_season": in_fire_season, |
| "age": age, |
| "sex": sex, |
| "setting": setting, |
| "is_child_u5": is_child, |
| "is_elderly_60plus": is_elderly, |
| "pre_existing_asthma": pre_existing_asthma, |
| "pre_existing_copd": pre_existing_copd, |
| "smoker": smoker, |
| "pm25_smoke_ugm3": round(pm25_smoke, 1), |
| "pm25_total_ugm3": round(pm25_total, 1), |
| "aqi_category": aqi_category, |
| "fire_proximity_km": round(fire_proximity_km, 1), |
| "smoke_days_per_season": smoke_days, |
| "fire_count": fire_count, |
| "mask_use": mask_use, |
| "stayed_indoors": stayed_indoors, |
| "vulnerability_index": round(vulnerability, 2), |
| "exposure_risk_score": round(exposure_risk, 3), |
| "cough": cough, |
| "wheeze": wheeze, |
| "dyspnoea": dyspnoea, |
| "eye_irritation": eye_irritation, |
| "ari_episode": ari_episode, |
| "asthma_exacerbation": asthma_exacerbation, |
| "copd_exacerbation": copd_exacerbation, |
| "er_visit": er_visit, |
| "hospitalised": hospitalised, |
| "mortality": mortality, |
| "climate_fire_trend": round(climate_fire_trend, 4), |
| } |
| 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() |
|
|