make musoTime function independent from setupMuso, GLUE...

This commit is contained in:
Roland Hollós 2018-07-26 13:56:56 +02:00
parent 1f770d6426
commit ef09f20c06
6 changed files with 78 additions and 54 deletions

View File

@ -86,3 +86,12 @@ stampAndDir <- function(outputLoc,names,stampDir, wrongDir, type="output", error
} }
compareNA <- function(v,a){
compared<- (v==a)
compared[is.na(compared)] <- FALSE
return(compared)
}

View File

@ -283,9 +283,9 @@ calibMuso <- function(settings=NULL,parameters=NULL, timee="d", debugging=FALSE,
if(leapYear){ if(leapYear){
Reva <- corrigMuso(settings,Reva) Reva <- corrigMuso(settings,Reva)
rownames(Reva) <- musoDate(settings) rownames(Reva) <- musoDate(settings$startYear,settings$numYears)
} else { } else {
rownames(Reva) <- musoDate(settings, corrigated=FALSE) rownames(Reva) <- musoDate(settings$startYear, settings$numYears, corrigated=FALSE)
} }

View File

@ -1,49 +1,66 @@
#' musoGlue ## #' musoGlue
#' ## #'
#' This ... ## #' This ...
#' #' @author Roland Hollos ## #' #' @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 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 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 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 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 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 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 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 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 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 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 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 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. ## #' @param skipSpinup With this parameter, you can turn of the spinup phase after the first spinup. I will decrease the time significantly.
#' @import dplyr ## #' @import dplyr
#' @import graphics ## #' @import graphics
#' @import grDevices ## #' @import grDevices
#' @import ggplot2 ## #' @import ggplot2
#' @export ## #' @export
musoGLUE <- function(monteCarloFile = NULL, ## musoGLUE <- function(monteCarloFile = NULL,
parameters = NULL, ## parameters = NULL,
settings = NULL, ## settings = NULL,
inputDir = "./", ## inputDir = "./",
outLoc = "./calib", ## outLoc = "./calib",
iterations = 30, ## filterCol=8,
preTag = "mont-", ## filterFlag=1,
outputType = "moreCsv", ## iterations = 30,
fun = mean, ## preTag = "mont-",
varIndex = 1, ## outputType = "moreCsv",
outputFile = "sensitivity.csv", ## fun = mean,
plotName = "sensitivity.png", ## varIndex = 1,
plotTitle = "Sensitivity", ## obsIndex =
skipSpinup = FALSE, ## outputFile = "sensitivity.csv",
dpi=300){ ## plotName = "sensitivity.png",
## plotTitle = "Sensitivity",
## skipSpinup = FALSE,
## dpi=300){
rmse <- function(modelled, measured){ ## rmse <- function(modelled, observed){
(modelled-measured) %>% ## (modelled-observed) %>%
(function(x) {x*x}) %>% # It is more clear than `^`(.,2) form, even it is longer ## (function(x) {x*x}) %>% # It is more clear than `^`(.,2) form, even it is longer
sum %>% ## sum %>%
sqrt ## sqrt
} ## }
## likelihoodNormal <- function(modelled, observed){
## if (sd <= 0){
## return(-Inf)
## } else {
## filtered <- observed[,filterCol]!=filterFlag
## }
## }
@ -52,6 +69,4 @@ musoGLUE <- function(monteCarloFile = NULL,
## }
}

View File

@ -116,16 +116,16 @@ musoLeapYears <- function(settings){
#' @return The exact date-vectors for the BioBGC-MuSo output. You can use this for labelling purpose for example. #' @return The exact date-vectors for the BioBGC-MuSo output. You can use this for labelling purpose for example.
#' @export #' @export
musoDate <- function(settings,timestep="d",combined=TRUE, corrigated=TRUE, format="en"){ musoDate <- function(startYear, numYears, timestep="d", combined=TRUE, corrigated=TRUE, format="en"){
##purpose: generate date label for muso ##purpose: generate date label for muso
days <- sumDaysOfPeriod(settings$startyear,settings$numYears, corrigated=corrigated) days <- sumDaysOfPeriod(startYear, numYears, corrigated=corrigated)
dates <- matrix(rep(NA,days*3),ncol=3) dates <- matrix(rep(NA,days*3),ncol=3)
dates[1,] <- c(1,1,settings$startyear) dates[1,] <- c(1,1,startYear)
for(i in 2:days){ for(i in 2:days){
dates[i,]<-dates[(i-1),] dates[i,]<-dates[(i-1),]
if((dates[i-1,2]==12)&(dates[i-1,1]==31)){ if((dates[i-1,2]==12)&(dates[i-1,1]==31)){

View File

@ -252,9 +252,9 @@ rungetMuso <- function(settings, timee="d", debugging=FALSE, logfilename=NULL, k
if(leapYear){ if(leapYear){
Reva <- corrigMuso(settings,Reva) Reva <- corrigMuso(settings,Reva)
rownames(Reva) <- musoDate(settings) rownames(Reva) <- musoDate(settings$startYear, settings$numYears)
} else { } else {
rownames(Reva) <- musoDate(settings, corrigated=FALSE) rownames(Reva) <- musoDate(settings$startYear, settings$numYears, corrigated=FALSE)
} }
if(export!=FALSE){ if(export!=FALSE){

View File

@ -221,8 +221,8 @@ setupMuso <- function(executable=NULL,
numValues <- as.numeric(unlist(strsplit(grep("number of daily output variables",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]) numValues <- as.numeric(unlist(strsplit(grep("number of daily output variables",iniFiles[[2]],value=TRUE),"[\ \t]"))[1])
## numValues will be replaced to numVar ## numValues will be replaced to numVar
## numValues<-unlist(read.table(iniInput[2],skip=102,nrows = 1)[1]) ## numValues<-unlist(read.table(iniInput[2],skip=102,nrows = 1)[1])
startyear <- as.numeric(unlist(strsplit(grep("first simulation year",iniFiles[[2]],value=TRUE),"[\ \t]"))[1]) startYear <- as.numeric(unlist(strsplit(grep("first simulation year",iniFiles[[2]],value=TRUE),"[\ \t]"))[1])
numData[1] <- numValues * sumDaysOfPeriod(startyear,numYears,corrigated=leapYear) numData[1] <- numValues * sumDaysOfPeriod(startYear,numYears,corrigated=leapYear)
numData[2] <- numYears * numValues*12 numData[2] <- numYears * numValues*12
numData[3] <- numYears * numValues numData[3] <- numYears * numValues
@ -255,7 +255,7 @@ setupMuso <- function(executable=NULL,
nitInput=inputs$nitInput, nitInput=inputs$nitInput,
inputFiles=inputFiles, inputFiles=inputFiles,
numData=numData, numData=numData,
startyear=startyear, startYear=startYear,
numYears=numYears, numYears=numYears,
outputVars=outputVars outputVars=outputVars
) )