Skip to content

Commit

Permalink
tiny release to CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Sep 13, 2023
1 parent abe6580 commit d2bcc45
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: aqp
Version: 2.01
Version: 2.0.1
Title: Algorithms for Quantitative Pedology
Authors@R: c(person(given="Dylan", family="Beaudette", role = c("aut", "cre"), email = "[email protected]"), person(given="Pierre", family="Roudier", email="[email protected]", role = c("aut", "ctb")), person(given="Andrew", family="Brown", email="[email protected]", role = c("aut", "ctb")))
Author: Dylan Beaudette [aut, cre], Pierre Roudier [aut, ctb], Andrew Brown [aut, ctb]
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# aqp 2.01 (2023-09-03)
# aqp 2.0.1 (2023-09-03)
* new function `flagOverlappingHz()` for identifying horizons with perfect overlap
* `fillHzGaps()`, `dice()`, `slab()`, and several other functions now safely handle horizons with perfect overlap (#296)

Expand Down
43 changes: 26 additions & 17 deletions misc/sandbox/SOC-stock-examples.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# library(aqp)
library(aqp)
library(soilDB)
library(lattice)
library(tactile)
Expand All @@ -19,7 +19,7 @@ table(x$taxonname)


# ignoring rock fragments for now
# SOC stock by horizon = thick (cm) * Db 1/3 bar (g/cm^3) * (soil fraction) * conversion factor (10)
# SOC stock by horizon = thick (cm) * Db 1/3 bar (g/cm^3) * (soil fraction) * SOC (%) * conversion factor (10)
x$thick <- x$hzn_bot - x$hzn_top
x$soc_kg_sq.m <- x$thick * x$db_13b * (x$estimated_oc / 100) * 10

Expand All @@ -31,8 +31,9 @@ z <- subset(x, soc.complete.pct > 0.9)

table(z$taxonname)

par(mar = c(0, 0, 3, 0))
par(mar = c(0, 0, 3, 2))
plotSPC(z, color = 'soc_kg_sq.m', width = 0.35, label = 'taxonname', name.style = 'center-center')

groupedProfilePlot(z, groups = 'taxonname', color = 'soc_kg_sq.m', width = 0.35, name.style = 'center-center', group.name.offset = -10, max.depth = 150)

groupedProfilePlot(z, groups = 'taxonname', color = 'moist_soil_color', width = 0.35, name.style = 'center-center', group.name.offset = -10, max.depth = 150)
Expand All @@ -55,7 +56,10 @@ x$SOC_stock <- profileApply(x, function(i) {
sum(i$soc_kg_sq.m, na.rm = TRUE)
})

par(mar = c(0, 0, 3, 1))
par(mar = c(0, 0, 3, 2))

groupedProfilePlot(x, groups = 'taxonname', color = 'moist_soil_color', width = 0.35, name.style = 'center-center', group.name.offset = -15, max.depth = 200, cex.names = 0.8)

groupedProfilePlot(x, groups = 'taxonname', color = 'soc_kg_sq.m', width = 0.35, name.style = 'center-center', group.name.offset = -15, max.depth = 200, cex.names = 0.8)


Expand All @@ -74,10 +78,10 @@ z$SOC_stock <- profileApply(z, function(i) {
sum(i$soc_kg_sq.m, na.rm = TRUE)
})

par(mar = c(0, 0, 3, 1))
par(mar = c(0, 0, 3, 2))
groupedProfilePlot(z, groups = 'taxonname', color = 'soc_kg_sq.m', width = 0.35, name.style = 'center-center', group.name.offset = -5, cex.names = 0.8, print.id = FALSE)

par(mar = c(0, 0, 3, 1))
par(mar = c(0, 0, 3, 2))
groupedProfilePlot(z, groups = 'taxonname', color = 'moist_soil_color', width = 0.35, name.style = 'center-center', group.name.offset = -5, cex.names = 0.66, print.id = FALSE)

d <- site(z)
Expand All @@ -89,7 +93,7 @@ tapply(d$SOC_stock, d$taxonname, quantile)

a <- alignTransect(z$SOC_stock, x.min = 1, x.max = length(z), fix = TRUE, thresh = 0.4, method = 'E', q = 2)

par(mar = c(2, 0, 3, 1))
par(mar = c(2, 0, 3, 2))
plotSPC(z, width = 0.25, name.style = 'center-center',
cex.names = 0.75, label = 'taxonname', color = 'moist_soil_color',
relative.pos = a$relative.pos, plot.order = a$order)
Expand All @@ -102,8 +106,8 @@ z$cumulative.soc_kg_sq.m <- profileApply(z, function(i) {
})


par(mar = c(2.5, 0, 3, 1))
groupedProfilePlot(z, groups = 'taxonname', color = 'cumulative.soc_kg_sq.m', width = 0.35, name.style = 'center-center', group.name.offset = -5, cex.names = 0.75, print.id = FALSE, col.label = 'Cumulative SOC Stock (kg C / m^2)', cex.depth.axis = 1, axis.line.offset = -4)
par(mar = c(3, 0, 3, 2), xpd = NA)
groupedProfilePlot(z, groups = 'taxonname', color = 'cumulative.soc_kg_sq.m', width = 0.35, name.style = 'center-center', group.name.offset = -5, cex.names = 0.75, print.id = FALSE, col.label = 'Cumulative SOC Stock (kg C / m^2)', depth.axis = list(cex = 1, line = -3))

.lsp <- get('last_spc_plot', envir = aqp.env)

Expand All @@ -113,8 +117,8 @@ text(x = 1:length(z), y = 105, labels = .lab, cex = 0.85)
mtext('SOC Stock (kg / m^2)', side = 1, line = 0.75, font = 2, cex = 0.85)


par(mar = c(2.5, 0, 0, 1))
groupedProfilePlot(z, groups = 'taxonname', color = 'moist_soil_color', width = 0.35, name.style = 'center-center', group.name.offset = -5, cex.names = 0.75, print.id = FALSE, col.label = 'Cumulative SOC Stock (kg C / m^2)', cex.depth.axis = 1, axis.line.offset = -4)
par(mar = c(2.5, 0, 0, 2), xpd = NA)
groupedProfilePlot(z, groups = 'taxonname', color = 'moist_soil_color', width = 0.35, name.style = 'center-center', group.name.offset = -5, cex.names = 0.75, print.id = FALSE, col.label = 'Cumulative SOC Stock (kg C / m^2)', depth.axis = list(cex = 1, line = -3))

.lsp <- get('last_spc_plot', envir = aqp.env)
.lab <- round(z$SOC_stock)[.lsp$plot.order]
Expand All @@ -123,8 +127,8 @@ text(x = 1:length(z), y = 105, labels = .lab, cex = 0.85)
mtext('SOC Stock (kg / m^2)', side = 1, line = 0.75, font = 2, cex = 0.85)


par(mar = c(2.5, 0, 0, 1))
groupedProfilePlot(z, groups = 'taxonname', name = NA, color = 'moist_soil_color', width = 0.4, name.style = 'center-center', group.name.offset = -5, cex.names = 0.75, print.id = FALSE, col.label = 'Cumulative SOC Stock (kg C / m^2)', cex.depth.axis = 1, axis.line.offset = -4, break.style = 'arrow', arrow.offset = -2, group.line.lty = 1, group.line.lwd = 1)
par(mar = c(2.5, 0, 0, 1), xpd = NA)
groupedProfilePlot(z, groups = 'taxonname', name = NA, color = 'moist_soil_color', width = 0.4, name.style = 'center-center', group.name.offset = -5, cex.names = 0.75, print.id = FALSE, col.label = 'Cumulative SOC Stock (kg C / m^2)', depth.axis = list(cex = 1, line = -3), break.style = 'arrow', arrow.offset = -2, group.line.lty = 1, group.line.lwd = 1)

.lsp <- get('last_spc_plot', envir = aqp.env)
.lab <- round(z$SOC_stock)[.lsp$plot.order]
Expand All @@ -137,14 +141,19 @@ mtext('SOC Stock (kg / m^2)', side = 1, line = 0.75, font = 2, cex = 0.85)

agg <- slab(z, fm = taxonname ~ cumulative.soc_kg_sq.m)

tps <- tactile.theme(
superpose.line = list(col = 'royalblue', lwd = 3)
)

xyplot(top ~ p.q50 | taxonname, data=agg, ylab='Depth',
xlab='median bounded by 25th and 75th percentiles',
xlab='Cumulative Soil Organic Carbon Stock (kg / m^2)\nmedian bounded by 5th and 95th percentiles',
lower=agg$p.q5, upper=agg$p.q95, ylim=c(110,-5),
panel=panel.depth_function,
prepanel=prepanel.depth_function,
cf=agg$contributing_fraction,
alpha=0.5,
layout=c(3,1), scales=list(x=list(alternating=1))
sync.colors = TRUE,
alpha=0.25,
layout=c(3,1), scales=list(x=list(relation = 'free', alternating = 1)),
par.settings = tps
)


Expand Down
51 changes: 51 additions & 0 deletions misc/sandbox/SPC-bracket-interval-via-transparency.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
library(aqp)

# example data from three official series descriptions
data("osd")



# https://msalganik.wordpress.com/2017/01/21/making-sense-of-the-rlnorm-function-in-r/comment-page-1/
# make rlnorm simpler to parameterize
# m: arithmetic mean
# s: standard deviation
rlnorm.helper <- function(n, m, s) {
location <- log(m^2 / sqrt(s^2 + m^2))
shape <- sqrt(log(1 + (s^2 / m^2)))
rlnorm(n, location, shape)
}

d <- lapply(profile_id(osd), function(i) {
s <- data.frame(id = i, top = rlnorm.helper(50, m = 50, s = 15))
s$bottom <- 0

for(i in seq_along(s$bottom)) {
s$bottom[i] <- s$top[i] + rlnorm.helper(1, m = 25, s = 15)
}

return(s)
})

d <- do.call('rbind', d)


# tighter margins
par(mar = c(0, 0, 0, 0))


# adjust default style
plotSPC(
osd,
name.style = 'center-center',
cex.names = 1,
width = 0.33,
cex.id = 0.9,
hz.distinctness.offset = 'hzd',
max.depth = 175,
depth.axis = FALSE,
hz.depths = TRUE
)

addBracket(d, offset = -0.38, tick.length = 0, lwd = 12, col = rgb(red=0, green=0, blue=1, alpha=0.03))


0 comments on commit d2bcc45

Please sign in to comment.