""" Dataset Generator: Displacement in Informal Settlements Africa Parameter Evidence Table: | Parameter | Value | Source | |-----------|-------|--------| | Annual eviction rate in slums | 5-15% | UN-Habitat 2023 | | Forced displacement drivers | Infrastructure, gentrification, events | UN-Habitat estimates | | Resettlement success rate | 20-40% adequate | World Bank displacement data | | Climate-related displacement | Increasing trend | OECD Africa Urbanization 2025 | | Year range | 2018-2025 | Project scope | | Countries | 15 African nations | Regional coverage | DAG Structure: country -> displacement_trigger -> eviction_event -> resettlement_outcome -> recovery_time """ import numpy as np import pandas as pd from pathlib import Path COUNTRIES = [ 'Nigeria', 'Kenya', 'Ethiopia', 'Egypt', 'South Africa', 'Tanzania', 'Morocco', 'Algeria', 'Ghana', 'Uganda', 'Mozambique', 'Zambia', 'Malawi', 'Rwanda', 'Senegal' ] SCENARIOS = { 'low_burden': {'n': 4000, 'displacement_rate': 0.03, 'seed': 42}, 'moderate': {'n': 5000, 'displacement_rate': 0.08, 'seed': 43}, 'high': {'n': 6000, 'displacement_rate': 0.15, 'seed': 44} } CITIES = { 'Nigeria': ['Lagos', 'Port Harcourt', 'Abuja'], 'Kenya': ['Nairobi', 'Mombasa'], 'Ethiopia': ['Addis Ababa'], 'Egypt': ['Cairo', 'Giza'], 'South Africa': ['Johannesburg', 'Durban'], 'Tanzania': ['Dar es Salaam'], 'Morocco': ['Casablanca', 'Marrakech'], 'Algeria': ['Algiers'], 'Ghana': ['Accra'], 'Uganda': ['Kampala'], 'Mozambique': ['Maputo'], 'Zambia': ['Lusaka'], 'Malawi': ['Lilongwe', 'Blantyre'], 'Rwanda': ['Kigali'], 'Senegal': ['Dakar'] } SETTLEMENTS = { 'Nigeria': ['Mushin', 'Ajegunle'], 'Kenya': ['Kibera', 'Mathare'], 'Ethiopia': ['Kality'], 'Egypt': ['Ezbet El-Nakhl'], 'South Africa': ['Soweto', 'Alexandra'], 'Tanzania': ['Kibera'], 'Ghana': ['Old Fadama'], 'Uganda': ['Kisenyi'] } DISPLACEMENT_TRIGGERS = [ 'infrastructure_development', 'gentrification', 'climate_disaster', 'eviction_order', 'land_reclamation', 'urban_renewal', 'sporting_event', 'political_decision', 'environmental_risk', 'commercial_development' ] def dag_sample_displacement_event(displacement_rate, rng): if rng.random() < displacement_rate: return rng.choice(DISPLACEMENT_TRIGGERS) return 'no_displacement' def dag_sample_eviction_details(trigger, rng): if trigger == 'no_displacement': return { 'evicted': False, 'households_affected': 0, 'resettlement_type': 'none' } households = int(rng.uniform(50, 5000)) resettlement = rng.choice(['none', 'in_situ', 'relocated', 'informal_compensation']) return { 'evicted': True, 'households_affected': households, 'resettlement_type': resettlement } def dag_sample_resettlement_outcome(resettlement_type, rng): if resettlement_type == 'none': return {'adequate_housing': False, 'recovery_years': 0, 'compensation': 0} adequate_chance = {'in_situ': 0.5, 'relocated': 0.25, 'informal_compensation': 0.15}.get(resettlement_type, 0.2) return { 'adequate_housing': rng.random() < adequate_chance, 'recovery_years': int(rng.uniform(1, 10)) if resettlement_type != 'none' else 0, 'compensation': int(rng.uniform(0, 5000)) if resettlement_type != 'none' else 0 } def generate_dataset(scenario, output_dir): config = SCENARIOS[scenario] rng = np.random.default_rng(config['seed']) data = { 'country': [], 'city': [], 'settlement': [], 'year': [], 'displacement_trigger': [], 'evicted': [], 'households_affected': [], 'resettlement_type': [], 'adequate_housing': [], 'recovery_years': [], 'compensation_received_usd': [], 'legal_recourse_available': [], 'notice_given_days': [], 'court_order_obtained': [], 'community_consultation': [], 'alternative_land_provided': [], 'follow_up_survey_available': [], 'psychological_impact': [], 'economic_impact_score': [], 'housing_quality_change': [] } for _ in range(config['n']): country = rng.choice(COUNTRIES) city = rng.choice(CITIES.get(country, ['Unknown'])) settlement = rng.choice(SETTLEMENTS.get(country, ['Unknown'])) year = rng.integers(2018, 2026) trigger = dag_sample_displacement_event(config['displacement_rate'], rng) eviction_details = dag_sample_eviction_details(trigger, rng) outcome = dag_sample_resettlement_outcome(eviction_details['resettlement_type'], rng) data['country'].append(country) data['city'].append(city) data['settlement'].append(settlement) data['year'].append(year) data['displacement_trigger'].append(trigger) data['evicted'].append(eviction_details['evicted']) data['households_affected'].append(eviction_details['households_affected']) data['resettlement_type'].append(eviction_details['resettlement_type']) data['adequate_housing'].append(outcome['adequate_housing']) data['recovery_years'].append(outcome['recovery_years']) data['compensation_received_usd'].append(outcome['compensation']) data['legal_recourse_available'].append(rng.choice([True, False], p=[0.4, 0.6])) data['notice_given_days'].append(int(rng.uniform(0, 90)) if eviction_details['evicted'] else 0) data['court_order_obtained'].append(rng.choice([True, False], p=[0.5, 0.5]) if eviction_details['evicted'] else False) data['community_consultation'].append(rng.choice(['none', 'minimal', 'adequate', 'robust'])) data['alternative_land_provided'].append(rng.choice([True, False], p=[0.2, 0.8]) if eviction_details['evicted'] else False) data['follow_up_survey_available'].append(rng.choice([True, False], p=[0.3, 0.7])) data['psychological_impact'].append(rng.choice(['none', 'mild', 'moderate', 'severe']) if eviction_details['evicted'] else 'none') data['economic_impact_score'].append(round(rng.uniform(10, 90), 1) if eviction_details['evicted'] else 0) data['housing_quality_change'].append(rng.choice(['improved', 'same', 'degraded', 'homeless']) if eviction_details['evicted'] else 'same') df = pd.DataFrame(data) output_dir.mkdir(parents=True, exist_ok=True) df.to_csv(output_dir / f'{scenario}.csv', index=False) print(f"Generated {scenario}: {len(df)} rows") if __name__ == '__main__': base_dir = Path(__file__).parent for scenario in SCENARIOS: generate_dataset(scenario, base_dir)