apsim_vector: Edit and Run an APSIM Simulation

Description Usage Arguments Details Value Examples

Description

This function will edit then run an APSIM simulation. It can be thought of as a vectorized version of apsim.

Usage

1
2
apsim_vector(X, exe, wd, vars, to.run, to.edit = to.run, overwrite = FALSE,
  g)

Arguments

X

N-by-p matrix of inputs with rows corresponding to runs and columns for variables

exe

where to find the APSIM executable

wd

directory where the .apsim file lives and where the results will be saved

vars

names of the variables, must be of the same length as 'X' has columns

to.run

the .apsim file in wd to run

to.edit

the .apsim file or .xml file to be edited

overwrite

logical; passed to the edit_apsim and edit_sim_file functions

g

a function of the output returned by apsim - must give vector or scalar result

Details

In order to link between the sensitivity package and APSIM, there needs to be a function that can edit then run APSIM that produces a univariate output. The apsim_vector function satisfies these conditions and can return multivariate output if a multivariate sensitivity analysis is of interest. See the examples section or the package vignette for details.

Value

a vector of length N

Examples

 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
## Not run: 
meanCowpea<-function(X){
 return(mean(X$lai_cowpea))
}

apsimWd <- "~/APSIM"
apsimVar <- c(rep("SoilWater/Thickness",11), "SoilOrganicMatter/SoilCN")
apsimValue <- matrix(c(rep(200, 2), rep(300, 9), 10,
                       rep(350, 2), rep(350, 9), 5),nrow=2,byrow=T)
apsimExe <-"C:/Program Files (x86)/Apsim75-r3008/Model/Apsim.exe"
apsimFile <- "Canopy.apsim"

#Run APSIM at each new parameter vector specified by apsimVar and only return the mean cowpea value
uniRes <- apsim_vector(X = apsimValue, exe = apsimExe, wd = apsimWd, vars = apsimVar,
         to.run = apsimFile, to.edit = apsimFile, g = meanCowpea)
uniRes


allCowpea <- function(x){
 return(x$lai_cowpea)
}

#Use allCowpea function to return all the cowpea values
multiRes <- apsim_vector(X = apsimValue, exe = apsimExe, wd = apsimWd, vars = apsimVar,
             to.run = apsimFile, to.edit = apsimFile, g = allCowpea)
multiRes

## End(Not run)

apsimr documentation built on May 2, 2019, 3:03 a.m.