"""Generate synthetic arsenic in groundwater & health dataset for SSA. Research-based parameterization: - WHO Fact Sheet: 140M people in 70+ countries drink water >10 µg/L As; 94-220M at risk globally. Skin lesions after ~5 yrs, skin/bladder/lung cancer, CVD, diabetes, cognitive impairment in children. - Burkina Faso (ScienceDirect 2017): 1,498 groundwater measurements with elevated As in geogenic formations. - Ghana (ScienceDirect 2024): 15.8% of population in certain basins exposed to As-contaminated groundwater; mining areas (Tarkwa) add anthropogenic contamination. - PLOS ONE (2022): WHO 10 µg/L guideline set in 1993; many SSA countries not routinely testing for As. - IARC: Arsenic classified as Group 1 carcinogen. - WHO: Skin lesions (melanosis, keratosis) = most characteristic sign; precursor to skin cancer. - Meru County Kenya (2024): As in groundwater linked to skin cancer prevalence. """ 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 = { # Geogenic hotspot (Burkina Faso / Sahel crystalline rock) "geogenic_sahel_hotspot": { "setting_probs": {"rural": 0.60, "peri_urban": 0.25, "urban": 0.15}, "water_source_probs": {"borehole": 0.40, "shallow_well": 0.30, "piped": 0.10, "surface_water": 0.20}, # Burkina Faso: elevated As in crystalline aquifers "water_as_gm": 25.0, "water_as_gsd": 2.5, # µg/L "pct_above_who": 0.40, "exposure_years_mean": 10, "skin_lesion_prev": 0.12, "keratosis_prev": 0.08, "melanosis_prev": 0.10, "testing_rate": 0.05, "safe_alternative_pct": 0.15, }, # Mining-affected area (Ghana Tarkwa / gold belt type) "mining_affected_area": { "setting_probs": {"rural_mining": 0.50, "peri_urban": 0.30, "urban": 0.20}, "water_source_probs": {"borehole": 0.35, "shallow_well": 0.25, "piped": 0.20, "surface_water": 0.20}, # Ghana mining: anthropogenic + geogenic As "water_as_gm": 35.0, "water_as_gsd": 2.8, "pct_above_who": 0.50, "exposure_years_mean": 8, "skin_lesion_prev": 0.15, "keratosis_prev": 0.10, "melanosis_prev": 0.12, "testing_rate": 0.08, "safe_alternative_pct": 0.20, }, # Low-moderate exposure (East African Rift / volcanic) "rift_valley_volcanic": { "setting_probs": {"rural": 0.50, "peri_urban": 0.30, "urban": 0.20}, "water_source_probs": {"borehole": 0.35, "shallow_well": 0.20, "piped": 0.25, "surface_water": 0.20}, # Rift Valley: volcanic geology, co-occurring fluoride "water_as_gm": 12.0, "water_as_gsd": 2.2, "pct_above_who": 0.25, "exposure_years_mean": 12, "skin_lesion_prev": 0.06, "keratosis_prev": 0.04, "melanosis_prev": 0.05, "testing_rate": 0.10, "safe_alternative_pct": 0.25, }, } SCENARIO_FILES = { "geogenic_sahel_hotspot": "arsenic_sahel_geogenic.csv", "mining_affected_area": "arsenic_mining_affected.csv", "rift_valley_volcanic": "arsenic_rift_volcanic.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)) setting = _choice(rng, params["setting_probs"]) age = int(np.clip(rng.normal(35, 18), 1, 75)) sex = rng.choice(["male", "female"], p=[0.48, 0.52]) is_child = int(age < 15) water_source = _choice(rng, params["water_source_probs"]) litres_per_day = float(np.clip(rng.normal(2.5, 0.8), 0.5, 6)) # Water arsenic concentration (µg/L) – log-normal water_as = float(np.clip( rng.lognormal(np.log(params["water_as_gm"]), np.log(params["water_as_gsd"])), 0.5, 500, )) # Piped water tends to be lower if water_source == "piped": water_as *= 0.4 elif water_source == "surface_water": water_as *= 0.6 above_who_10 = int(water_as > 10) above_50 = int(water_as > 50) exposure_years = int(np.clip(rng.normal(params["exposure_years_mean"], 5), 0, 40)) cumulative_dose = float(water_as * litres_per_day * exposure_years * 365 / 1000) # mg # As testing (most SSA countries don't routinely test) water_tested = int(rng.random() < params["testing_rate"]) safe_alternative_available = int(rng.random() < params["safe_alternative_pct"]) uses_safe_alternative = int(safe_alternative_available and rng.random() < 0.50) # Adjust effective exposure if using safe alternative effective_as = water_as * (0.2 if uses_safe_alternative else 1.0) # Biomarker: urinary As (µg/L) urine_as = float(np.clip( rng.lognormal(np.log(max(effective_as * 0.6, 1)), 0.6), 1, 500, )) elevated_urine_as = int(urine_as > 50) # Health effects (WHO: skin lesions after ~5 yrs) risk_mult = np.clip(effective_as / 10 * (exposure_years / 10), 0, 5) # Skin (WHO: most characteristic effects) melanosis = int(exposure_years >= 3 and rng.random() < np.clip( params["melanosis_prev"] * risk_mult, 0, 0.40)) keratosis = int(exposure_years >= 5 and rng.random() < np.clip( params["keratosis_prev"] * risk_mult, 0, 0.35)) skin_lesion = int(melanosis or keratosis) # Cancer (IARC Group 1: skin, bladder, lung) skin_cancer = int(exposure_years >= 10 and rng.random() < np.clip( 0.005 * risk_mult, 0, 0.05)) bladder_cancer = int(age >= 40 and exposure_years >= 10 and rng.random() < np.clip( 0.003 * risk_mult, 0, 0.03)) lung_cancer = int(age >= 40 and exposure_years >= 10 and rng.random() < np.clip( 0.002 * risk_mult, 0, 0.02)) any_cancer = int(skin_cancer or bladder_cancer or lung_cancer) # CVD & diabetes (WHO) cardiovascular = int(age >= 30 and rng.random() < np.clip( 0.04 + risk_mult * 0.02, 0, 0.15)) diabetes = int(age >= 25 and rng.random() < np.clip( 0.03 + risk_mult * 0.015, 0, 0.12)) # Peripheral neuropathy neuropathy = int(exposure_years >= 5 and rng.random() < np.clip( 0.03 * risk_mult, 0, 0.15)) # Child effects (WHO: cognitive development, mortality) child_cognitive = int(is_child and rng.random() < np.clip(risk_mult * 0.05, 0, 0.20)) adverse_pregnancy = int(sex == "female" and 15 <= age <= 45 and rng.random() < np.clip( 0.03 * risk_mult, 0, 0.10)) # Nutritional factors (malnutrition increases susceptibility) malnourished = int(rng.random() < 0.25) if malnourished: risk_mult *= 1.3 # Co-occurring contaminants fluoride_coexposure = int(rng.random() < (0.30 if "rift" in name else 0.10)) iron_coexposure = int(rng.random() < 0.20) record = { "record_id": f"{name[:3].upper()}-{idx:05d}", "scenario": name, "year": year, "setting": setting, "age": age, "sex": sex, "is_child": is_child, "water_source": water_source, "litres_per_day": round(litres_per_day, 1), "water_arsenic_ugL": round(water_as, 1), "above_who_10": above_who_10, "above_50": above_50, "exposure_years": exposure_years, "cumulative_dose_mg": round(cumulative_dose, 1), "water_tested": water_tested, "safe_alternative_available": safe_alternative_available, "uses_safe_alternative": uses_safe_alternative, "urine_arsenic_ugL": round(urine_as, 1), "elevated_urine_as": elevated_urine_as, "melanosis": melanosis, "keratosis": keratosis, "skin_lesion": skin_lesion, "skin_cancer": skin_cancer, "bladder_cancer": bladder_cancer, "lung_cancer": lung_cancer, "any_cancer": any_cancer, "cardiovascular": cardiovascular, "diabetes": diabetes, "neuropathy": neuropathy, "child_cognitive": child_cognitive, "adverse_pregnancy": adverse_pregnancy, "malnourished": malnourished, "fluoride_coexposure": fluoride_coexposure, "iron_coexposure": iron_coexposure, } 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()