-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval-DSM-data.Rmd
262 lines (190 loc) · 5.84 KB
/
eval-DSM-data.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
---
title: "Coweeta Raster Soil Survey"
author: "D.E. Beaudette"
date: "`r Sys.Date()`"
output:
html_document:
mathjax: null
jquery: null
smart: no
number_sections: yes
toc: yes
toc_depth: 3
toc_float:
collapsed: true
smooth_scroll: false
---
```{r setup, echo=FALSE, results='hide', warning=FALSE}
library(knitr, quietly=TRUE)
opts_chunk$set(
message = FALSE,
warning = FALSE,
background = '#F7F7F7',
fig.align = 'center',
dev = 'png',
fig.retina = 2,
tidy = FALSE,
verbose = FALSE
)
options(width=100, stringsAsFactors=FALSE)
```
```{r}
library(soilDB)
library(aqp)
library(sharpshootR)
library(terra)
library(rasterVis)
library(sf)
library(stringi)
library(knitr)
library(kableExtra)
# RSS: cell values are map unit keys
# has a simple raster attribute table
r <- rast('grids/rss_utm.tif')
# Coweeta watersheds
b <- read_sf('vect/Coweeta_Hydrologic_Laboratory.shp')
# points
p <- read_sf('vect/Soil_Moisture_Sites_CW.shp')
# reduce to single polygon
x <- st_union(b)
# get intersecting SSURGO linework as SpatialPolygonsDataFrame from SDA
# this uses the bounding-box
mu.poly <- SDA_spatialQuery(x, what = 'mupolygon', geomIntersection = TRUE)
mu.poly <- st_transform(mu.poly, st_crs(crs(r)))
# transform to common CRS
b <- st_transform(b, st_crs(r))
p <- st_transform(p, st_crs(r))
```
Load pre-processed tabular data.
```{r}
load('data/rss-tab-data-raw.rda')
```
Develop thematic data
```{r}
## TODO / BUD: 0-values added to RAT
# grids loaded via raster() have a 0-entry in the RAT
r.mukey <- raster('grids/rss_mukey.tif')
r.coname <- raster('grids/rss_coname.tif')
r.mukind <- raster('grids/rss_mukind.tif')
r.taxpartsize <- raster('grids/rss_taxpartsize.tif')
r.aws050 <- raster('grids/rss_aws050.tif')
```
```{r}
```
```{r}
```
```{r}
# rastervis requires sp objects
mu.sp <- as(mu.poly, 'Spatial')
```
```{r fig.width=8, fig.height=10}
levelplot(
r.mukind,
att = 'category',
margin = FALSE,
col.regions = viridis,
main = 'Map Unit Kind',
scales = list(draw = FALSE),
panel = function(...) {
panel.levelplot(...)
sp.lines(as(b, 'Spatial'), col = 'white', lwd = 2)
}
)
levelplot(
r.coname,
att = 'co.names',
margin = FALSE,
col.regions = viridis,
main = 'RSS Components',
scales = list(draw = FALSE),
panel = function(...) {
panel.levelplot(...)
sp.lines(as(b, 'Spatial'), col = 'white', lwd = 2)
}
)
levelplot(
r.taxpartsize,
att = 'taxpartsize',
margin = FALSE,
col.regions = viridis,
main = 'Particle Size Class\n(Dominant Condition)',
scales = list(draw = FALSE),
panel = function(...) {
panel.levelplot(...)
sp.lines(as(b, 'Spatial'), col = 'black', lwd = 2)
}
)
levelplot(
r.aws050,
margin = FALSE,
col.regions = viridis,
main = 'PAWS 0-50cm (cm)\n(Dominant Value)',
scales = list(draw = FALSE),
panel = function(...) {
panel.levelplot(...)
sp.lines(as(b, 'Spatial'), col = 'white', lwd = 2)
}
)
levelplot(
r.coname,
att = 'co.names',
margin = FALSE,
col.regions = viridis,
main = 'RSS + SSURGO Linework',
sub = 'SSURGO (white lines) and Rock outcrop-Cleveland complex (red lines)',
scales = list(draw = FALSE),
panel = function(...) {
panel.levelplot(...)
# all SSURGO polygons in the BBOX
sp.lines(mu.sp, col = 'white')
# Rock outcrop-Cleveland complex, 30 to 95 percent slopes
sp.lines(mu.sp[which(mu.sp$mukey == '545857'), ], col = 'firebrick')
}
)
```
```{r}
## approximate acreage
## pixel-based estimates of area (largest, non-misc. area)
mu.area <- na.omit(as.data.frame(freq(r.mukey)))
mu.area$ac <- mu.area$count * (mean(res(r.mukey))^2) * 0.000247105
a <- merge(mu.area, rss.co[rss.co$compkind == 'Series', ], by.x = 'value', by.y = 'mukey', sort = FALSE, all.x = TRUE)
a$comp.ac <- a$ac * (a$comppct_r / 100)
co.area <- aggregate(comp.ac ~ compname, data = a, FUN = sum)
co.area <- co.area[order(co.area$comp.ac, decreasing = TRUE), ]
# proportion
co.area$proportion <- co.area$comp.ac / sum(co.area$comp.ac)
# investigate named components
osds <- fetchOSD(co.area$compname)
# encode horizon boundary distinctness
osds$hzd <- hzDistinctnessCodeToOffset(osds$distinctness)
# # hmm...
# kable_styling(kable(co.area, row.names = FALSE, digits = 2), full_width = FALSE, font_size = 10)
```
```{r}
# join to SPC
co.area$id <- toupper(co.area$compname)
site(osds) <- co.area[, c('id', 'comp.ac', 'proportion')]
s <- site(osds)
kable_styling(kable(s[, c('id', 'family', 'drainagecl', 'proportion')], digits = 2), full_width = FALSE, font_size = 10)
```
```{r fig.width=10, fig.height=6}
SoilTaxonomyDendrogram(osds, width = 0.35, name.style = 'center-center', y.offset = 0.4, hz.distinctness.offset = 'hzd', shrink = TRUE)
# get plotting details from aqp environment
lsp <- get('last_spc_plot', envir = aqp.env)
# sensor depths
.depths <- (c(10, 20, 50, 80, 100) * lsp$scaling.factor) + lsp$y.offset[1]
abline(h = .depths, lty = 2, col = 'green')
```
```{r fig.width=10, fig.height=6}
o.sub <- osds
idx <- order(o.sub$comp.ac, decreasing = TRUE)
ragg::agg_png(filename = 'RSS-OSDs.png', width = 1800, height = 900, scaling = 1.5)
par(mar = c(0, 0, 0, 0.5))
plotSPC(o.sub, width = 0.35, name.style = 'center-center', hz.distinctness.offset = 'hzd', shrink = TRUE, hz.depths = TRUE, fixLabelCollisions = TRUE, hz.depths.offset = 0.05, id.style = 'top', cex.names = 0.75, plot.order = idx, cex.id = 0.66, max.depth = 225, axis.line.offset = -4, cex.depth.axis = 1, n.depth.ticks = 10)
# planned depths for soil sensors
.depths <- c(10, 20, 50, 80, 100)
segments(x0 = 0.5, y0 = .depths, x1 = length(o.sub) + 1, y1 = .depths, lty = 2, col = 'blue', lwd = 1.5)
axis(side = 1, at = 1:length(o.sub), labels = round(o.sub$proportion[idx], 2), line = -5, cex.axis = 1)
mtext('Approximate Area Proportion within Coweeta', side = 1, line = -2.5, at = 0.5, adj = 0, font = 2)
dev.off()
```