Interface to use Simplace from R"

withSimplace <- FALSE
try({
  withSimplace <- !is.na(simplace::findFirstSimplaceInstallation())
})

Introduction

This package provides methods to interact with the modelling framework Simplace^[ Scientific Impact assessment and Modelling PLatform for Advanced Crop and Ecosystem management. See www.simplace.net for more information on Simplace]. Simplace is written in Java (and some parts in Scala) so one can access it from R via rJava. The purpose of this package is to simplify the interaction between R and Simplace, by providing functions to:

Installing the Simplace Framework

For installing Simplace, please consult the webpage www.simplace.net. A brief guide to install Simplace:

install.packages('simplace')

Basic Usage

The usage of Simplace in R follows roughly this scheme:

Troubleshooting

Example

Run the simulation

library(simplace)
SimplaceInstallationDir <- findFirstSimplaceInstallation()

Solution <- paste(SimplaceInstallationDir,
        "simplace_run/simulation/gk/solution/complete/Complete.sol.xml",sep="")

simplace <- initSimplace(SimplaceInstallationDir)

openProject(simplace, Solution)

parameter <- list()
parameter$enddate <- "31-12-1992"

sid <- createSimulation(simplace,parameter)
runSimulations(simplace)

result <- getResult(simplace,"DIAGRAM_OUT", sid);

closeProject(simplace)

After specifying the directories and the solution, the framework is initialized and the project opened. The end date of the simulation is (re)set and the simulation is run. After the run the result is retrieved.

\newpage

Get the result and plot it

simdata <- resultToDataframe(result)

dates <- 300:730
weights <- simdata[dates,
    c("TOP_LINE_Roots","TOP_LINE_Leaves","TOP_LINE_Stems","TOP_LINE_StorageOrgans")]
matplot(dates,weights,type="l",xlab="Days",ylab="Weight [g/m2]",main="Simulated Biomass")
legend(300,800,legend=c("Roots","Leaves","Stems","Storage Organs"),lty=1:4,col=1:4)

The result is converted to a dataframe. Interesting variables are extracted and then plotted.

\newpage

Get arrays and plot them as contour plot

resultlistexp <- resultToList(result,expand=TRUE)
water <- resultlistexp$BOTTOM_ARRAY_VolumetricWaterContent
wmat <- do.call(rbind,water)
wmatpart <- wmat[dates,]
layers <- dim(wmatpart)[2]
filled.contour(dates,-(layers:1),wmatpart[,layers:1],
               xlab="Day", ylab="Layer", main="Water content in soil",
               color.palette = function(n){rgb((n:1)/n,(n:1)/n,1)})

As the result contains an array which holds the water content for 40 layers, it is transformed to a list and the array is expanded.

\newpage \tableofcontents



Try the simplace package in your browser

Any scripts or data that you put into this service are public.

simplace documentation built on Aug. 24, 2023, 3:03 p.m.