forked from cropsinsilico/BML-yggdrasil
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiocro_wrapper.R
More file actions
52 lines (46 loc) · 1.28 KB
/
biocro_wrapper.R
File metadata and controls
52 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
library(BioCro)
with_ephoto = (nchar(Sys.getenv("WITH_EPHOTO")) > 0)
if (with_ephoto) {
library(yggdrasilBML)
}
BioCroWrapper <- function(param) {
crop = 'soybean'
year = '2002'
param_names = names(param)
if ("crop" %in% param_names) {
crop = param[['crop']]
}
if ("year" %in% param_names) {
year = param[['year']]
}
enzyme_sf = 1.0
water_stress_approach = 1
if (crop == 'soybean') {
initial_values <- soybean$initial_values
parameters <- soybean$parameters
weather = get(toString(year), soybean_weather)
direct_modules <- soybean$direct_modules
differential_modules <- soybean$differential_modules
ode_solver <- soybean$ode_solver
} else {
stop('Invalid crop name \"' + name + '\"')
}
parameters$enzyme_sf = enzyme_sf
parameters$water_stress_approach = water_stress_approach
if (with_ephoto) {
# Replace BioCro ten layer canopy modules
direct_modules[[10]] = "yggdrasilBML:ten_layer_canopy_properties"
direct_modules[[11]] = "yggdrasilBML:ten_layer_c3_canopy"
direct_modules[[12]] = "yggdrasilBML:ten_layer_canopy_integrator"
}
weather = weather[10,]
result <- run_biocro(
initial_values,
parameters,
weather,
direct_modules,
differential_modules,
ode_solver
)
return(result)
}