New feature: saveAllMusoPlots
This commit is contained in:
parent
6cdcb4d4d6
commit
ddb5934b3e
@ -1,6 +1,6 @@
|
||||
Package: RBBGCMuso
|
||||
Title: An R package for BiomeBGC-MuSo ecosystem modelling
|
||||
Version: 0.6.2.0
|
||||
Version: 0.6.3.0
|
||||
Authors@R: person("Roland", "Hollo's", , "hollorol@gmail.com", role = c("aut", "cre"))
|
||||
Description: What the package does (one paragraph).
|
||||
Depends: R (>= 3.3.2)
|
||||
|
||||
@ -24,6 +24,7 @@ export(plotMusoWithData)
|
||||
export(randEpc)
|
||||
export(runMuso)
|
||||
export(rungetMuso)
|
||||
export(saveAllMusoPlots)
|
||||
export(setupMuso)
|
||||
export(spinupMuso)
|
||||
export(supportedMuso)
|
||||
@ -53,6 +54,7 @@ importFrom(ggplot2,ggtitle)
|
||||
importFrom(ggplot2,labs)
|
||||
importFrom(ggplot2,scale_y_continuous)
|
||||
importFrom(ggplot2,theme)
|
||||
importFrom(ggplot2,theme_classic)
|
||||
importFrom(ggplot2,xlab)
|
||||
importFrom(ggplot2,ylab)
|
||||
importFrom(limSolve,xsample)
|
||||
@ -60,6 +62,7 @@ importFrom(magrittr,'%<>%')
|
||||
importFrom(magrittr,'%>%')
|
||||
importFrom(rmarkdown,pandoc_version)
|
||||
importFrom(rmarkdown,render)
|
||||
importFrom(scales,percent)
|
||||
importFrom(tcltk,tk_choose.files)
|
||||
importFrom(tibble,rownames_to_column)
|
||||
importFrom(tidyr,gather)
|
||||
|
||||
@ -29,12 +29,16 @@ getmonthlyout<-function(settings){
|
||||
}
|
||||
|
||||
getyearlyout<-function(settings){
|
||||
binaryname<-paste(settings$inputloc,settings$outputname,".annout",sep="")
|
||||
d<-file(binaryname,"rb")
|
||||
yearoutput<-matrix(readBin(d,"double",size=4,n=(settings$numdata[3])),(settings$numyears),byrow=TRUE)
|
||||
close(d)
|
||||
return(yearoutput)
|
||||
binaryname<-paste0(settings$inputLoc,"/",settings$outputName[2],".annout")
|
||||
## d<-file(binaryname,"rb")
|
||||
## yearoutput<-matrix(readBin(d,"double",size=4,n=(settings$numData[3])),(settings$numYears),byrow=TRUE)
|
||||
## close(d)
|
||||
## return(yearoutput)
|
||||
outPut <- read.table(binaryname,skip = 1)
|
||||
colnames(outPut) <- c("year", paste0("var_",settings$annualVarCodes))
|
||||
outPut
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,21 +1,18 @@
|
||||
#' musoSensi
|
||||
#'
|
||||
#' This function performs multiple linear regression based global sensitivity analysis using on the output of musoMonte. The algorithm implements the method proposed by Verbeeck et al. 2006 (Tree Physiology 26, 807–817). First the user has to select the parameters of interest with possible minimum and maximum values. After execution musoSensi will then assign weights to the predefined parameters which means that the importance of the parameters will be ranked. The sensitivity analysis calculates the effect of input variability on the output variability in Monte Carlo framework. The result will largely depend on the selected output variable (GPP, evapotranspiration, LAI, soil water content), and on the parameter ranges. Other factors like climate, management and site specific conditions might affect the results.
|
||||
#' @author Roland HOLLOS
|
||||
#' @param monteCarloFile If you run the musoMonte function previously, you do not have to re-run the monteCarlo experiment, simply provide the preservedEpc.csv file to musoSensi with its path. If you do not set this parameter, musoSensi will run the musoMonte function to get all necessary information.
|
||||
#' @param outputFile The filename in which the output of the musoSensi function will be saved. By default it is "sensitivity.csv"
|
||||
#' @param plotName The name of the output barplot. It's default value is "sensitivity.jpg"
|
||||
#' @param settings A list of environmental variables for the Monte Carlo experiment. These settings are generated by the setupMuso function. By default the settings parameter is generated automatically.
|
||||
#' @param parameters This is a dataframe (heterogeneous data-matrix), where the first column is the name of the parameter, the second is a numeric vector of the rownumbers of the given variable in the input EPC file, and the last two columns describe the minimum and the maximum of the parameter (i.e. the parameter ranges), defining the interval for the randomization.
|
||||
#' @param calibrationPar You might want to change some parameters in your EPC file before you run the modell. You have to select the appropirate model parameters here. You can refer to the parameters by the number of the line in the EPC file where the variables are defined. The indexing of the lines starts at 1, and each line matters (like in any simple text file). You should use a vector for this selection like c(1,5,8)
|
||||
#' @param inputDir The location of the input directory for the Biome-BGCMuSo model. This directory must contain a viable pack of all input files and the model executable file.
|
||||
#' @param iterations Number of the Monte Carlo simulations.
|
||||
#' @param preTag This defines the name of the output files. This tag will be re-used so that the results will be like preTag-1.csv, preTag-2csv...
|
||||
#' @param outputType This parameter can be "oneCsv", "moreCsv", and "netCDF". If "oneCsv" is chosen the function creates one large csv file for all of the runs. If "moreCsv" is chosen, every model output goes to separate files. If netCDF is selected the output will be stored in a netCDF file. The default value of the outputTypes is "moreCsv". Note that netCDF is not implemented yet.
|
||||
#' @param fun If you select a variable from the possible outputs (by using 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 needs.
|
||||
#' @param varIndex This parameter specifies which parameter will be used for the Monte Carlo experiment from the output list of Biome-BGCMuSo (defined by the INI file). You can extract this information from the INI files. At the output parameter specifications, the parameter order will determine this number. For example, if you have set these output parameters: 412, 874, 926, 888, and you want to use 926 for the experiment, you should specify varIndex as 3.
|
||||
#' @param skipSpinup With this parameter you can turn off the spinup phase after the first spinup was successfully executed (endpoint file is available). This option can dramatically decrease the time needed for the sensitivity analysis. Note that in case of natural vegetation this option might not be feasible. For croplands this is more feasible.
|
||||
#' This function does regression based sensitivity analysis based on the output of musoMonte.
|
||||
#' @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.
|
||||
#' @param skipSpinup With this parameter, you can turn of the spinup phase after the first spinup. I will decrease the time significantly.
|
||||
#' @importFrom ggplot2 geom_bar ggplot aes theme element_text xlab ylab ggtitle ggsave scale_y_continuous
|
||||
#' @importFrom scales percent
|
||||
#' @export
|
||||
|
||||
musoSensi <- function(monteCarloFile = NULL,
|
||||
|
||||
@ -27,30 +27,18 @@
|
||||
#' @importFrom tidyr separate gather
|
||||
#' @export
|
||||
|
||||
plotMuso <- function(settings=NULL,
|
||||
variable=1,
|
||||
##compare,
|
||||
##plotname,
|
||||
timee="d",
|
||||
silent=TRUE,
|
||||
calibrationPar=NULL,
|
||||
parameters=NULL,
|
||||
debugging=FALSE,
|
||||
keepEpc=FALSE,
|
||||
fileToChange="epc",
|
||||
logfilename=NULL,
|
||||
aggressive=FALSE,
|
||||
leapYear=FALSE,
|
||||
plotName=NULL,
|
||||
plotType="cts",
|
||||
layerPlot=FALSE,
|
||||
colour="blue",
|
||||
skipSpinup=TRUE,
|
||||
fromData=FALSE,
|
||||
timeFrame="day",
|
||||
selectYear=NULL,
|
||||
groupFun=mean,
|
||||
dpi=300){
|
||||
plotMuso <- function(settings = NULL, variable = 1,
|
||||
##compare, ##plotname,
|
||||
timee = "d", silent = TRUE,
|
||||
calibrationPar = NULL, parameters = NULL,
|
||||
debugging = FALSE, keepEpc = FALSE,
|
||||
fileToChange = "epc", logfilename = NULL,
|
||||
aggressive = FALSE, leapYear = FALSE,
|
||||
plotName = NULL, plotType = "cts",
|
||||
layerPlot = FALSE, colour = "blue",
|
||||
skipSpinup = TRUE, fromData = FALSE,
|
||||
timeFrame = "day", selectYear = NULL,
|
||||
groupFun = mean, separateFile = FALSE, dpi=300){
|
||||
|
||||
if( plotType!="cts" && plotType != "dts"){
|
||||
warning(paste0("The plotType ", plotType," is not implemented, plotType is set to cts"))
|
||||
@ -63,6 +51,7 @@ plotMuso <- function(settings=NULL,
|
||||
|
||||
numberOfYears <- settings$numYears
|
||||
startYear <- settings$startYear
|
||||
dailyVarCodes <- settings$dailyVarCodes
|
||||
## musoData <- rungetMuso(settings=settings,
|
||||
## silent=silent,
|
||||
## timee=timee,
|
||||
@ -164,20 +153,21 @@ plotMuso <- function(settings=NULL,
|
||||
}
|
||||
p
|
||||
} else{
|
||||
p <- musoData %>%
|
||||
select(c("date",variableName))%>%
|
||||
gather(., key= outputs, value = bla,variableName) %>%
|
||||
p <- musoData %>%
|
||||
select(c("date",variableName))%>%
|
||||
gather(., key= outputs, value = bla,variableName) %>%
|
||||
# head %>%
|
||||
ggplot(aes(x=date,y=bla))+
|
||||
facet_wrap(~ outputs, scales = "free_y",ncol=1) +
|
||||
geom_line(colour=colour)+
|
||||
theme(
|
||||
axis.title.y = element_blank()
|
||||
)
|
||||
if(!is.null(plotName)){
|
||||
ggsave(as.character(plotName),p)
|
||||
}
|
||||
p
|
||||
ggplot(aes(x=date,y=bla))+
|
||||
facet_wrap(~ outputs, scales = "free_y",ncol=1) +
|
||||
geom_line(colour=colour)+
|
||||
theme(
|
||||
axis.title.y = element_blank()
|
||||
)
|
||||
if(!is.null(plotName)){
|
||||
ggsave(as.character(plotName),p)
|
||||
}
|
||||
p
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -323,4 +313,47 @@ compareMuso <- function(settings=NULL,parameters, variable=1, calibrationPar=NUL
|
||||
|
||||
}
|
||||
|
||||
#' saveAllMusoPlots
|
||||
#'
|
||||
#' This simple function takes the parameters from the ini files and generates graphics for all output variable.
|
||||
#'
|
||||
#' @author Roland HOLLOS
|
||||
#' @param settings RBBGCMuso uses variables that define the entire simulation environment. Those environment variables include the name of the INI files, the name of the meteorology files, the path to the model executable and its file name, the entire output list, the entire output variable matrix, the dependency rules for the EPC parameters etc. Using the runMuso function RBBGCMuso can automatically create those environment variables by inspecting the files in the working directory (this happens through the setupMuso function). It means that by default model setup is performed automatically in the background and the user has nothing to do. With this settings parameter we can force runMuso to skip automatic environment setup as we provide the environment settings to runMuso. In a typical situation the user can skip this option.
|
||||
#' @param plotName The basename for the output plots
|
||||
#' @param destination The destination for the output plots, it not exits the function will create it.
|
||||
#' @param silent if true do not suspect for printfs...
|
||||
#' @importFrom ggplot2 theme_classic ggplot geom_line geom_point theme element_blank geom_bar labs aes_string aes ggsave
|
||||
#' @export
|
||||
|
||||
|
||||
saveAllMusoPlots <- function(settings=NULL, plotName = ".png",
|
||||
silent = TRUE, type = "line",
|
||||
colour = NULL, skipSpinup = FALSE){
|
||||
|
||||
if(is.null(settings)){
|
||||
settings <- setupMuso()
|
||||
}
|
||||
|
||||
dailyVarCodes <- settings$dailyVarCodes
|
||||
annualVarCodes <-settings$annualVarCodes
|
||||
outputVars <- unlist(settings$outputVars[[1]])
|
||||
musoData <- calibMuso(settings = settings, prettyOut = TRUE, silent = silent, skipSpinup = skipSpinup)
|
||||
for(i in seq_along(dailyVarCodes)){
|
||||
bases <- ggplot(data = musoData, mapping = aes_string(x = "date", y = outputVars[i]))
|
||||
object <-ifelse(type == "line",paste0("geom_line(colour = '",colour,"')"),
|
||||
ifelse(type == "point",paste0("geom_line(colour = ",colour,")"),
|
||||
stop("The")))
|
||||
outPlot <- bases + eval(parse(text = object)) + theme_classic() + theme(axis.title.x=element_blank())
|
||||
ggsave(paste0("daily-",dailyVarCodes[i],plotName),outPlot)
|
||||
}
|
||||
|
||||
musoYData <- getyearlyout(settings)
|
||||
|
||||
for(i in seq_along(annualVarCodes)){
|
||||
outPlot <- ggplot(data = musoYData, mapping = aes_string(x = "year", y = paste0("var_",annualVarCodes[i])))+
|
||||
geom_bar(stat = "identity")+ labs(y = musoMapping(annualVarCodes[i])) + theme_classic() +
|
||||
theme(axis.title.x=element_blank())
|
||||
ggsave(paste0("annual-",annualVarCodes[i],plotName),outPlot)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -268,7 +268,8 @@ setupMuso <- function(executable=NULL,
|
||||
startYear=startYear,
|
||||
numYears=numYears,
|
||||
outputVars=outputVars,
|
||||
dailyVarCodes= gsub("\\s.*","",dailyVarCodes)
|
||||
dailyVarCodes= gsub("\\s.*","",dailyVarCodes),
|
||||
annualVarCodes = gsub("\\s.*","",annualVarCodes)
|
||||
)
|
||||
|
||||
if(writep!=nrow(grepHelper)){
|
||||
|
||||
@ -12,35 +12,26 @@ musoSensi(monteCarloFile = NULL, parameters = NULL, settings = NULL,
|
||||
skipSpinup = TRUE, dpi = 300)
|
||||
}
|
||||
\arguments{
|
||||
\item{monteCarloFile}{If you run the musoMonte function previously, you do not have to re-run the monteCarlo experiment, simply provide the preservedEpc.csv file to musoSensi with its path. If you do not set this parameter, musoSensi will run the musoMonte function to get all necessary information.}
|
||||
\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{parameters}{This is a dataframe (heterogeneous data-matrix), where the first column is the name of the parameter, the second is a numeric vector of the rownumbers of the given variable in the input EPC file, and the last two columns describe the minimum and the maximum of the parameter (i.e. the parameter ranges), defining the interval for the randomization.}
|
||||
\item{settings}{A list of montecarlos environmental variables. It is generated by the setupMuso() function. In default the settings parameter is generated automatically.}
|
||||
|
||||
\item{settings}{A list of environmental variables for the Monte Carlo experiment. These settings are generated by the setupMuso function. By default the settings parameter is generated automatically.}
|
||||
\item{inputDir}{The location of the input directory, this directory must content a viable pack of all inputfiles and the executable file.}
|
||||
|
||||
\item{inputDir}{The location of the input directory for the Biome-BGCMuSo model. This directory must contain a viable pack of all input files and the model executable file.}
|
||||
\item{iterations}{number of the monteCarlo run.}
|
||||
|
||||
\item{iterations}{Number of the Monte Carlo simulations.}
|
||||
\item{preTag}{It will be the name of the output files. For example preTag-1.csv, pretag-2csv...}
|
||||
|
||||
\item{preTag}{This defines the name of the output files. This tag will be re-used so that the results will be like preTag-1.csv, preTag-2csv...}
|
||||
\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}{This parameter can be "oneCsv", "moreCsv", and "netCDF". If "oneCsv" is chosen the function creates one large csv file for all of the runs. If "moreCsv" is chosen, every model output goes to separate files. If netCDF is selected the output will be stored in a netCDF file. The default value of the outputTypes is "moreCsv". Note that netCDF is not implemented yet.}
|
||||
\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}{If you select a variable from the possible outputs (by using 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 needs.}
|
||||
\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{varIndex}{This parameter specifies which parameter will be used for the Monte Carlo experiment from the output list of Biome-BGCMuSo (defined by the INI file). You can extract this information from the INI files. At the output parameter specifications, the parameter order will determine this number. For example, if you have set these output parameters: 412, 874, 926, 888, and you want to use 926 for the experiment, you should specify varIndex as 3.}
|
||||
\item{skipSpinup}{With this parameter, you can turn of the spinup phase after the first spinup. I will decrease the time significantly.}
|
||||
|
||||
\item{outputFile}{The filename in which the output of the musoSensi function will be saved. By default it is "sensitivity.csv"}
|
||||
|
||||
\item{plotName}{The name of the output barplot. It's default value is "sensitivity.jpg"}
|
||||
|
||||
\item{skipSpinup}{With this parameter you can turn off the spinup phase after the first spinup was successfully executed (endpoint file is available). This option can dramatically decrease the time needed for the sensitivity analysis. Note that in case of natural vegetation this option might not be feasible. For croplands this is more feasible.}
|
||||
|
||||
\item{calibrationPar}{You might want to change some parameters in your EPC file before you run the modell. You have to select the appropirate model parameters here. You can refer to the parameters by the number of the line in the EPC file where the variables are defined. The indexing of the lines starts at 1, and each line matters (like in any simple text file). You should use a vector for this selection like c(1,5,8)}
|
||||
\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 function performs multiple liear regression based global sensitivity analysis based on the output of musoMonte. First the user has to select the parameters of interest with possible minimum and maximum values. After execution musoSensi will then assign weights to the predefined parameters which means that the importance of the parameters will be ranked. The sensitivity analysis calculates the effect of input variability on the output variability in Monte Carlo framework. The result will largely depend on the selected output variable (GPP, evapotranspiration, LAI, soil water content), and on the parameter ranges. Other factors like climate, management and site specific conditions might affect the results.
|
||||
}
|
||||
\author{
|
||||
Roland HOLLOS
|
||||
This function does regression based sensitivity analysis based on the output of musoMonte.
|
||||
}
|
||||
|
||||
24
RBBGCMuso/man/saveAllMusoPlots.Rd
Normal file
24
RBBGCMuso/man/saveAllMusoPlots.Rd
Normal file
@ -0,0 +1,24 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/plotMuso.R
|
||||
\name{saveAllMusoPlots}
|
||||
\alias{saveAllMusoPlots}
|
||||
\title{saveAllMusoPlots}
|
||||
\usage{
|
||||
saveAllMusoPlots(settings = NULL, plotName = ".png", silent = TRUE,
|
||||
type = "line", colour = NULL, skipSpinup = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{settings}{RBBGCMuso uses variables that define the entire simulation environment. Those environment variables include the name of the INI files, the name of the meteorology files, the path to the model executable and its file name, the entire output list, the entire output variable matrix, the dependency rules for the EPC parameters etc. Using the runMuso function RBBGCMuso can automatically create those environment variables by inspecting the files in the working directory (this happens through the setupMuso function). It means that by default model setup is performed automatically in the background and the user has nothing to do. With this settings parameter we can force runMuso to skip automatic environment setup as we provide the environment settings to runMuso. In a typical situation the user can skip this option.}
|
||||
|
||||
\item{plotName}{The basename for the output plots}
|
||||
|
||||
\item{silent}{if true do not suspect for printfs...}
|
||||
|
||||
\item{destination}{The destination for the output plots, it not exits the function will create it.}
|
||||
}
|
||||
\description{
|
||||
This simple function takes the parameters from the ini files and generates graphics for all output variable.
|
||||
}
|
||||
\author{
|
||||
Roland HOLLOS
|
||||
}
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
* The RBBGCMuso Package
|
||||
#+AUTHOR: Roland HOLLÓS, Dóra HIDY, Zoltán BARCZA
|
||||
*Current version: 0.6.2.0*
|
||||
*Current version: 0.6.3.0*
|
||||
|
||||
RBBGCMuso is an R package which supports the easy but powerful application of the [[http://agromo.agrar.mta.hu/bbgc/][Biome-BGCMuSo]] biogeochemical model in R environment. It also provides some additional tools for the model such as Biome-BGCMuSo optimized Monte-Carlo simulation and global sensitivity analysis. If you would like to use the framework, please read the following description.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user