Skip to content

Commit 3aeb7eb

Browse files
committed
Keep only improved version
of getPotentialEvaporation()
1 parent 8e7e8f9 commit 3aeb7eb

5 files changed

Lines changed: 50 additions & 148 deletions

File tree

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export(actualEvaporation)
77
export(call_with_data)
88
export(getDefaultConfiguration)
99
export(getPotentialEvaporation)
10-
export(getPotentialEvaporation2)
1110
export(getPrecipitation)
1211
export(getSoilProperties)
1312
export(getUsageTuple)

R/getPotentialEvaporation.R

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,53 @@
1-
# getPotentialEvaporation ------------------------------------------------------
1+
# getPotentialEvaporation -----------------------------------------------------
22

33
#' Provide Data on Potential Evaporation
44
#'
5-
#' @param input data frame with columns \code{usage}, \code{district}
6-
#' @param config list with entry \code{potentialEvaporation}
7-
#' @param default_etp default value for etp
8-
#' @param default_etps default value for etps
9-
#' @param default_etp_waterbody default value for etp for usage = 110
10-
#' (waterbody)
5+
#' @param isWaterbody (vector of) logical indicating whether a block area is
6+
#' of type (from the type/yield/irrigation tuple) "waterbody"
7+
#' @param district (vector of) integer indicating the district number of the
8+
#' plot area (from the original input column "BEZIRK")
9+
#' @param config list structure as returned by
10+
#' \code{\link{abimo_config_to_config}}
1111
#' @export
1212
#' @examples
13-
#' getPotentialEvaporation(data.frame(usage = 10, district = 1), config = list(
14-
#' potentialEvaporation = list(district_1 = list(etp = 100, etps = 200))
15-
#' ))
13+
#' \dontrun{
14+
#' config <- abimo_config_to_config(kwb.abimo:::read_config())
15+
#' getPotentialEvaporation(
16+
#' is_waterbody = TRUE,
17+
#' district = 1,
18+
#' config = config
19+
#' )
20+
#' }
1621
#'
17-
getPotentialEvaporation <- function(
18-
input,
19-
config,
20-
default_etp = 660L,
21-
default_etps = 530L,
22-
default_etp_waterbody = 775L
23-
)
22+
getPotentialEvaporation <- function(isWaterbody, district, config)
2423
{
24+
#`%>%` <- magrittr::`%>%`
2525
#kwb.utils::assignPackageObjects("kwb.rabimo")
26-
#input <- kwb.abimo::abimo_input_2019[1:10, ]
27-
#config <- getDefaultConfiguration(1)
26+
#abimo_config <- kwb.abimo:::read_config()
2827

29-
# If more than one row is given, call this function for each row
30-
if (nrow(input) > 1L) {
28+
#data <- data.frame(isWaterbody = FALSE, district = 10L)
29+
#data <- data.frame(isWaterbody = c(FALSE, TRUE, FALSE), district = 22:24)
3130

32-
results <- lapply(seq_len(nrow(input)), function(i) {
33-
as.data.frame(getPotentialEvaporation(input[i, ], config))
34-
})
35-
36-
return(do.call(rbind, results))
37-
}
31+
# Prepare input data for multi_column_lookup
32+
data <- data.frame(
33+
isWaterbody = isWaterbody,
34+
district = district
35+
)
3836

39-
# waterbody?
40-
result <- if (select_elements(input, "usage") == 110) {
37+
# Create lookup table from abimo configuration object
38+
lookup <- select_elements(config, "potentialEvaporation")
4139

42-
list(
43-
perYearInteger = default_etp_waterbody,
44-
inSummerInteger = -1 # check that
45-
)
40+
result <- c(perYearInteger = "etp", inSummerInteger = "etps") %>%
41+
lapply(function(column) {
42+
multi_column_lookup(data, select_columns(lookup, c(names(data), column)))
43+
})
4644

47-
} else {
45+
result[["perYearFloat"]] <- as.double(result[["perYearInteger"]])
4846

49-
element <- paste0("district_", select_columns(input, "district"))
50-
x <- select_elements(config, "potentialEvaporation")[[element]]
51-
given <- !is.null(x)
5247

53-
list(
54-
perYearInteger = if (given) select_elements(x, "etp") else default_etp,
55-
inSummerInteger = if (given) select_elements(x, "etps") else default_etps
56-
)
48+
if (all(lengths(result) == 1L)) {
49+
return(result)
5750
}
5851

59-
result[["perYearFloat"]] = as.double(result[["perYearInteger"]])
60-
61-
result
52+
as.data.frame(result)
6253
}

R/getPotentialEvaporation2.R

Lines changed: 0 additions & 53 deletions
This file was deleted.

man/getPotentialEvaporation.Rd

Lines changed: 15 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/getPotentialEvaporation2.Rd

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)