From 5f337de25c51e188680930b48758e9293b9063b5 Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 13:56:06 +0100 Subject: [PATCH 1/9] set to 9000 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e19f05d..c0a6492 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BLN Type: Package Title: Calculate the Soil Quality Assessment Score using the Dutch BLN framework -Version: 0.3.0 +Version: 0.3.9000 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 = "aut"), From 4acc9cef914f8208f2ca344e7bbc62d6d911f249 Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 15:29:52 +0100 Subject: [PATCH 2/9] Add helper function --- tests/testthat/test-bln_format_gtclass.R | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/testthat/test-bln_format_gtclass.R diff --git a/tests/testthat/test-bln_format_gtclass.R b/tests/testthat/test-bln_format_gtclass.R new file mode 100644 index 0000000..394aadf --- /dev/null +++ b/tests/testthat/test-bln_format_gtclass.R @@ -0,0 +1,11 @@ +test_that("bln_format_gtclass works", { + + expect_equal( + bln_format_gtclass( + B_GWL_GHG = c(5, 16, 135, 34, 41, 98), + B_GWL_GLG = c(41, 60, 157, 156, 55, 135) + ), + expected = c("I", "II", "VII", "Vb", "-", "VII"), + tolerance = 0 + ) +}) From 4229b324a75b0f669fed9cdfdc1db4ac16d52831 Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 15:30:27 +0100 Subject: [PATCH 3/9] Creation of function 'format groundwater table class' --- man/bln_format_gtclass.Rd | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 man/bln_format_gtclass.Rd diff --git a/man/bln_format_gtclass.Rd b/man/bln_format_gtclass.Rd new file mode 100644 index 0000000..d5a9114 --- /dev/null +++ b/man/bln_format_gtclass.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bln_format_gtclass.R +\name{bln_format_gtclass} +\alias{bln_format_gtclass} +\title{Determine groundwater table class based on highest and lowest mean groundwater levels} +\usage{ +bln_format_gtclass(B_GWL_GHG, B_GWL_GLG) +} +\arguments{ +\item{B_GWL_GHG}{(numeric) The average highest groundwater level in cm below field level (Gemiddeld Hoogste Grondwaterstand)} + +\item{B_GWL_GLG}{(numeric) The average lowest groundwater level in cm below field level (Gemiddeld Laagste Grondwaterstand)} +} +\value{ +A standardized B_GWL_CLASS value as required for BLN functions. A character string. +} +\description{ +Determine groundwater table class based on highest and lowest mean groundwater levels +} +\examples{ +bln_format_gtclass(B_GWL_GHG = 35, B_GWL_GLG = 55) +bln_format_gtclass(B_GWL_GHG = 70, B_GWL_GLG = 155) + +} From bd419056f3a5732bab00ffc3a3b0697f983470eb Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 15:34:03 +0100 Subject: [PATCH 4/9] Description of added function bln_format_gtclass --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index a9d273a..d7904be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# BLN 0.4.0 2024-12-24 + +## Added +* function `bln_format_gtclass` for creating classes of ground water table data, based on GHG and GLG +* test function `test-bln_format_gtclass` of the function described above + # BLN 0.3.0 2024-12-23 ## Added From 3daa2a5a25b1649b339805e28cef410a77e6358a Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 15:35:12 +0100 Subject: [PATCH 5/9] create function to classify ground water data based on GHG and GLG --- R/bln_format_gtclass.R | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 R/bln_format_gtclass.R diff --git a/R/bln_format_gtclass.R b/R/bln_format_gtclass.R new file mode 100644 index 0000000..28df067 --- /dev/null +++ b/R/bln_format_gtclass.R @@ -0,0 +1,62 @@ +#' Determine groundwater table class based on highest and lowest mean groundwater levels +#' +#' @param B_GWL_GHG (numeric) The average highest groundwater level in cm below field level (Gemiddeld Hoogste Grondwaterstand) +#' @param B_GWL_GLG (numeric) The average lowest groundwater level in cm below field level (Gemiddeld Laagste Grondwaterstand) +#' +#' @import data.table +#' +#' @examples +#' bln_format_gtclass(B_GWL_GHG = 35, B_GWL_GLG = 55) +#' bln_format_gtclass(B_GWL_GHG = 70, B_GWL_GLG = 155) +#' +#' @return +#' A standardized B_GWL_CLASS value as required for BLN functions. A character string. +#' +#' @export +bln_format_gtclass <- function(B_GWL_GHG, B_GWL_GLG) { + + # Add visual bindings + B_GWL_CLASS = NULL + + # Check arguments + arg.length <- max(length(B_GWL_GLG), length(B_GWL_GHG)) + checkmate::assert_numeric(B_GWL_GLG, lower = 0, any.missing = FALSE, len = arg.length) + checkmate::assert_numeric(B_GWL_GHG, lower = 0, any.missing = FALSE, len = arg.length) + checkmate::assert_true(all(B_GWL_GHG < B_GWL_GLG)) + + # Make internal table + dt = data.table(B_GWL_GHG = B_GWL_GHG, B_GWL_GLG = B_GWL_GLG) + + # Classification is based on the article: + # Knotters, M., Walvoort., D., Brouwer, .F, Stuyt, L., Okx, J. (2018). Landsdekkende, actuele informatie + # over grondwatertrappen digitaal beschikbaar. KNW, Den Haag. + + # GW classes range from I to VIII, with 'a' and 'b' as a sub categorization. + + dt[, B_GWL_CLASS := '-'] + + dt[B_GWL_GHG < 40 & B_GWL_GLG < 50, B_GWL_CLASS := 'I'] + + dt[B_GWL_GHG < 25 & B_GWL_GLG >= 50 & B_GWL_GLG < 80, B_GWL_CLASS := 'II'] + dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 50 & B_GWL_GLG < 80, B_GWL_CLASS := 'IIb'] + + dt[B_GWL_GHG < 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'III'] + dt[B_GWL_GHG < 25 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IIIa'] + dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IIIb'] + + dt[B_GWL_GHG >= 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IV'] + + dt[B_GWL_GHG < 40 & B_GWL_GLG >= 120, B_GWL_CLASS := 'V'] + dt[B_GWL_GHG < 25 & B_GWL_GLG >= 120, B_GWL_CLASS := 'Va'] + dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 120, B_GWL_CLASS := 'Vb'] + + dt[B_GWL_GHG >= 40 & B_GWL_GHG < 80 & B_GWL_GLG >= 120, B_GWL_CLASS := 'VI'] + + dt[B_GWL_GHG >= 80 & B_GWL_GHG < 140 & B_GWL_GLG >= 120, B_GWL_CLASS := 'VII'] + + dt[B_GWL_GHG >= 140 & B_GWL_GLG >= 120, B_GWL_CLASS := 'VIII'] + + value = dt[, B_GWL_CLASS] + return(value) + +} From 1539055cf3003273913930651f8c1b1284a0641e Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 15:35:51 +0100 Subject: [PATCH 6/9] new export: bln_format_gtclass --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 9a357f2..507f2de 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ export(bln_evaluate_parabolic) export(bln_field) export(bln_field_optimiser) export(bln_format_aer) +export(bln_format_gtclass) export(bln_nut_nitrogen) export(bln_nut_nue) export(bln_nut_phosphorus) From 8f3069cae79103c94fa955c3f330626c1bf42268 Mon Sep 17 00:00:00 2001 From: Noud Date: Tue, 24 Dec 2024 15:47:11 +0100 Subject: [PATCH 7/9] update to version 4.0 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c0a6492..9dbcbd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BLN Type: Package Title: Calculate the Soil Quality Assessment Score using the Dutch BLN framework -Version: 0.3.9000 +Version: 0.4.0 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 = "aut"), From 8957faa794e8b6c6f7bbff20471c7992b099ba7a Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 25 Dec 2024 17:08:04 +0100 Subject: [PATCH 8/9] add some extra rules for options that are not classified plus some comments --- R/bln_format_gtclass.R | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/R/bln_format_gtclass.R b/R/bln_format_gtclass.R index 28df067..e7e4e3b 100644 --- a/R/bln_format_gtclass.R +++ b/R/bln_format_gtclass.R @@ -25,38 +25,44 @@ bln_format_gtclass <- function(B_GWL_GHG, B_GWL_GLG) { checkmate::assert_true(all(B_GWL_GHG < B_GWL_GLG)) # Make internal table - dt = data.table(B_GWL_GHG = B_GWL_GHG, B_GWL_GLG = B_GWL_GLG) + dt <- data.table(B_GWL_GHG = B_GWL_GHG, B_GWL_GLG = B_GWL_GLG) # Classification is based on the article: # Knotters, M., Walvoort., D., Brouwer, .F, Stuyt, L., Okx, J. (2018). Landsdekkende, actuele informatie # over grondwatertrappen digitaal beschikbaar. KNW, Den Haag. # GW classes range from I to VIII, with 'a' and 'b' as a sub categorization. - dt[, B_GWL_CLASS := '-'] + # set Gt class for wet soils (I-II-III) dt[B_GWL_GHG < 40 & B_GWL_GLG < 50, B_GWL_CLASS := 'I'] - dt[B_GWL_GHG < 25 & B_GWL_GLG >= 50 & B_GWL_GLG < 80, B_GWL_CLASS := 'II'] - dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 50 & B_GWL_GLG < 80, B_GWL_CLASS := 'IIb'] - + dt[B_GWL_GHG >= 25 & B_GWL_GHG <= 40 & B_GWL_GLG >= 50 & B_GWL_GLG < 80, B_GWL_CLASS := 'IIb'] + dt[B_GWL_GHG > 40 & B_GWL_GLG >= 50 & B_GWL_GLG < 80, B_GWL_CLASS := 'IIb'] # IIc originally dt[B_GWL_GHG < 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'III'] - dt[B_GWL_GHG < 25 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IIIa'] - dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IIIb'] + dt[B_GWL_GHG < 25 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IIIa'] + dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IIIb'] + # set Gt class for intermediate soils (IV-V-VI) dt[B_GWL_GHG >= 40 & B_GWL_GLG >= 80 & B_GWL_GLG < 120, B_GWL_CLASS := 'IV'] - dt[B_GWL_GHG < 40 & B_GWL_GLG >= 120, B_GWL_CLASS := 'V'] - dt[B_GWL_GHG < 25 & B_GWL_GLG >= 120, B_GWL_CLASS := 'Va'] - dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 120, B_GWL_CLASS := 'Vb'] - + dt[B_GWL_GHG < 25 & B_GWL_GLG >= 120, B_GWL_CLASS := 'Va'] + dt[B_GWL_GHG >= 25 & B_GWL_GHG < 40 & B_GWL_GLG >= 120, B_GWL_CLASS := 'Vb'] dt[B_GWL_GHG >= 40 & B_GWL_GHG < 80 & B_GWL_GLG >= 120, B_GWL_CLASS := 'VI'] + # set Gt class for dry soils (VII-VIII) dt[B_GWL_GHG >= 80 & B_GWL_GHG < 140 & B_GWL_GLG >= 120, B_GWL_CLASS := 'VII'] - dt[B_GWL_GHG >= 140 & B_GWL_GLG >= 120, B_GWL_CLASS := 'VIII'] + # overwrite "-" when its clear dry soils + dt[B_GWL_GHG >= 140 & B_GWL_CLASS == '-', B_GWL_CLASS := 'VIII'] + dt[B_GWL_GHG >= 80 & B_GWL_GHG < 140 & B_GWL_CLASS == '-', B_GWL_CLASS := 'VII'] + dt[B_GWL_GLG <= 50 & B_GWL_CLASS == '-', B_GWL_CLASS := 'I'] + + # select GT class value = dt[, B_GWL_CLASS] + + # return value return(value) } From 13ae354aba4b33b2609b1f7579f6c889bf06916b Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 25 Dec 2024 17:29:16 +0100 Subject: [PATCH 9/9] update check --- tests/testthat/test-bln_format_gtclass.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-bln_format_gtclass.R b/tests/testthat/test-bln_format_gtclass.R index 394aadf..4ac3853 100644 --- a/tests/testthat/test-bln_format_gtclass.R +++ b/tests/testthat/test-bln_format_gtclass.R @@ -5,7 +5,7 @@ test_that("bln_format_gtclass works", { B_GWL_GHG = c(5, 16, 135, 34, 41, 98), B_GWL_GLG = c(41, 60, 157, 156, 55, 135) ), - expected = c("I", "II", "VII", "Vb", "-", "VII"), + expected = c("I", "II", "VII", "Vb", "IIb", "VII"), tolerance = 0 ) })