Skip to content

Commit 6eba51a

Browse files
authored
Merge pull request #1 from KWB-R/dev
Adaptations after comparing Abimo and R-Abimo results
2 parents 3aeb7eb + 24e45b9 commit 6eba51a

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

R/getSoilProperties.R

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ getMeanPotentialCapillaryRiseRate <- function(
112112
]
113113
)
114114

115-
as.integer(estimateDaysOfGrowth(usage, yieldPower) * kr)
115+
days_of_growth <- estimateDaysOfGrowth(usage, yieldPower)
116+
117+
as.integer(round(days_of_growth * kr))
116118
}
117119

118120
# MEAN_POTENTIAL_CAPILLARY_RISE_RATES_SUMMER_MATRIX ----------------------------
@@ -152,24 +154,20 @@ MEAN_POTENTIAL_CAPILLARY_RISE_RATES_SUMMER_MATRIX <- local({
152154
})
153155

154156
# estimateDaysOfGrowth ---------------------------------------------------------
155-
estimateDaysOfGrowth <- function(usage, yield)
157+
estimateDaysOfGrowth <- function(usage, yield, default = 50)
156158
{
159+
# Special case for agricultural use
157160
if (usage == "agricultural_L") {
158161
return(ifelse(yield <= 50, 60, 75))
159162
}
160163

161-
if (usage == "vegetationless_D") {
162-
return(50)
163-
}
164-
165-
if (usage == "horticultural_K") {
166-
return(100)
167-
}
168-
169-
if (usage == "forested_W") {
170-
return(90)
171-
}
164+
# Constant estimates for other uses
165+
days_of_growth <- list(
166+
vegetationless_D = 50,
167+
horticultural_K = 100,
168+
forested_W = 90
169+
)
172170

173-
# default value for any other case
174-
50
171+
# Lookup constant estimate. Return default if use is not in list
172+
kwb.utils::defaultIfNULL(days_of_growth[[usage]], default)
175173
}

R/utils.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ filter_elements <- function(x, pattern)
4747
}
4848

4949
# helpers_index ----------------------------------------------------------------
50-
helpers_index <- function(x, values)
50+
helpers_index <- function(x, values, epsilon = 0.0001)
5151
{
52-
which.min(abs(x - values)) - 1L
52+
indices <- which(x <= values + epsilon)
53+
54+
ifelse(length(indices), min(indices), length(values)) - 1L
5355
}
5456

5557
# index_string_to_integers -----------------------------------------------------

0 commit comments

Comments
 (0)