AQP + DSM = ESD ?

Dylan Beaudette (USDA-NRCS Sonora, CA)
October 7, 2014











This document is based on aqp version 1.7-6, soilDB version 1.3-5, and sharpshootR version 0.6-7.

Caveat emptor

  • I don't know all that much about ESI / ESD.
  • Dog and pony show– live demonstration more interesting.
  • Be sure to follow embedded links to full documentation.
  • Check out the AQP project website.
  • You can reproduce much of this document with:
# install stable versions
install.packages('aqp', dep=TRUE) 
install.packages('soilDB', dep=TRUE)
install.packages('sharpshootR', dep=TRUE)

# install latest versions from R-Forge:
install.packages('aqp', repos="http://R-Forge.R-project.org", type='source')
install.packages('soilDB', repos="http://R-Forge.R-project.org", type='source')
install.packages('sharpshootR', repos="http://R-Forge.R-project.org", type='source')
# load libraries
library(aqp)
library(soilDB)
library(sharpshootR)
library(lattice)
library(plyr)
library(Hmisc)

# set options
options(width=100, stringsAsFactors=FALSE)

Preaching to the Choir: why R?

  • repeatable, self-documenting work:

    • uni-variate / multivariate summaries
    • graphical representations of complex data
    • 2800+ packages on CRAN: 100+ packages on GIS, ecology, and soils!
  • algorithm development by experts, application by trained users

    • testing by eye: simple graphical “grammar” used to plot data
    • formalized testing: correlation, regression, classification, ordination, …
    • I/O capabilities: file, URL, SOAP, SQL, ODBC, PDF, PNG, SHP, KML, …
    • optimizers, matrix operations, custom data structures, …

Outline

  • AQP family of packages

    • aqp
    • soilDB
    • sharpshootR
  • Examples

    • soil profile simulation
    • profile sketches
    • “slicing”
    • aggregation
  • Details on numerical classification algorithm (?)

  • Live demo (?)

aqp package: Algorithms for Quantitative Pedology

a “vocabulary” for soil data analysis

  • special data structures: avoids annoying book-keeping code
  • visualization: soil profile sketches
  • aggregation: depth-slice summaries
  • classification: pair-wise dissimilarity of profiles

alt text

→ aqp manual page

soilDB package: Soil Database Interface

access to soil data should be simple, often it is not

  • PedonPC: pedon data
  • NASIS: pedon, component, map unit, ESD, etc.
  • KSSL: lab data
  • SDA: “live” SSURGO tabular data
  • OSD: official series descriptions
  • SSURGO: main soil survey product (spatial + tabular)
  • SoilWeb: snapshot-based window into the above
  • SCAN: soil climate network
# soilDB one-liners
auburn.lab <- fetchKSSL("auburn")  # KSSL data
auburn.extent <- seriesExtent("auburn")  # SSURGO-based series extent map
auburn.compdata <- SDA_query("<SQL>")  # SSURGO-based tabular data

→ soilDB manual page

sharpshootR package

prototypes, templates, and ideas to be built-upon

like this: example

→ sharpshootR manual page

SoilProfileCollection Objects

custom datatype to store/access hierarchy of soil profile information

# sample dataset, extracted from NASIS
library(soilDB)
data(loafercreek)
str(loafercreek, 2)
Formal class 'SoilProfileCollection' [package "aqp"] with 7 slots
  ..@ idcol     : chr "peiid"
  ..@ depthcols : chr [1:2] "hzdept" "hzdepb"
  ..@ metadata  :'data.frame':  1 obs. of  1 variable:
  ..@ horizons  :'data.frame':  308 obs. of  34 variables:
  ..@ site      :'data.frame':  54 obs. of  59 variables:
  ..@ sp        :Formal class 'SpatialPoints' [package "sp"] with 3 slots
  ..@ diagnostic:'data.frame':  177 obs. of  4 variables:

plot of chunk SPC-2

SoilProfileCollection Objects

Typical pedon/site data:

id, top, bottom, name, group
1,  0,   10,     A,    g1
1,  10,  18,     AB,   g1
          ...
2,  12,   22,    E,    g2
2,  22,   45,    Bhs1, g2

Converting data.frameSoilProfileCollection:

x <- read.csv(file = ...)
# promote to SoilProfileCollection
depths(x) <- id ~ top + bottom
# move 'site data' into @site
site(x) <- ~group

Functions that return SoilProfileCollection:

x <- fetchOSD()
x <- fetchKSSL()
x <- fetchPedonPC()
x <- fetchNASIS()
x <- fetchNASIS_component_data()

→ SoilProfileCollection tutorial

SoilProfileCollection Objects

  • object inspection
idname(sp4) # pedon ID name
horizonDepths(sp4) # colum names containing top and bottom depths
depth_units(sp4) # defaults to 'cm'
metadata(sp4) # data.frame with 1 row
profile_id(sp4) # vector of profile IDs
  • overloads to common functions
length(sp4) # number of profiles in the collection
nrow(sp4) # number of horizons in the collection
names(sp4) # column names from site and horizon data
min(sp4) # shallowest profile depth in collection
max(sp4) # deepest profile depth in collection
sp4[i, j] # get profile "i", horizon "j"
  • getting / setting of components
horizons(sp4) # get / set horizon data
site(sp4)  # get / set site data
diagnostic_hz(sp4) # get / set diagnostic horizons
proj4string(sp4) # get / set CRS
coordinates(sp4) # get / set coordinates
  • coercion to SpatialPointsDataFrame or data.frame
as(sp4, 'SpatialPointsDataFrame')
as(sp4, 'data.frame')

Plotting SoilProfileCollection Objects

flexible generation of soil profile sketches using “base graphics”