More documentation and todos

This commit is contained in:
hollorol 2017-07-18 00:57:23 +02:00
parent ad1497ce64
commit 9172edd200
14 changed files with 244 additions and 130 deletions

View File

@ -1,105 +0,0 @@
isLeapyear <- function(year){
##This Boolean function tells us whether the given year is leapyear or not
if(((year%%4==0)&(year%%100!=0))|(year%%400==0)){
return(TRUE)
} else {
return(FALSE)
}
}
dayOfMonths <- function(year,corrigated=TRUE){
##This function tells us how many days are in the months in the choosen year.
dayMonths <- c(31,28,31,30,31,30,31,31,30,31,30,31)
if(corrigated){
if(isLeapyear(year)==TRUE){
dayMonths[2] <-29
}
}
return(dayMonths)
}
dayOfYears <- function(year, corrigated=TRUE){
##This function tells us how many days are in the given year.
if(corrigated){
if(isLeapyear(year)==TRUE){
return(366)
} else {
return(365)
}
} else {
return(365)
}
}
sumDaysOfPeriod <- function(year, periodlen, corrigated=TRUE){
##How many days are from the given date and given period length(periodlen)?
years <- year:(year+periodlen)
if(corrigated){
years100 <-length(which(years%%100==0))
years400 <-length(which(years%%400==0))
years4 <- length(which(years%%4==0))
numberOfLeapdays <- years4-years100+years400
days <- periodlen*365+numberOfLeapdays
return(days)
} else {
days <- periodlen*365
}
}
musoLeapYears <- function(settings){
days <- 365*settings$numyears
years <- settings$startyear:(settings$startyear+settings$numyears-1)
Leapyears <-unlist(lapply(years,isLeapyear))
return(Leapyears)
}
musoDate <- function(settings,timestep="d",combined=TRUE, corrigated=TRUE, format="en"){
##purpose: generate date label for muso
days <- sumDaysOfPeriod(settings$startyear,settings$numyears, corrigated=corrigated)
dates <- matrix(rep(NA,days*3),ncol=3)
dates[1,] <- c(1,1,settings$startyear)
for(i in 2:days){
dates[i,]<-dates[(i-1),]
if((dates[i-1,2]==12)&(dates[i-1,1]==31)){
dates[i,] <-c(1,1,(dates[(i-1),3]+1))
} else {
if(dates[i-1,1]==(dayOfMonths(dates[(i-1),3],corrigated=corrigated)[dates[(i-1),2]] )){
dates[i,]<-c(1,(dates[(i-1),2]+1),dates[(i-1),3])
} else {
dates[i,1]<-dates[(i-1),1]+1
}
}
}
if(format=="en"){
} else {
if(format=="hu"){
dates<-dates[,c(3,2,1)]
} else {
cat("format is coerced to english, because I don't know",format)
}
}
if(combined==TRUE){
dates <- apply(dates,1,function(x) paste(x,collapse="."))
return(dates)
}
return(dates)
}

View File

@ -221,22 +221,39 @@ stamp<-function(path="./"){
if(debugging=="stamplog"){
stampnum<-stamp(dirName)
lapply( logfiles, function (x) file.rename(from=paste(inputloc,x, sep=""), to=paste(dirName, "/",(stampnum+1),"-",x,sep="")))
if(inputloc==outputloc){
lapply( logfiles, function (x) file.rename(from=paste(outputloc,x, sep=""), to=paste(dirName, "/",(stampnum+1),"-",x,sep="")))
} else {
lapply( logfiles, function (x) file.rename(from=paste(outputloc,x, sep="/"), to=paste(dirName, "/",(stampnum+1),"-",x,sep="")))
}
if(errorsign==1){
lapply( logfiles, function (x) file.copy(from=paste(dirName, "/",(stampnum+1),"-",x,sep=""), to=dirERROR ))}
} else { if(debugging){
if(is.null(logfilename)){
lapply( logfiles, function (x) file.rename(from=paste(inputloc,x, sep=""), to=paste(dirName,"/", x, sep="")))
if(inputloc==outputloc){
lapply( logfiles, function (x) file.rename(from=paste(outputloc,x, sep=""), to=paste(dirName,"/", x, sep="")))
} else {
lapply( logfiles, function (x) file.rename(from=paste(outputloc,x, sep="/"), to=paste(dirName,"/", x, sep="")))
}
if(errorsign==1){
lapply( logfiles, function (x) file.rename(from=paste(dirName,"/", x, sep=""), to=dirERROR))
}
} else {
lapply( logfiles, function (x) file.rename(from=paste(inputloc,x, sep=""), to=paste(dirName, "/",logfilename,"-",x,sep="")))
if(inputloc==outputloc){#These are very ugly solutions for a string problem: inputloc: "./", if outputloc equalent of inputloc, it ends with "/", the string manipulation can not handle this. The better solution is easy, but I dont have enough time(Roland Hollo's)
lapply( logfiles, function (x) file.rename(from=paste(outputloc,x, sep=""), to=paste(dirName, "/",logfilename,"-",x,sep="")))
} else {
lapply( logfiles, function (x) file.rename(from=paste(outputloc,x, sep="/"), to=paste(dirName, "/",logfilename,"-",x,sep="")))
}
if(errorsign==1){
lapply( logfiles, function (x) file.rename(from=paste(dirName, "/",logfilename,"-",x,sep=""), to=dirERROR))
}
@ -257,6 +274,7 @@ stamp<-function(path="./"){
}
if(leapYear){
Reva <- corrigMuso(settings,Reva)
rownames(Reva) <- musoDate(settings)

View File

@ -1,3 +1,14 @@
#' isLeapyear
#'
#'This function tells us if its argument a leapyear or not.
#'
#'@param year a year
#'@usage isLeapyear(year)
#'@examples
#' isLeapyear(2004)
#' isLeapyear(2000)
#' isLeapyear(2100)
#'@return TRUE, if leapyear, FALSE if dont.
isLeapyear <- function(year){
##This Boolean function tells us whether the given year is leapyear or not
@ -9,6 +20,22 @@ isLeapyear <- function(year){
}
}
#' dayOfMonths
#'
#'This function gives as a vector which contains the number of the days per each month
#'
#'@param year a year
#'@param corrigated Do you want to handle the leapyears, if yes choose TRUE
#'@usage dayOfMonths(year, corrigated=TRUE)
#'@examples
#' dayOfMonths(2004, corrigated=TRUE)
#'
#' dayOfMonths(2004, corrigated=FALSE)
#'
#'@return vector with 12 element. First is January, the last is December. All of the vector element represents the number of the days in that specific month
dayOfMonths <- function(year,corrigated=TRUE){
##This function tells us how many days are in the months in the choosen year.
@ -24,6 +51,8 @@ dayOfMonths <- function(year,corrigated=TRUE){
return(dayMonths)
}
dayOfYears <- function(year, corrigated=TRUE){
##This function tells us how many days are in the given year.
@ -67,6 +96,8 @@ musoDate <- function(settings,timestep="d",combined=TRUE, corrigated=TRUE, forma
##purpose: generate date label for muso
days <- sumDaysOfPeriod(settings$startyear,settings$numyears, corrigated=corrigated)
dates <- matrix(rep(NA,days*3),ncol=3)

View File

@ -1,4 +1,6 @@
#' 'Funtion for getting cumulative yearly data from observations
#' getyearlycum
#'
#' Funtion for getting cumulative yearly data from observations
#' @author Roland Hollós
#' @param A vector of the daily observations.
#' @return A vector of yearly data
@ -17,10 +19,13 @@ getyearlycum<-function(daily_observations){
return(yearlycum)
}
#' 'Function for getting the maximum values of the years, from daily data
#' getyearlymax
#'
#' Function for getting the maximum values of the years, from daily data
#' @author Roland Hollós
#' @param A vector of the daily observations
#' @param daily_observations vector of the daily observations
#' @return A vector of yearly data
#' @usage getyearlymax(daily_observations)
getyearlymax<-function(daily_observations){
number_of_years<-length(daily_observations)/365
@ -35,12 +40,32 @@ getyearlymax<-function(daily_observations){
return(yearlymax)
}
fextension <- function(x){
#' fextension
#'
#' A function for extracting the extension name from the filename string
#' @author Roland Hollós
#' @param filename The string of the filenam
#' @return the extension of the given file
#' @usage fextension(filename)
#' @example
#' fextension(filename="file.csv")
fextension <- function(filename){
#this function gives back the given filenames extension
fextension <- tail(unlist(strsplit(x,"\\.")),1)
fextension <- tail(unlist(strsplit(filename,"\\.")),1)
}
supportedMuso <- function(x="outputs"){
#'supportedMuso
#'
#' A function for getting the list of the output formats which is supported by RBBGCMuso
#' @author Roland Hollós
#' @param type "outputs" or "message", if you choose "outputs", it gives you a simple vector of the formats, if you choose "message", it gives you a full sentence which contains the same information.
#' @return if you choose "outputs", it gives you a simple vector of the formats, if you choose "message", it gives you a full sentence which contains the same information.
#' @usage supportedMuso(type="outputs")
#' @example
#' supportedMuso(type="outputs")
supportedMuso <- function(type="outputs"){
supportedFormats <- c("xls","xlsx","odt","csv","txt")
if(x=="outputs"){
@ -52,16 +77,26 @@ supportedMuso <- function(x="outputs"){
}
}
insertRow <- function(existingDF, newrow, r){
nr <- nrow(existingDF)
existingDF <- rbind(existingDF,rep(NA,ncol(existingDF)))
existingDF[seq(r+1,nr+1),] <- existingDF[seq(r,nr),]
existingDF[r,] <- newrow
existingDF
}
#' corrigMuso
#'
#' This function leapyear-corrigate the output of the modell
#' @author Roland Hollós
#' @param settings This is the output of the setupMuso() function. It contains all of the RBBGCMuso settings
#' @param data the models outputdata
#' @return It returns the modells leapyear-corrigated output data.
#' @usage corrigMuso(settings, data)
corrigMuso <- function(settings, data){
insertRow <- function(existingDF, newrow, r){
nr <- nrow(existingDF)
existingDF <- rbind(existingDF,rep(NA,ncol(existingDF)))
existingDF[seq(r+1,nr+1),] <- existingDF[seq(r,nr),]
existingDF[r,] <- newrow
existingDF
}
numdays <- nrow(data)
data <- data
numyears <- settings$numyears

View File

@ -10,7 +10,7 @@
#' @param export if it is yes or you give a filename here, it converts the output to the specific extension. For example, if you set export to "example.csv", it converts the output to "csv", if you set it to "example.xls" it converts to example.xls with the xlsx package. If it is not installed it gives back a warning message and converts it to csv.
#' @param silent If you set it TRUE all off the modells output to the screen will be suppressed. It can be usefull, because it increases the model-speed.
#' @param aggressive It deletes every possible modell-outputs from the previous modell runs.
#' @param leapyear future feature.
#' @param leapyear Should the function do a leapyear correction on the outputdata? If TRUE, then the 31.12 day will be doubled.
#' @return It depends on the export parameter. The function returns with a matrix with the modell output, or writes this in a file, which is given previously
#' @usage rungetMuso(settings, timee="d", debugging=FALSE, logfilename=NULL,
#' keepEpc=FALSE, export=FALSE, silent=FALSE, aggressive=FALSE, leapYear=FALSE)

View File

@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/otherUsefullFunctions.R
\name{corrigMuso}
\alias{corrigMuso}
\title{corrigMuso}
\usage{
corrigMuso(settings, data)
}
\arguments{
\item{settings}{This is the output of the setupMuso() function. It contains all of the RBBGCMuso settings}
\item{data}{the models outputdata}
}
\value{
It returns the modells leapyear-corrigated output data.
}
\description{
This function leapyear-corrigate the output of the modell
}
\author{
Roland Hollós
}

View File

@ -0,0 +1,25 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/musoTime.R
\name{dayOfMonths}
\alias{dayOfMonths}
\title{dayOfMonths}
\usage{
dayOfMonths(year, corrigated=TRUE)
}
\arguments{
\item{year}{a year}
\item{corrigated}{Do you want to handle the leapyears, if yes choose TRUE}
}
\value{
vector with 12 element. First is January, the last is December. All of the vector element represents the number of the days in that specific month
}
\description{
This function gives as a vector which contains the number of the days per each month
}
\examples{
dayOfMonths(2004, corrigated=TRUE)
dayOfMonths(2004, corrigated=FALSE)
}

View File

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/otherUsefullFunctions.R
\name{fextension}
\alias{fextension}
\title{fextension}
\usage{
fextension(filename)
}
\arguments{
\item{filename}{The string of the filenam}
}
\value{
the extension of the given file
}
\description{
A function for extracting the extension name from the filename string
}
\author{
Roland Hollós
}

View File

@ -2,7 +2,7 @@
% Please edit documentation in R/otherUsefullFunctions.R
\name{getyearlycum}
\alias{getyearlycum}
\title{'Funtion for getting cumulative yearly data from observations}
\title{getyearlycum}
\usage{
getyearlycum(daily_observations)
}
@ -13,7 +13,7 @@ getyearlycum(daily_observations)
A vector of yearly data
}
\description{
'Funtion for getting cumulative yearly data from observations
Funtion for getting cumulative yearly data from observations
}
\author{
Roland Hollós

View File

@ -2,18 +2,18 @@
% Please edit documentation in R/otherUsefullFunctions.R
\name{getyearlymax}
\alias{getyearlymax}
\title{'Function for getting the maximum values of the years, from daily data}
\title{getyearlymax}
\usage{
getyearlymax(daily_observations)
}
\arguments{
\item{A}{vector of the daily observations}
\item{daily_observations}{vector of the daily observations}
}
\value{
A vector of yearly data
}
\description{
'Function for getting the maximum values of the years, from daily data
Function for getting the maximum values of the years, from daily data
}
\author{
Roland Hollós

View File

@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/musoTime.R
\name{isLeapyear}
\alias{isLeapyear}
\title{isLeapyear}
\usage{
isLeapyear(year)
}
\arguments{
\item{year}{a year}
}
\value{
TRUE, if leapyear, FALSE if dont.
}
\description{
This function tells us if its argument a leapyear or not.
}
\examples{
isLeapyear(2004)
isLeapyear(2000)
isLeapyear(2100)
}

View File

@ -22,7 +22,7 @@ keepEpc=FALSE, export=FALSE, silent=FALSE, aggressive=FALSE, leapYear=FALSE)
\item{aggressive}{It deletes every possible modell-outputs from the previous modell runs.}
\item{leapyear}{future feature.}
\item{leapyear}{Should the function do a leapyear correction on the outputdata? If TRUE, then the 31.12 day will be doubled.}
}
\value{
It depends on the export parameter. The function returns with a matrix with the modell output, or writes this in a file, which is given previously

View File

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/otherUsefullFunctions.R
\name{supportedMuso}
\alias{supportedMuso}
\title{supportedMuso}
\usage{
supportedMuso(type="outputs")
}
\arguments{
\item{type}{"outputs" or "message", if you choose "outputs", it gives you a simple vector of the formats, if you choose "message", it gives you a full sentence which contains the same information.}
}
\value{
if you choose "outputs", it gives you a simple vector of the formats, if you choose "message", it gives you a full sentence which contains the same information.
}
\description{
A function for getting the list of the output formats which is supported by RBBGCMuso
}
\author{
Roland Hollós
}

26
TODOS Normal file
View File

@ -0,0 +1,26 @@
DOCUMENTATIONS
===========================================================
1. Rewriting some of the man pages (for better english)
2. Description for the functions
3. Details for the functions
4. Vignettes...
PROGRAMING
===========================================================
1. Automatic handle for executable files
2. Fix the spinumMuso, and the normalMuso functions
3. Fix the export functions.
4. Build in the mtclim43 to RBBGCMuso
TESTING
===========================================================
1. Jasca
2. Kiskun
3. HHS
4. Bugac
CALIBRATION AND OTHERS
============================================================
1. Local sensitivity analysis
2. Morriss sensitivity analysis
3. MCMC