From c2c89ebe8189b2ca6991ba0bb20a98be26e2c6b1 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 16:36:42 +0100 Subject: [PATCH 01/10] set version to 2.2.1 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b261a93..2f85b23 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BBWPC Type: Package Title: Calculator for BedrijfsBodemWaterPlan (BBWP) -Version: 2.1.1 +Version: 2.2.1 Authors@R: c( person("Gerard", "Ros", email = "gerard.ros@nmi-agro.nl", role = c("aut","cre")), person("Sven", "Verweij", email = "sven.verweij@nmi-agro.nl", role = c("aut")), From af4fb8326fc22bf3e314186cf46acf28c45860c6 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 16:58:07 +0100 Subject: [PATCH 02/10] add penalty argument to wf --- R/bbwp_helpers.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/bbwp_helpers.R b/R/bbwp_helpers.R index 16e86bf..ac1f48a 100644 --- a/R/bbwp_helpers.R +++ b/R/bbwp_helpers.R @@ -33,18 +33,22 @@ cdf_rank <- function(smean,ssd,svalue){ #' #' @param x The risk or score value to be weighted #' @param type Use the weighing function for indicators or score +#' @param penalty (boolean) the option to apply a penalty for high risk BBWP field indicators #' #' @export -wf <- function(x, type = "indicators") { +wf <- function(x, type = "indicators", penalty = TRUE) { - if (type == "indicators") { + if (type == "indicators" & penalty == TRUE) { y <- 1 / (1 - x + 0.2) - } else if (type == "score") { + } else if (type == "score" & penalty == TRUE) { y <- 1 / (x * 0.01 + 0.2) + } else if(penalty == FALSE){ + + y = 1 } return(y) From 5b7b7ba2f5ed8ecb5f0834f5512ac935923b03a1 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 16:58:18 +0100 Subject: [PATCH 03/10] add penalty argument to field_indicators --- R/bbwp_field_indicators.R | 53 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/R/bbwp_field_indicators.R b/R/bbwp_field_indicators.R index 5223531..2d7a64f 100644 --- a/R/bbwp_field_indicators.R +++ b/R/bbwp_field_indicators.R @@ -30,6 +30,7 @@ #' @param D_WUE_WWRI (numeric) The relative score of soil wetness stress for improved efficiency of water #' @param D_WUE_WDRI (numeric) The relative score of drought stress for improved efficiency of water #' @param D_WUE_WHC (numeric) The relative score of drought stress for improved efficiency of water +#' @param penalty (boolean) the option to apply a penalty for high risk BBWP field indicators #' #' @import data.table #' @import OBIC @@ -40,7 +41,7 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, D_NSW_SCR,D_NSW_GWT,D_NSW_RO,D_NSW_SLOPE, D_NSW_WS,D_NSW_NLV, D_PSW_SCR,D_PSW_GWT,D_PSW_RO,D_PSW_SLOPE,D_PSW_WS,D_PSW_PCC,D_PSW_PSG,D_PSW_PRET, D_NUE_WRI,D_NUE_PBI,D_NUE_WDRI,D_NUE_NLV, - D_WUE_WWRI,D_WUE_WDRI,D_WUE_WHC){ + D_WUE_WWRI,D_WUE_WDRI,D_WUE_WHC, penalty = TRUE){ # add visual bindings D_RISK_NGW = D_RISK_NSW = D_RISK_PSW = D_RISK_NUE = D_RISK_WB = id = NULL @@ -93,30 +94,31 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, # integrate all relative field risk indicators into one for indictor for N loss to groundwater - dt[, D_RISK_NGW := (wf(D_NGW_SCR) * D_NGW_SCR + - 3 * wf(D_NGW_LEA) * D_NGW_LEA + - 2 * wf(D_NGW_NLV) * D_NGW_NLV) / - (wf(D_NGW_SCR) + 3 * wf(D_NGW_LEA) + 2 * wf(D_NGW_NLV))] + dt[, D_RISK_NGW := (wf(D_NGW_SCR,penalty) * D_NGW_SCR + + 3 * wf(D_NGW_LEA,penalty) * D_NGW_LEA + + 2 * wf(D_NGW_NLV,penalty) * D_NGW_NLV) / + (wf(D_NGW_SCR,penalty) + 3 * wf(D_NGW_LEA,penalty) + 2 * wf(D_NGW_NLV,penalty))] # integrate all relative field risk indicators into one for indictor for N loss to surface water - dt[, D_RISK_NSW := (wf(D_NSW_SCR) * D_NSW_SCR + - wf(D_NSW_GWT) * D_NSW_GWT + - wf(D_NSW_SLOPE) * D_NSW_SLOPE + - wf(D_NSW_RO) * D_NSW_RO + - wf(D_NSW_WS) * D_NSW_WS + - 3 * wf(D_NSW_NLV) * D_NSW_NLV ) / - (wf(D_NSW_SCR) + wf(D_NSW_GWT) + wf(D_NSW_SLOPE) + wf(D_NSW_RO) + wf(D_NSW_WS) + 3 * wf(D_NSW_NLV))] + dt[, D_RISK_NSW := (wf(D_NSW_SCR,penalty) * D_NSW_SCR + + wf(D_NSW_GWT,penalty) * D_NSW_GWT + + wf(D_NSW_SLOPE,penalty) * D_NSW_SLOPE + + wf(D_NSW_RO,penalty) * D_NSW_RO + + wf(D_NSW_WS,penalty) * D_NSW_WS + + 3 * wf(D_NSW_NLV,penalty) * D_NSW_NLV ) / + (wf(D_NSW_SCR,penalty) + wf(D_NSW_GWT,penalty) + wf(D_NSW_SLOPE,penalty) + wf(D_NSW_RO,penalty) + wf(D_NSW_WS,penalty) + 3 * wf(D_NSW_NLV,penalty))] # integrate all relative field risk indicators into one for indictor for P loss to surface water - dt[, D_RISK_PSW := (2 * wf(D_PSW_SCR) * D_PSW_SCR + - wf(D_PSW_GWT) * D_PSW_GWT + - 2 * wf(D_PSW_RO) * D_PSW_RO + + dt[, D_RISK_PSW := (2 * wf(D_PSW_SCR,penalty) * D_PSW_SCR + + wf(D_PSW_GWT,penalty) * D_PSW_GWT + + 2 * wf(D_PSW_RO,penalty) * D_PSW_RO + wf(D_PSW_SLOPE) * D_PSW_SLOPE + - 2 * wf(D_PSW_WS) * D_PSW_WS + - wf(D_PSW_PCC) * D_PSW_PCC + - wf(D_PSW_PSG) * D_PSW_PSG + - wf(D_PSW_PRET) * D_PSW_PRET) / - (2 * wf(D_PSW_SCR) + wf(D_PSW_GWT) + 2 * wf(D_PSW_RO) + wf(D_PSW_SLOPE) + 2 * wf(D_PSW_WS) + wf(D_PSW_PCC) + wf(D_PSW_PSG) + wf(D_PSW_PRET))] + 2 * wf(D_PSW_WS,penalty) * D_PSW_WS + + wf(D_PSW_PCC,penalty) * D_PSW_PCC + + wf(D_PSW_PSG,penalty) * D_PSW_PSG + + wf(D_PSW_PRET,penalty) * D_PSW_PRET) / + (2 * wf(D_PSW_SCR,penalty) + wf(D_PSW_GWT,penalty) + 2 * wf(D_PSW_RO,penalty) + wf(D_PSW_SLOPE,penalty) + + 2 * wf(D_PSW_WS,penalty) + wf(D_PSW_PCC,penalty) + wf(D_PSW_PSG,penalty) + wf(D_PSW_PRET,penalty))] # minimize risks when there are no ditches around (wet surrounding fraction < 0.2) dt[D_NSW_WS <= 0.2 & D_PSW_SLOPE < 1,D_RISK_PSW := 0.1] @@ -125,11 +127,16 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, dt[D_NSW_WS <= 0.1 & D_PSW_SLOPE < 1,D_RISK_NSW := 0.01] # integrate all relative field risk indicators into one for indictor for N and P efficiency of inputs - dt[, D_RISK_NUE := (wf(D_NUE_WRI) * D_NUE_WRI + 2 * wf(D_NUE_PBI) * D_NUE_PBI + wf(D_NUE_NLV) * D_NUE_NLV + wf(D_NUE_WDRI) * D_NUE_WDRI) / - (wf(D_NUE_WRI) + 2 * wf(D_NUE_PBI) + wf(D_NUE_NLV) + wf(D_NUE_WDRI))] + dt[, D_RISK_NUE := (wf(D_NUE_WRI,penalty) * D_NUE_WRI + + 2 * wf(D_NUE_PBI,penalty) * D_NUE_PBI + + wf(D_NUE_NLV,penalty) * D_NUE_NLV + + wf(D_NUE_WDRI,penalty) * D_NUE_WDRI) / + (wf(D_NUE_WRI,penalty) + 2 * wf(D_NUE_PBI,penalty) + wf(D_NUE_NLV,penalty) + wf(D_NUE_WDRI,penalty))] # integrate all relative field risk indicators into one for indictor for water retention and efficiency - dt[, D_RISK_WB := (wf(D_WUE_WWRI) * D_WUE_WWRI + wf(D_WUE_WDRI) * D_WUE_WDRI + 2 * wf(D_WUE_WHC) * D_WUE_WHC) / (wf(D_WUE_WWRI) + wf(D_WUE_WDRI) + 2 * wf(D_WUE_WHC))] + dt[, D_RISK_WB := (wf(D_WUE_WWRI,penalty) * D_WUE_WWRI + + wf(D_WUE_WDRI,penalty) * D_WUE_WDRI + + 2 * wf(D_WUE_WHC,penalty) * D_WUE_WHC) / (wf(D_WUE_WWRI,penalty) + wf(D_WUE_WDRI,penalty) + 2 * wf(D_WUE_WHC,penalty))] # normalise these indicators ??? From 1d51a5419e2a9b1e11ede0b0f9ceb5ac61e964f3 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 16:58:42 +0100 Subject: [PATCH 04/10] add penalty argument to field_scores --- R/bbwp_field_scores.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/bbwp_field_scores.R b/R/bbwp_field_scores.R index d3c682e..86f6fb8 100644 --- a/R/bbwp_field_scores.R +++ b/R/bbwp_field_scores.R @@ -23,7 +23,7 @@ #' @param B_CT_NSW_MAX (numeric) the max critical target for N reduction loss (kg N / ha) #' @param measures (data.table) the measures planned / done per fields #' @param sector (string) a vector with the farm type given the agricultural sector (options: 'dairy', 'arable', 'tree_nursery', 'bulbs') -#' +#' @param penalty (boolean) the option to apply a penalty for high risk BBWP field indicators #' #' @import data.table #' @@ -32,7 +32,7 @@ bbwp_field_scores <- function(B_SOILTYPE_AGR, B_GWL_CLASS, A_P_SG, B_SLOPE_DEGREE, B_LU_BBWP,B_AER_CBS, M_DRAIN, D_SA_W, D_RISK_NGW, D_RISK_NSW, D_RISK_PSW, D_RISK_NUE, D_RISK_WB, B_GWP, B_AREA_DROUGHT, B_CT_PSW, B_CT_NSW, - B_CT_PSW_MAX = 0.5, B_CT_NSW_MAX = 5.0, measures, sector){ + B_CT_PSW_MAX = 0.5, B_CT_NSW_MAX = 5.0, measures, sector,penalty = TRUE){ # add visual bindings cfngw = cfwb = cfnsw = cfpsw = cfnue = NULL @@ -182,13 +182,13 @@ bbwp_field_scores <- function(B_SOILTYPE_AGR, B_GWL_CLASS, A_P_SG, B_SLOPE_DEGRE dt[,S_BBWP_NUE := 100 * D_OPI_NUE] dt[,S_BBWP_WB := 100 * D_OPI_WB] - dt[,S_BBWP_TOT := (S_BBWP_NGW * wf(S_BBWP_NGW, type="score") + - S_BBWP_NSW * wf(S_BBWP_NSW, type="score") + - S_BBWP_PSW * wf(S_BBWP_PSW, type="score") + - S_BBWP_NUE * wf(S_BBWP_NUE, type="score") + - S_BBWP_WB * wf(S_BBWP_WB, type="score")) / - (wf(S_BBWP_NGW, type="score") + wf(S_BBWP_NSW, type="score") + wf(S_BBWP_PSW, type="score") + - wf(S_BBWP_NUE, type="score") + wf(S_BBWP_WB, type="score"))] + dt[,S_BBWP_TOT := (S_BBWP_NGW * wf(S_BBWP_NGW, type="score",penalty) + + S_BBWP_NSW * wf(S_BBWP_NSW, type="score",penalty) + + S_BBWP_PSW * wf(S_BBWP_PSW, type="score",penalty) + + S_BBWP_NUE * wf(S_BBWP_NUE, type="score",penalty) + + S_BBWP_WB * wf(S_BBWP_WB, type="score",penalty)) / + (wf(S_BBWP_NGW, type="score",penalty) + wf(S_BBWP_NSW, type="score",penalty) + wf(S_BBWP_PSW, type="score",penalty) + + wf(S_BBWP_NUE, type="score",penalty) + wf(S_BBWP_WB, type="score",penalty))] # order the fields setorder(dt, id) From 6b8447f85b74cf65324d7d0d1354a8663b1fde6c Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 16:59:12 +0100 Subject: [PATCH 05/10] add penalty argument to main --- R/bbwp_main.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/bbwp_main.R b/R/bbwp_main.R index 906e80c..eab14a0 100644 --- a/R/bbwp_main.R +++ b/R/bbwp_main.R @@ -37,7 +37,8 @@ #' @param measures (data.table) the measures planned / done per fields #' @param sector (string) a vector with the farm type given the agricultural sector (options: options: 'dairy', 'arable', 'tree_nursery', 'bulbs') #' @param output (string) a vector specifying the output type of the function. Options: scores, measures -#' +#' @param penalty (boolean) the option to apply a penalty for high risk BBWP field indicators +#' #' @details #' B_SLOPE_DEGREE should be used, for backwards compatibility B_SLOPE can still be used. At least one of the must be used, when both are supplied, B_SLOPE is ignored. #' LSW is by default a data.table with LSW properties, being calculated from bbwp_lsw_properties. Note that all B_LSW_IDs should be preset in the LSW data.table. @@ -52,7 +53,7 @@ bbwp <- function(B_SOILTYPE_AGR, B_LU_BBWP,B_GWL_CLASS, B_SC_WENR, B_HELP_WENR,B B_GWP, B_AREA_DROUGHT, B_CT_PSW, B_CT_NSW,B_CT_PSW_MAX = 0.5, B_CT_NSW_MAX = 5.0, D_SA_W, D_RO_R, B_AREA, M_DRAIN, B_LSW_ID, LSW = NULL, - measures, sector,output = 'scores'){ + measures, sector,output = 'scores',penalty=TRUE){ # add visual binding field_id = code = value_min = value_max = NULL @@ -158,7 +159,8 @@ bbwp <- function(B_SOILTYPE_AGR, B_LU_BBWP,B_GWL_CLASS, B_SC_WENR, B_HELP_WENR,B D_NUE_NLV = dt$npe_nlv, D_WUE_WWRI = dt$wue_wwri, D_WUE_WDRI = dt$wue_wdri, - D_WUE_WHC = dt$wue_whc + D_WUE_WHC = dt$wue_whc, + penalty = penalty ) # Calculate BBWP field scores @@ -187,7 +189,8 @@ bbwp <- function(B_SOILTYPE_AGR, B_LU_BBWP,B_GWL_CLASS, B_SC_WENR, B_HELP_WENR,B B_CT_PSW_MAX = B_CT_PSW_MAX, B_CT_NSW_MAX = B_CT_NSW_MAX, measures = measures, - sector = sector + sector = sector, + penalty = penalty ) # Calculate the BBWP farm score From 20e8ea4134f112148fcff437dde03511e4d96dac Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 16:59:19 +0100 Subject: [PATCH 06/10] update news --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index a69af59..f2b0987 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# BBWPC v2.2.1 2023-12-28 +## Added +* possibility to falisfy the weighing fraction for evaluation of risks in `wf` function, default set to TRUE, #BBWP-67 +* argument `penalty` added to the functions `bbwp_field_indicators`, `bbwp_field_scores` and `bbwp_main` + # BBWPC v2.1.1 2023-12-27 ## Added * function `bbwp_format_sc_wenr` to ensure that B_SC_WENR is an integer conform format Van den Akker (2006), #BBWP-66 From 1ff6f3ce2ce4c81e66650a3423ae2c93e44ae284 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 17:08:33 +0100 Subject: [PATCH 07/10] fix errors after check and update documentation --- NEWS.md | 2 +- R/bbwp_field_indicators.R | 59 ++++++++++++++++++------------------ R/bbwp_field_scores.R | 12 ++++---- man/bbwp.Rd | 5 ++- man/bbwp_field_indicators.Rd | 5 ++- man/bbwp_field_scores.Rd | 5 ++- man/wf.Rd | 4 ++- 7 files changed, 52 insertions(+), 40 deletions(-) diff --git a/NEWS.md b/NEWS.md index f2b0987..11bcfd7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # BBWPC v2.2.1 2023-12-28 ## Added * possibility to falisfy the weighing fraction for evaluation of risks in `wf` function, default set to TRUE, #BBWP-67 -* argument `penalty` added to the functions `bbwp_field_indicators`, `bbwp_field_scores` and `bbwp_main` +* argument `penalty` added to the functions `bbwp_field_indicators`, `bbwp_field_scores` and `bbwp_main`, #BBWP-67 # BBWPC v2.1.1 2023-12-27 ## Added diff --git a/R/bbwp_field_indicators.R b/R/bbwp_field_indicators.R index 2d7a64f..401dc3b 100644 --- a/R/bbwp_field_indicators.R +++ b/R/bbwp_field_indicators.R @@ -94,31 +94,32 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, # integrate all relative field risk indicators into one for indictor for N loss to groundwater - dt[, D_RISK_NGW := (wf(D_NGW_SCR,penalty) * D_NGW_SCR + - 3 * wf(D_NGW_LEA,penalty) * D_NGW_LEA + - 2 * wf(D_NGW_NLV,penalty) * D_NGW_NLV) / - (wf(D_NGW_SCR,penalty) + 3 * wf(D_NGW_LEA,penalty) + 2 * wf(D_NGW_NLV,penalty))] + dt[, D_RISK_NGW := (wf(D_NGW_SCR,penalty = penalty) * D_NGW_SCR + + 3 * wf(D_NGW_LEA,penalty = penalty) * D_NGW_LEA + + 2 * wf(D_NGW_NLV,penalty = penalty) * D_NGW_NLV) / + (wf(D_NGW_SCR,penalty = penalty) + 3 * wf(D_NGW_LEA,penalty = penalty) + 2 * wf(D_NGW_NLV,penalty = penalty))] # integrate all relative field risk indicators into one for indictor for N loss to surface water - dt[, D_RISK_NSW := (wf(D_NSW_SCR,penalty) * D_NSW_SCR + - wf(D_NSW_GWT,penalty) * D_NSW_GWT + - wf(D_NSW_SLOPE,penalty) * D_NSW_SLOPE + - wf(D_NSW_RO,penalty) * D_NSW_RO + - wf(D_NSW_WS,penalty) * D_NSW_WS + - 3 * wf(D_NSW_NLV,penalty) * D_NSW_NLV ) / - (wf(D_NSW_SCR,penalty) + wf(D_NSW_GWT,penalty) + wf(D_NSW_SLOPE,penalty) + wf(D_NSW_RO,penalty) + wf(D_NSW_WS,penalty) + 3 * wf(D_NSW_NLV,penalty))] + dt[, D_RISK_NSW := (wf(D_NSW_SCR,penalty = penalty) * D_NSW_SCR + + wf(D_NSW_GWT,penalty = penalty) * D_NSW_GWT + + wf(D_NSW_SLOPE,penalty = penalty) * D_NSW_SLOPE + + wf(D_NSW_RO,penalty = penalty) * D_NSW_RO + + wf(D_NSW_WS,penalty = penalty) * D_NSW_WS + + 3 * wf(D_NSW_NLV,penalty = penalty) * D_NSW_NLV ) / + (wf(D_NSW_SCR,penalty = penalty) + wf(D_NSW_GWT,penalty = penalty) + wf(D_NSW_SLOPE,penalty = penalty) + + wf(D_NSW_RO,penalty = penalty) + wf(D_NSW_WS,penalty = penalty) + 3 * wf(D_NSW_NLV,penalty = penalty))] # integrate all relative field risk indicators into one for indictor for P loss to surface water - dt[, D_RISK_PSW := (2 * wf(D_PSW_SCR,penalty) * D_PSW_SCR + - wf(D_PSW_GWT,penalty) * D_PSW_GWT + - 2 * wf(D_PSW_RO,penalty) * D_PSW_RO + - wf(D_PSW_SLOPE) * D_PSW_SLOPE + - 2 * wf(D_PSW_WS,penalty) * D_PSW_WS + - wf(D_PSW_PCC,penalty) * D_PSW_PCC + - wf(D_PSW_PSG,penalty) * D_PSW_PSG + - wf(D_PSW_PRET,penalty) * D_PSW_PRET) / - (2 * wf(D_PSW_SCR,penalty) + wf(D_PSW_GWT,penalty) + 2 * wf(D_PSW_RO,penalty) + wf(D_PSW_SLOPE,penalty) + - 2 * wf(D_PSW_WS,penalty) + wf(D_PSW_PCC,penalty) + wf(D_PSW_PSG,penalty) + wf(D_PSW_PRET,penalty))] + dt[, D_RISK_PSW := (2 * wf(D_PSW_SCR,penalty = penalty) * D_PSW_SCR + + wf(D_PSW_GWT,penalty = penalty) * D_PSW_GWT + + 2 * wf(D_PSW_RO,penalty = penalty) * D_PSW_RO + + wf(D_PSW_SLOPE, penalty = penalty) * D_PSW_SLOPE + + 2 * wf(D_PSW_WS,penalty = penalty) * D_PSW_WS + + wf(D_PSW_PCC,penalty = penalty) * D_PSW_PCC + + wf(D_PSW_PSG,penalty = penalty) * D_PSW_PSG + + wf(D_PSW_PRET,penalty = penalty) * D_PSW_PRET) / + (2 * wf(D_PSW_SCR,penalty = penalty) + wf(D_PSW_GWT,penalty = penalty) + 2 * wf(D_PSW_RO,penalty = penalty) + wf(D_PSW_SLOPE,penalty = penalty) + + 2 * wf(D_PSW_WS,penalty = penalty) + wf(D_PSW_PCC,penalty = penalty) + wf(D_PSW_PSG,penalty = penalty) + wf(D_PSW_PRET,penalty = penalty))] # minimize risks when there are no ditches around (wet surrounding fraction < 0.2) dt[D_NSW_WS <= 0.2 & D_PSW_SLOPE < 1,D_RISK_PSW := 0.1] @@ -127,16 +128,16 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, dt[D_NSW_WS <= 0.1 & D_PSW_SLOPE < 1,D_RISK_NSW := 0.01] # integrate all relative field risk indicators into one for indictor for N and P efficiency of inputs - dt[, D_RISK_NUE := (wf(D_NUE_WRI,penalty) * D_NUE_WRI + - 2 * wf(D_NUE_PBI,penalty) * D_NUE_PBI + - wf(D_NUE_NLV,penalty) * D_NUE_NLV + - wf(D_NUE_WDRI,penalty) * D_NUE_WDRI) / - (wf(D_NUE_WRI,penalty) + 2 * wf(D_NUE_PBI,penalty) + wf(D_NUE_NLV,penalty) + wf(D_NUE_WDRI,penalty))] + dt[, D_RISK_NUE := (wf(D_NUE_WRI,penalty = penalty) * D_NUE_WRI + + 2 * wf(D_NUE_PBI,penalty = penalty) * D_NUE_PBI + + wf(D_NUE_NLV,penalty = penalty) * D_NUE_NLV + + wf(D_NUE_WDRI,penalty = penalty) * D_NUE_WDRI) / + (wf(D_NUE_WRI,penalty = penalty) + 2 * wf(D_NUE_PBI,penalty = penalty) + wf(D_NUE_NLV,penalty = penalty) + wf(D_NUE_WDRI,penalty = penalty))] # integrate all relative field risk indicators into one for indictor for water retention and efficiency - dt[, D_RISK_WB := (wf(D_WUE_WWRI,penalty) * D_WUE_WWRI + - wf(D_WUE_WDRI,penalty) * D_WUE_WDRI + - 2 * wf(D_WUE_WHC,penalty) * D_WUE_WHC) / (wf(D_WUE_WWRI,penalty) + wf(D_WUE_WDRI,penalty) + 2 * wf(D_WUE_WHC,penalty))] + dt[, D_RISK_WB := (wf(D_WUE_WWRI,penalty = penalty) * D_WUE_WWRI + + wf(D_WUE_WDRI,penalty = penalty) * D_WUE_WDRI + + 2 * wf(D_WUE_WHC,penalty = penalty) * D_WUE_WHC) / (wf(D_WUE_WWRI,penalty = penalty) + wf(D_WUE_WDRI,penalty = penalty) + 2 * wf(D_WUE_WHC,penalty = penalty))] # normalise these indicators ??? diff --git a/R/bbwp_field_scores.R b/R/bbwp_field_scores.R index 86f6fb8..2844141 100644 --- a/R/bbwp_field_scores.R +++ b/R/bbwp_field_scores.R @@ -182,13 +182,13 @@ bbwp_field_scores <- function(B_SOILTYPE_AGR, B_GWL_CLASS, A_P_SG, B_SLOPE_DEGRE dt[,S_BBWP_NUE := 100 * D_OPI_NUE] dt[,S_BBWP_WB := 100 * D_OPI_WB] - dt[,S_BBWP_TOT := (S_BBWP_NGW * wf(S_BBWP_NGW, type="score",penalty) + - S_BBWP_NSW * wf(S_BBWP_NSW, type="score",penalty) + - S_BBWP_PSW * wf(S_BBWP_PSW, type="score",penalty) + - S_BBWP_NUE * wf(S_BBWP_NUE, type="score",penalty) + + dt[,S_BBWP_TOT := (S_BBWP_NGW * wf(S_BBWP_NGW, type="score",penalty = penalty) + + S_BBWP_NSW * wf(S_BBWP_NSW, type="score",penalty = penalty) + + S_BBWP_PSW * wf(S_BBWP_PSW, type="score",penalty = penalty) + + S_BBWP_NUE * wf(S_BBWP_NUE, type="score",penalty = penalty) + S_BBWP_WB * wf(S_BBWP_WB, type="score",penalty)) / - (wf(S_BBWP_NGW, type="score",penalty) + wf(S_BBWP_NSW, type="score",penalty) + wf(S_BBWP_PSW, type="score",penalty) + - wf(S_BBWP_NUE, type="score",penalty) + wf(S_BBWP_WB, type="score",penalty))] + (wf(S_BBWP_NGW, type="score",penalty = penalty) + wf(S_BBWP_NSW, type="score",penalty = penalty) + wf(S_BBWP_PSW, type="score",penalty = penalty) + + wf(S_BBWP_NUE, type="score",penalty = penalty) + wf(S_BBWP_WB, type="score",penalty = penalty))] # order the fields setorder(dt, id) diff --git a/man/bbwp.Rd b/man/bbwp.Rd index eb8964a..d56723e 100644 --- a/man/bbwp.Rd +++ b/man/bbwp.Rd @@ -38,7 +38,8 @@ bbwp( LSW = NULL, measures, sector, - output = "scores" + output = "scores", + penalty = TRUE ) } \arguments{ @@ -109,6 +110,8 @@ bbwp( \item{sector}{(string) a vector with the farm type given the agricultural sector (options: options: 'dairy', 'arable', 'tree_nursery', 'bulbs')} \item{output}{(string) a vector specifying the output type of the function. Options: scores, measures} + +\item{penalty}{(boolean) the option to apply a penalty for high risk BBWP field indicators} } \description{ Estimate the potential to contribute to agronomic and environmental challenges in a region for a farm and assess the impact of farm measures taken. diff --git a/man/bbwp_field_indicators.Rd b/man/bbwp_field_indicators.Rd index 8167bd9..fbc04c2 100644 --- a/man/bbwp_field_indicators.Rd +++ b/man/bbwp_field_indicators.Rd @@ -28,7 +28,8 @@ bbwp_field_indicators( D_NUE_NLV, D_WUE_WWRI, D_WUE_WDRI, - D_WUE_WHC + D_WUE_WHC, + penalty = TRUE ) } \arguments{ @@ -79,6 +80,8 @@ bbwp_field_indicators( \item{D_WUE_WDRI}{(numeric) The relative score of drought stress for improved efficiency of water} \item{D_WUE_WHC}{(numeric) The relative score of drought stress for improved efficiency of water} + +\item{penalty}{(boolean) the option to apply a penalty for high risk BBWP field indicators} } \description{ These include indicators: diff --git a/man/bbwp_field_scores.Rd b/man/bbwp_field_scores.Rd index 1bbc227..04afdcb 100644 --- a/man/bbwp_field_scores.Rd +++ b/man/bbwp_field_scores.Rd @@ -25,7 +25,8 @@ bbwp_field_scores( B_CT_PSW_MAX = 0.5, B_CT_NSW_MAX = 5, measures, - sector + sector, + penalty = TRUE ) } \arguments{ @@ -70,6 +71,8 @@ bbwp_field_scores( \item{measures}{(data.table) the measures planned / done per fields} \item{sector}{(string) a vector with the farm type given the agricultural sector (options: 'dairy', 'arable', 'tree_nursery', 'bulbs')} + +\item{penalty}{(boolean) the option to apply a penalty for high risk BBWP field indicators} } \description{ Estimate the potential to contribute to agronomic and environmental challenges in a region diff --git a/man/wf.Rd b/man/wf.Rd index d9be6ea..2292052 100644 --- a/man/wf.Rd +++ b/man/wf.Rd @@ -4,12 +4,14 @@ \alias{wf} \title{Helper function to weight and correct the risk and scores} \usage{ -wf(x, type = "indicators") +wf(x, type = "indicators", penalty = TRUE) } \arguments{ \item{x}{The risk or score value to be weighted} \item{type}{Use the weighing function for indicators or score} + +\item{penalty}{(boolean) the option to apply a penalty for high risk BBWP field indicators} } \description{ Helper function to weight and correct the risk and scores From 9348a724d474d5fd807ceae4e0967bf1ed7f4446 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 17:55:36 +0100 Subject: [PATCH 08/10] simplify code field_indicators, and update test-bbwp due to small changes --- R/bbwp_field_indicators.R | 153 ++++++++++++++++--------------------- tests/testthat/test-bbwp.R | 16 ++-- 2 files changed, 75 insertions(+), 94 deletions(-) diff --git a/R/bbwp_field_indicators.R b/R/bbwp_field_indicators.R index 401dc3b..e43acba 100644 --- a/R/bbwp_field_indicators.R +++ b/R/bbwp_field_indicators.R @@ -45,6 +45,7 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, # add visual bindings D_RISK_NGW = D_RISK_NSW = D_RISK_PSW = D_RISK_NUE = D_RISK_WB = id = NULL + risk_cor = value = group = risk = mcf = WS = SLOPE = NULL # check length inputs arg.length <- max( @@ -55,93 +56,73 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, length(D_WUE_WWRI),length(D_WUE_WDRI),length(D_WUE_WHC) ) - # add checks on input - - # copy input in one data.table - dt <- data.table( - id = 1:arg.length, - D_NGW_SCR = D_NGW_SCR, - D_NGW_LEA = D_NGW_LEA, - D_NGW_NLV = D_NGW_NLV, - D_NSW_SCR = D_NSW_SCR, - D_NSW_GWT = D_NSW_GWT, - D_NSW_RO = D_NSW_RO, - D_NSW_SLOPE = D_NSW_SLOPE, - D_NSW_WS = D_NSW_WS, - D_NSW_NLV = D_NSW_NLV, - D_PSW_SCR = D_PSW_SCR, - D_PSW_GWT = D_PSW_GWT, - D_PSW_RO = D_PSW_RO, - D_PSW_SLOPE = D_PSW_SLOPE, - D_PSW_WS = D_PSW_WS, - D_PSW_PCC = D_PSW_PCC, - D_PSW_PSG = D_PSW_PSG, - D_PSW_PRET = D_PSW_PRET, - D_NUE_WRI = D_NUE_WRI, - D_NUE_PBI = D_NUE_PBI, - D_NUE_WDRI = D_NUE_WDRI, - D_NUE_NLV = D_NUE_NLV, - D_WUE_WWRI = D_WUE_WWRI, - D_WUE_WDRI = D_WUE_WDRI, - D_WUE_WHC = D_WUE_WHC, - D_RISK_NGW = NA_real_, - D_RISK_NSW = NA_real_, - D_RISK_PSW = NA_real_, - D_RISK_NUE = NA_real_, - D_RISK_WB = NA_real_ - ) - - - # integrate all relative field risk indicators into one for indictor for N loss to groundwater - dt[, D_RISK_NGW := (wf(D_NGW_SCR,penalty = penalty) * D_NGW_SCR + - 3 * wf(D_NGW_LEA,penalty = penalty) * D_NGW_LEA + - 2 * wf(D_NGW_NLV,penalty = penalty) * D_NGW_NLV) / - (wf(D_NGW_SCR,penalty = penalty) + 3 * wf(D_NGW_LEA,penalty = penalty) + 2 * wf(D_NGW_NLV,penalty = penalty))] - - # integrate all relative field risk indicators into one for indictor for N loss to surface water - dt[, D_RISK_NSW := (wf(D_NSW_SCR,penalty = penalty) * D_NSW_SCR + - wf(D_NSW_GWT,penalty = penalty) * D_NSW_GWT + - wf(D_NSW_SLOPE,penalty = penalty) * D_NSW_SLOPE + - wf(D_NSW_RO,penalty = penalty) * D_NSW_RO + - wf(D_NSW_WS,penalty = penalty) * D_NSW_WS + - 3 * wf(D_NSW_NLV,penalty = penalty) * D_NSW_NLV ) / - (wf(D_NSW_SCR,penalty = penalty) + wf(D_NSW_GWT,penalty = penalty) + wf(D_NSW_SLOPE,penalty = penalty) + - wf(D_NSW_RO,penalty = penalty) + wf(D_NSW_WS,penalty = penalty) + 3 * wf(D_NSW_NLV,penalty = penalty))] - - # integrate all relative field risk indicators into one for indictor for P loss to surface water - dt[, D_RISK_PSW := (2 * wf(D_PSW_SCR,penalty = penalty) * D_PSW_SCR + - wf(D_PSW_GWT,penalty = penalty) * D_PSW_GWT + - 2 * wf(D_PSW_RO,penalty = penalty) * D_PSW_RO + - wf(D_PSW_SLOPE, penalty = penalty) * D_PSW_SLOPE + - 2 * wf(D_PSW_WS,penalty = penalty) * D_PSW_WS + - wf(D_PSW_PCC,penalty = penalty) * D_PSW_PCC + - wf(D_PSW_PSG,penalty = penalty) * D_PSW_PSG + - wf(D_PSW_PRET,penalty = penalty) * D_PSW_PRET) / - (2 * wf(D_PSW_SCR,penalty = penalty) + wf(D_PSW_GWT,penalty = penalty) + 2 * wf(D_PSW_RO,penalty = penalty) + wf(D_PSW_SLOPE,penalty = penalty) + - 2 * wf(D_PSW_WS,penalty = penalty) + wf(D_PSW_PCC,penalty = penalty) + wf(D_PSW_PSG,penalty = penalty) + wf(D_PSW_PRET,penalty = penalty))] - - # minimize risks when there are no ditches around (wet surrounding fraction < 0.2) - dt[D_NSW_WS <= 0.2 & D_PSW_SLOPE < 1,D_RISK_PSW := 0.1] - dt[D_NSW_WS <= 0.2 & D_PSW_SLOPE < 1,D_RISK_NSW := 0.1] - dt[D_NSW_WS <= 0.1 & D_PSW_SLOPE < 1,D_RISK_PSW := 0.01] - dt[D_NSW_WS <= 0.1 & D_PSW_SLOPE < 1,D_RISK_NSW := 0.01] - - # integrate all relative field risk indicators into one for indictor for N and P efficiency of inputs - dt[, D_RISK_NUE := (wf(D_NUE_WRI,penalty = penalty) * D_NUE_WRI + - 2 * wf(D_NUE_PBI,penalty = penalty) * D_NUE_PBI + - wf(D_NUE_NLV,penalty = penalty) * D_NUE_NLV + - wf(D_NUE_WDRI,penalty = penalty) * D_NUE_WDRI) / - (wf(D_NUE_WRI,penalty = penalty) + 2 * wf(D_NUE_PBI,penalty = penalty) + wf(D_NUE_NLV,penalty = penalty) + wf(D_NUE_WDRI,penalty = penalty))] - - # integrate all relative field risk indicators into one for indictor for water retention and efficiency - dt[, D_RISK_WB := (wf(D_WUE_WWRI,penalty = penalty) * D_WUE_WWRI + - wf(D_WUE_WDRI,penalty = penalty) * D_WUE_WDRI + - 2 * wf(D_WUE_WHC,penalty = penalty) * D_WUE_WHC) / (wf(D_WUE_WWRI,penalty = penalty) + wf(D_WUE_WDRI,penalty = penalty) + 2 * wf(D_WUE_WHC,penalty = penalty))] - - # normalise these indicators ??? - - setorder(dt, id) + dt <- data.table(id = 1:arg.length, + D_NGW_SCR = D_NGW_SCR, + D_NGW_LEA = D_NGW_LEA, + D_NGW_NLV = D_NGW_NLV, + D_NSW_SCR = D_NSW_SCR, + D_NSW_GWT = D_NSW_GWT, + D_NSW_RO = D_NSW_RO, + D_NSW_SLOPE = D_NSW_SLOPE, + D_NSW_WS = D_NSW_WS, + D_NSW_NLV = D_NSW_NLV, + D_PSW_SCR = D_PSW_SCR, + D_PSW_GWT = D_PSW_GWT, + D_PSW_RO = D_PSW_RO, + D_PSW_SLOPE = D_PSW_SLOPE, + D_PSW_WS = D_PSW_WS, + D_PSW_PCC = D_PSW_PCC, + D_PSW_PSG = D_PSW_PSG, + D_PSW_PRET = D_PSW_PRET, + D_NUE_WRI = D_NUE_WRI, + D_NUE_PBI = D_NUE_PBI, + D_NUE_WDRI = D_NUE_WDRI, + D_NUE_NLV = D_NUE_NLV, + D_WUE_WWRI = D_WUE_WWRI, + D_WUE_WDRI = D_WUE_WDRI, + D_WUE_WHC = D_WUE_WHC + ) + + # melt the data.table to simplify corrections + dt.melt <- data.table::melt(dt, id.vars = 'id',variable.name = 'risk') + + # add correction factor based on risk itself + dt.melt[,risk_cor := wf(value,type = "indicators",penalty = penalty)] + + # add groups of risk indicators + dt.melt[,group := gsub('_[A-Z]+$','',gsub('D_','',risk))] + + # add manual weighing factor for risks + dt.melt[,mcf := 1] + dt.melt[group=='NGW' & grepl('_LEA$',risk), mcf := 2] + dt.melt[group=='NGW' & grepl('_NLV$',risk), mcf := 3] + dt.melt[group=='NSW' & grepl('_NLV$',risk), mcf := 3] + dt.melt[group=='PSW' & grepl('_SCR$|_RO$|_WS$',risk), mcf := 2] + dt.melt[group=='NUE' & grepl('_PBI$',risk), mcf := 2] + dt.melt[group=='WUE' & grepl('_WHC$',risk), mcf := 2] + + + # minimize risks when there are no ditches around the field (wet surrounding fraction < 0.2) + + # add criteria properties as column (to use as filter) + dt.melt[,WS := value[risk=='D_NSW_WS'],by='id'] + dt.melt[,SLOPE := value[risk=='D_NSW_SLOPE'],by='id'] + + # ensure that the final risk after aggregation gets the value 0.1 or 0.01 + dt.melt[WS <= 0.2 & SLOPE < 1 & group %in% c('NSW','PSW'), c('mcf','risk_cor','value') := list(1,1000,0.1)] + dt.melt[WS <= 0.1 & SLOPE < 1 & group %in% c('NSW','PSW'), c('mcf','risk_cor','value') := list(1,1000,0.01)] + dt.melt[,c('WS','SLOPE') := NULL] + + # calculate the mean aggregated risk indicators + dt <- dt.melt[,list(risk = sum(risk_cor * value * mcf)/sum(risk_cor * mcf)),by=c('id','group')] + dt <- dcast(dt,id~group,value.var='risk') + + # replace output names + setnames(dt,old=c('NGW','NSW','NUE','PSW','WUE'),new = c('D_RISK_NGW','D_RISK_NSW','D_RISK_NUE','D_RISK_PSW','D_RISK_WB')) + + # sort output based on id + setorder(dt,id) # extract output out <- dt[,mget(c('D_RISK_NGW','D_RISK_NSW','D_RISK_PSW','D_RISK_NUE','D_RISK_WB'))] diff --git a/tests/testthat/test-bbwp.R b/tests/testthat/test-bbwp.R index 6120f2b..3c13654 100644 --- a/tests/testthat/test-bbwp.R +++ b/tests/testthat/test-bbwp.R @@ -115,14 +115,14 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = test$fields$s_bbwp_tot, - expected = c(69,45,29), + expected = c(68,45,28), tolerance = 0.01) }) test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(58,77,62,66,46,90), + expected = c(57,72,62,66,46,90), tolerance = 0.01) }) @@ -227,14 +227,14 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = test$fields$s_bbwp_tot, - expected = c(90,45,55), + expected = c(89,45,55), tolerance = 0.01) }) test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(70,85,63,67,72,92), + expected = c(69,82,63,67,72,92), tolerance = 0.01) }) @@ -291,14 +291,14 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = test$fields$s_bbwp_tot, - expected = c(69,45,29), + expected = c(68,45,28), tolerance = 0.01) }) test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(58,77,62,66,46,90), + expected = c(57,72,62,66,46,90), tolerance = 0.01) }) @@ -342,7 +342,7 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(24,86,8,6,32,84), + expected = c(24,81,8,6,32,84), tolerance = 0.01) }) @@ -430,7 +430,7 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(53,86,49,43,32,84), + expected = c(52,81,49,43,32,84), tolerance = 0.01) }) From 005e6babd0117c8cfbc6d38955d2af47469b5a8c Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 18:00:52 +0100 Subject: [PATCH 09/10] update news --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 11bcfd7..8c65d88 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,9 @@ * possibility to falisfy the weighing fraction for evaluation of risks in `wf` function, default set to TRUE, #BBWP-67 * argument `penalty` added to the functions `bbwp_field_indicators`, `bbwp_field_scores` and `bbwp_main`, #BBWP-67 +## Changed +* function `bbwp_field_indicators` is simplified + # BBWPC v2.1.1 2023-12-27 ## Added * function `bbwp_format_sc_wenr` to ensure that B_SC_WENR is an integer conform format Van den Akker (2006), #BBWP-66 From 9a4269efb280a6982a87a14e9171f2fa7061a01a Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Dec 2023 18:05:01 +0100 Subject: [PATCH 10/10] redo changes in test-bbwp due to small error in bbwp_field_indicators. now test remains unchanged --- R/bbwp_field_indicators.R | 4 ++-- tests/testthat/test-bbwp.R | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/R/bbwp_field_indicators.R b/R/bbwp_field_indicators.R index e43acba..202ce59 100644 --- a/R/bbwp_field_indicators.R +++ b/R/bbwp_field_indicators.R @@ -95,8 +95,8 @@ bbwp_field_indicators <- function(D_NGW_SCR,D_NGW_LEA,D_NGW_NLV, # add manual weighing factor for risks dt.melt[,mcf := 1] - dt.melt[group=='NGW' & grepl('_LEA$',risk), mcf := 2] - dt.melt[group=='NGW' & grepl('_NLV$',risk), mcf := 3] + dt.melt[group=='NGW' & grepl('_LEA$',risk), mcf := 3] + dt.melt[group=='NGW' & grepl('_NLV$',risk), mcf := 2] dt.melt[group=='NSW' & grepl('_NLV$',risk), mcf := 3] dt.melt[group=='PSW' & grepl('_SCR$|_RO$|_WS$',risk), mcf := 2] dt.melt[group=='NUE' & grepl('_PBI$',risk), mcf := 2] diff --git a/tests/testthat/test-bbwp.R b/tests/testthat/test-bbwp.R index 3c13654..da02381 100644 --- a/tests/testthat/test-bbwp.R +++ b/tests/testthat/test-bbwp.R @@ -115,14 +115,14 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = test$fields$s_bbwp_tot, - expected = c(68,45,28), + expected = c(69,45,29), tolerance = 0.01) }) test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(57,72,62,66,46,90), + expected = c(58,77,62,66,46,90), tolerance = 0.01) }) @@ -227,14 +227,14 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = test$fields$s_bbwp_tot, - expected = c(89,45,55), + expected = c(90,45,55), tolerance = 0.01) }) test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(69,82,63,67,72,92), + expected = c(70,85,63,67,72,92), tolerance = 0.01) }) @@ -291,14 +291,14 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = test$fields$s_bbwp_tot, - expected = c(68,45,28), + expected = c(69,45,29), tolerance = 0.01) }) test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(57,72,62,66,46,90), + expected = c(58,77,62,66,46,90), tolerance = 0.01) }) @@ -342,7 +342,7 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(24,81,8,6,32,84), + expected = c(24,86,8,6,32,84), tolerance = 0.01) }) @@ -430,7 +430,7 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), test_that("check bbwp", { expect_equal( object = as.numeric(unlist(test$farm)), - expected = c(52,81,49,43,32,84), + expected = c(53,86,49,43,32,84), tolerance = 0.01) }) @@ -509,4 +509,5 @@ test <- bbwp(B_SOILTYPE_AGR = c('dekzand', 'loess', 'rivierklei'), LSW = NULL )) }) + \ No newline at end of file