| """ |
| Climate Vulnerability and Exposure Dataset Generator for Africa |
| |
| ================================================================================ |
| PARAMETER EVIDENCE TABLE |
| ================================================================================ |
| | Parameter | Value/Range | Source | |
| |------------------------------|-----------------------|--------------------------| |
| | Africa warming rate | 1.5x global average | IPCC AR6 2023 | |
| | Extreme heat events increase | 4x since 1990 | WMO State of Climate | |
| | Climate-related displacement | 7M annually | IDMC 2024 | |
| | Agricultural GDP loss risk | 10-15% by 2050 | World Bank 2023 | |
| | Adaptive capacity index | 0.25-0.45 (Africa) | ND-GAIN 2024 | |
| | Climate finance gap | $250B annually | AfDB 2024 | |
| | Coastal flood exposure | 54M people | WRI Aqueduct 2024 | |
| | Rainfall variability | ±40% from mean | ClimDev-Africa 2024 | |
| ================================================================================ |
| |
| DAG Structure: |
| geographic_exposure -> climate_hazard_probability -> vulnerability_index |
| economic_capacity -> adaptive_capacity |
| infrastructure_resilience -> exposure_score |
| institutional_capacity -> response_capability |
| temperature_trends -> heat_stress_index |
| precipitation_patterns -> drought_flood_risk |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| from pathlib import Path |
|
|
| COUNTRIES = [ |
| "Kenya", "Uganda", "Nigeria", "Ghana", "Tanzania", "Ethiopia", |
| "Malawi", "Zambia", "Senegal", "Rwanda", "Niger", "Mali", |
| "DRC", "Mozambique", "South Africa" |
| ] |
|
|
| YEARS = list(range(2018, 2026)) |
|
|
| COUNTRY_VULNERABILITY_BASE = { |
| "Niger": {"exposure": 0.85, "adaptive_capacity": 0.25}, |
| "Mali": {"exposure": 0.82, "adaptive_capacity": 0.28}, |
| "DRC": {"exposure": 0.75, "adaptive_capacity": 0.30}, |
| "Mozambique": {"exposure": 0.78, "adaptive_capacity": 0.32}, |
| "Ethiopia": {"exposure": 0.72, "adaptive_capacity": 0.35}, |
| "Malawi": {"exposure": 0.70, "adaptive_capacity": 0.33}, |
| "Tanzania": {"exposure": 0.65, "adaptive_capacity": 0.38}, |
| "Uganda": {"exposure": 0.62, "adaptive_capacity": 0.40}, |
| "Kenya": {"exposure": 0.58, "adaptive_capacity": 0.42}, |
| "Zambia": {"exposure": 0.60, "adaptive_capacity": 0.40}, |
| "Ghana": {"exposure": 0.50, "adaptive_capacity": 0.48}, |
| "Senegal": {"exposure": 0.55, "adaptive_capacity": 0.45}, |
| "Nigeria": {"exposure": 0.52, "adaptive_capacity": 0.44}, |
| "Rwanda": {"exposure": 0.48, "adaptive_capacity": 0.52}, |
| "South Africa": {"exposure": 0.42, "adaptive_capacity": 0.58}, |
| } |
|
|
| CLIMATE_ZONES = ["arid", "semi_arid", "tropical_wet", "tropical_dry", "mediterranean", "highland"] |
|
|
| def generate_dataset(scenario: str, n_samples: int, seed: int) -> pd.DataFrame: |
| rng = np.random.default_rng(seed) |
| |
| burden_mod = {"low_burden": 0.7, "moderate_burden": 1.0, "high_burden": 1.4}[scenario] |
| |
| countries = rng.choice(COUNTRIES, size=n_samples) |
| years = rng.choice(YEARS, size=n_samples) |
| |
| data = { |
| "record_id": [f"CLIM_{i:06d}" for i in range(n_samples)], |
| "country": countries, |
| "year": years, |
| "climate_zone": rng.choice(CLIMATE_ZONES, size=n_samples, |
| p=[0.15, 0.25, 0.20, 0.20, 0.05, 0.15]), |
| } |
| |
| zone = data["climate_zone"] |
| base_exposure = np.array([COUNTRY_VULNERABILITY_BASE[c]["exposure"] for c in countries]) |
| base_adaptive = np.array([COUNTRY_VULNERABILITY_BASE[c]["adaptive_capacity"] for c in countries]) |
| |
| year_factor = (years - 2018) * 0.02 * burden_mod |
| data["geographic_exposure_index"] = np.clip( |
| base_exposure * (1 + year_factor) + rng.normal(0, 0.05, n_samples), 0.1, 1.0 |
| ).round(3) |
| |
| data["coastal_proximity"] = rng.choice([0, 1], size=n_samples, p=[0.6, 0.4]) |
| data["elevation_category"] = rng.choice(["lowland", "mid_elevation", "highland"], |
| size=n_samples, p=[0.4, 0.35, 0.25]) |
| |
| zone_temp_factor = {"arid": 1.2, "semi_arid": 1.1, "tropical_wet": 0.9, |
| "tropical_dry": 1.0, "mediterranean": 0.8, "highland": 0.7} |
| temp_factors = np.array([zone_temp_factor[z] for z in zone]) |
| |
| data["temperature_anomaly_c"] = np.clip( |
| (0.8 + year_factor) * temp_factors * rng.uniform(0.5, 1.5, n_samples), 0.2, 3.5 |
| ).round(2) |
| |
| zone_precip_factor = {"arid": 1.3, "semi_arid": 1.2, "tropical_wet": 1.1, |
| "tropical_dry": 1.4, "mediterranean": 1.2, "highland": 1.0} |
| precip_factors = np.array([zone_precip_factor[z] for z in zone]) |
| |
| data["precipitation_variability_pct"] = np.clip( |
| 25 + year_factor * 10 * precip_factors + rng.normal(0, 5, n_samples), 10, 60 |
| ).round(1) |
| |
| data["extreme_heat_days_year"] = np.clip( |
| (20 + data["temperature_anomaly_c"] * 15) * burden_mod * |
| rng.uniform(0.8, 1.2, n_samples), 5, 150 |
| ).astype(int) |
| |
| data["heat_stress_index"] = np.clip( |
| (data["temperature_anomaly_c"] / 2 + data["extreme_heat_days_year"] / 50) * |
| burden_mod, 0, 10 |
| ).round(2) |
| |
| data["drought_probability"] = np.clip( |
| data["geographic_exposure_index"] * 0.5 + |
| data["precipitation_variability_pct"] / 200 + |
| rng.uniform(-0.1, 0.1, n_samples), 0, 1 |
| ).round(3) |
| |
| data["flood_probability"] = np.clip( |
| (data["coastal_proximity"] * 0.2 + |
| data["precipitation_variability_pct"] / 150) * |
| burden_mod + rng.uniform(0, 0.15, n_samples), 0, 0.8 |
| ).round(3) |
| |
| data["climate_hazard_index"] = np.clip( |
| (data["drought_probability"] * 0.4 + |
| data["flood_probability"] * 0.3 + |
| data["heat_stress_index"] / 20) * burden_mod, 0, 1 |
| ).round(3) |
| |
| data["gdp_per_capita_usd"] = np.clip( |
| rng.exponential(3000, n_samples) * (1 - data["geographic_exposure_index"] * 0.5), |
| 300, 15000 |
| ).astype(int) |
| |
| data["agriculture_gdp_share_pct"] = np.clip( |
| 30 - data["gdp_per_capita_usd"] / 500 + rng.normal(0, 5, n_samples), 5, 50 |
| ).round(1) |
| |
| data["infrastructure_quality_index"] = np.clip( |
| base_adaptive * 0.8 + rng.normal(0, 0.1, n_samples), 0.1, 0.9 |
| ).round(3) |
| |
| data["healthcare_access_index"] = np.clip( |
| base_adaptive * 0.9 + data["gdp_per_capita_usd"] / 20000 + |
| rng.normal(0, 0.1, n_samples), 0.1, 0.95 |
| ).round(3) |
| |
| data["early_warning_coverage_pct"] = np.clip( |
| base_adaptive * 60 + rng.normal(10, 15, n_samples), 5, 90 |
| ).round(1) |
| |
| data["social_protection_coverage_pct"] = np.clip( |
| data["gdp_per_capita_usd"] / 150 + rng.normal(5, 10, n_samples), 2, 60 |
| ).round(1) |
| |
| data["adaptive_capacity_index"] = np.clip( |
| (data["infrastructure_quality_index"] * 0.3 + |
| data["healthcare_access_index"] * 0.25 + |
| data["early_warning_coverage_pct"] / 200 + |
| data["social_protection_coverage_pct"] / 150) + |
| rng.normal(0, 0.05, n_samples), 0.1, 0.95 |
| ).round(3) |
| |
| data["climate_policy_strength"] = np.clip( |
| base_adaptive * 1.2 + rng.normal(0, 0.15, n_samples), 0.1, 0.9 |
| ).round(3) |
| |
| data["ndc_ambition_score"] = np.clip( |
| data["climate_policy_strength"] * 0.8 + rng.uniform(0, 0.3, n_samples), 0.1, 1.0 |
| ).round(3) |
| |
| data["climate_finance_access_million_usd"] = np.clip( |
| data["climate_policy_strength"] * 500 + rng.exponential(100, n_samples), 10, 2000 |
| ).astype(int) |
| |
| data["vulnerability_index"] = np.clip( |
| (data["climate_hazard_index"] * 0.5 + |
| data["geographic_exposure_index"] * 0.3 + |
| (1 - data["adaptive_capacity_index"]) * 0.2) * burden_mod, 0, 1 |
| ).round(3) |
| |
| data["exposure_score"] = np.clip( |
| (data["geographic_exposure_index"] + data["climate_hazard_index"]) / 2, 0, 1 |
| ).round(3) |
| |
| data["risk_category"] = np.select( |
| [data["vulnerability_index"] < 0.3, |
| data["vulnerability_index"] < 0.5, |
| data["vulnerability_index"] < 0.7, |
| data["vulnerability_index"] < 0.85, |
| data["vulnerability_index"] >= 0.85], |
| ["Very_Low", "Low", "Moderate", "High", "Very_High"] |
| ) |
| |
| data["population_at_risk_millions"] = np.clip( |
| data["vulnerability_index"] * 15 * burden_mod + |
| rng.exponential(2, n_samples), 0.5, 50 |
| ).round(2) |
| |
| data["potential_economic_loss_pct_gdp"] = np.clip( |
| data["vulnerability_index"] * 20 + data["agriculture_gdp_share_pct"] / 5, 1, 25 |
| ).round(1) |
| |
| return pd.DataFrame(data) |
|
|
| def main(): |
| output_dir = Path(__file__).parent |
| |
| scenarios = [ |
| ("low_burden", 4000, 42), |
| ("moderate_burden", 5000, 43), |
| ("high_burden", 6000, 44), |
| ] |
| |
| for scenario, n, seed in scenarios: |
| df = generate_dataset(scenario, n, seed) |
| output_file = output_dir / f"climate_vulnerability_exposure_africa_{scenario}.csv" |
| df.to_csv(output_file, index=False) |
| print(f"Generated {output_file}: {len(df)} records") |
|
|
| if __name__ == "__main__": |
| main() |
|
|