From 08b0cd69f46d3a86dde83199bcaaae14ae7d17f5 Mon Sep 17 00:00:00 2001 From: Brent Date: Thu, 4 May 2023 13:48:50 +0200 Subject: [PATCH 1/3] remove sptf_whc12 --- NAMESPACE | 1 - NEWS.md | 4 +++ R/whc.R | 75 ++++++++++++++++++++++++----------------------- man/sptf_whc12.Rd | 1 + 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 2f7ba80..6436811 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 0595efa..479d507 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/whc.R b/R/whc.R index 642ce89..e950f00 100644 --- a/R/whc.R +++ b/R/whc.R @@ -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 @@ -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') } diff --git a/man/sptf_whc12.Rd b/man/sptf_whc12.Rd index 9e486ca..4a8599a 100644 --- a/man/sptf_whc12.Rd +++ b/man/sptf_whc12.Rd @@ -14,6 +14,7 @@ sptf_whc12(A_C_OF, A_CLAY_MI, A_SAND_MI) \item{A_SAND_MI}{(numeric) Sand content (\%)} } \description{ +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. } \details{ From a43ef138c6fff1cd7a05a2d3a033710c9b6f2922 Mon Sep 17 00:00:00 2001 From: Brent Date: Thu, 4 May 2023 14:02:30 +0200 Subject: [PATCH 2/3] comment out call to sptf_whc12 in ptf_whc_all --- R/sptf_predict.R | 2 +- man/sptf_whc12.Rd | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/sptf_predict.R b/R/sptf_predict.R index b011540..62f987c 100644 --- a/R/sptf_predict.R +++ b/R/sptf_predict.R @@ -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)] diff --git a/man/sptf_whc12.Rd b/man/sptf_whc12.Rd index 4a8599a..89e0f30 100644 --- a/man/sptf_whc12.Rd +++ b/man/sptf_whc12.Rd @@ -15,9 +15,11 @@ sptf_whc12(A_C_OF, A_CLAY_MI, A_SAND_MI) } \description{ 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. } \details{ +Note: Calculation of whc parameters may be wrong. The calculated water content is out of normal range. Original literature cannot be found on web. + + mp_fc must be either 10 or 33 } \references{ From 728bb69ba7a81ec8d8720aa412f664aa8ea24ad1 Mon Sep 17 00:00:00 2001 From: Brent Date: Thu, 4 May 2023 14:29:31 +0200 Subject: [PATCH 3/3] correct typos and retrieve numbers and percentages of bd functions dynamically using table sptf_bulkdensity --- vignettes/introduction.Rmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index 8191e12..b057441 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -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. @@ -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: @@ -97,7 +97,7 @@ 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') @@ -105,7 +105,7 @@ The bulk density declines when more SOC is available. This is illustrated below 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'),