Overview
This repository contains the complete set of R and Google Earth Engine (GEE) scripts used to produce national-scale digital soil maps for Namibia at 90 m spatial resolution. The workflow covers all stages of the mapping pipeline — from soil profile data preprocessing and depth harmonisation, through feature selection, hyperparameter tuning, Random Forest modelling, map post-processing, uncertainty quantification, spectral modelling, and external validation.
The code is organised into six sequential modules, each stored in its own folder with dedicated input/, output/, and script/ sub-directories. A master document (Project_Overview_pipeline_environment.txt) describes the full directory tree, the recommended execution order, and the R computing environment required for reproducibility.
Soil Properties Mapped
The pipeline was applied to map 16 soil properties across three standard depth intervals (0–30, 30–60, 60–100 cm): Sand (%), Silt (%), Clay (%), Bulk Density (kg/dm³), pH (water), Organic Carbon (%), Total Nitrogen (mg/kg), Plant-available Phosphorus (mg/kg), Extractable Calcium (mg/kg), Magnesium (mg/kg), Potassium (mg/kg), and Sodium (mg/kg), CEC (cmolc/kg), Base Saturation (%), Electrical Conductivity – 1:2.5 (µS/cm), and Electrical Conductivity – saturated paste (µS/cm).
Pipeline Structure
Module
Folder
Description
1
1_data_treatement/
Soil profile data cleaning, table joining, missing-value treatment, and equal-area spline depth harmonisation to the three standard depth intervals. Includes exploratory data assessment scripts, histograms, boxplots, and spatial distribution plots.
2
2_feature_selection_tuning/
Boruta-based feature selection and Random Forest hyperparameter tuning (ntree, mtry, nodesize, sampsize) using the regression matrix exported from GEE. Outputs per-property configuration files consumed by the GEE modelling step.
2.5
2.5_GEE/
Google Earth Engine scripts for covariate preparation (lithological indices, Landsat spectral bands, ASTER mineral indices, terrain and climate layers), regression matrix export, and the core Random Forest modelling with 20-iteration bootstrap. Outputs Cloud-Optimised GeoTIFFs (mean, 5th and 95th percentiles) and per-iteration performance metrics. The full GEE repository is accessible at:
code.earthengine.google.com or via git clone
earthengine.googlesource.com.
3
3_final_maps/
Post-processing of GEE outputs: applies physically meaningful min/max limits per property, computes the 90% prediction interval width (PI90), and generates publication-ready cartographic plots (PNG).
4
4_PICP/
Computes the 90% Prediction Interval Coverage Probability (PICP90) to evaluate whether the bootstrap-derived uncertainty bands contain the observed values at the expected nominal rate.
5
5_modeling_spectra_data_sfa/
Independent spectral modelling workflow: merges mid-infrared (MIR) spectra with wet chemistry reference data from the Soils for Africa (S4A) project, trains predictive models (Cubist, PLSR, Random Forest), and summarises results. Used to generate external validation predictions.
6
6_external_validation_sfa/
External validation: extracts predicted values from the Namibia maps, SoilGrids, and iSDAsoil at independent sample locations; harmonises units and depths; computes validation metrics (RMSE, R², CCC) and produces comparison plots.
Repository File Tree
Namibia_soil_maps_2024_2026/
├── Project_Overview_pipeline_environment.txt
│
├── 1_data_treatement/
│ ├── input/
│ │ ├── NamProfCleaned_21Mar2024.xlsx
│ │ └── National_boundary.shp (.dbf, .prj, .shx)
│ ├── metadata/
│ │ └── selected soil properties.txt
│ ├── output/
│ │ ├── datasets/ (splines, exploratory, GEE-ready exports)
│ │ ├── plots/ (histograms, boxplots, spatial distributions)
│ │ └── shapes/ (soil point shapefiles per property)
│ └── script/
│ ├── 1_Soil_data_join_tables_v2_preparation_for_splines.R
│ ├── 2_Soil_data_treatment_missing_values_depth_function_splines_new_0_30_60_100.R
│ ├── 2.1_Plots_centroids_Soil_data_treatment_…_splines_0_5_15_30_60_100_200_.R
│ ├── 3_plot_depth_hist.R
│ ├── 4_plot_hist_boxplot_splined_data_0_30_60_100.R
│ └── Exploratory_analyses_plots/
│ ├── Soil_data_assessment_…_Soil_classes_complete_info_OC_pH_BS_Sand_Clay_EC_BD.R
│ ├── Soil_data_assessment_…_Subsurface.R
│ └── Soil_data_assessment_…_Top_horiz.R
│
├── 2_feature_selection_tuning/
│ ├── input/
│ │ └── extracted_points_Nam_0_30_60_100_cm.csv
│ ├── output/
│ │ ├── plots/
│ │ └── properties_settings/ (per-property tuning configs)
│ └── script/
│ ├── 1_tuning_feature_selection_rf.R
│ ├── 2_check_data.R
│ └── 3_rename_github_gee_js.R
│
├── 2.5_GEE/
│ ├── input/ → GEE assets (see Readme.txt)
│ ├── outputs/ → Google Drive / GEE assets
│ └── script/
│ ├── 1_lithological_indexes
│ ├── 2_gee_covariates_preparation
│ ├── 3_Export_regression_matrix_to_R_tunning
│ ├── 4_Extract_modeling_metrics_COG
│ ├── 5_thumbnail_all_covars_legend (independent/optional)
│ └── properties_settings/
│ ├── as_txt/ (48 config files, one per property × depth)
│ └── as_js_for_GEE/
│
├── 3_final_maps/
│ ├── input/
│ │ └── earth_engine_Nam_modeling_output_*/ (GeoTIFFs + metrics CSVs)
│ ├── output/
│ │ ├── dataset/ (prop.limits.csv, ref_vals.csv, summary.limits.csv)
│ │ └── plots/ (PNG maps: mean, lower, upper, range)
│ └── script/
│ └── make_maps_nam_v7_min_max_lg.R
│
├── 4_PICP/
│ ├── input/
│ ├── output/plots/
│ └── script/
│ ├── 0_PICP_source_function.R
│ └── 1_PICP.R
│
├── 5_modeling_spectra_data_sfa/
│ ├── input/
│ │ ├── s4a_submissions_Namibia_2023-09-28.xlsx
│ │ ├── S4A_Wetchem_20240911_NA.xlsx
│ │ └── spectral_data_Namibia_20250716.csv
│ ├── output/
│ │ ├── dataset/
│ │ ├── graphs_plots/
│ │ ├── metadata/
│ │ └── modeling_output/
│ └── script/
│ ├── 0_plot_fun_source.R
│ ├── 1_merge_spectra_mir_wetchem.R
│ ├── 2_modeling.R
│ └── 3_summarize_results.R
│
└── 6_external_validation_sfa/
├── input/
│ ├── s4a_submissions_Namibia_2023-06-23.csv
│ ├── S4A_Wetchem_20240911_NA.xlsx
│ ├── S4A_Wetchem_20240911_NA_Topsoil_Samples_Coordinates.csv
│ └── units_conversion.csv
├── output/plots/
└── script/
├── 1_extract_samples_points__soil_grids_isda_Nam_maps.R
├── 2_units_conversion_depths_interpolation_v3_loop_datasets.R
└── 3_validation_metrics_plots.R
Input Data
Model training was based on analytical data from the Namibian Soil Profile Database (NSPD2025) (
zenodo.org). Environmental covariates (65 layers covering terrain, climate, remote sensing, geology, and land cover) were assembled in Google Earth Engine. External validation used independent soil data from the Soils for Africa (S4A) project in Namibia.
Computing Environment
R scripts were developed and tested under R 4.3.3 on Ubuntu 24.04 LTS. Key R packages include: terra (spatial data handling), ranger (Random Forest), Boruta (feature selection), tuneRanger / mlr (hyperparameter tuning), caret (model evaluation), ithir (depth splines), Cubist and pls (spectral modelling), ggplot2 (visualisation), and doParallel / foreach (parallel processing). Geospatial libraries: GDAL 3.8.4, GEOS 3.12.1, PROJ 9.4.0. The complete sessionInfo() output and driver list are provided in Project_Overview_pipeline_environment.txt.
How to Run
Recommended execution order:
1_data_treatement — Soil data cleaning and depth harmonisation
2_feature_selection_tuning — Feature selection and RF tuning in R
2.5_GEE — Covariate assembly and RF modelling in Google Earth Engine
3_final_maps — Map post-processing and cartographic outputs
4_PICP — Prediction interval coverage evaluation
5_modeling_spectra_data_sfa — Spectral modelling (optional / independent)
6_external_validation_sfa — External validation (optional / independent)
Each module reads from its own input/ folder and writes to output/. Intermediate outputs propagate to downstream modules as described in the readme files within each folder.
Related Datasets and Publications
The predicted soil maps (GeoTIFF and PNG) for each property and depth interval are published as separate Zenodo records. Quick-start scripts for reading, cropping, and exporting NamSoil layers directly from Zenodo — without downloading the full files — are available at:
github.com.
A full methodological description, model evaluation framework, and interpretation of results are provided in:[Publication DOI to be added]