File size: 13,989 Bytes
7bc82b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
"""
Irrigation Access and Efficiency - Sub-Saharan Africa
=======================================================
Based on research:
- FAO 2024: Only 3-6% of cropland under irrigation in SSA
- World Bank 2023: Water use efficiency 30-50% below potential
- IWMI 2023: Small-scale irrigation expanding 2-3% annually
- AfDB 2023: Irrigation potential utilization 20-40%
- AGRA 2023: Solar-powered irrigation growing 15% annually

PARAMETER EVIDENCE TABLE
─────────────────────────────────────────────────────────────────────────
Parameter              │ Value Used       │ Source                    │ Year
───────────────────────┼──────────────────┼───────────────────────────┼──────
Irrigated cropland     │ 3-6%             │ FAO 2024                  │ 2024
Water use efficiency   │ 30-50% below     │ World Bank 2023           │ 2023
Small-scale growth     │ 2-3% annually    │ IWMI 2023                 │ 2023
Potential utilization  │ 20-40%           │ AfDB 2023                 │ 2023
Solar irrigation       │ 15% growth       │ AGRA 2023                 │ 2023

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']
IRRIGATION_TYPES = ['surface', 'sprinkler', 'drip', 'flood', 'center_pivot', 'manual']
WATER_SOURCES = ['river', 'groundwater', 'reservoir', 'rainwater_harvesting', 'lake', 'wetland']
ENERGY_SOURCES = ['diesel', 'electric', 'solar', 'gravity', 'manual', 'wind']
OWNERSHIP = ['individual', 'shared', 'cooperative', 'government', 'private_company']
CROPS_IRRIGATED = ['vegetables', 'rice', 'maize', 'sugarcane', 'fruits', 'cotton', 'horticulture']
YEARS = list(range(2018, 2026))

COUNTRY_IRRIGATION_RATE = {
    'Kenya': 0.04, 'Uganda': 0.02, 'Nigeria': 0.03, 'Ghana': 0.04,
    'Tanzania': 0.02, 'Ethiopia': 0.05, 'Malawi': 0.03, 'Zambia': 0.06,
    'Mali': 0.04, 'Burkina Faso': 0.03
}

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"IRR-{country[:3].upper()}-{year}-{i+1:05d}"
        
        farm_size = rng.lognormal(0.3, 0.7)
        farm_size = np.clip(farm_size, 0.2, 50.0)
        
        farm_type = sc({'subsistence': 0.50, 'semi-commercial': 0.40, 'commercial': 0.10}, rng)
        
        base_irrigation_rate = COUNTRY_IRRIGATION_RATE[country]
        irrigation_prob = base_irrigation_rate + 0.02 * (year - 2018)
        irrigation_prob += 0.05 if farm_type == 'commercial' else 0.02 if farm_type == 'semi-commercial' else 0
        
        has_irrigation = rng.random() < irrigation_prob
        
        rainfall_mm = rng.normal(900, 250)
        rainfall_mm = np.clip(rainfall_mm, 400, 2000)
        
        rainfall_variability = rng.uniform(15, 35)
        
        drought_frequency = rng.choice(['rare', 'occasional', 'frequent'], p=[0.30, 0.45, 0.25])
        
        water_stress_months = rng.integers(2, 8)
        
        if has_irrigation:
            irrigation_type = rng.choice(IRRIGATION_TYPES, p=[0.25, 0.20, 0.15, 0.25, 0.05, 0.10])
            
            water_source = rng.choice(WATER_SOURCES, p=[0.30, 0.25, 0.15, 0.15, 0.10, 0.05])
            
            energy_source = rng.choice(ENERGY_SOURCES, p=[0.30, 0.20, 0.15, 0.20, 0.10, 0.05])
            
            if year > 2020 and energy_source == 'solar':
                energy_source = 'solar'
            elif year > 2022 and rng.random() < 0.20:
                energy_source = 'solar'
            
            ownership = rng.choice(OWNERSHIP, p=[0.45, 0.20, 0.15, 0.15, 0.05])
            
            area_irrigated_ha = farm_size * rng.uniform(0.3, 1.0)
            
            irrigation_capacity_m3_day = area_irrigated_ha * rng.uniform(30, 60)
            
            system_age_years = rng.integers(0, 20)
            
            system_condition = rng.choice(['excellent', 'good', 'fair', 'poor'], p=[0.15, 0.35, 0.35, 0.15])
            
            installation_cost_usd = area_irrigated_ha * {'surface': 800, 'sprinkler': 1500, 'drip': 2500, 'flood': 400, 'center_pivot': 5000, 'manual': 200}[irrigation_type]
            
            annual_maintenance_usd = installation_cost_usd * rng.uniform(0.05, 0.15)
            
            water_applied_mm = rng.uniform(300, 800)
            
            crop_water_requirement_mm = rng.uniform(400, 700)
            
            application_efficiency = {'surface': 0.55, 'sprinkler': 0.75, 'drip': 0.90, 'flood': 0.45, 'center_pivot': 0.80, 'manual': 0.60}[irrigation_type]
            application_efficiency *= rng.uniform(0.85, 1.10)
            application_efficiency = np.clip(application_efficiency, 0.30, 0.95)
            
            effective_water_mm = water_applied_mm * application_efficiency
            
            water_productivity_kg_m3 = rng.uniform(0.8, 2.5)
            
            conveyance_efficiency = rng.uniform(0.70, 0.95)
            
            distribution_uniformity = rng.uniform(0.60, 0.90)
            
            if irrigation_type == 'drip':
                distribution_uniformity = np.clip(distribution_uniformity + 0.10, 0.70, 0.95)
            
            energy_cost_per_season = 0
            if energy_source == 'diesel':
                energy_cost_per_season = area_irrigated_ha * rng.uniform(100, 300)
            elif energy_source == 'electric':
                energy_cost_per_season = area_irrigated_ha * rng.uniform(50, 150)
            
            labor_hours_per_season = area_irrigated_ha * {'surface': 30, 'sprinkler': 20, 'drip': 15, 'flood': 40, 'center_pivot': 10, 'manual': 80}[irrigation_type]
            
            irrigation_frequency = rng.choice(['daily', 'weekly', 'biweekly', 'as_needed'], p=[0.20, 0.35, 0.25, 0.20])
            
            scheduling_method = rng.choice(['visual', 'calendar', 'soil_moisture', 'weather_based'], p=[0.40, 0.35, 0.15, 0.10])
            
            yield_increase_pct = rng.uniform(20, 60)
            
            cropping_intensity = rng.uniform(1.2, 2.5)
            
            seasons_irrigated = rng.choice([1, 2, 3], p=[0.50, 0.40, 0.10])
            
            water_user_association = rng.random() < 0.25
            
            permit_obtained = rng.random() < 0.30
            
            water_conflicts = rng.random() < 0.20
            
            groundwater_depth_m = rng.uniform(5, 80) if water_source == 'groundwater' else 0
            
            pump_capacity_hp = rng.uniform(2, 25) if energy_source in ['diesel', 'electric', 'solar'] else 0
            
            maintenance_quality = 'good' if system_condition in ['excellent', 'good'] else 'poor'
            
            technology_level = 'high' if irrigation_type in ['drip', 'center_pivot'] else 'medium' if irrigation_type == 'sprinkler' else 'low'
            
            water_scarcity_impact = drought_frequency == 'frequent' and not water_conflicts
            
            expansion_potential = water_source in ['groundwater', 'reservoir'] and system_condition in ['excellent', 'good']
            
        else:
            irrigation_type = 'none'
            water_source = 'none'
            energy_source = 'none'
            ownership = 'none'
            area_irrigated_ha = 0
            irrigation_capacity_m3_day = 0
            system_age_years = 0
            system_condition = 'na'
            installation_cost_usd = 0
            annual_maintenance_usd = 0
            water_applied_mm = 0
            crop_water_requirement_mm = rng.uniform(400, 700)
            application_efficiency = 0
            effective_water_mm = 0
            water_productivity_kg_m3 = 0
            conveyance_efficiency = 0
            distribution_uniformity = 0
            energy_cost_per_season = 0
            labor_hours_per_season = 0
            irrigation_frequency = 'none'
            scheduling_method = 'none'
            yield_increase_pct = 0
            cropping_intensity = 1.0
            seasons_irrigated = 0
            water_user_association = False
            permit_obtained = False
            water_conflicts = False
            groundwater_depth_m = 0
            pump_capacity_hp = 0
            maintenance_quality = 'na'
            technology_level = 'none'
            water_scarcity_impact = drought_frequency == 'frequent'
            expansion_potential = False
        
        primary_crop = rng.choice(CROPS_IRRIGATED, p=[0.25, 0.20, 0.15, 0.10, 0.15, 0.08, 0.07])
        
        rainfed_area_ha = farm_size - area_irrigated_ha
        
        total_water_use_m3_season = area_irrigated_ha * water_applied_mm * 10
        
        water_withdrawal_per_ha_m3 = total_water_use_m3_season / area_irrigated_ha if area_irrigated_ha > 0 else 0
        
        irrigation_efficiency_index = application_efficiency * conveyance_efficiency * distribution_uniformity * 100 if has_irrigation else 0
        
        investment_return_years = installation_cost_usd / (yield_increase_pct * farm_size * 500 / 100) if has_irrigation and yield_increase_pct > 0 else 0
        
        subsidy_received = has_irrigation and rng.random() < 0.25
        subsidy_amount_usd = installation_cost_usd * rng.uniform(0.30, 0.60) if subsidy_received else 0
        
        financing = has_irrigation and rng.random() < 0.30
        
        technical_support = has_irrigation and rng.random() < 0.35
        
        recs.append({
            'record_id': i + 1,
            'irrigation_id': record_id,
            'country': country,
            'year': year,
            'farm_size_ha': round(farm_size, 2),
            'farm_type': farm_type,
            'has_irrigation': has_irrigation,
            'annual_rainfall_mm': round(rainfall_mm, 0),
            'rainfall_variability_pct': round(rainfall_variability, 1),
            'drought_frequency': drought_frequency,
            'water_stress_months': water_stress_months,
            'irrigation_type': irrigation_type,
            'water_source': water_source,
            'energy_source': energy_source,
            'ownership': ownership,
            'area_irrigated_ha': round(area_irrigated_ha, 2),
            'rainfed_area_ha': round(rainfed_area_ha, 2),
            'irrigation_pct': round(area_irrigated_ha / farm_size * 100, 1) if farm_size > 0 else 0,
            'irrigation_capacity_m3_day': round(irrigation_capacity_m3_day, 0),
            'system_age_years': system_age_years,
            'system_condition': system_condition,
            'installation_cost_usd': round(installation_cost_usd, 0),
            'annual_maintenance_usd': round(annual_maintenance_usd, 0),
            'subsidy_received': subsidy_received,
            'subsidy_amount_usd': round(subsidy_amount_usd, 0),
            'financing_access': financing,
            'water_applied_mm': round(water_applied_mm, 0),
            'crop_water_requirement_mm': round(crop_water_requirement_mm, 0),
            'application_efficiency_pct': round(application_efficiency * 100, 1),
            'effective_water_mm': round(effective_water_mm, 0),
            'water_productivity_kg_m3': round(water_productivity_kg_m3, 2),
            'conveyance_efficiency_pct': round(conveyance_efficiency * 100, 1),
            'distribution_uniformity_pct': round(distribution_uniformity * 100, 1),
            'irrigation_efficiency_index': round(irrigation_efficiency_index, 1),
            'energy_cost_usd_season': round(energy_cost_per_season, 0),
            'labor_hours_season': round(labor_hours_per_season, 0),
            'irrigation_frequency': irrigation_frequency,
            'scheduling_method': scheduling_method,
            'primary_crop': primary_crop,
            'yield_increase_pct': round(yield_increase_pct, 1),
            'cropping_intensity': round(cropping_intensity, 2),
            'seasons_irrigated': seasons_irrigated,
            'total_water_use_m3': round(total_water_use_m3_season, 0),
            'water_withdrawal_m3_ha': round(water_withdrawal_per_ha_m3, 0),
            'water_user_association': water_user_association,
            'permit_obtained': permit_obtained,
            'water_conflicts': water_conflicts,
            'groundwater_depth_m': round(groundwater_depth_m, 1),
            'pump_capacity_hp': round(pump_capacity_hp, 1),
            'maintenance_quality': maintenance_quality,
            'technology_level': technology_level,
            'technical_support': technical_support,
            'water_scarcity_impact': water_scarcity_impact,
            'expansion_potential': expansion_potential,
            'investment_return_years': round(investment_return_years, 1),
            'irrigation_category': 'none' if not has_irrigation else 'modern' if irrigation_type in ['drip', 'sprinkler'] else 'traditional'
        })
    
    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'irrigation_access_efficiency_africa_{sn}.csv'), index=False)
        print(f"Saved: irrigation_access_efficiency_africa_{sn}.csv, n={len(d)}")