minor changes and 2 digit rounding in sensitivity analysis

This commit is contained in:
hollorol 2018-05-14 10:05:54 +02:00
parent d2fce92741
commit 0dd73ac350
5 changed files with 143 additions and 2 deletions

View File

@ -12,7 +12,6 @@ export(musoMapping)
export(musoMonte) export(musoMonte)
export(musoRandomizer) export(musoRandomizer)
export(musoSensi) export(musoSensi)
export(paramSweepŰ)
export(plotMuso) export(plotMuso)
export(rungetMuso) export(rungetMuso)
export(setupMuso) export(setupMuso)

View File

@ -63,7 +63,7 @@ musoSensi <- function(monteCarloFile = NULL,
S[i] <- ((w[i]^2*Sv[i])/(overalVar))*100 S[i] <- ((w[i]^2*Sv[i])/(overalVar))*100
} }
S <- round(S) S <- round(S,digits=2)
names(S)<-varNames names(S)<-varNames
write.csv(file = outputFile, x = S) write.csv(file = outputFile, x = S)

View File

@ -0,0 +1,13 @@
## #' paramsweep
## #'
## #' This function update the the muso outputcode-variable matrix
## #' @author Roland Hollos
## #' @return The outputcode-variable matrix, and also change the global variable
## #' @import rmarkdown
## #' @export
## paramSweep <- function(inputDir="./",parameters=NULL,outputDir=NULL){
## read.csv(system.file("markdowns","parameters.csv",package="RBBGCMuso"))
## }

View File

@ -0,0 +1,115 @@
---
title: "ParameterSweep"
auth or: ""
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r,echo=FALSE}
library("RBBGCMuso")
quickAndDirty <- function(settings, parameters, inputDir= "./", outLoc, iterations=2, outVar=8,){
outLocPlain <- basename(outLoc)
currDir <- getwd()
inputDir <- normalizePath(inputDir)
tmp <- file.path(outLoc,"tmp/")
if(!dir.exists(outLoc)){
dir.create(outLoc)
warning(paste(outLoc," is not exists, so it was created"))
}
if(dir.exists(tmp)){
stop("There is a tmp directory inside the output location, please replace it. tmp is an important temporary directory for the function")
}
dir.create(tmp)
outLoc <- normalizePath(outLoc)
tmp <- normalizePath(tmp)
inputFiles <- file.path(inputDir,grep(basename(outLoc),list.files(inputDir),invert = TRUE,value = TRUE))
for(i in inputFiles){
file.copy(i,tmp)
}
setwd(tmp)
if(is.null(settings)){
settings <- setupMuso()
}
file.copy(settings$epcInput[2],"epc-save",overwrite = TRUE)
calibrationPar <- matrix[,"INDEX"]
npar <- nrow(matrix)
paramMatrices <- list()
parameters <- matrix(nrow = npar,ncol = iterations)
paramtest <- parameters
rownames(paramtest) <- matrix[,1]
for(i in 1:npar){
parameters[i,] <- seq(from=matrix[i,5],to=matrix[i,6],length=iterations)
#print(parameters[i,])
settings$calibrationPar <- calibrationPar[i]
for(j in 1:iterations){
p <- try(calibMuso(settings,parameters =parameters[i,j],silent=TRUE))
if(length(p)>1){
paramtest[i,j] <- max(p[,outVar])
# print(paramtest)
} else {
paramtest[i,j] <- NA
# print(paramtest)
}
}
file.copy("epc-save",settings$epcInput[2],overwrite = TRUE)
}
print("###################################################")
paramMatrices <- (function(){
for(i in 1:nrow(paramtest)){
matrx <- matrix(ncol = 2,nrow=iterations)
matrx[,1] <- parameters[i,]
matrx[,2] <- paramtest[i,]
paramMatrices[[i]] <- matrx
names(paramMatrices)[i] <- rownames(paramtest)[i]
}
return(paramMatrices)
})()
return(list(paramtest,paramMatrices))
}
```
```{r, echo=FALSE,cache=TRUE}
parconstrains <- read.csv("parconstrains_extended.csv")
settings <- setupMuso()
parSeq<-quickAndDirty(settings = settings,matrix = parconstrains,outVar = 8,iterations = 5)
```
```{r}
parSeq
```
```{r,echo=FALSE}
parlist<-parSeq[[2]]
lparlist<-length(parlist)
for(i in 1:lparlist){
title<-names(parlist)[i]
plot(x = parlist[[i]][,1], y= parlist[[i]][,2], ylim=c(0,15), main=title,ylab="LAI")
}
```

View File

@ -0,0 +1,14 @@
NAME,INDEX,MIN,MAX
BASETEMP,25,3,9
WPM,36,0,0.1
CN_lv,38,10,50
CN_li,39,32,70
CN_root,40,20,70
CN_fruit,41,10.50,70
CN_stem,42,0,70
CLEC,55,0.4,0.8
FLNR,61,0.05,0.8
STOMA,63,0.003,0.015
ROOTDEPTH,74,0.3,2.
SWCGERMIN,87,0.2,0.9
NH4MOBILEPROP,120,0.05,0.7
1 NAME INDEX MIN MAX
2 BASETEMP 25 3 9
3 WPM 36 0 0.1
4 CN_lv 38 10 50
5 CN_li 39 32 70
6 CN_root 40 20 70
7 CN_fruit 41 10.50 70
8 CN_stem 42 0 70
9 CLEC 55 0.4 0.8
10 FLNR 61 0.05 0.8
11 STOMA 63 0.003 0.015
12 ROOTDEPTH 74 0.3 2.
13 SWCGERMIN 87 0.2 0.9
14 NH4MOBILEPROP 120 0.05 0.7