#!/usr/bin/env python3 """ Leptospirosis Environmental Surveillance Dataset =================================================== Each record = ONE leptospirosis surveillance event. Literature: [1] Costa et al. (2015). Global morbidity and mortality of leptospirosis. PLOS NTDs. DOI: 10.1371/journal.pntd.0003898. 1.03 million cases/yr, 58,900 deaths globally. Highest in tropical SSA, SE Asia, Oceania. [2] Allan et al. (2015). Leptospirosis in northern Tanzania: seroprevalence 15.4% in febrile patients. PLOS NTDs. DOI: 10.1371/journal.pntd.0004230 [3] Maze et al. (2018). The epidemiology of febrile illness in SSA: implications for diagnosis and management. Clin Microbiol Infect. Leptospirosis misdiagnosed as malaria in 5-15% of febrile cases. [4] WHO (2003). Human leptospirosis guidance. Risk: flooding, rice farming, animal husbandry, urban slums with rodent exposure. [5] De Vries et al. (2014). Leptospirosis in SSA review. Seroprevalence 7-35% depending on occupation. DOI: 10.1016/j.ijid.2014.06.013 """ import numpy as np, pandas as pd, argparse, os SCENARIOS = { 'active_surveillance': { 'exemplar': 'Tanzania/Kenya', 'seroprevalence': 0.15, 'detection_rate': 0.30, 'lab_confirmation': 0.25, 'misdiagnosed_malaria': 0.10, 'flooding_exposure': 0.35, 'rodent_exposure': 0.50, 'treatment_rate': 0.55, 'cfr': 0.05, 'environmental_monitoring': 0.35, 'one_health_score': 0.40, }, 'moderate_awareness': { 'exemplar': 'Uganda/Mozambique', 'seroprevalence': 0.12, 'detection_rate': 0.12, 'lab_confirmation': 0.10, 'misdiagnosed_malaria': 0.25, 'flooding_exposure': 0.40, 'rodent_exposure': 0.55, 'treatment_rate': 0.30, 'cfr': 0.10, 'environmental_monitoring': 0.15, 'one_health_score': 0.20, }, 'unrecognized_burden': { 'exemplar': 'DRC/Nigeria/Ghana', 'seroprevalence': 0.20, 'detection_rate': 0.03, 'lab_confirmation': 0.03, 'misdiagnosed_malaria': 0.45, 'flooding_exposure': 0.50, 'rodent_exposure': 0.65, 'treatment_rate': 0.12, 'cfr': 0.18, 'environmental_monitoring': 0.05, 'one_health_score': 0.08, }, } def generate_dataset(n=10000, seed=42, scenario='moderate_awareness'): rng = np.random.default_rng(seed) sc = SCENARIOS[scenario] records = [] for idx in range(n): rec = {'id': idx + 1} rec['age'] = int(np.clip(rng.normal(30, 14), 3, 75)) rec['sex'] = rng.choice(['male','female'], p=[0.62, 0.38]) rec['residence'] = rng.choice(['urban_slum','peri_urban','rural_farming','rural_pastoral'], p=[0.20, 0.15, 0.40, 0.25]) rec['occupation'] = rng.choice(['rice_farmer','livestock_herder','fisher','abattoir_worker', 'market_vendor','urban_informal','child','other'], p=[0.20, 0.18, 0.10, 0.08, 0.08, 0.15, 0.10, 0.11]) # Exposure rec['flooding_exposure'] = 1 if rng.random() < sc['flooding_exposure'] else 0 rec['rodent_exposure'] = 1 if rng.random() < sc['rodent_exposure'] else 0 rec['animal_contact'] = 1 if rec['occupation'] in ['livestock_herder','abattoir_worker','rice_farmer'] else (1 if rng.random() < 0.20 else 0) rec['contaminated_water'] = 1 if (rec['flooding_exposure'] or rng.random() < 0.30) else 0 rec['season'] = rng.choice(['wet','dry'], p=[0.65, 0.35]) rec['recent_flood'] = 1 if (rec['season'] == 'wet' and rng.random() < 0.40) else 0 # Clinical rec['fever'] = 1 if rng.random() < 0.95 else 0 rec['jaundice'] = 1 if rng.random() < 0.25 else 0 rec['renal_failure'] = 1 if rng.random() < 0.12 else 0 rec['hemorrhagic'] = 1 if rng.random() < 0.08 else 0 rec['meningitis'] = 1 if rng.random() < 0.05 else 0 rec['weil_disease'] = 1 if (rec['jaundice'] and rec['renal_failure']) else 0 rec['severity'] = 'severe' if rec['weil_disease'] else ('moderate' if rec['jaundice'] or rec['renal_failure'] else 'mild') # Diagnosis diag_p = np.array([max(0.05, sc['detection_rate']), sc['misdiagnosed_malaria'], 0.15, 0.08, 0.05, 0.20]) diag_p = diag_p / diag_p.sum() rec['initial_diagnosis'] = rng.choice(['leptospirosis','malaria','typhoid','hepatitis','dengue_like','unknown'], p=diag_p) rec['lab_tested_lepto'] = 1 if rng.random() < sc['lab_confirmation'] else 0 rec['mat_positive'] = 1 if (rec['lab_tested_lepto'] and rng.random() < 0.40) else 0 rec['pcr_positive'] = 1 if (rec['lab_tested_lepto'] and rng.random() < 0.25) else 0 rec['confirmed_lepto'] = 1 if (rec['mat_positive'] or rec['pcr_positive']) else 0 # Treatment rec['treated_antibiotics'] = 1 if rng.random() < sc['treatment_rate'] else 0 rec['hospitalized'] = 1 if (rec['severity'] != 'mild' and rng.random() < 0.50) else 0 rec['dialysis'] = 1 if (rec['renal_failure'] and rng.random() < 0.15) else 0 cfr = sc['cfr'] * (3 if rec['weil_disease'] else 1) * (0.3 if rec['treated_antibiotics'] else 1) rec['died'] = 1 if rng.random() < min(0.50, cfr) else 0 # Environmental rec['environmental_monitoring'] = round(np.clip(rng.normal(sc['environmental_monitoring'], 0.10), 0, 1), 2) rec['rodent_control_program'] = 1 if rng.random() < sc['environmental_monitoring'] * 0.5 else 0 rec['one_health_coordination'] = round(np.clip(rng.normal(sc['one_health_score'], 0.12), 0, 1), 2) rec['water_sanitation_score'] = round(np.clip(rng.normal(0.30 + sc['one_health_score'] * 0.3, 0.12), 0, 1), 2) rec['year'] = rng.choice([2019,2020,2021,2022,2023], p=[0.12,0.18,0.20,0.25,0.25]) records.append(rec) df = pd.DataFrame(records) print(f"\n{'='*60}\nLeptospirosis — {scenario} ({sc['exemplar']})") print(f" Detection: {sc['detection_rate']*100:.0f}% | Misdiagnosed malaria: {sc['misdiagnosed_malaria']*100:.0f}%") print(f" Confirmed: {df['confirmed_lepto'].mean()*100:.1f}% | Deaths: {df['died'].sum()}") print(f" Weil disease: {df['weil_disease'].mean()*100:.1f}%") return df if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--all-scenarios', action='store_true') parser.add_argument('--n', type=int, default=10000) parser.add_argument('--seed', type=int, default=42) args = parser.parse_args() os.makedirs('data', exist_ok=True) if args.all_scenarios: for sc in SCENARIOS: df = generate_dataset(n=args.n, seed=args.seed, scenario=sc) df.to_csv(os.path.join('data', f'lepto_{sc}.csv'), index=False) print(f" -> Saved\n") else: df = generate_dataset(n=args.n, seed=args.seed) df.to_csv(os.path.join('data', 'lepto_moderate_awareness.csv'), index=False)