Datasets:
Upload folder using huggingface_hub
Browse files- README.md +87 -0
- data/soil_industrial_farms.csv +0 -0
- data/soil_roadside_gardens.csv +0 -0
- data/soil_wastewater_irrigated.csv +0 -0
- generate_dataset.py +201 -0
- requirements.txt +3 -0
- validate_dataset.py +92 -0
- validation_report.png +3 -0
README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
tags:
|
| 8 |
+
- environmental-health
|
| 9 |
+
- soil-contamination
|
| 10 |
+
- urban-agriculture
|
| 11 |
+
- heavy-metals
|
| 12 |
+
- food-safety
|
| 13 |
+
- synthetic
|
| 14 |
+
- sub-saharan-africa
|
| 15 |
+
pretty_name: Soil Contamination & Urban Agriculture Safety (SSA)
|
| 16 |
+
size_categories:
|
| 17 |
+
- 10K<n<100K
|
| 18 |
+
configs:
|
| 19 |
+
- config_name: industrial_adjacent_farms
|
| 20 |
+
data_files: data/soil_industrial_farms.csv
|
| 21 |
+
default: true
|
| 22 |
+
- config_name: wastewater_irrigated
|
| 23 |
+
data_files: data/soil_wastewater_irrigated.csv
|
| 24 |
+
- config_name: roadside_market_gardens
|
| 25 |
+
data_files: data/soil_roadside_gardens.csv
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
# Soil Contamination & Urban Agriculture Safety in Sub-Saharan Africa
|
| 29 |
+
|
| 30 |
+
## Abstract
|
| 31 |
+
|
| 32 |
+
Synthetic dataset modelling heavy metal contamination in urban agricultural soils and food crops across three settings in SSA. Wastewater irrigation and industrial proximity elevate Pb, Cd, Cr in soils and leafy vegetables, exceeding Codex Alimentarius limits.
|
| 33 |
+
|
| 34 |
+
### Scenarios
|
| 35 |
+
|
| 36 |
+
- **Industrial Adjacent Farms**: Near factories with soil Pb ~120 mg/kg; 40% crop Pb exceedance.
|
| 37 |
+
- **Wastewater Irrigated**: Peri-urban farms using wastewater; 50% wastewater irrigation.
|
| 38 |
+
- **Roadside Market Gardens**: Urban roadside plots with traffic-related contamination.
|
| 39 |
+
|
| 40 |
+
## Parameterization Evidence
|
| 41 |
+
|
| 42 |
+
| Parameter | Value | Source | Year |
|
| 43 |
+
| --- | --- | --- | --- |
|
| 44 |
+
| Nairobi urban farms: Pb, Cd, Cr in leafy greens | SSA data | Springer | 2025 |
|
| 45 |
+
| Hg, Pb, Cd in Nairobi industrial drainage | SSA data | Nature Sci Rep | 2020 |
|
| 46 |
+
| Nigeria food crop heavy metal contamination | SSA data | PMC6748284 | 2019 |
|
| 47 |
+
| Leafy greens accumulate more heavy metals | Uptake | MDPI | 2025 |
|
| 48 |
+
| Codex limits: Pb 0.3 mg/kg, Cd 0.2 mg/kg vegetables | Standard | WHO/FAO Codex | 2023 |
|
| 49 |
+
|
| 50 |
+
## Validation
|
| 51 |
+
|
| 52 |
+

|
| 53 |
+
|
| 54 |
+
## Usage
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from datasets import load_dataset
|
| 58 |
+
ds = load_dataset("electricsheepafrica/soil-contamination-urban-agriculture", "industrial_adjacent_farms")
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Limitations
|
| 62 |
+
|
| 63 |
+
- Synthetic data; not for clinical decision-making.
|
| 64 |
+
- Soil-plant transfer factors simplified; depend on pH, organic matter, species.
|
| 65 |
+
|
| 66 |
+
## References
|
| 67 |
+
|
| 68 |
+
1. Springer. Heavy metal contamination in Nairobi urban agriculture. 2025.
|
| 69 |
+
2. Nature Scientific Reports. Heavy metals in Nairobi industrial drainage. 2020.
|
| 70 |
+
3. PMC6748284. Heavy metal contamination of food crops in Nigeria. 2019.
|
| 71 |
+
4. WHO/FAO Codex Alimentarius. Maximum levels for contaminants in food. 2023.
|
| 72 |
+
|
| 73 |
+
## Citation
|
| 74 |
+
|
| 75 |
+
```bibtex
|
| 76 |
+
@dataset{electricsheepafrica_soil_contamination_urban_agriculture_2025,
|
| 77 |
+
title={Soil Contamination and Urban Agriculture Safety in Sub-Saharan Africa},
|
| 78 |
+
author={Electric Sheep Africa},
|
| 79 |
+
year={2025},
|
| 80 |
+
publisher={HuggingFace},
|
| 81 |
+
url={https://huggingface.co/datasets/electricsheepafrica/soil-contamination-urban-agriculture}
|
| 82 |
+
}
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
## License
|
| 86 |
+
|
| 87 |
+
CC-BY-4.0
|
data/soil_industrial_farms.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/soil_roadside_gardens.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/soil_wastewater_irrigated.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generate synthetic soil contamination & urban agriculture safety dataset for SSA.
|
| 2 |
+
|
| 3 |
+
Research-based parameterization:
|
| 4 |
+
- Springer (2025): Heavy metals (Pb, Cd, Cr) in leafy greens from Nairobi
|
| 5 |
+
urban farms; random geographical sampling.
|
| 6 |
+
- Nature (2020): Hg, Pb, Cd, Cr, Ni, Tl in wastewater & soil from Nairobi
|
| 7 |
+
industrial drainage channels using ICP-MS.
|
| 8 |
+
- PMC6748284: Heavy metal contamination of food crops in Nigeria; Pb, Cd,
|
| 9 |
+
Cu, Zn from industrial/traffic sources.
|
| 10 |
+
- MDPI (2025): Heavy metal accumulation in wastewater-irrigated vegetables;
|
| 11 |
+
leafy greens accumulate more metals.
|
| 12 |
+
- PMC7996329: Soil Pb, Cd, Cu, Zn exceed MRLs; health risks from
|
| 13 |
+
consumption of contaminated crops.
|
| 14 |
+
- WHO/FAO: Codex Alimentarius limits for Pb (0.3 mg/kg), Cd (0.2 mg/kg)
|
| 15 |
+
in vegetables.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
import numpy as np
|
| 23 |
+
import pandas as pd
|
| 24 |
+
|
| 25 |
+
SEED = 42
|
| 26 |
+
N_PER_SCENARIO = 10_000
|
| 27 |
+
|
| 28 |
+
YEAR_RANGE = np.arange(2010, 2025)
|
| 29 |
+
YEAR_WEIGHTS = np.linspace(0.85, 1.3, len(YEAR_RANGE))
|
| 30 |
+
YEAR_WEIGHTS = YEAR_WEIGHTS / YEAR_WEIGHTS.sum()
|
| 31 |
+
|
| 32 |
+
SCENARIOS = {
|
| 33 |
+
"industrial_adjacent_farms": {
|
| 34 |
+
"setting_probs": {"urban_industrial": 0.40, "peri_urban": 0.35, "urban_roadside": 0.25},
|
| 35 |
+
"crop_probs": {"leafy_greens": 0.35, "tomato_pepper": 0.20, "root_vegetables": 0.15,
|
| 36 |
+
"maize": 0.15, "legumes": 0.15},
|
| 37 |
+
"irrigation_probs": {"wastewater": 0.35, "stream_river": 0.25, "borehole": 0.20,
|
| 38 |
+
"piped": 0.10, "rainwater": 0.10},
|
| 39 |
+
"soil_pb_mean": 120, "soil_pb_sd": 80,
|
| 40 |
+
"soil_cd_mean": 3.5, "soil_cd_sd": 2.5,
|
| 41 |
+
"soil_cr_mean": 60, "soil_cr_sd": 40,
|
| 42 |
+
"crop_pb_exceedance": 0.40,
|
| 43 |
+
"crop_cd_exceedance": 0.30,
|
| 44 |
+
"health_risk_awareness": 0.15,
|
| 45 |
+
},
|
| 46 |
+
"wastewater_irrigated": {
|
| 47 |
+
"setting_probs": {"peri_urban": 0.45, "urban_lowland": 0.30, "rural_adjacent": 0.25},
|
| 48 |
+
"crop_probs": {"leafy_greens": 0.40, "tomato_pepper": 0.25, "root_vegetables": 0.15,
|
| 49 |
+
"cabbage": 0.10, "legumes": 0.10},
|
| 50 |
+
"irrigation_probs": {"wastewater": 0.50, "stream_river": 0.25, "borehole": 0.15,
|
| 51 |
+
"piped": 0.05, "rainwater": 0.05},
|
| 52 |
+
"soil_pb_mean": 80, "soil_pb_sd": 50,
|
| 53 |
+
"soil_cd_mean": 2.5, "soil_cd_sd": 1.8,
|
| 54 |
+
"soil_cr_mean": 45, "soil_cr_sd": 30,
|
| 55 |
+
"crop_pb_exceedance": 0.30,
|
| 56 |
+
"crop_cd_exceedance": 0.25,
|
| 57 |
+
"health_risk_awareness": 0.10,
|
| 58 |
+
},
|
| 59 |
+
"roadside_market_gardens": {
|
| 60 |
+
"setting_probs": {"urban_roadside": 0.40, "peri_urban": 0.35, "urban_residential": 0.25},
|
| 61 |
+
"crop_probs": {"leafy_greens": 0.30, "tomato_pepper": 0.25, "herbs": 0.15,
|
| 62 |
+
"root_vegetables": 0.15, "maize": 0.15},
|
| 63 |
+
"irrigation_probs": {"borehole": 0.30, "piped": 0.25, "stream_river": 0.20,
|
| 64 |
+
"wastewater": 0.15, "rainwater": 0.10},
|
| 65 |
+
"soil_pb_mean": 60, "soil_pb_sd": 40,
|
| 66 |
+
"soil_cd_mean": 1.5, "soil_cd_sd": 1.0,
|
| 67 |
+
"soil_cr_mean": 30, "soil_cr_sd": 20,
|
| 68 |
+
"crop_pb_exceedance": 0.20,
|
| 69 |
+
"crop_cd_exceedance": 0.15,
|
| 70 |
+
"health_risk_awareness": 0.20,
|
| 71 |
+
},
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
SCENARIO_FILES = {
|
| 75 |
+
"industrial_adjacent_farms": "soil_industrial_farms.csv",
|
| 76 |
+
"wastewater_irrigated": "soil_wastewater_irrigated.csv",
|
| 77 |
+
"roadside_market_gardens": "soil_roadside_gardens.csv",
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _choice(rng, prob_map):
|
| 82 |
+
keys = list(prob_map.keys())
|
| 83 |
+
weights = np.array(list(prob_map.values()), dtype=float)
|
| 84 |
+
weights = weights / weights.sum()
|
| 85 |
+
return rng.choice(keys, p=weights)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _simulate_scenario(name, params, seed):
|
| 89 |
+
rng = np.random.default_rng(seed)
|
| 90 |
+
records = []
|
| 91 |
+
|
| 92 |
+
for idx in range(N_PER_SCENARIO):
|
| 93 |
+
year = int(rng.choice(YEAR_RANGE, p=YEAR_WEIGHTS))
|
| 94 |
+
setting = _choice(rng, params["setting_probs"])
|
| 95 |
+
farm_size_m2 = float(np.clip(rng.lognormal(np.log(200), 0.8), 20, 5000))
|
| 96 |
+
farmer_age = int(np.clip(rng.normal(38, 12), 18, 70))
|
| 97 |
+
farmer_sex = rng.choice(["male", "female"], p=[0.40, 0.60])
|
| 98 |
+
hh_consumers = int(np.clip(rng.normal(5, 2), 1, 12))
|
| 99 |
+
children_consuming = int(np.clip(rng.poisson(1.5), 0, 5))
|
| 100 |
+
|
| 101 |
+
crop_type = _choice(rng, params["crop_probs"])
|
| 102 |
+
irrigation_source = _choice(rng, params["irrigation_probs"])
|
| 103 |
+
uses_wastewater = int(irrigation_source == "wastewater")
|
| 104 |
+
|
| 105 |
+
# Soil contamination (mg/kg)
|
| 106 |
+
ww_factor = 1.5 if uses_wastewater else 1.0
|
| 107 |
+
soil_pb = float(np.clip(rng.lognormal(np.log(params["soil_pb_mean"] * ww_factor), 0.7), 5, 2000))
|
| 108 |
+
soil_cd = float(np.clip(rng.lognormal(np.log(params["soil_cd_mean"] * ww_factor), 0.6), 0.1, 50))
|
| 109 |
+
soil_cr = float(np.clip(rng.lognormal(np.log(params["soil_cr_mean"] * ww_factor), 0.6), 1, 500))
|
| 110 |
+
|
| 111 |
+
soil_pb_exceeds = int(soil_pb > 100)
|
| 112 |
+
soil_cd_exceeds = int(soil_cd > 3)
|
| 113 |
+
|
| 114 |
+
# Crop contamination (mg/kg fresh weight)
|
| 115 |
+
# Leafy greens accumulate more (Springer 2025)
|
| 116 |
+
uptake_factor = 1.5 if crop_type in ("leafy_greens", "herbs") else 0.8
|
| 117 |
+
crop_pb = float(np.clip(soil_pb * 0.003 * uptake_factor * rng.lognormal(0, 0.5), 0.01, 10))
|
| 118 |
+
crop_cd = float(np.clip(soil_cd * 0.05 * uptake_factor * rng.lognormal(0, 0.5), 0.001, 5))
|
| 119 |
+
|
| 120 |
+
# Codex limits: Pb 0.3 mg/kg, Cd 0.2 mg/kg in vegetables
|
| 121 |
+
crop_pb_exceeds_codex = int(crop_pb > 0.3)
|
| 122 |
+
crop_cd_exceeds_codex = int(crop_cd > 0.2)
|
| 123 |
+
|
| 124 |
+
# Water quality
|
| 125 |
+
water_pb_ugL = float(np.clip(rng.lognormal(np.log(10 if uses_wastewater else 3), 0.7), 0.5, 200))
|
| 126 |
+
water_cd_ugL = float(np.clip(rng.lognormal(np.log(2 if uses_wastewater else 0.5), 0.6), 0.05, 50))
|
| 127 |
+
|
| 128 |
+
# Health risk assessment (HQ = hazard quotient)
|
| 129 |
+
daily_intake_kg = float(np.clip(rng.normal(0.15, 0.05), 0.03, 0.5))
|
| 130 |
+
body_weight = float(np.clip(rng.normal(60, 10), 30, 90))
|
| 131 |
+
edi_pb = crop_pb * daily_intake_kg / body_weight * 1000 # µg/kg bw/day
|
| 132 |
+
edi_cd = crop_cd * daily_intake_kg / body_weight * 1000
|
| 133 |
+
|
| 134 |
+
hq_pb = edi_pb / 3.5 # USEPA RfD for Pb ~3.5 µg/kg/day
|
| 135 |
+
hq_cd = edi_cd / 1.0 # USEPA RfD for Cd ~1.0 µg/kg/day
|
| 136 |
+
hazard_index = hq_pb + hq_cd
|
| 137 |
+
unacceptable_risk = int(hazard_index > 1)
|
| 138 |
+
|
| 139 |
+
# Health outcomes (chronic exposure)
|
| 140 |
+
gi_symptoms = int(rng.random() < np.clip(0.05 + hazard_index * 0.03, 0, 0.20))
|
| 141 |
+
child_developmental = int(children_consuming > 0 and crop_pb_exceeds_codex and rng.random() < 0.08)
|
| 142 |
+
kidney_effects = int(crop_cd_exceeds_codex and rng.random() < 0.05)
|
| 143 |
+
|
| 144 |
+
# Soil testing & awareness
|
| 145 |
+
soil_tested = int(rng.random() < 0.05)
|
| 146 |
+
crop_tested = int(rng.random() < 0.03)
|
| 147 |
+
aware_of_risk = int(rng.random() < params["health_risk_awareness"])
|
| 148 |
+
uses_compost = int(rng.random() < 0.25)
|
| 149 |
+
phytoremediation = int(rng.random() < 0.02)
|
| 150 |
+
|
| 151 |
+
record = {
|
| 152 |
+
"record_id": f"{name[:3].upper()}-{idx:05d}",
|
| 153 |
+
"scenario": name,
|
| 154 |
+
"year": year,
|
| 155 |
+
"setting": setting,
|
| 156 |
+
"farm_size_m2": round(farm_size_m2, 0),
|
| 157 |
+
"farmer_age": farmer_age,
|
| 158 |
+
"farmer_sex": farmer_sex,
|
| 159 |
+
"hh_consumers": hh_consumers,
|
| 160 |
+
"children_consuming": children_consuming,
|
| 161 |
+
"crop_type": crop_type,
|
| 162 |
+
"irrigation_source": irrigation_source,
|
| 163 |
+
"uses_wastewater": uses_wastewater,
|
| 164 |
+
"soil_pb_mgkg": round(soil_pb, 1),
|
| 165 |
+
"soil_cd_mgkg": round(soil_cd, 2),
|
| 166 |
+
"soil_cr_mgkg": round(soil_cr, 1),
|
| 167 |
+
"soil_pb_exceeds": soil_pb_exceeds,
|
| 168 |
+
"soil_cd_exceeds": soil_cd_exceeds,
|
| 169 |
+
"crop_pb_mgkg": round(crop_pb, 3),
|
| 170 |
+
"crop_cd_mgkg": round(crop_cd, 3),
|
| 171 |
+
"crop_pb_exceeds_codex": crop_pb_exceeds_codex,
|
| 172 |
+
"crop_cd_exceeds_codex": crop_cd_exceeds_codex,
|
| 173 |
+
"water_pb_ugL": round(water_pb_ugL, 1),
|
| 174 |
+
"water_cd_ugL": round(water_cd_ugL, 2),
|
| 175 |
+
"hazard_index": round(hazard_index, 2),
|
| 176 |
+
"unacceptable_risk": unacceptable_risk,
|
| 177 |
+
"gi_symptoms": gi_symptoms,
|
| 178 |
+
"child_developmental": child_developmental,
|
| 179 |
+
"kidney_effects": kidney_effects,
|
| 180 |
+
"soil_tested": soil_tested,
|
| 181 |
+
"crop_tested": crop_tested,
|
| 182 |
+
"aware_of_risk": aware_of_risk,
|
| 183 |
+
"uses_compost": uses_compost,
|
| 184 |
+
"phytoremediation": phytoremediation,
|
| 185 |
+
}
|
| 186 |
+
records.append(record)
|
| 187 |
+
|
| 188 |
+
return pd.DataFrame(records)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def main():
|
| 192 |
+
output_dir = Path("data")
|
| 193 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 194 |
+
for idx, (name, params) in enumerate(SCENARIOS.items()):
|
| 195 |
+
df = _simulate_scenario(name, params, SEED + idx * 211)
|
| 196 |
+
df.to_csv(output_dir / SCENARIO_FILES[name], index=False)
|
| 197 |
+
print(f"Saved {name} -> {SCENARIO_FILES[name]}")
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
if __name__ == "__main__":
|
| 201 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy>=1.24
|
| 2 |
+
pandas>=2.0
|
| 3 |
+
matplotlib>=3.7
|
validate_dataset.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Validate synthetic soil contamination & urban agriculture safety dataset."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import matplotlib.pyplot as plt
|
| 8 |
+
import pandas as pd
|
| 9 |
+
|
| 10 |
+
SCENARIO_FILES = {
|
| 11 |
+
"industrial_adjacent_farms": "soil_industrial_farms.csv",
|
| 12 |
+
"wastewater_irrigated": "soil_wastewater_irrigated.csv",
|
| 13 |
+
"roadside_market_gardens": "soil_roadside_gardens.csv",
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
COLORS = {"industrial_adjacent_farms": "#e6550d", "wastewater_irrigated": "#756bb1", "roadside_market_gardens": "#31a354"}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def load_data() -> pd.DataFrame:
|
| 20 |
+
frames = []
|
| 21 |
+
for scenario, filename in SCENARIO_FILES.items():
|
| 22 |
+
df = pd.read_csv(Path("data") / filename)
|
| 23 |
+
frames.append(df)
|
| 24 |
+
return pd.concat(frames, ignore_index=True)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def plot_validation(df: pd.DataFrame, output_path: Path) -> None:
|
| 28 |
+
fig, axes = plt.subplots(4, 2, figsize=(14, 16))
|
| 29 |
+
axes = axes.flatten()
|
| 30 |
+
|
| 31 |
+
for s in SCENARIO_FILES:
|
| 32 |
+
subset = df[df["scenario"] == s]
|
| 33 |
+
axes[0].hist(subset["soil_pb_mgkg"], bins=40, alpha=0.5, color=COLORS[s], label=s, range=(0, 500))
|
| 34 |
+
axes[0].axvline(100, color="red", ls="--", lw=1, label="100 mg/kg")
|
| 35 |
+
axes[0].set_title("Soil Lead Distribution (mg/kg)")
|
| 36 |
+
axes[0].legend(fontsize=6)
|
| 37 |
+
|
| 38 |
+
exc_cols = ["crop_pb_exceeds_codex", "crop_cd_exceeds_codex", "unacceptable_risk"]
|
| 39 |
+
exc = df.groupby("scenario")[exc_cols].mean() * 100
|
| 40 |
+
exc.plot(kind="bar", ax=axes[1])
|
| 41 |
+
axes[1].set_title("Codex Exceedance & Unacceptable Risk (%)")
|
| 42 |
+
axes[1].legend(fontsize=6)
|
| 43 |
+
|
| 44 |
+
crop = df.groupby(["scenario", "crop_type"]).size().groupby(level=0).apply(lambda s: s / s.sum())
|
| 45 |
+
crop.unstack().plot(kind="bar", stacked=True, ax=axes[2])
|
| 46 |
+
axes[2].set_title("Crop Type Distribution")
|
| 47 |
+
axes[2].legend(fontsize=5)
|
| 48 |
+
|
| 49 |
+
irr = df.groupby(["scenario", "irrigation_source"]).size().groupby(level=0).apply(lambda s: s / s.sum())
|
| 50 |
+
irr.unstack().plot(kind="bar", stacked=True, ax=axes[3])
|
| 51 |
+
axes[3].set_title("Irrigation Source Distribution")
|
| 52 |
+
axes[3].legend(fontsize=5)
|
| 53 |
+
|
| 54 |
+
for s in SCENARIO_FILES:
|
| 55 |
+
subset = df[df["scenario"] == s]
|
| 56 |
+
axes[4].scatter(subset["soil_pb_mgkg"], subset["crop_pb_mgkg"],
|
| 57 |
+
s=4, alpha=0.05, color=COLORS[s], label=s)
|
| 58 |
+
axes[4].set_title("Soil Pb vs Crop Pb")
|
| 59 |
+
axes[4].legend(fontsize=7)
|
| 60 |
+
|
| 61 |
+
health_cols = ["gi_symptoms", "child_developmental", "kidney_effects"]
|
| 62 |
+
health = df.groupby("scenario")[health_cols].mean() * 100
|
| 63 |
+
health.plot(kind="bar", ax=axes[5])
|
| 64 |
+
axes[5].set_title("Health Outcomes (%)")
|
| 65 |
+
axes[5].legend(fontsize=7)
|
| 66 |
+
|
| 67 |
+
for s in SCENARIO_FILES:
|
| 68 |
+
subset = df[df["scenario"] == s]
|
| 69 |
+
axes[6].hist(subset["hazard_index"], bins=40, alpha=0.5, color=COLORS[s], label=s, range=(0, 5))
|
| 70 |
+
axes[6].axvline(1, color="red", ls="--", lw=1, label="HI=1")
|
| 71 |
+
axes[6].set_title("Hazard Index Distribution")
|
| 72 |
+
axes[6].legend(fontsize=7)
|
| 73 |
+
|
| 74 |
+
mit_cols = ["soil_tested", "crop_tested", "aware_of_risk", "uses_compost"]
|
| 75 |
+
mit = df.groupby("scenario")[mit_cols].mean() * 100
|
| 76 |
+
mit.plot(kind="bar", ax=axes[7])
|
| 77 |
+
axes[7].set_title("Testing & Awareness (%)")
|
| 78 |
+
axes[7].legend(fontsize=6)
|
| 79 |
+
|
| 80 |
+
plt.tight_layout()
|
| 81 |
+
fig.savefig(output_path, dpi=200)
|
| 82 |
+
plt.close(fig)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def main() -> None:
|
| 86 |
+
df = load_data()
|
| 87 |
+
plot_validation(df, Path("validation_report.png"))
|
| 88 |
+
print("Saved validation_report.png")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
main()
|
validation_report.png
ADDED
|
Git LFS Details
|