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

Kd waterfuns #159

Merged
merged 109 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
943363a
Merge remote-tracking branch 'origin/development' into gr_waterfuns
KeesDoolNMI Sep 21, 2021
cf6c6b6
Update surpluss calculation and add surface water leaching
KeesDoolNMI Sep 22, 2021
a6b0a7a
Put back water functions to wrapper
KeesDoolNMI Sep 22, 2021
6622760
Update weights.obic
KeesDoolNMI Sep 22, 2021
ea74b4a
Update weights.obic
KeesDoolNMI Oct 5, 2021
ebb8435
Fix error in selection of natural grassland
KeesDoolNMI Oct 5, 2021
d322156
Add separate indicator calculation for N-efficiency
KeesDoolNMI Oct 5, 2021
187b8fe
Fix error for catch crop addition in last year
KeesDoolNMI Oct 5, 2021
f1a7616
Update wrapper function
KeesDoolNMI Oct 5, 2021
7c627f8
Merge remote-tracking branch 'origin/development' into gr_waterfuns
KeesDoolNMI Oct 29, 2021
fc05821
Merge branch 'gr_waterfuns' into kd_waterfuns
KeesDoolNMI Oct 29, 2021
4308878
Remove NLV and depp and update NUE
KeesDoolNMI Nov 11, 2021
4f058ce
Update calculation groundwater recharge
KeesDoolNMI Nov 16, 2021
5f7c778
Add indicator function precipitation surplus
KeesDoolNMI Nov 16, 2021
5da62c1
Add undifined veraibles
KeesDoolNMI Nov 16, 2021
8dd93b1
Update wrapper function
KeesDoolNMI Nov 16, 2021
0982d0e
Update tests
KeesDoolNMI Nov 16, 2021
ac74dad
Add evaluation ind_psp for grassland
KeesDoolNMI Nov 22, 2021
6b7aef3
Remove NLV from function
KeesDoolNMI Nov 22, 2021
7840ebe
Update wrapper
KeesDoolNMI Nov 22, 2021
e6b0dcc
Update tests
KeesDoolNMI Nov 22, 2021
48a2212
Update namespace
KeesDoolNMI Nov 22, 2021
522aa00
Update Description
KeesDoolNMI Nov 22, 2021
bd44475
Add vignette
KeesDoolNMI Nov 24, 2021
101b4e1
Fix error
KeesDoolNMI Jan 19, 2022
58d0fd0
Add switch for seperate evaluation of psp grasland
KeesDoolNMI Jan 19, 2022
ccd9477
Update vignette
KeesDoolNMI Jan 20, 2022
66975ac
Typos
KeesDoolNMI Jan 20, 2022
583ac2a
Update tests
KeesDoolNMI Jan 20, 2022
7d98464
set crop&soil-specific median NLV
yuki-nmi Jan 20, 2022
1fd51f1
set crop&soil-specific median NLV
yuki-nmi Jan 20, 2022
fe196dc
update test function
yuki-nmi Jan 20, 2022
f9d87b4
solve conflict
yuki-nmi Jan 20, 2022
4dd1606
solve conflict2
yuki-nmi Jan 20, 2022
3904af1
add visiual binding for med_nlv
gerardhros Jan 20, 2022
8fc4c51
update news
gerardhros Jan 20, 2022
65dd7c3
set version 2.0.1
gerardhros Jan 20, 2022
056be6f
Update packages.bib
KeesDoolNMI Apr 22, 2022
63751a9
Update description visual bindings
KeesDoolNMI May 13, 2022
fe1b05d
Update id in dt
KeesDoolNMI May 13, 2022
98912f2
Merge branch 'development' into kd_waterfuns
KeesDoolNMI May 13, 2022
54c4b0d
Update examples
KeesDoolNMI May 13, 2022
a7a30a0
Update example for obic_field
KeesDoolNMI May 13, 2022
bc28c9b
Bump version number
KeesDoolNMI May 13, 2022
8d50a6e
Update news
KeesDoolNMI May 13, 2022
780ca50
Fix type in news
KeesDoolNMI May 13, 2022
934b6a3
add makkink for 'natuurlijk grasland'
BrentWHR Oct 25, 2022
4c4e8a1
start better crops.obic making
BrentWHR Oct 25, 2022
dfdcd70
backup legacy crops.obic
BrentWHR Oct 25, 2022
d34b959
add n-norm data
BrentWHR Oct 25, 2022
2499c5c
script to make crops.obic from csv
BrentWHR Oct 26, 2022
f9b48aa
replace crops_obic.RData with crops.obic.rda
BrentWHR Oct 26, 2022
f7e3556
save new crops.obic as csv for tracking
BrentWHR Oct 26, 2022
740f3fe
Update crops.obic documentation
BrentWHR Oct 26, 2022
2bf903e
remove script creating crops.obic
BrentWHR Oct 26, 2022
6f43b01
update NEWS
BrentWHR Oct 26, 2022
7162c9e
make crops.obic alias of crops_obic
BrentWHR Oct 26, 2022
cc03695
replace crops_obic.rda containing crops_obic by crops_obic.RData cont…
BrentWHR Oct 26, 2022
a4cd231
update documentation
BrentWHR Oct 26, 2022
773aad1
fix exports and documentation
BrentWHR Oct 26, 2022
33df0d7
move legacy crops.obic file to data-raw
BrentWHR Oct 26, 2022
808ffdf
add data-raw to Rbuildignore
BrentWHR Oct 26, 2022
5f19b80
update vignette bibliography
BrentWHR Oct 26, 2022
74e0dc4
update NEWS
BrentWHR Oct 26, 2022
3390c65
update d_n_norm data
BrentWHR Oct 31, 2022
ae2eb17
update b_lu_brp data
BrentWHR Oct 31, 2022
101c341
fix typo and uloaded object
BrentWHR Oct 31, 2022
0ea2354
update crops.obic N use norms
BrentWHR Oct 31, 2022
5b64fdc
improve script documentation
BrentWHR Oct 31, 2022
298c3b8
replace "ï" with "i" in crop names
BrentWHR Oct 31, 2022
206fb38
update NEWS
BrentWHR Oct 31, 2022
882b197
Update GitHub Actions
SvenVw Nov 11, 2022
f7a5e54
Merge branch 'development' into update_crops.obic
SvenVw Nov 11, 2022
967da56
restore OBIC package reference
BrentWHR Dec 12, 2022
226dfea
improve changelog regarding changes in N-use norms
BrentWHR Dec 12, 2022
8a989ab
remove crops.obic making from OBIC
BrentWHR Dec 20, 2022
7742882
update crops.obic
BrentWHR Dec 20, 2022
415084d
fix documentation typo
BrentWHR Dec 20, 2022
535d21e
let Roxygen do the format description of tables
BrentWHR Dec 20, 2022
81c4e4a
Merge branch 'master' into development
SvenVw Jan 11, 2023
04a582e
Merge remote-tracking branch 'origin/development' into yf_modify_nret…
SvenVw Jan 11, 2023
ebd8547
Bump dev version and fix version number
SvenVw Jan 11, 2023
4cad51f
Merge branch 'development' into update_crops.obic
SvenVw Jan 11, 2023
94de9c0
Set to dev version
SvenVw Jan 11, 2023
ab7ef66
Merge pull request #160 from AgroCares/yf_modify_nretention
SvenVw Jan 11, 2023
82d6f97
Merge branch 'development' into update_crops.obic
SvenVw Jan 11, 2023
c71ceb9
Fix changelog
SvenVw Jan 11, 2023
a1830b8
Merge pull request #172 from AgroCares/update_crops.obic
SvenVw Jan 11, 2023
a5a9499
Run standard check also for development
SvenVw Jan 11, 2023
436f8a4
Remove full check as it replaced by standard check
SvenVw Jan 11, 2023
c464d18
Merge remote-tracking branch 'origin/development' into kd_waterfuns
SvenVw Jan 11, 2023
e086e3e
Fix changelog
SvenVw Jan 11, 2023
71d8407
merge master into kd_waterfuns
gerardhros Oct 16, 2023
d1d7179
remove old code from ppr_crops_obic
gerardhros Oct 16, 2023
6cf11a8
update weights.obic, column description for water funs, and outcommen…
gerardhros Oct 18, 2023
50b98f3
add check calc_nleach
gerardhros Oct 18, 2023
766a409
mean NLV was added to make nleaching more regionally specific for lan…
gerardhros Oct 18, 2023
36f4ac8
outcomment I_H in test function obic_field_dt
gerardhros Oct 18, 2023
d40c73e
outcomment I_H indicators in obic_field
gerardhros Oct 18, 2023
0742ed7
merge master 2.2.1 into kd_waterfuns
gerardhros Oct 18, 2023
5fb29d6
Fix typo in changelog
SvenVw Oct 18, 2023
a1f94f9
Remove outdated changelog item
SvenVw Oct 18, 2023
8fff483
Fix changelog section headers
SvenVw Oct 18, 2023
6efd450
Update references for waterfunctions
KeesDoolNMI Oct 18, 2023
b0c7e87
Update leaching_to options in calc_n_efficiency and related variables
KeesDoolNMI Oct 18, 2023
3694131
Elaborate changelog and set major verision bump
KeesDoolNMI Oct 18, 2023
95838f4
Make seperate PSP evaluation for grassland standard
KeesDoolNMI Oct 18, 2023
09d1153
Remove unnecessary lines from changelog
KeesDoolNMI Oct 18, 2023
8d8c809
Evaluate PSP in the same way for each land use
KeesDoolNMI Oct 19, 2023
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: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
^Meta$
^dev$
^DEV$
^data-raw$
^\.github$
^codecov\.yml$
^LICENSE
4 changes: 2 additions & 2 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, development]
pull_request:
branches: [main, master]
branches: [main, master, development]

name: R-CMD-check

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: OBIC
Type: Package
Title: Calculate the Open Bodem Index (OBI) Score
Version: 2.2.1
Version: 2.3.0
Authors@R: c(
person(given = "Sven",
family = "Verweij",
Expand Down
8 changes: 6 additions & 2 deletions DEV/data/column_description.csv
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ I_P_CO;indicator;Ondergrondverdichting;Compaction;-;
I_P_WRI;indicator;Plant beschikbaar water;Water retention;-;
I_P_CEC;indicator;Aggregaatstabiliteit;Aggregate stability;-;
I_P_WO;indicator;Bewerkbaarheid;Workability;-;
I_B_DI;indicator;Ziektewerendheid;Disease / pest resistance;;
I_B_SF;indicator;Activiteit bodemleven;Soil life activity;;
I_B_DI;indicator;Ziektewerendheid;Disease / pest resistance;-;
I_B_SF;indicator;Activiteit bodemleven;Soil life activity;-;
I_H_GWR;indicator;Doorlatendheid voor water;Unsaturated permeability;-;
I_H_NGW;indicator;Efficientie van stikstofmeststoffen in relatie tot kwaliteit grondwater;Nitrogen efficiency for ground water;-;
I_H_NOW;indicator;Efficientie van stikstofmeststoffen in relatie tot kwaliteit oppervlaktewater;Nitrogen efficiency for surface water;-;
I_H_PEST;indicator;Uitspoelingsrisico gewasbestrijdingsmiddelen naar grondwater;Leaching risk of pesticides to groundwater;-;
I_B_NEM;indicator;Plant parasitaire nematoden;Plant parasitic nematodes;;
I_E_NGW;indicator;N vasthoudend vermogen voor grondwater;Nitrogen retention for ground water;;
I_E_NSW;indicator;N vasthoudend vermogen voor oppervlaktewater;Nitrogen retention for surface water;;
Expand Down
Binary file modified DEV/data/column_description_obic.rds
Binary file not shown.
16 changes: 16 additions & 0 deletions DEV/data/weight_obic.csv
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ I_M_CLIMATE;indicator;akkerbouw;1;1
I_M_WATERQUALITY;indicator;akkerbouw;1;1
I_M_BIODIVERSITY;indicator;akkerbouw;1;1
I_BCS;indicator;akkerbouw;1;1
I_H_GWR;indicator;akkerbouw;1;1
I_H_NGW;indicator;akkerbouw;1;1
I_H_NOW;indicator;akkerbouw;1;1
I_H_PEST;indicator;akkerbouw;1;1
M_GREEN;measurement;akkerbouw;1;1
M_COMPOST;measurement;akkerbouw;1;1
M_NONBARE;measurement;akkerbouw;1;1
Expand Down Expand Up @@ -74,6 +78,10 @@ I_M_CLIMATE;indicator;mais;1;1
I_M_WATERQUALITY;indicator;mais;1;1
I_M_BIODIVERSITY;indicator;mais;1;1
I_BCS;indicator;mais;1;1
I_H_GWR;indicator;mais;1;1
I_H_NGW;indicator;mais;1;1
I_H_NOW;indicator;mais;1;1
I_H_PEST;indicator;mais;1;1
M_GREEN;measurement;mais;1;1
M_COMPOST;measurement;mais;1;1
M_NONBARE;measurement;mais;1;1
Expand Down Expand Up @@ -119,6 +127,10 @@ I_M_CLIMATE;indicator;grasland;1;1
I_M_WATERQUALITY;indicator;grasland;1;1
I_M_BIODIVERSITY;indicator;grasland;1;1
I_BCS;indicator;grasland;1;1
I_H_GWR;indicator;grasland;1;1
I_H_NGW;indicator;grasland;1;1
I_H_NOW;indicator;grasland;1;1
I_H_PEST;indicator;grasland;-1;-1
M_GREEN;measurement;grasland;-1;-1
M_COMPOST;measurement;grasland;1;1
M_NONBARE;measurement;grasland;-1;-1
Expand Down Expand Up @@ -164,6 +176,10 @@ I_M_CLIMATE;indicator;natuur;1;1
I_M_WATERQUALITY;indicator;natuur;1;1
I_M_BIODIVERSITY;indicator;natuur;1;1
I_BCS;indicator;natuur;1;1
I_H_GWR;indicator;grasland;-1;-1
I_H_NGW;indicator;grasland;-1;-1
I_H_NOW;indicator;grasland;-1;-1
I_H_PEST;indicator;grasland;-1;-1
M_GREEN;measurement;natuur;-1;-1
M_COMPOST;measurement;natuur;1;1
M_NONBARE;measurement;natuur;1;1
Expand Down
6 changes: 3 additions & 3 deletions DEV/scripts/ppr_crops_obic.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# load package
library(data.table)

# Load crops.obic (copied csv from pandex)
cr <- fread('DEV/data/crops_obic.csv')
# update the csv and Rdata file

# update the Rdata file
crops.obic <- copy(cr)
save(crops.obic, file = 'data/crops_obic.RData')

Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(calc_n_efficiency)
export(calc_nleach)
export(calc_nlv)
export(calc_organic_carbon)
export(calc_permeability)
export(calc_pesticide_leaching)
export(calc_ph_delta)
export(calc_phosphate_availability)
Expand Down Expand Up @@ -55,11 +56,13 @@ export(ind_nematodes)
export(ind_nematodes_list)
export(ind_nitrogen)
export(ind_nretention)
export(ind_permeability)
export(ind_pesticide_leaching)
export(ind_ph)
export(ind_phosphate_availability)
export(ind_pmn)
export(ind_potassium)
export(ind_psp)
export(ind_resistance)
export(ind_sealing)
export(ind_sulfur)
Expand Down
33 changes: 33 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# OBIC 2.3.0 2023-10-16

## Added
* To `crops.obic`, crop_codes: 6632 (zoete aardappelen), 6636 (naakte haver), 6660 (uien, gele, zaai), and 6664 (uien, rode, zaai)
* Add `calc_permeability` for calculating top soil permeability
* Add `ind_permeability` for calculatin the index for top soil permeability
* Add vignette `obic_water_functions`, describing the functions that evaluate the effect of soil quality on groundwater quality

## Changed
* Updated N use norms for onions
* Update calc_nleach by soil and land use dependent default n supply, issue #154
* Update calculations in the functions `calc_pesticide_leaching`, `ind_pesticide_leaching`, `calc_psp`, `ind_psp`, `ind_gw_recharge`,`calc_n_efficiency` and `ind_n_efficiency`
* add soil type and land use dependent NLV estimate in calc_nleach

### Fixed
* Fixes plotting of regime curve in workability vignette #149
* Extremely high EOS values for some cultivations fixing #162 & #134
* Updated bibliography of packages in vignettes
* N use norm for 1935 (maiskolfsilage)
* N use norms of 1926 and 1927 (agrarisch natuurmengsel and overige akkerbouwgewassen), increased to match "Akkerbouwgewassen, overig" (RVO, 2022)

### Deprecated
* building and modifying crops.obic from a script in OBIC

# OBIC 2.2.1 2023-10-16
### Added
* CITATION file and additional author data in the package DESCRIPTION
Expand Down Expand Up @@ -43,6 +67,15 @@
* Update the GitHub Actions to the most recent version
* Update `RoxygenNote` to v7.2.3

# OBIC 2.0.2 2022-05-13
### Changed
* Update calculations in the functions `calc_pesticide_leaching`, `ind_pesticide_leaching`, `calc_psp`, `ind_psp`, `ind_gw_recharge`,`calc_n_efficiency` and `ind_n_efficiency`

# Added
* Add `calc_permeability` for calculating top soil permeability
* Add `ind_permeability` for calculatin the index for top soil permeability
* Add vignette `obic_water_functions`, describing the functions that evaluate the effect of soil quality on groundwater quality

# OBIC 2.0.1 2022-03-26
### Changed
* The function `ind_sulpher` is renamed to `ind_sulfur` in documentation
Expand Down
126 changes: 106 additions & 20 deletions R/groundwater_recharge.R
Original file line number Diff line number Diff line change
@@ -1,58 +1,144 @@
#' Calculate groundwater recharge of a soil
#'
#' This function calculates an index score for groundwater storage based on WHC, sealing risk, drainage and subsoil compaction
#' This function calculates an index score for groundwater storage based on precipitation surplus, infiltration at saturation, sealing risk, drainage and subsoil compaction
#'
#'
#' @param D_WRI_WHC (numeric) The value for Water Retention index (WRI) for WHC as calculated by \code{\link{calc_waterretention}}
#' @param B_LU_BRP (numeric) The crop code from the BRP
#' @param D_PSP (numeric) The precipitation surplus per crop calculated by \code{\link{calc_psp}}
#' @param D_WRI_K (numeric) The value for top soil permeability (cm/d) as calculated by \code{\link{calc_permeability}}
#' @param I_P_SE (numeric) The indicator value for soil sealing
#' @param I_P_CO (numeric) The indicator value for occurrence of subsoil compaction
#' @param B_DRAIN (boolean) Are drains installed to drain the field (options: yes or no)
#' @param B_GWL_CLASS (character) The groundwater table class
#'
#' @examples
#' ind_gw_recharge(D_WRI_WHC = 0.6, D_PSP = 200, I_P_SE = 0.6, I_P_CO = 0.9)
#' ind_gw_recharge(D_WRI_WHC = 0.8, D_PSP = 400, I_P_SE = 0.4, I_P_CO = 0.2)
#' ind_gw_recharge(B_LU_BRP = 265,D_PSP = 200, D_WRI_K = 10, I_P_SE = 0.6, I_P_CO = 0.9,
#' B_DRAIN = FALSE, B_GWL_CLASS = 'GtV')
#' ind_gw_recharge(B_LU_BRP = 233, D_PSP = 400, D_WRI_K = 10, I_P_SE = 0.4, I_P_CO = 0.2,
#' B_DRAIN = TRUE, B_GWL_CLASS = 'GtII')
#'
#' @return
#' The evaluated score for the soil function to improve groundwater recharge. A numeric value between 0 and 1.
#'
#' @export
ind_gw_recharge <- function(D_WRI_WHC, D_PSP, I_P_SE, I_P_CO, B_DRAIN = FALSE){
ind_gw_recharge <- function(B_LU_BRP, D_PSP, D_WRI_K, I_P_SE, I_P_CO, B_DRAIN, B_GWL_CLASS){
KeesDoolNMI marked this conversation as resolved.
Show resolved Hide resolved

I_WRI_WHC = I_W_GWS = cf_compaction = cf_drain = D_I_PSP = NULL
I_H_GWR = D_I_WRI_K = cf_compaction = cf_drain = D_I_PSP = NULL

# Check inputs
arg.length <- max(length(I_P_CO),length(B_DRAIN))
checkmate::assert_numeric(D_WRI_WHC, lower = 0, upper = 1000, any.missing = FALSE)
checkmate::assert_numeric(D_PSP, lower = 0, upper = 1000, any.missing = FALSE)
checkmate::assert_numeric(I_P_CO, lower = 0, upper = 1, any.missing = FALSE, len = arg.length)
checkmate::assert_numeric(I_P_SE, lower = 0, upper = 1, any.missing = FALSE, len = arg.length)
arg.length <- max(length(B_LU_BRP),length(D_WRI_K),length(D_PSP),length(I_P_SE),length(I_P_CO),length(B_DRAIN))


checkmate::assert_numeric(B_LU_BRP, any.missing = FALSE, min.len = 1, len = arg.length)
checkmate::assert_subset(B_LU_BRP, choices = unique(OBIC::crops.obic$crop_code), empty.ok = FALSE)
checkmate::assert_numeric(D_WRI_K, any.missing = FALSE, len = arg.length)
checkmate::assert_numeric(D_PSP, any.missing = FALSE, len = arg.length)
checkmate::assert_numeric(I_P_SE, any.missing = FALSE, len = arg.length)
checkmate::assert_numeric(I_P_CO, any.missing = FALSE, len = arg.length)
checkmate::assert_logical(B_DRAIN, any.missing = FALSE, len = arg.length)
checkmate::assert_subset(B_GWL_CLASS, choices = c('GtI','GtII','GtIII','GtIV','GtV','GtVI','GtVII','GtVIII',
'GtIIb','GtIIIb','GtVb'), empty.ok = FALSE)

# import data into table
dt <- data.table(D_WRI_WHC = D_WRI_WHC,
dt <- data.table(B_LU_BRP = B_LU_BRP,
D_PSP = D_PSP,
D_WRI_K = D_WRI_K,
I_P_SE = I_P_SE,
I_P_CO = I_P_CO,
B_DRAIN = B_DRAIN)
B_DRAIN = B_DRAIN,
B_GWL_CLASS = B_GWL_CLASS)

# Calculate the indicator value for water holding capacity
dt[,I_WRI_WHC := ind_waterretention(D_WRI_WHC,type = 'water holding capacity')]
dt[,D_I_WRI_K := ind_permeability(D_WRI_K)]

# Calculate indicator value for precipitation surpluss
dt[,D_I_PSP := evaluate_logistic(D_PSP,0.05,300,2.5)]
# Calculate indicator value for precipitation surplus
dt[,D_I_PSP := ind_psp(D_PSP,B_LU_BRP)]

# Correct for subsoil compaction or drainage
dt[B_DRAIN == TRUE, c('cf_drain','cf_compaction') := list(0.6,1)]
dt[B_DRAIN == FALSE, c('cf_drain','cf_compaction') := list(1,fifelse(I_P_CO < 0.5,0.8,1))]
dt[B_DRAIN == TRUE & B_GWL_CLASS %in% c('GtIIIb','GtIV'), c('cf_drain','cf_compaction') := list(0.6,1)]
dt[B_DRAIN == FALSE | B_GWL_CLASS %in% c('GtI','GtII','GtIII','GtV','GtVI','GtVII','GtVIII','GtIIb','GtVb'),
c('cf_drain','cf_compaction') := list(1,fifelse(I_P_CO < 0.5,0.8,1))]

# Calculate aggregated score
dt[,I_W_GWS := (0.35 * I_WRI_WHC + 0.35 * D_I_PSP + 0.3 * I_P_SE) * cf_compaction * cf_drain]
dt[,I_H_GWR := (0.7 * D_I_PSP + 0.15 * D_I_WRI_K + 0.15 * I_P_SE) * cf_compaction * cf_drain]

# Calculate mean
out <- dt[,I_W_GWS]
out <- dt[,I_H_GWR]

return(out)
}



#' Calculate the permeability of the top soil
#'
#' This function calculates the permeability of the top soil
#'
#'
#' @param A_CLAY_MI (numeric) The clay content of the soil (\%)
#' @param A_SAND_MI (numeric) The sand content of the soil (\%)
#' @param A_SILT_MI (numeric) The silt content of the soil (\%)
#' @param A_SOM_LOI (numeric) The organic matter content of the soil (\%)
#'
#'
#' @export
calc_permeability <- function(A_CLAY_MI,A_SAND_MI,A_SILT_MI,A_SOM_LOI){

id = thetaS = thetaR = alfa = n = ksat = l = Pleem = mineral = D_WRI_K = NULL

# Check inputs
arg.length <- max(length(A_CLAY_MI), length(A_SAND_MI),length(A_SILT_MI), length(A_SOM_LOI))
checkmate::assert_numeric(A_CLAY_MI, lower = 0, upper = 100, any.missing = FALSE)
checkmate::assert_numeric(A_SAND_MI, lower = 0, upper = 100, any.missing = FALSE)
checkmate::assert_numeric(A_SILT_MI, lower = 0, upper = 100, any.missing = FALSE)
checkmate::assert_numeric(A_SOM_LOI, lower = 0, upper = 100, any.missing = FALSE)

# Collect data in a table
dt <- data.table(
id = 1:arg.length,
A_CLAY_MI = A_CLAY_MI,
A_SAND_MI = A_SAND_MI,
A_SILT_MI = A_SILT_MI,
A_SOM_LOI = A_SOM_LOI,
value = NA_real_
)

# Calculate mineral fractions
dt[,mineral := A_CLAY_MI + A_SAND_MI + A_SILT_MI]
dt[,A_CLAY_MI := A_CLAY_MI * 100 / mineral]
dt[,A_SILT_MI := A_SILT_MI * 100 / mineral]
dt[,Pleem := A_CLAY_MI + A_SILT_MI]


# Calculate unsaturated permeability
dt[, c("Dichtheid", "thetaR", "thetaS", "alfa", "n", "ksat", "l") := pFpara_ptf_Wosten2001(A_CLAY_MI, Pleem, A_SOM_LOI, 150, 1)]

# Calculate permeabilty
dt[,D_WRI_K := ksat * (((1 + alfa * thetaR^n)^(1 - 1/n) - alfa * thetaR^(n - 1))^2) / ((1 + alfa * thetaR^n)^((1 - 1/n) * (l + 2)))]
KeesDoolNMI marked this conversation as resolved.
Show resolved Hide resolved

# output
return(dt[,D_WRI_K])

}



#' Calculate the indicator score for the permeability of the top soil
#'
#' This function calculates the indicator score for the permeability of the top soil
#'
#'
#' @param D_WRI_K (numeric) The value for top soil permeability (cm/d) as calculated by \code{\link{calc_permeability}}
#'
#'
#' @export
ind_permeability <- function(D_WRI_K){

# Check inputs
checkmate::assert_numeric(D_WRI_K, lower = 0, any.missing = FALSE)

D_I_WRI_K <- evaluate_logistic(D_WRI_K,0.08,50,0.4)

return(D_I_WRI_K)
}

Loading