Chapter 3 Soil Data

3.1 Soil organic carbon (SOC) ground measurements

SOC concentration samples (g kg-1) were acquired from the Rapid Carbon Assessment Project (RCAP) using the SoilWeb RaCA Query API and the SoilDB package. This database contains standardized soil data of 38 RACA sites, 188 profiles and 846 horizons, and a Depth range of 26 - 203 cm.

3.2 Some Libraries

library(soilDB)
require(aqp)
library(plyr)
library(maps)
library(lattice)
library(reshape2)
library(cluster)
library(GSIF)
library(tidyverse)
library(rgdal)
library(sp)

3.3 Input data in R

# Fetch SoilProfileCollection (SPC) data by State
r.state <- fetchRaCA(state='NJ')
# Extract site/pedon data
rData <- r.state$pedons
# View first 6 rows
head(rData)
## SoilProfileCollection with 6 profiles and 25 horizons
## profile ID: rcapid  |  horizon ID: phiid 
## Depth range: 95 - 100 cm
## 
## ----- Horizons (6 / 25 rows  |  10 / 23 columns) -----
##  hzname    rcapid   phiid hzdept hzdepb clay silt sand texture_class phfield
##     Ap1 C1201C061 2944764      0      5   NA   NA   NA             l      NA
##     Ap2 C1201C061 2944765      5     28   NA   NA   NA             l      NA
##      Bt C1201C061 2944766     28     54   NA   NA   NA            sl      NA
##       C C1201C061 2944767     54    100   NA   NA   NA          lcos      NA
##     Ap1 C1201C062 2944760      0      5   NA   NA   NA             l      NA
##     Ap2 C1201C062 2944761      5     30   NA   NA   NA             l      NA
## [... more horizons ...]
## 
## ----- Sites (6 / 6 rows  |  10 / 54 columns) -----
##     rcapid  peiid siteiid   pedon_id rcasiteid rcapointnumber       plotconfig
##  C1201C061 636193  642286 C1201C06-1  C1201C06              1 Standard cluster
##  C1201C062 636192  642286 C1201C06-2  C1201C06              2 Standard cluster
##  C1201C063 636194  642286 C1201C06-3  C1201C06              3 Standard cluster
##  C1201C064 636195  642286 C1201C06-4  C1201C06              4 Standard cluster
##  C1201C065 636196  642286 C1201C06-5  C1201C06              5 Standard cluster
##  C1201F291 636197  642287 C1201F29-1  C1201F29              1 Standard cluster
##  exposedsoilpct azimuthfromplotcenter distancefromplotcenter
##              10                     0                      1
##              10                   360                     30
##              10                    90                     30
##              10                   180                     30
##              10                   270                     30
##               0                    30                    180
## 
## Spatial Data:
## [EMPTY]
# Extract and add carbon data to the SPC
site(rData) <- r.state$stock

# convert taxonname to a factor
rData$taxonname <- factor(rData$taxonname)

# Create a dataframe with site/horizon and cstock
nData <- merge(rData@horizons,rData@site) 

# Check the data type
class(nData)
## [1] "data.frame"

3.4 Create the SOC data

# Select Soil and Site Data
mSoil  <- nData %>% dplyr::select(rcapid, phiid, hzdept, hzdepb, value_30cm, clay, silt, sand, total_frags_pct)  
mSites <- nData %>% dplyr::select(rcapid, tax_subgroup, x, y)
# Rename the Columns
names(mSoil)[c(1,2,3,4,5,9)] <- c("ProfID", "HorID", "top", "bottom", "SOC", "CRFVOL")
names(mSites)[c(1,2,3,4)] <- c("ProfID", "soiltype", "X", "Y")  # X== -Ve n Y = +Ve

# Add index number to data
X.1 = row.names(mSites)
mSites <- cbind(X.1, mSites)
mSites$X.1 = as.integer(mSites$X.1)
# Promote to SoilProfileCollection
# The SoilProfileCollection is a object class in R designed to handle soil profile data
depths(mSoil) <- ProfID ~ top + bottom
class(mSoil)
## [1] "SoilProfileCollection"
## attr(,"package")
## [1] "aqp"
# Merge the soil horizons information with the site-level
site(mSoil) <- mSites
# Set spatial coordinates
coordinates(mSoil) <- ~ X + Y

3.5 Working Data

# Estimate 0-30 standard horizon using mass preserving splines
try(SOC <- mpspline(mSoil, 'SOC', d = t(c(0,30))))
try(CRFVOL <- mpspline(mSoil, 'CRFVOL', d = t(c(0,30))))
# Prepare final data frame
nj.Data <- data.frame(id = mSoil@site$ProfID,
                    Y = mSoil@sp@coords[,2],
                    X = mSoil@sp@coords[,1],
                    SOC = SOC$var.std[,1],
                    CRFVOL = CRFVOL$var.std[,1]) 
# removes missing or NA values
nj.Data <- nj.Data[complete.cases(nj.Data),]