| """ |
| Livestock Health and Productivity - Sub-Saharan Africa |
| ======================================================== |
| Based on research: |
| - FAO 2024: Cattle mortality 8-15% in smallholder systems |
| - ILRI 2023: Milk yields 2-5L/day vs 15-25L potential |
| - World Bank 2023: Poultry mortality 15-30% in traditional systems |
| - AU-IBAR 2023: Disease prevalence 20-40% for endemic diseases |
| - GALVmed 2023: Vaccination coverage 10-30% for priority diseases |
| |
| PARAMETER EVIDENCE TABLE |
| ───────────────────────────────────────────────────────────────────────── |
| Parameter │ Value Used │ Source │ Year |
| ───────────────────────┼──────────────────┼───────────────────────────┼────── |
| Cattle mortality │ 8-15% │ FAO 2024 │ 2024 |
| Milk yields │ 2-5L/day │ ILRI 2023 │ 2023 |
| Poultry mortality │ 15-30% │ World Bank 2023 │ 2023 |
| Disease prevalence │ 20-40% │ AU-IBAR 2023 │ 2023 |
| Vaccination coverage │ 10-30% │ GALVmed 2023 │ 2023 |
| Goat mortality │ 10-20% │ FAO 2024 │ 2024 |
| |
| Author: Electric Sheep Africa |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| import argparse |
| import os |
|
|
| np.random.default_rng(42) |
|
|
| COUNTRIES = ['Kenya', 'Uganda', 'Nigeria', 'Ghana', 'Tanzania', 'Ethiopia', 'Malawi', 'Zambia', 'Mali', 'Burkina Faso'] |
| SPECIES = ['cattle', 'goats', 'sheep', 'poultry', 'pigs', 'donkeys'] |
| PRODUCTION_SYSTEMS = ['extensive', 'semi_intensive', 'intensive', 'pastoral', 'agropastoral'] |
| BREED_TYPES = ['local', 'crossbreed', 'exotic'] |
| FEED_SOURCES = ['grazing', 'crop_residues', 'concentrates', 'fodder_crops', 'mixed'] |
| HEALTH_ISSUES = ['tick_borne', 'respiratory', 'digestive', 'parasitic', 'metabolic', 'reproductive'] |
| YEARS = list(range(2018, 2026)) |
|
|
| SPECIES_BASE_MORTALITY = { |
| 'cattle': 0.12, 'goats': 0.15, 'sheep': 0.14, 'poultry': 0.22, 'pigs': 0.18, 'donkeys': 0.08 |
| } |
|
|
| SPECIES_BASE_PRODUCTIVITY = { |
| 'cattle': {'milk_l_day': 3.5, 'weight_gain_kg_day': 0.4, 'calving_rate': 0.55}, |
| 'goats': {'milk_l_day': 0.8, 'weight_gain_kg_day': 0.06, 'kidding_rate': 1.2}, |
| 'sheep': {'milk_l_day': 0.5, 'weight_gain_kg_day': 0.08, 'lambing_rate': 1.1}, |
| 'poultry': {'eggs_year': 80, 'weight_gain_kg_week': 0.15}, |
| 'pigs': {'litter_size': 8, 'weight_gain_kg_day': 0.35}, |
| 'donkeys': {'work_hours_day': 4, 'weight_gain_kg_day': 0.1} |
| } |
|
|
| DISEASE_PREVALENCE = { |
| 'tick_borne': 0.23, 'respiratory': 0.17, 'digestive': 0.14, |
| 'parasitic': 0.28, 'metabolic': 0.07, 'reproductive': 0.11 |
| } |
|
|
| def sc(p, rng): |
| a = np.array(list(p.values())) |
| return rng.choice(list(p.keys()), p=a/a.sum()) |
|
|
| def gen(n=5000, seed=42): |
| rng = np.random.default_rng(seed) |
| recs = [] |
| |
| for i in range(n): |
| country = rng.choice(COUNTRIES) |
| year = rng.choice(YEARS) |
| |
| record_id = f"LVS-{country[:3].upper()}-{year}-{i+1:05d}" |
| |
| farm_size = rng.lognormal(0.2, 0.6) |
| farm_size = np.clip(farm_size, 0.2, 30.0) |
| |
| production_system = sc({ |
| 'extensive': 0.35, 'semi_intensive': 0.25, 'intensive': 0.10, |
| 'pastoral': 0.15, 'agropastoral': 0.15 |
| }, rng) |
| |
| primary_species = rng.choice(SPECIES, p=[0.30, 0.25, 0.15, 0.20, 0.07, 0.03]) |
| |
| herd_size_base = {'cattle': 8, 'goats': 15, 'sheep': 12, 'poultry': 35, 'pigs': 6, 'donkeys': 2}[primary_species] |
| herd_size = int(rng.lognormal(np.log(herd_size_base), 0.8)) |
| herd_size = np.clip(herd_size, 1, {'cattle': 100, 'goats': 200, 'sheep': 150, 'poultry': 500, 'pigs': 50, 'donkeys': 10}[primary_species]) |
| |
| breed_type = sc({ |
| 'local': 0.60, 'crossbreed': 0.30, 'exotic': 0.10 |
| }, rng) |
| |
| feed_source = sc({ |
| 'grazing': 0.45, 'crop_residues': 0.20, 'concentrates': 0.10, |
| 'fodder_crops': 0.10, 'mixed': 0.15 |
| }, rng) |
| |
| if production_system in ['pastoral', 'extensive']: |
| feed_source = 'grazing' |
| elif production_system == 'intensive': |
| feed_source = rng.choice(['concentrates', 'mixed'], p=[0.5, 0.5]) |
| |
| water_access = rng.choice(['adequate', 'seasonal', 'limited', 'poor'], p=[0.35, 0.30, 0.25, 0.10]) |
| |
| housing_type = rng.choice(['none', 'simple_shelter', 'improved_shelter', 'modern'], p=[0.35, 0.35, 0.20, 0.10]) |
| |
| base_mortality = SPECIES_BASE_MORTALITY[primary_species] |
| mortality_modifier = 1.0 |
| mortality_modifier *= 0.7 if production_system == 'intensive' else 1.2 if production_system in ['pastoral', 'extensive'] else 1.0 |
| mortality_modifier *= 0.8 if breed_type == 'local' else 1.1 if breed_type == 'exotic' else 1.0 |
| mortality_modifier *= 0.9 if housing_type in ['improved_shelter', 'modern'] else 1.1 if housing_type == 'none' else 1.0 |
| |
| mortality_rate = base_mortality * mortality_modifier * rng.uniform(0.8, 1.2) |
| mortality_rate = np.clip(mortality_rate, 0.03, 0.45) |
| |
| animals_died = int(herd_size * mortality_rate) |
| |
| disease_outbreak = rng.random() < 0.20 |
| |
| primary_disease = None |
| if disease_outbreak: |
| primary_disease = rng.choice(list(DISEASE_PREVALENCE.keys()), |
| p=list(DISEASE_PREVALENCE.values())) |
| |
| disease_severity = rng.choice(['mild', 'moderate', 'severe'], p=[0.40, 0.40, 0.20]) if disease_outbreak else 'none' |
| |
| vaccination_coverage = rng.lognormal(np.log(0.20), 0.8) |
| vaccination_coverage = np.clip(vaccination_coverage, 0.02, 0.60) |
| |
| animals_vaccinated = int(herd_size * vaccination_coverage) |
| |
| deworming_frequency = rng.choice(['never', 'yearly', 'biannual', 'quarterly'], p=[0.30, 0.35, 0.25, 0.10]) |
| |
| tick_control = rng.random() < 0.45 |
| |
| veterinary_access = rng.random() < 0.35 |
| |
| vet_visits_year = rng.integers(0, 6) if veterinary_access else 0 |
| |
| health_insurance = rng.random() < 0.05 |
| |
| base_prod = SPECIES_BASE_PRODUCTIVITY[primary_species] |
| |
| prod_modifier = 1.0 |
| prod_modifier *= 1.3 if breed_type == 'exotic' else 1.1 if breed_type == 'crossbreed' else 1.0 |
| prod_modifier *= 0.85 if disease_outbreak else 1.0 |
| prod_modifier *= 0.9 if water_access in ['limited', 'poor'] else 1.0 |
| prod_modifier *= 1.15 if production_system == 'intensive' else 0.9 if production_system == 'pastoral' else 1.0 |
| prod_modifier *= 1.1 if feed_source in ['concentrates', 'mixed'] else 0.95 if feed_source == 'grazing' else 1.0 |
| |
| if primary_species == 'cattle': |
| milk_yield_l_day = base_prod['milk_l_day'] * prod_modifier * rng.uniform(0.8, 1.2) |
| milk_yield_l_day = np.clip(milk_yield_l_day, 0.5, 20) |
| lactation_length_days = int(rng.normal(250, 40)) |
| annual_milk_l = milk_yield_l_day * lactation_length_days |
| weight_gain_kg_day = base_prod['weight_gain_kg_day'] * prod_modifier * rng.uniform(0.7, 1.3) |
| calving_rate = base_prod['calving_rate'] * prod_modifier * rng.uniform(0.8, 1.1) |
| calving_rate = np.clip(calving_rate, 0.3, 0.9) |
| live_weight_kg = rng.normal(320, 60) if breed_type == 'local' else rng.normal(400, 70) |
| elif primary_species == 'goats': |
| milk_yield_l_day = base_prod['milk_l_day'] * prod_modifier * rng.uniform(0.7, 1.3) |
| weight_gain_kg_day = base_prod['weight_gain_kg_day'] * prod_modifier |
| kidding_rate = base_prod['kidding_rate'] * prod_modifier |
| annual_milk_l = milk_yield_l_day * 180 |
| calving_rate = kidding_rate |
| lactation_length_days = 180 |
| live_weight_kg = rng.normal(28, 8) |
| elif primary_species == 'sheep': |
| milk_yield_l_day = base_prod['milk_l_day'] |
| weight_gain_kg_day = base_prod['weight_gain_kg_day'] * prod_modifier |
| annual_milk_l = 0 |
| lambing_rate = base_prod['lambing_rate'] |
| calving_rate = lambing_rate |
| lactation_length_days = 0 |
| live_weight_kg = rng.normal(32, 7) |
| elif primary_species == 'poultry': |
| eggs_per_year = int(base_prod['eggs_year'] * prod_modifier * rng.uniform(0.7, 1.3)) |
| weight_gain_kg_week = base_prod['weight_gain_kg_week'] * prod_modifier |
| weight_gain_kg_day = weight_gain_kg_week / 7 |
| milk_yield_l_day = 0 |
| annual_milk_l = 0 |
| calving_rate = 0 |
| lactation_length_days = 0 |
| live_weight_kg = rng.normal(1.8, 0.5) |
| elif primary_species == 'pigs': |
| litter_size = int(base_prod['litter_size'] * prod_modifier * rng.uniform(0.8, 1.2)) |
| weight_gain_kg_day = base_prod['weight_gain_kg_day'] * prod_modifier |
| litters_per_year = rng.uniform(1.8, 2.3) |
| milk_yield_l_day = 0 |
| annual_milk_l = 0 |
| calving_rate = litter_size |
| lactation_length_days = 0 |
| live_weight_kg = rng.normal(80, 20) |
| else: |
| milk_yield_l_day = 0 |
| annual_milk_l = 0 |
| calving_rate = 0 |
| lactation_length_days = 0 |
| weight_gain_kg_day = base_prod['weight_gain_kg_day'] |
| live_weight_kg = rng.normal(140, 25) |
| |
| reproductive_health = rng.random() < 0.75 |
| fertility_issues = not reproductive_health and rng.random() < 0.25 |
| |
| body_condition_score = rng.integers(1, 6) |
| |
| nutrition_status = 'adequate' if body_condition_score >= 3 else 'poor' |
| |
| supplementation = rng.random() < 0.30 |
| |
| mineral_supplement = rng.random() < 0.20 |
| |
| forage_quality = rng.choice(['poor', 'moderate', 'good'], p=[0.30, 0.45, 0.25]) |
| |
| breeding_method = rng.choice(['natural', 'artificial_insemination', 'both'], p=[0.75, 0.10, 0.15]) |
| |
| record_keeping = rng.random() < 0.20 |
| |
| market_access = rng.choice(['farm_gate', 'local_market', 'regional', 'export'], p=[0.40, 0.35, 0.20, 0.05]) |
| |
| price_per_head = live_weight_kg * rng.lognormal(np.log(2.5), 0.3) |
| |
| annual_revenue = herd_size * price_per_head * 0.3 |
| |
| feed_cost = herd_size * rng.uniform(20, 80) if feed_source in ['concentrates', 'mixed'] else herd_size * rng.uniform(5, 20) |
| health_cost = animals_vaccinated * 2 + vet_visits_year * 25 |
| labor_cost = herd_size * rng.uniform(5, 15) |
| |
| total_cost = feed_cost + health_cost + labor_cost |
| |
| net_income = annual_revenue - total_cost |
| |
| productivity_index = 50 + (body_condition_score - 2) * 10 + (10 if reproductive_health else -5) |
| productivity_index = np.clip(productivity_index, 10, 100) |
| |
| health_index = 100 - mortality_rate * 200 - (15 if disease_outbreak else 0) + vaccination_coverage * 50 |
| health_index = np.clip(health_index, 10, 100) |
| |
| recs.append({ |
| 'record_id': i + 1, |
| 'livestock_id': record_id, |
| 'country': country, |
| 'year': year, |
| 'farm_size_ha': round(farm_size, 2), |
| 'production_system': production_system, |
| 'primary_species': primary_species, |
| 'herd_size': herd_size, |
| 'breed_type': breed_type, |
| 'feed_source': feed_source, |
| 'water_access': water_access, |
| 'housing_type': housing_type, |
| 'mortality_rate_pct': round(mortality_rate * 100, 1), |
| 'animals_died': animals_died, |
| 'disease_outbreak': disease_outbreak, |
| 'primary_disease': primary_disease if primary_disease else 'none', |
| 'disease_severity': disease_severity, |
| 'vaccination_coverage_pct': round(vaccination_coverage * 100, 1), |
| 'animals_vaccinated': animals_vaccinated, |
| 'deworming_frequency': deworming_frequency, |
| 'tick_control': tick_control, |
| 'veterinary_access': veterinary_access, |
| 'vet_visits_per_year': vet_visits_year, |
| 'health_insurance': health_insurance, |
| 'milk_yield_l_day': round(milk_yield_l_day, 2) if milk_yield_l_day > 0 else 0, |
| 'lactation_length_days': lactation_length_days if lactation_length_days > 0 else 0, |
| 'annual_milk_l': round(annual_milk_l, 0) if annual_milk_l > 0 else 0, |
| 'weight_gain_kg_day': round(weight_gain_kg_day, 3) if primary_species in ['cattle', 'goats', 'sheep', 'pigs'] else 0, |
| 'live_weight_kg': round(live_weight_kg, 1), |
| 'reproductive_rate': round(calving_rate, 2) if calving_rate > 0 else 0, |
| 'reproductive_health': reproductive_health, |
| 'fertility_issues': fertility_issues, |
| 'body_condition_score': body_condition_score, |
| 'nutrition_status': nutrition_status, |
| 'supplementation': supplementation, |
| 'mineral_supplement': mineral_supplement, |
| 'forage_quality': forage_quality, |
| 'breeding_method': breeding_method, |
| 'record_keeping': record_keeping, |
| 'market_access': market_access, |
| 'price_per_head_usd': round(price_per_head, 2), |
| 'annual_revenue_usd': round(annual_revenue, 2), |
| 'feed_cost_usd': round(feed_cost, 2), |
| 'health_cost_usd': round(health_cost, 2), |
| 'labor_cost_usd': round(labor_cost, 2), |
| 'total_cost_usd': round(total_cost, 2), |
| 'net_income_usd': round(net_income, 2), |
| 'productivity_index': round(productivity_index, 1), |
| 'health_index': round(health_index, 1), |
| 'mortality_category': 'low' if mortality_rate < 0.10 else 'moderate' if mortality_rate < 0.20 else 'high', |
| 'intervention_priority': 'high' if mortality_rate > 0.20 or disease_outbreak else 'moderate' if mortality_rate > 0.12 else 'low' |
| }) |
| |
| return pd.DataFrame(recs) |
|
|
| if __name__ == "__main__": |
| p = argparse.ArgumentParser() |
| p.add_argument('--n', type=int, default=5000) |
| p.add_argument('--output', type=str, default='.') |
| a = p.parse_args() |
| |
| for sn, m, s in [('low_burden', 0.8, 42), ('moderate_burden', 1.0, 43), ('high_burden', 1.2, 44)]: |
| d = gen(int(a.n * m), s) |
| d['scenario'] = sn |
| d.to_csv(os.path.join(a.output, f'livestock_health_productivity_africa_{sn}.csv'), index=False) |
| print(f"Saved: livestock_health_productivity_africa_{sn}.csv, n={len(d)}") |
|
|