debug
This commit is contained in:
parent
e24f985aa6
commit
0b3e29f40e
@ -10,6 +10,7 @@ NeedsCompilation: no
|
||||
Packaged: 2017-07-19 14:00:04 UTC; hollorol
|
||||
Author: Roland Hollo's [aut, cre]
|
||||
Imports:
|
||||
grDevices,
|
||||
stats,
|
||||
utils,
|
||||
graphics,
|
||||
|
||||
@ -9,7 +9,9 @@ export(getyearlycum)
|
||||
export(getyearlymax)
|
||||
export(musoDate)
|
||||
export(musoMapping)
|
||||
export(musoMonte)
|
||||
export(musoRandomizer)
|
||||
export(musoSensi)
|
||||
export(plotMuso)
|
||||
export(rungetMuso)
|
||||
export(setupMuso)
|
||||
@ -17,6 +19,7 @@ export(spinupMuso)
|
||||
export(supportedMuso)
|
||||
export(updateMusoMapping)
|
||||
import(dplyr)
|
||||
import(grDevices)
|
||||
import(graphics)
|
||||
import(magrittr)
|
||||
import(stats)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#' musoMonte
|
||||
#'
|
||||
#' This funcion is fundamental for the BiomBGC-MuSo modell related functions like spinupMuso, normalMuso, rungetMuso, because it sets the modells environment.
|
||||
#' inputDir = "./",
|
||||
#' This function does monteCarlo on BiomeBGC-MuSo. It samples specified modell variables in given rangge from conditional multivariate uniform distribution, and runs the modell for each run.
|
||||
#' @author Roland Hollos
|
||||
#' @param settings A list of montecarlos environmental variables. It is generated by the setupMuso() function. In default the settings parameter is generated automatically.
|
||||
#' @param parameters This is a dataframe (heterogen data-matrix), which first column is the name of the parameters, the second is a numeric vector of the rownumbers of the given variable in the epc-fie, the last two column consist the endpont of the parameter-ranges, where the parameters will be randomized.
|
||||
@ -9,11 +8,9 @@
|
||||
#' @param inputDir The location of the input directory, this directory must content a viable pack of all inputfiles and the executable file.
|
||||
#' @param iterations number of the monteCarlo run.
|
||||
#' @param preTag It will be the name of the output files. For example preTag-1.csv, pretag-2csv...
|
||||
#' @param outputType Via planting parameter, you can tell the modell where are the data files, which contains the planting informations. As default it reads this from the iniFiles.
|
||||
#' @param fun Via thining parameter, you can tell the modell where are the data files, which contains the thining informations. As default it reads this from the iniFiles.
|
||||
#' @param varIndex Via mowing parameter, you can tell the modell where are the data files, which contains the mowing informations. As default it reads this from the iniFiles.
|
||||
#' @param doSensitivity Via grazing parameter, you can tell the modell where are the data files, which contains the grazing informations. As default it reads this from the iniFiles.
|
||||
#' @param onDisk Via harvesting parameter, you can tell the modell where are the data files, which contains the harvesting informations. As default it reads this from the iniFiles.
|
||||
#' @param outputType This parameter can be "oneCsv", "moreCsv", and "netCDF". If "oneCsv" is choosen the function create 1 big csv file for all of the runs, if "moreCsv" is choosen, every modell output goes to separate files, if netCDF is selected the outputs will be put in a netCDF file. The default value of the outputTypes is "moreCsv". netCDF is not implemented yet.
|
||||
#' @param fun If you select a variable from the possible outputs (with specify the varIndex parameter), you have to provide a function which maps to a subset of real numbers. The most frequent possibilities are: mean, min, max, var, but you can define any function for your need.
|
||||
#' @param varIndex This parameter specify which parameter of the output will be used. You can extract this information from the ini-files. At the output parameter specifications, the parameters order will determine this number. For example, if you have set these output parameters: 412, 874, 926, 888, and you want to use 926, you should address varIndex with 3.
|
||||
#' @export
|
||||
|
||||
musoMonte <- function(settings=NULL,
|
||||
|
||||
@ -1,3 +1,24 @@
|
||||
#' musoSensi
|
||||
#'
|
||||
#' This function does regression based sensitivity analysis based on the output of musoMonte.
|
||||
#' @author Roland Hollos
|
||||
#' @param monteCarloFile If you run musoMonte function previously, you did not have to rerun the monteCarlo, just provide the preservedEpc.csv file with its path. If you do not set this parameter, musoSensi will fun the musoMonte function to get all of the information.
|
||||
#' @param outputFile The filename in which the output of musoSensi function will be saved. It's default value is: "sensitivity.csv"
|
||||
#' @param plotName The name of the output barplot. It's default value is: "sensitivity.jpg"
|
||||
#' @param settings A list of montecarlos environmental variables. It is generated by the setupMuso() function. In default the settings parameter is generated automatically.
|
||||
#' @param parameters This is a dataframe (heterogen data-matrix), which first column is the name of the parameters, the second is a numeric vector of the rownumbers of the given variable in the epc-fie, the last two column consist the endpont of the parameter-ranges, where the parameters will be randomized.
|
||||
#' @param calibrationPar You may want to change some parameters in your epc file, before you run the modell. You have to select the appropirate modell parameters. You can refence to these with the number of the line in the epc file where the variables are. It indexes from one. You should use a vector for this, like: c(1,5,8)
|
||||
#' @param inputDir The location of the input directory, this directory must content a viable pack of all inputfiles and the executable file.
|
||||
#' @param iterations number of the monteCarlo run.
|
||||
#' @param preTag It will be the name of the output files. For example preTag-1.csv, pretag-2csv...
|
||||
#' @param outputType This parameter can be "oneCsv", "moreCsv", and "netCDF". If "oneCsv" is choosen the function create 1 big csv file for all of the runs, if "moreCsv" is choosen, every modell output goes to separate files, if netCDF is selected the outputs will be put in a netCDF file. The default value of the outputTypes is "moreCsv". netCDF is not implemented yet.
|
||||
#' @param fun If you select a variable from the possible outputs (with specify the varIndex parameter), you have to provide a function which maps to a subset of real numbers. The most frequent possibilities are: mean, min, max, var, but you can define any function for your need.
|
||||
#' @param varIndex This parameter specify which parameter of the output will be used. You can extract this information from the ini-files. At the output parameter specifications, the parameters order will determine this number. For example, if you have set these output parameters: 412, 874, 926, 888, and you want to use 926, you should address varIndex with 3.
|
||||
#' @import dplyr
|
||||
#' @import graphics
|
||||
#' @import grDevices
|
||||
#' @export
|
||||
|
||||
musoSensi <- function(monteCarloFile = NULL,
|
||||
parameters,
|
||||
settings = NULL,
|
||||
@ -23,12 +44,13 @@ musoSensi <- function(monteCarloFile = NULL,
|
||||
varIndex = varIndex
|
||||
)
|
||||
npar <- ncol(M)-1
|
||||
y <- M[,(npar+1)]
|
||||
M %<>%
|
||||
tbl_df() %>%
|
||||
filter(.,!is.na(y)) %>%
|
||||
as.data.frame()
|
||||
y <- M[,(npar+1)]
|
||||
M <- apply(M[,1:npar],2,function(x){x-mean(x)})
|
||||
varNames<- colnames(M)[1:npar]
|
||||
w <- lm(y~M)$coefficients[-1]
|
||||
Sv <- apply(M,2,var)
|
||||
overalVar <- sum(Sv^2*w^2)
|
||||
@ -36,23 +58,20 @@ musoSensi <- function(monteCarloFile = NULL,
|
||||
for(i in 1:npar){
|
||||
S[i] <- ((w[i]^2*Sv[i]^2)/overalVar)*100
|
||||
}
|
||||
|
||||
jpg(plotName)
|
||||
barplot(S)
|
||||
dev.off()
|
||||
|
||||
write.csv(file = outputFile, x = S)
|
||||
barplot(S)
|
||||
names(S)<-varNames
|
||||
barplot(S,las=2)
|
||||
return(S)
|
||||
} else {
|
||||
M <- read.csv(monteCarloFile)
|
||||
npar <- ncol(M)-1
|
||||
y <- M[,(npar+1)]
|
||||
M %<>%
|
||||
tbl_df() %>%
|
||||
filter(.,!is.na(y)) %>%
|
||||
as.data.frame()
|
||||
y <- M[,(npar+1)]
|
||||
M <- apply(M[,1:npar],2,function(x){x-mean(x)})
|
||||
varNames<- colnames(M)[1:npar]
|
||||
w <- lm(y~M)$coefficients[-1]
|
||||
Sv <- apply(M,2,var)
|
||||
overalVar <- sum(Sv^2*w^2)
|
||||
@ -60,13 +79,9 @@ musoSensi <- function(monteCarloFile = NULL,
|
||||
for(i in 1:npar){
|
||||
S[i] <- ((w[i]^2*Sv[i]^2)/overalVar)*100
|
||||
}
|
||||
|
||||
jpg(plotName)
|
||||
barplot(S)
|
||||
dev.off()
|
||||
|
||||
names(S)<-varNames
|
||||
write.csv(file = outputFile, x = S)
|
||||
barplot(S)
|
||||
barplot(S,las=2)
|
||||
return(S)
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,37 +6,29 @@
|
||||
\usage{
|
||||
musoMonte(settings = NULL, parameters, inputDir = "./",
|
||||
outLoc = "./calib", iterations = 10, preTag = "mont-",
|
||||
inputName = paste0(pretag, "epcs.csv"), outputType = "moreCsv",
|
||||
fun = mean, varIndex = 8, doSensitivity = FALSE, onDisk = FALSE, ...)
|
||||
outputType = "moreCsv", fun = mean, varIndex = 1, ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{settings}{Do you want to run multiple modell paralelly, if yes, set this variable to TRUE}
|
||||
\item{settings}{A list of montecarlos environmental variables. It is generated by the setupMuso() function. In default the settings parameter is generated automatically.}
|
||||
|
||||
\item{parameters}{stores the place of the modell-executable file. In normal usage, you don't have to be set this, because a RBBgcmuso package contains allways the latest modell executable. In spite of this, if you would like to use this package for modell development or just want to use different models (for example for comparison), you will find it useful}
|
||||
\item{parameters}{This is a dataframe (heterogen data-matrix), which first column is the name of the parameters, the second is a numeric vector of the rownumbers of the given variable in the epc-fie, the last two column consist the endpont of the parameter-ranges, where the parameters will be randomized.}
|
||||
|
||||
\item{outLoc}{Where should the modell puts its outputs. You should give a location for it via this variable, for example: outputLoc="/place/of/the/outputs/"}
|
||||
\item{inputDir}{The location of the input directory, this directory must content a viable pack of all inputfiles and the executable file.}
|
||||
|
||||
\item{iterations}{Usually it is the root directory, where you put the iniFiles for the modell}
|
||||
\item{iterations}{number of the monteCarlo run.}
|
||||
|
||||
\item{preTag}{Via metInput parameter, you can tell the modell where are the meteorological files. As default it reads this from the iniFiles.}
|
||||
\item{preTag}{It will be the name of the output files. For example preTag-1.csv, pretag-2csv...}
|
||||
|
||||
\item{inputName}{Via CO2 parameter, you can tell the modell where are the CO2 data files. As default it reads this from the iniFiles.}
|
||||
\item{outputType}{This parameter can be "oneCsv", "moreCsv", and "netCDF". If "oneCsv" is choosen the function create 1 big csv file for all of the runs, if "moreCsv" is choosen, every modell output goes to separate files, if netCDF is selected the outputs will be put in a netCDF file. The default value of the outputTypes is "moreCsv". netCDF is not implemented yet.}
|
||||
|
||||
\item{outputType}{Via planting parameter, you can tell the modell where are the data files, which contains the planting informations. As default it reads this from the iniFiles.}
|
||||
\item{fun}{If you select a variable from the possible outputs (with specify the varIndex parameter), you have to provide a function which maps to a subset of real numbers. The most frequent possibilities are: mean, min, max, var, but you can define any function for your need.}
|
||||
|
||||
\item{fun}{Via thining parameter, you can tell the modell where are the data files, which contains the thining informations. As default it reads this from the iniFiles.}
|
||||
|
||||
\item{varIndex}{Via mowing parameter, you can tell the modell where are the data files, which contains the mowing informations. As default it reads this from the iniFiles.}
|
||||
|
||||
\item{doSensitivity}{Via grazing parameter, you can tell the modell where are the data files, which contains the grazing informations. As default it reads this from the iniFiles.}
|
||||
|
||||
\item{onDisk}{Via harvesting parameter, you can tell the modell where are the data files, which contains the harvesting informations. As default it reads this from the iniFiles.}
|
||||
\item{varIndex}{This parameter specify which parameter of the output will be used. You can extract this information from the ini-files. At the output parameter specifications, the parameters order will determine this number. For example, if you have set these output parameters: 412, 874, 926, 888, and you want to use 926, you should address varIndex with 3.}
|
||||
|
||||
\item{calibrationPar}{You may want to change some parameters in your epc file, before you run the modell. You have to select the appropirate modell parameters. You can refence to these with the number of the line in the epc file where the variables are. It indexes from one. You should use a vector for this, like: c(1,5,8)}
|
||||
}
|
||||
\description{
|
||||
This funcion is fundamental for the BiomBGC-MuSo modell related functions like spinupMuso, normalMuso, rungetMuso, because it sets the modells environment.
|
||||
inputDir = "./",
|
||||
This function does monteCarlo on BiomeBGC-MuSo. It samples specified modell variables in given rangge from conditional multivariate uniform distribution, and runs the modell for each run.
|
||||
}
|
||||
\author{
|
||||
Roland Hollos
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +0,0 @@
|
||||
library(testthat)
|
||||
library(RBBGCMuso)
|
||||
|
||||
test_check("RBBGCMuso")
|
||||
Loading…
Reference in New Issue
Block a user