add some more plotting functions

This commit is contained in:
Roland Hollós 2018-09-14 14:58:09 +02:00
parent 3cba0ca4a2
commit 7e143ca21c
8 changed files with 86 additions and 14 deletions

View File

@ -18,7 +18,9 @@ Imports:
magrittr, magrittr,
dplyr, dplyr,
ggplot2, ggplot2,
rmarkdown rmarkdown,
tibble,
tidyr
LinkingTo: Rcpp LinkingTo: Rcpp
Maintainer: Roland Hollo's <hollorol@gmail.com> Maintainer: Roland Hollo's <hollorol@gmail.com>
RoxygenNote: 6.0.1 RoxygenNote: 6.0.1

View File

@ -14,6 +14,7 @@ export(musoRandomizer)
export(musoSensi) export(musoSensi)
export(normalMuso) export(normalMuso)
export(plotMuso) export(plotMuso)
export(plotMusoWithData)
export(rungetMuso) export(rungetMuso)
export(setupMuso) export(setupMuso)
export(spinupMuso) export(spinupMuso)

View File

@ -74,8 +74,63 @@ plotMuso <- function(settings=NULL,
} }
}
#'plot the BBGCMuso output with data
#'
#' This function runs the BBGC-MuSo model and reads in its outputfile in a very structured way, and after that plot the results automaticly along with a given measurement
#'
#' @author Roland Hollos, Dora Hidy
#' @param settings You have to run the setupMuso function before rungetMuso. It is its output which contains all of the necessary system variables. It sets the whole environment
#' @param sep This is the separator used in the measurement file
#' @param savePlot It it is specified, the plot will be saved in a format specified with the immanent extension
#' @param variable The name of the output variable to plot
#' @param NACHAR This is not implemented yet
#' @param csvFile The file of the measurement. It must contain a header.
#' @usage plotMuso(settings, variable,
#' timee="d", silent=TRUE,
#' debugging=FALSE, keepEpc=FALSE,
#' logfilename=NULL, aggressive=FALSE,
#' leapYear=FALSE, export=FALSE)
#' @import ggplot2
#' @export
plotMusoWithData <- function(csvFile, variable, NACHAR=NA, settings=NULL, sep=",", savePlot=NULL){
if(!is.na(NACHAR)){
warning("NACHAR is not implemented yet")
}
if(is.null(settings)){
settings <- setupMuso()
}
numberOfYears <- settings$numYears
startYear <- settings$startYear
yearVec <- seq(from = startYear, length=numberOfYears,by=1)
data <- read.table(csvFile,header = TRUE, sep = ",") %>%
select(variable)
baseData <- calibMuso(settings,silent=TRUE) %>%
as.data.frame() %>%
tibble::rownames_to_column("date") %>%
dplyr::mutate(date2=date,date=as.Date(date,"%d.%m.%Y"),yearDay=rep(1:365,numberOfYears)) %>%
tidyr::separate(date2,c("day","month","year"),sep="\\.")
baseData <- cbind(baseData,data)
colnames(baseData)[ncol(baseData)] <- "measuredData"
p <- baseData %>%
ggplot(aes_string("date",variable)) +
geom_line(colour = "blue") +
geom_point(aes(date,measuredData)) +
labs(y = paste0(variable,"_measured"))+
theme(axis.title.x = element_blank())
if(!is.null(savePlot)){
return(p)
} else {
ggsave(savePlot,p)
return(p)
}
} }

View File

@ -12,7 +12,7 @@ keepEpc=FALSE, export=FALSE, silent=FALSE, aggressive=FALSE, leapYear=FALSE)
\item{parameters}{In the settings variable you have set the row indexes of the variables, you wish to change. In this parameter you can give an exact value for them in a vector like: c(1,2,3,4)} \item{parameters}{In the settings variable you have set the row indexes of the variables, you wish to change. In this parameter you can give an exact value for them in a vector like: c(1,2,3,4)}
\item{timee}{The required timesteps in the modell output. It can be "d", if it is daily, "m", if it's monthly, "y", it it is yearly} \item{timee}{The required timesteps in the modell output. It can be "d", if it is daily, "m", if it's monthly, "y", it it is yearly. I recommend to use daily data, the yearly and monthly data is not well-tested yet.}
\item{debugging}{If it is TRUE, it copies the log file to a Log directory to store it, if it is stamplog it contatenate a number before the logfile, which is one more than the maximum of the represented ones in the LOG directory. If it is true or stamplog it collects the "wrong" logfiles} \item{debugging}{If it is TRUE, it copies the log file to a Log directory to store it, if it is stamplog it contatenate a number before the logfile, which is one more than the maximum of the represented ones in the LOG directory. If it is true or stamplog it collects the "wrong" logfiles}
@ -27,6 +27,12 @@ keepEpc=FALSE, export=FALSE, silent=FALSE, aggressive=FALSE, leapYear=FALSE)
\item{aggressive}{It deletes every possible modell-outputs from the previous modell runs.} \item{aggressive}{It deletes every possible modell-outputs from the previous modell runs.}
\item{leapYear}{Should the function do a leapyear correction on the outputdata? If TRUE, then the 31.12 day will be doubled.} \item{leapYear}{Should the function do a leapyear correction on the outputdata? If TRUE, then the 31.12 day will be doubled.}
\item{keepBinary}{In default RBBGCMuso to keep working area as clean as possible, deletes all the regular output files. The results are directly printed to the standard output, but you can redirect it, and save it to a variable, or you can export your results to the desired destination in a desired format. Whith this variable you can enable to keep the binary output files. If you want to set the location of the binary output, please take a look at the binaryPlace argument.}
\item{binaryPlace}{The place of the binary output files.}
\item{fileToChange}{You can change any line of the epc or the ini file, you just have to specify with this variable which file you van a change. Two options possible: "epc", "ini"}
} }
\value{ \value{
No return, outputs are written to file No return, outputs are written to file

View File

@ -4,12 +4,10 @@
\alias{musoDate} \alias{musoDate}
\title{It generates BiomeBGC-MuSo dates} \title{It generates BiomeBGC-MuSo dates}
\usage{ \usage{
musoDate(settings, timestep = "d", combined = TRUE, corrigated = TRUE, musoDate(startYear, numYears, timestep = "d", combined = TRUE,
format = "en") corrigated = TRUE, format = "en")
} }
\arguments{ \arguments{
\item{settings}{You have to run the setupMuso function before musoDate. It is its output which contains all of the necessary system variables. It sets the whole environment.}
\item{timestep}{timestep, which can be daily ("d"), monthly ("m"), yearly("y")} \item{timestep}{timestep, which can be daily ("d"), monthly ("m"), yearly("y")}
\item{combined}{If FALSE the output is a vector of 3 string: day, month year, if true, these strings will be concatenated.} \item{combined}{If FALSE the output is a vector of 3 string: day, month year, if true, these strings will be concatenated.}
@ -17,6 +15,8 @@ musoDate(settings, timestep = "d", combined = TRUE, corrigated = TRUE,
\item{corrigated}{If True it counts with leapyears, else dont.} \item{corrigated}{If True it counts with leapyears, else dont.}
\item{format}{This is the format of the date. It can be "en" (dd.mm.yyyy), or "hu" (yyyy.mm.dd)} \item{format}{This is the format of the date. It can be "en" (dd.mm.yyyy), or "hu" (yyyy.mm.dd)}
\item{settings}{You have to run the setupMuso function before musoDate. It is its output which contains all of the necessary system variables. It sets the whole environment.}
} }
\value{ \value{
The exact date-vectors for the BioBGC-MuSo output. You can use this for labelling purpose for example. The exact date-vectors for the BioBGC-MuSo output. You can use this for labelling purpose for example.

View File

@ -4,9 +4,10 @@
\alias{musoMonte} \alias{musoMonte}
\title{musoMonte} \title{musoMonte}
\usage{ \usage{
musoMonte(settings = NULL, parameters, inputDir = "./", musoMonte(settings = NULL, parameters = NULL, inputDir = "./",
outLoc = "./calib", iterations = 10, preTag = "mont-", outLoc = "./calib", iterations = 10, preTag = "mont-",
outputType = "moreCsv", fun = mean, varIndex = 1, silent = TRUE, ...) outputType = "moreCsv", fun = mean, varIndex = 1, silent = TRUE,
skipSpinup = FALSE, debugging = FALSE, keepEpc = FALSE, ...)
} }
\arguments{ \arguments{
\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 montecarlos environmental variables. It is generated by the setupMuso() function. In default the settings parameter is generated automatically.}
@ -25,6 +26,10 @@ musoMonte(settings = NULL, parameters, inputDir = "./",
\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 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{debugging}{If you set this parameter, you can save every logfile, and RBBGCMuso will select those which contains errors.}
\item{keepEpc}{if you set keepEpc also true, it will save every selected epc file, and put the wrong ones in the WRONGEPC directory.}
\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)} \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{ \description{

View File

@ -5,10 +5,11 @@
\title{musoSensi} \title{musoSensi}
\usage{ \usage{
musoSensi(monteCarloFile = NULL, parameters = NULL, settings = NULL, musoSensi(monteCarloFile = NULL, parameters = NULL, settings = NULL,
parametersFromFile = FALSE, inputDir = "./", outLoc = "./calib", inputDir = "./", outLoc = "./calib", iterations = 30,
iterations = 30, preTag = "mont-", outputType = "moreCsv", fun = mean, preTag = "mont-", outputType = "moreCsv", fun = mean,
varIndex = 1, outputFile = "sensitivity.csv", varIndex = 1, outputFile = "sensitivity.csv",
plotName = "sensitivity.png", plotTitle = "Sensitivity", dpi = 300) plotName = "sensitivity.png", plotTitle = "Sensitivity",
skipSpinup = FALSE, dpi = 300)
} }
\arguments{ \arguments{
\item{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.} \item{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.}
@ -33,6 +34,8 @@ musoSensi(monteCarloFile = NULL, parameters = NULL, settings = NULL,
\item{plotName}{The name of the output barplot. It's default value is: "sensitivity.jpg"} \item{plotName}{The name of the output barplot. It's default value is: "sensitivity.jpg"}
\item{skipSpinup}{With this parameter, you can turn of the spinup phase after the first spinup. I will decrease the time significantly.}
\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)} \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{ \description{

View File

@ -4,8 +4,8 @@
\alias{stampAndDir} \alias{stampAndDir}
\title{stampAndCopy} \title{stampAndCopy}
\usage{ \usage{
stampAndDir(outputLoc, names, stampDir, wrongDir, type = "output", errorsign, stampAndDir(outputLoc, names, stampDir, wrongDir, type = "output",
logfiles) errorsign, logfiles)
} }
\arguments{ \arguments{
\item{outputLoc}{This is the location of the output files.} \item{outputLoc}{This is the location of the output files.}