Code for Modeling Monthly Soil Respiration across China's Forests (2000-2020)

Read full text
Authors: Ni Huang, Jiaming Chang
Cited by: 0

Abstract

RF_leave_one_site_crossvalidation.m: This code implements a Random Forest (RF) regression framework with Leave-One-Site-Out Cross Validation (LOSOCV) to assess model generalization across spatially independent sites. Geographic sites are defined by unique latitude–longitude pairs, and in each iteration, all observations from one site are held out for testing while the remaining sites are used for model training. Within each training fold, a random hyper-parameter search is performed to optimize key RF parameters, including the number of trees, minimum leaf size, and number of predictors sampled at each split, using out-of-bag root mean square error (RMSE) as the selection criterion. The optimized model is then applied to the held-out site, and predictive performance is evaluated across all sites using the coefficient of determination (R2) and RMSE. XGBoost_leave_one_site_crossvalidation.m: This code implements an extreme gradient boosting (XGBoost) regression framework evaluated using LOSOCV to assess predictive performance across spatially independent sites. Sites are defined by unique latitude–longitude pairs, and in each cross-validation fold all observations from one site are held out for testing while the remaining sites are used for model training. Within each training fold, a random hyper-parameter search is conducted by sampling discrete combinations of key XGBoost parameters, including tree depth, learning rate, subsampling ratios, regularization terms, and the number of boosting iterations. The optimal hyper-parameter set is selected based on training RMSE, and the final model is subsequently applied to the held-out site. The implementation integrates MATLAB with Python XGBoost, employs fixed random seeds to ensure reproducibility, and uses a dedicated prediction wrapper to enforce consistent output dimensions. Model performance is summarized using the R2 and RMSE across all sites. GWRF_leave_one_site_crossvalidation.m: This code implements a geographically weighted RF (GWRF) regression framework to model spatially heterogeneous relationships at the site level. Unique sites are defined by latitude–longitude pairs, and site-level mean predictor features are first computed and standardized to construct a feature-based distance space. For each target site, a local training dataset is formed by identifying the K nearest neighboring sites in the standardized feature space and assigning Gaussian kernel weights based on inter-site distances. Observations from neighboring sites are aggregated into a weighted training set, and a local RF model is trained using observation weights within the TreeBagger framework. A random search over both neighborhood size (K) and key RF hyper-parameters is conducted for each site, with the optimal configuration selected based on minimum RMSE evaluated on the target site. Model predictive performance is subsequently summarized using R2 and RMSE. The best-performing local configurations are recorded for all sites, enabling site-specific model calibration and analysis of spatial non-stationarity. GWXGBoost_leave_one_site_crossvalidation.m: This code implements a local spatially weighted XGBoost (GWXGBoost) regression framework, as defined in this study, with per-site random feature selection to capture spatial heterogeneity in soil respiration modeling. Spatial sites are defined by unique latitude–longitude pairs, and observation-level predictors are first aggregated to site-level means and standardized to construct a feature-based similarity space. For each target site, a local training dataset is formed by identifying the K nearest neighboring sites in the standardized feature space and assigning Gaussian kernel weights based on inter-site feature distances. The local model is trained using a weighted XGBoost approach, where observation weights reflect site similarity. Multiple random subsets of predictors are sampled independently for each site, and a random search over feature subsets, neighborhood size (K), and XGBoost hyper-parameters is performed. The optimal site-specific configuration is selected based on minimum RMSE evaluated on the target site. Model predictive performance is subsequently summarized using R2 and RMSE. The implementation integrates MATLAB with Python XGBoost, enforces reproducible randomness via fixed random seeds, and outputs the optimal neighborhood size, hyper-parameters, and selected predictors for each site. GWXGBoost_china_forest_model_zone.m:This code constructs an environmental similarity–based zone map to support geographically weighted model application at the pixel level. The workflow first applies a China spatial mask and a vegetation mask (MODIS IGBP classes 1–9) to define valid pixels. Multi-year mean environmental predictors are then extracted, followed by robust outlier removal using a 3×IQR rule and z-score standardization. Standardized predictor values are sampled at observation sites (latitude–longitude pairs), and site-wise centroid vectors are computed as the mean predictor signature for each site (or site group). Each valid pixel is subsequently assigned to the nearest centroid using Euclidean distance in the standardized predictor space, producing an “environmental similarity zone” raster that links pixels to the most representative site centroid. The script exports both a regional zone map and a China-cropped zone map in GeoTIFF format, which can be used to select site-specific geographically weighted models for spatial upscaling and product generation. GWXGBoost_product_china_forest_Rs.m:This code generates spatially explicit monthly soil respiration (Rs) products using site-specific geographically weighted XGBoost (GWXGBoost) models with previously optimized configurations. The script first loads the optimal neighborhood size (K), XGBoost hyper-parameters, and selected predictor subsets for each site derived from the model calibration stage. For each site, a local spatially weighted XGBoost model is retrained using observation-level data from neighboring sites, where neighbor selection is based on standardized site-level environmental similarity and Gaussian kernel weights. The trained site-specific models are then applied to gridded environmental predictor datasets to produce monthly Rs estimates at 500-m spatial resolution. A zone-based mapping strategy is used to assign each grid cell to its corresponding site-specific model, and the resulting Rs predictions are exported as GeoTIFF files for each month. This script enables the spatial upscaling of locally calibrated GWXGBoost models to continuous gridded products.

Publication details

Journal / source
Zenodo (CERN European Organization for Nuclear Research)
Publication date
2 January 2026