minor changes and 2 digit rounding in sensitivity analysis
This commit is contained in:
parent
d2fce92741
commit
0dd73ac350
@ -12,7 +12,6 @@ export(musoMapping)
|
||||
export(musoMonte)
|
||||
export(musoRandomizer)
|
||||
export(musoSensi)
|
||||
export(paramSweepŰ)
|
||||
export(plotMuso)
|
||||
export(rungetMuso)
|
||||
export(setupMuso)
|
||||
|
||||
@ -63,7 +63,7 @@ musoSensi <- function(monteCarloFile = NULL,
|
||||
S[i] <- ((w[i]^2*Sv[i])/(overalVar))*100
|
||||
}
|
||||
|
||||
S <- round(S)
|
||||
S <- round(S,digits=2)
|
||||
names(S)<-varNames
|
||||
write.csv(file = outputFile, x = S)
|
||||
|
||||
|
||||
13
RBBGCMuso/R/parametersweep.R
Normal file
13
RBBGCMuso/R/parametersweep.R
Normal 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"))
|
||||
## }
|
||||
115
RBBGCMuso/inst/markdowns/parameterSweep.rmd
Normal file
115
RBBGCMuso/inst/markdowns/parameterSweep.rmd
Normal 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")
|
||||
}
|
||||
```
|
||||
14
RBBGCMuso/inst/markdowns/parameters.csv
Normal file
14
RBBGCMuso/inst/markdowns/parameters.csv
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user