Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rm sptf whc12 #32 #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ export(sptf_vg2)
export(sptf_whc1)
export(sptf_whc10)
export(sptf_whc11)
export(sptf_whc12)
export(sptf_whc13)
export(sptf_whc14)
export(sptf_whc15)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog soilptf

## Version 0.5.1.9000
## Removed
* function `sptf_whc12` as it most likely did not work as intended. Closes #32.

## Version 0.5.0 2023-04-29

## Added
Expand Down
2 changes: 1 addition & 1 deletion R/sptf_predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ ptf_whc_all <- function(dt){
# # PTF11: Calculation of wrc parameters may be wrong. The calculated water content is out of normal range.
dt[, p11 := sptf_whc11(A_C_OF = A_C_OF, A_CLAY_MI = A_CLAY_MI, A_SILT_MI = A_SILT_MI)]
# # PTF12: Calculation of wrc parameters may be wrong. The calculated water content is out of normal range.
dt[, p12 := sptf_whc12(A_C_OF = A_C_OF,A_CLAY_MI = A_CLAY_MI, A_SAND_MI = A_SAND_MI)]
# dt[, p12 := sptf_whc12(A_C_OF = A_C_OF,A_CLAY_MI = A_CLAY_MI, A_SAND_MI = A_SAND_MI)]
dt[, p13 := sptf_whc13(A_C_OF = A_C_OF, A_CLAY_MI = A_CLAY_MI,A_SAND_MI = A_SAND_MI)]
dt[, p14 := sptf_whc14(A_SOM_LOI = A_SOM_LOI,A_CLAY_MI = A_CLAY_MI,A_SILT_MI = A_SILT_MI)]
dt[, p15 := sptf_whc15(A_SOM_LOI = A_SOM_LOI,A_CLAY_MI = A_CLAY_MI,A_SILT_MI = A_SILT_MI)]
Expand Down
75 changes: 39 additions & 36 deletions R/whc.R
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ sptf_whc11 <- function(A_C_OF,A_CLAY_MI,A_SILT_MI) {

#' Calculate the water holding capacity given the pedotransferfunction of Rawls & Brakensiek 1985
#'
#' DEPRECATED
#'
#' Note: Calculation of whc parameters may be wrong. The calculated water content is out of normal range. Original literature cannot be found on web.
#'
#' @inheritParams sptf_bd0
Expand All @@ -621,44 +623,45 @@ sptf_whc11 <- function(A_C_OF,A_CLAY_MI,A_SILT_MI) {
#'
#' @references Rawls & Brakensiek (1985) Prediction of Soil Water Properties for Hydrologic Modelling
#'
#' @export
#'
sptf_whc12 <- function(A_C_OF,A_CLAY_MI,A_SAND_MI) {

# Add visual bindings
theta_sat = theta_res = theta_fc = alfa = n = por = psi_b = lambda = theta_wp = NULL
D_BDS = NULL

# set default parameters for this function
mp_fc = 2.0
mp_wp = 4.2

# Check input
arg.length <-max(length(A_C_OF), length(A_CLAY_MI),length(A_SAND_MI))
checkmate::assert_numeric(A_C_OF, lower = 0, upper = 1000,len = arg.length)
checkmate::assert_numeric(A_CLAY_MI, lower = 0, upper = 100, len = arg.length)
checkmate::assert_numeric(A_SAND_MI, lower = 0, upper = 100, len = arg.length)
checkmate::assert_numeric(mp_wp, any.missing = FALSE)
checkmate::assert_subset(mp_fc, choices = c(2, 4.2))

# Collect data into a table
dt <- data.table(A_C_OF = A_C_OF,
A_CLAY_MI = A_CLAY_MI,
A_SAND_MI = A_SAND_MI,
value = NA_real_
)

# add density (with Corg in g/kg as input) in units g/cm3
dt[,D_BDS := (1617 - 77.4 * log(A_C_OF) - 3.49 * A_C_OF)*0.001]

# Calcaulte parameters of water retention curve of Brooks and Corey (1964)
dt[, value := calc_soil_porosity(D_BDS)]

# return value
value <- dt[, value]

# return value
return(value)

# # Add visual bindings
# theta_sat = theta_res = theta_fc = alfa = n = por = psi_b = lambda = theta_wp = NULL
# D_BDS = NULL
#
# # set default parameters for this function
# mp_fc = 2.0
# mp_wp = 4.2
#
# # Check input
# arg.length <-max(length(A_C_OF), length(A_CLAY_MI),length(A_SAND_MI))
# checkmate::assert_numeric(A_C_OF, lower = 0, upper = 1000,len = arg.length)
# checkmate::assert_numeric(A_CLAY_MI, lower = 0, upper = 100, len = arg.length)
# checkmate::assert_numeric(A_SAND_MI, lower = 0, upper = 100, len = arg.length)
# checkmate::assert_numeric(mp_wp, any.missing = FALSE)
# checkmate::assert_subset(mp_fc, choices = c(2, 4.2))
#
# # Collect data into a table
# dt <- data.table(A_C_OF = A_C_OF,
# A_CLAY_MI = A_CLAY_MI,
# A_SAND_MI = A_SAND_MI,
# value = NA_real_
# )
#
# # add density (with Corg in g/kg as input) in units g/cm3
# dt[,D_BDS := (1617 - 77.4 * log(A_C_OF) - 3.49 * A_C_OF)*0.001]
#
# # Calcaulte parameters of water retention curve of Brooks and Corey (1964)
# dt[, value := calc_soil_porosity(D_BDS)]
#
# # return value
# value <- dt[, value]
#
# # return value
# return(value)

return('This function is deprecated')
}


Expand Down
5 changes: 4 additions & 1 deletion man/sptf_whc12.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ library(soilptf); library(data.table);require(ggplot2)
```

# 1. Soilptf package
Soil indicators help to access quality of soils. In Netherlands, an indicator set called BLN (‘Bodemindicatoren voor Landbouwgronden in Nederland’) was developed to integrally evaluate the quality of agricultural soils (de Haan et al., 2021). This set of soil health indicators was merged in 2023 with the soil evaluation framework of the Open Soilindex (Ros et al., 2023).
Soil indicators help to assess quality of soils. In Netherlands, an indicator set called BLN (‘Bodemindicatoren voor Landbouwgronden in Nederland’) was developed to integrally evaluate the quality of agricultural soils (de Haan et al., 2021). This set of soil health indicators was merged in 2023 with the soil evaluation framework of the Open Soilindex (Ros et al., 2023).

Quantifying BLN indicators often requires labour-intensive measurements, limiting their on-farm use. An alternative might be to include methods to estimate those difficult-to-measure parameters by so called pedotransferfunctions (PTFs), being empirical relationships calibrated on large datasets. The use of ptfs helps the application of soil health indicators on a much larger spatial scale at lower cost. The ptfs might also help to underpin site specific threshold values.

Expand Down Expand Up @@ -55,10 +55,10 @@ Are you interested to contribute? See the `vignette("howtocontribute")`.
## 2.1. Bulk density

### 2.1.1. introduction
Soil bulk density is one of the most important soil properties. On the one hand, it describes the quality of the soil since soil bulk density directly reflects soil porosity and compaction which influence water and air soil properties. On the other hand, soil bulk density is a crucial parameter used in balancing and modelling of various processes in the environment. Soil bulk density can be determined in two ways: directly in laboratory using core samples by a thermogravimetric method and indirectly using prediction methods including the use of PTFs which are equations or algorithms representing relationships between soil properties different in difficulty of their measurement or their availability. PTFs use thereby other parameters of soil to estimate its bulk density such as soil organic matter, soil organic carbon, and soil mineralogy (clay, sand or silt content).
Soil bulk density is one of the most important soil properties. On the one hand, it describes the quality of the soil since soil bulk density directly reflects soil porosity and compaction which influence water and air soil properties. On the other hand, soil bulk density is a crucial parameter used in balancing and modelling of various processes in the environment. Soil bulk density can be determined in two ways: directly in laboratory using core samples by a thermogravimetric method and indirectly, using prediction methods including the use of PTFs. PTFs use other parameters of the soil to estimate its bulk density such as soil organic matter, soil organic carbon, and soil mineralogy (clay, sand or silt content).

### 2.1.2. ptfs in package
A number of PTFs exists to estimate soil bulk density. Of 181 collected PTF’s, more than half of the PTF’s were built on data of Europe (39%) or North America (19%). Some PTFs are built on data of specific land use type, such as forest (23%), nature (3%) or agriculture (11%). More than half of the PTFs require only 1 input parameter (54%), followed by 2 parameters (20 %) and 3 parameters (16 %). Almost all PTFs use soil organic matter or soil organic carbon as input parameter, and many also use soil minerology (e.g. sand and clay content) as additional input parameters.
A number of PTFs exists to estimate soil bulk density. Of the `r nrow(sptf_bulkdensity)` collected PTF’s, more than half of the PTF’s were built on data of Europe (`r round(nrow(sptf_bulkdensity[continent_code == 'NA'])/nrow(sptf_bulkdensity)*100)`%) or North America (`r round(nrow(sptf_bulkdensity[continent_code == 'EU'])/nrow(sptf_bulkdensity)*100)`%). Some PTFs are built on data of specific land use type, such as forest (`r round(nrow(sptf_bulkdensity[landuse == 'forest'])/nrow(sptf_bulkdensity)*100)`%), nature (`r round(nrow(sptf_bulkdensity[landuse == 'nature'])/nrow(sptf_bulkdensity)*100)`%) or agriculture (`r round(nrow(sptf_bulkdensity[landuse == 'agriculture'])/nrow(sptf_bulkdensity)*100)`%). More than half of the PTFs require only 1 input parameter (`round(nrow(sptf_bulkdensity[!grepl('\\|\\|',soilproperties)])/nrow(sptf_bulkdensity)*100)`%), followed by 2 parameters (`round(nrow(sptf_bulkdensity[grepl('^\\w+\\|\\|\\w+$',soilproperties)])/nrow(sptf_bulkdensity)*100)` %) and 3 parameters (`round(nrow(sptf_bulkdensity[grepl('^\\w+\\|\\|\\w+\\|\\|\\w+$',soilproperties)])/nrow(sptf_bulkdensity)*100)` %). Almost all PTFs use soil organic matter or soil organic carbon as input parameter, and many also use soil mineralogy (e.g. sand and clay content) as additional input parameters.

### 2.1.3. examples
The function to predict the bulk density from soil properties can be used as follows:
Expand Down Expand Up @@ -97,15 +97,15 @@ The bulk density declines when more SOC is available. This is illustrated below
# the cation exchange capacity
dt1.bd <- ptf_bd_all(dt1)

# retreive the mean and standard deviation of top 10 best ones
# retrieve the mean and standard deviation of top 10 best ones
dt1.bd <- dt1.bd[,list(bd.mean = mean(bd,na.rm=T),
bd.se = sd(bd,na.rm=T)/sqrt(sum(!is.na(bd)))),by='id']
dt1 <- merge(dt1,dt1.bd,by='id')
m.bd <- lm(bd.mean~A_C_OF + I(log(A_C_OF)),data=dt1)
p.bd <- predict(m.bd,newdata = data.frame(A_C_OF = dt1$A_C_OF))
l.bd <- paste('CEC == ', '2125 -1.056 * C - 257 * log(C)')

# se theme for figures of the pedotransfer functions
# set theme for figures of the pedotransfer functions
ptl <- theme(plot.subtitle=element_text(size=10, face="italic", color="black"),
axis.text = element_text(size = 12,colour ='black'),
axis.title = element_text(size = 12,colour ='black'),
Expand Down