From c8c6eb4af577deb3dfc9090faae0a61932c13d05 Mon Sep 17 00:00:00 2001 From: yuki-nmi Date: Mon, 30 Sep 2019 14:51:22 +0200 Subject: [PATCH 1/3] adjust lookup table to calculate cor.A_OS_GV --- R/sealing.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/sealing.R b/R/sealing.R index de2dc305..669384f9 100644 --- a/R/sealing.R +++ b/R/sealing.R @@ -37,8 +37,14 @@ calc_sealing_risk <- function(A_CLAY_MI, A_OS_GV) { dt[is.na(value), value.A_CLAY_MI := fun.A_CLAY_MI(A_CLAY_MI)] # Create organic matter correction function and calculate correction for A_OS_GV - fun.cor.A_OS_GV <- approxfun(x = df.lookup$value.A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2) - dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(value.A_CLAY_MI)] + #fun.cor.A_OS_GV <- approxfun(x = df.lookup$value.A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2) + #dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(value.A_CLAY_MI)] + + # Change made by YF: correction factor is now calculated based on A_CLAY_MI (clay content), instead of value.A_CLAY_MI (basic point) + # because otherwise the resulting values of 'verslempingsgevoeligheid' begomes zig-zag. + # see Appendix II of factsheet + fun.cor.A_OS_GV <- approxfun(x = df.lookup$A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2) + dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(A_CLAY_MI)] # Calculate the value dt[is.na(value), value := value.A_CLAY_MI + cor.A_OS_GV * A_OS_GV] From 7f248d757f7e83a1df6e654b8390acb8b92dad12 Mon Sep 17 00:00:00 2001 From: Sven <37927107+SvenVw@users.noreply.github.com> Date: Thu, 10 Oct 2019 13:52:42 +0200 Subject: [PATCH 2/3] Remove comments and fixed test --- R/sealing.R | 6 ------ tests/testthat/test-sealing.R | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/R/sealing.R b/R/sealing.R index 669384f9..71a9a6cc 100644 --- a/R/sealing.R +++ b/R/sealing.R @@ -37,12 +37,6 @@ calc_sealing_risk <- function(A_CLAY_MI, A_OS_GV) { dt[is.na(value), value.A_CLAY_MI := fun.A_CLAY_MI(A_CLAY_MI)] # Create organic matter correction function and calculate correction for A_OS_GV - #fun.cor.A_OS_GV <- approxfun(x = df.lookup$value.A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2) - #dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(value.A_CLAY_MI)] - - # Change made by YF: correction factor is now calculated based on A_CLAY_MI (clay content), instead of value.A_CLAY_MI (basic point) - # because otherwise the resulting values of 'verslempingsgevoeligheid' begomes zig-zag. - # see Appendix II of factsheet fun.cor.A_OS_GV <- approxfun(x = df.lookup$A_CLAY_MI, y = df.lookup$cor.A_OS_GV, rule = 2) dt[is.na(value), cor.A_OS_GV := fun.cor.A_OS_GV(A_CLAY_MI)] diff --git a/tests/testthat/test-sealing.R b/tests/testthat/test-sealing.R index a25ddc16..81efbda2 100644 --- a/tests/testthat/test-sealing.R +++ b/tests/testthat/test-sealing.R @@ -4,7 +4,7 @@ test_that("calc_sealing works", { A_CLAY_MI = 20, A_OS_GV = 5 ), - expected = 8.625, + expected = 8.4375, tolerance = 0.001 ) expect_equal( @@ -12,7 +12,7 @@ test_that("calc_sealing works", { A_CLAY_MI = c(25, 20), A_OS_GV = c(1.5, 8) ), - expected = c(8.6, 10.5), + expected = c(8.6, 10.2), tolerance = 0.001 ) }) From 38a29d66b294f7742c721b44bea73224e064060f Mon Sep 17 00:00:00 2001 From: Sven <37927107+SvenVw@users.noreply.github.com> Date: Thu, 10 Oct 2019 13:56:22 +0200 Subject: [PATCH 3/3] Update changelog --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c3e02e8d..ca98a5a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ ### Fixed * Fixed typo if mais in `ind_managment` * Fixed test for winderodibility +* Use the correct correction factor in `calc_sealing_risk` #19 ## Version 0.8.0 2019-08-02 ### Added