Skip to content

Commit

Permalink
version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ecor authored and gaborcsardi committed Jan 4, 2014
1 parent f5ccbbd commit 5e2ea6c
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 61 deletions.
35 changes: 16 additions & 19 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@ Title: RClimMAWGEN (R Climate Index Multi-site Auto-regressive Weather
indices from RMAWGEN generations.
Type: Package
Author: Emanuele Cordano, Annalisa Di Piazza
Description: This package contains wrapper functions and methods which
allow to use "climdex.pcic" and "RMAWGEN" packages. With this
simple approach it is possible to calculate climate change
indices, suggested by the WMO-CCL, CLIVAR,
ETCCDMI(http://www.climdex.org),on stochastic generations of
temperature and precipitation time series, obtained by the
application of RMAWGEN. Each index can be applied to both
observed data and to synthetic time series produced by the
Weather Generator, over a reference period (e.g. 1981-2010, as
in the example). It contains also functions and methods to
evaluate the generated time series of climate change indices
consistency by statistical
tests.Bugs/comments/questions/collaboration of any kind are
warmly welcomed.
Version: 1.0
Description: This package contains wrapper functions and methods which allow to
use "climdex.pcic" and "RMAWGEN" packages. With this simple approach it is
possible to calculate climate change indices, suggested by the WMO-CCL,
CLIVAR, ETCCDMI(http://www.climdex.org),on stochastic generations of
temperature and precipitation time series, obtained by the application of
RMAWGEN. Each index can be applied to both observed data and to synthetic
time series produced by the Weather Generator, over a reference period
(e.g. 1981-2010, as in the example). It contains also functions and methods
to evaluate the generated time series of climate change indices consistency
by statistical tests.Bugs/comments/questions/collaboration of any kind are
warmly welcomed.
Version: 1.1
Repository: CRAN
Date: 2013-02-25
Date: 2014-01-04
Depends: R (>= 2.10),climdex.pcic,RMAWGEN
URL: http://presentations.copernicus.org/EGU2012-5404_presentation.pdf
Collate: 'accepted.R' 'as.clindex.data.frame.R' 'as.data.frame.R'
'clindex.data.frame.R' 'ks.test.R' 'RClimMAWGEN-package.R'
'climdex.data.frame.R' 'ks.test.R' 'RClimMAWGEN-package.R'
'temperature_max.R' 'temperature_min.R' 'wilcox.test.R'
Packaged: 2013-02-25 19:04:06 UTC; ecor
Packaged: 2014-01-05 14:33:05 UTC; ecor
NeedsCompilation: no
Date/Publication: 2013-02-25 20:16:31
Date/Publication: 2014-01-05 17:09:55
18 changes: 9 additions & 9 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
7531ef00a37c5635fb1155e06b449909 *DESCRIPTION
258069e70c4caefef072e359ecf2f1fa *NAMESPACE
750b57799258a2c90ade5d9aea2aa05e *R/RClimMAWGEN-package.R
d4ba81fc9e072b4e35e6dbb3bab0e2bd *DESCRIPTION
f5ba90b8d73643e805bbd63c68b622d6 *NAMESPACE
15446af6aedc46bbb835e3a0536a94b8 *R/RClimMAWGEN-package.R
89b143a32235e88511ce892115b8d852 *R/accepted.R
1b75f811fe6a60ff76d63b2a99ec7950 *R/as.clindex.data.frame.R
4e1b25794b176c9000fe12d14b0534d4 *R/as.data.frame.R
f5f8fa17b0253e317d345882b71af30e *R/clindex.data.frame.R
965e3df70927a31dae3cb51eeae99cd6 *R/climdex.data.frame.R
a9dadc0e4a367c6c45081d344ef1e843 *R/ks.test.R
9920d3b4d7335245432053e20a73da42 *R/temperature_max.R
583b122acbed0c0a69f19cbf19e01d30 *R/temperature_min.R
b5cb98d1c1bed23458625c5a2e1c2e5d *R/wilcox.test.R
74fe9a8e7d1d29c39ed9ebb97e48e2b9 *data/datalist
4ac77bbbb2c8a1256ff543572f98c014 *data/generation_p1.rda
161235ebd02e9af7eaedf29eb852c978 *data/trentino_1958_2010.rda
030c21fd22a4e9efa2a3a8a153945e9e *data/generation_p1.rda
8e81bde14d04cc9004b7003ef96fcf82 *data/trentino_1958_2010.rda
c92f791f23d137b27acae1089a503533 *inst/examples/generations.R
eed3828dd6a287a5df3e2d1e8116785d *man/RClimMAWGEN-package.Rd
df50eb27c6824b99d8c0ea9ca5f9e976 *man/RClimMAWGEN-package.Rd
283ee7c4c01a34652bf6ac5be2822674 *man/accepted.Rd
e76e0ca68cb0e66ea54368721ffeffb2 *man/as.climdex.data.frame.Rd
70f19ec0724aae951e928a4dec104ade *man/as.data.frame.Rd
77005f33a88701c057a1e89a64523850 *man/climdex.data.frame.Rd
bd96fcd5ad3ee7dc8e04f1d76a6436db *man/generation_p1.Rd
176e19c81388b3c705194305c4367b12 *man/climdex.data.frame.Rd
d9db0e91d69f0cde7074606482684266 *man/generation_p1.Rd
779db5334535131e58cf80e7c2182aa7 *man/ks.test.climdex.data.frame.Rd
219256cdfbd791e3895e03db5c362c41 *man/temperature_max_daily.Rd
a824610f17fd73e6e1d08b6a74f55d46 *man/temperature_min_daily.Rd
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export(climdex.data.frame)
export(ks.test.climdex.data.frame)
export(temperature_max_daily)
export(temperature_min_daily)
import(climdex.pcic)
import(RMAWGEN)
import(stats)
S3method(as.data.frame,climdex.data.frame)
S3method(wilcox.test,climdex.data.frame)
4 changes: 2 additions & 2 deletions R/RClimMAWGEN-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#' \tabular{ll}{
#' Package: \tab RClimMAWGEN\cr
#' Type: \tab Package\cr
#' Version: \tab 1.0\cr
#' Date: \tab 2013-02-21\cr
#' Version: \tab 1.1\cr
#' Date: \tab 2014-01-04\cr
#' License: \tab GPL (>= 2) \cr
#' LazyLoad: \tab yes\cr
#' Depends: climdex.pcic,RMAWGEN \cr
Expand Down
120 changes: 102 additions & 18 deletions R/clindex.data.frame.R → R/climdex.data.frame.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

NULL
#'
#' Create input object for clim,ete index analyis from RMAWWGEN output.
#' Create input object for clim,ete index analyis from RMAWGEN output.
#'
#' @param data data.frame containing realizations of weather variables, e.g. the one retured as \code{output} by \code{\link{ComprehensiveTemperatureGenerator}}
#' @param station names of weather stations where to apply climate indices
Expand All @@ -17,11 +17,27 @@ NULL
#' @param prefix name for time series on which climate indices are calculated.
#' @param date.series see \code{\link{climdexInput.raw}}. If missing, it is automatically calculated from \code{start_date} and \code{end_date}
#' @param frequency string value. Default is \code{c("yearly","monthly","daily")}. Set one of these, if the climate indices are referred to each year, month or day respectively.
#'
#' @param freq string value. Default is \code{c("default","monthly", "annual")}. It has the same role of \code{"frequency"} and is used in several \code{cilmdex.pcic} indices. If it is omitted (Default) the frequency is obtaind by \code{frequency} argument. See \code{\link{climdex.tn90p}},\code{\link{climdex.tx90p}} .
#' @param ... further arguments
#'
#' @title ClimDex Data Frame
#'
#'
# Check usage coherence before submitting to CRAN
#' @usage climdex.data.frame(data, station, realization_TN,
#' realization_TX, realization_PREC,
#' start_date = "1981-01-01", end_date = "2010-12-31",
#' climate_index = "climdex.gsl", frequency = c("yearly", "monthly", "daily"),
#' freq = c("default", "monthly", "annual"),
#' date.series = seq(as.PCICt(start_date, cal = "gregorian"), as.PCICt(end_date, cal = "gregorian"), by = "days"),
#' base.range = c(1990, 2002), n = 5, prefix = NULL, ...)
#'

#'
#' @return a \code{climdex.data.frame} object (see the variable \code{climdex} in the examples.)
#' @export
#' @seealso \code{\link{as.climdex.data.frame}},\code{\link{climdexInput.raw}}
#' @seealso \code{\link{as.climdex.data.frame}},\code{\link{climdexInput.raw}},\code{\link{climdex.tn90p}},\code{\link{climdex.tx90p}}
#' @import climdex.pcic RMAWGEN
#'
#' @references \url{http://www.climdex.org}
#' @author Emanuele Cordano, Annalisa Di Piazzaa
Expand All @@ -30,7 +46,8 @@ NULL
#' @examples
#'rm(list=ls())
#'library(RClimMAWGEN)
#' # generated and observed daily temperature data for the considering period (1981-2010)(RMAWGEN output data structure)
#' # generated and observed daily temperature data for the considering period
#' # (1981-2010)(RMAWGEN output data structure)
#' data (generation_p1)
#'
#'
Expand All @@ -51,20 +68,39 @@ NULL
#' start_date = "1981-01-01"
#' end_date = "2010-12-31"
#'
#' # The indices \link{climdex.tn90p},\link{climdex.tx90p} are considered in this example
#' climate_indices = c("climdex.tn90p","climdex.tx90p")
#'
#' frequency = "monthly"
#'
#' date.series = seq(as.PCICt(start_date, cal = "gregorian"), as.PCICt(end_date, cal = "gregorian"), by = "days")
#' date.series = seq(as.PCICt(start_date, cal = "gregorian"),
#' as.PCICt(end_date, cal = "gregorian"), by = "days")
#'
#' base.range = c(1990, 2002)
#' n = 5
#' prefix = NULL
#'
#'
#' climdex <- climdex.data.frame(data=realizations, station=stations, realization_TN=realizations_TN,realization_TX=realizations_TX,realization_PREC=NULL, start_date= start_date, end_date = end_date ,climate_index = climate_indices,frequency = frequency,date.series = date.series,base.range = base.range, n = n, prefix = prefix)
#'
#' climdex <- climdex.data.frame(data=realizations, station=stations,
#' realization_TN=realizations_TN,realization_TX=realizations_TX,realization_PREC=NULL,
#' start_date= start_date, end_date = end_date ,climate_index = climate_indices,
#' frequency = frequency,date.series = date.series,base.range = base.range,
#' n = n, prefix = prefix)
#'
#' str(climdex)
#'
#' ## Function 'climdex.data.frame' can be also used with annual frequency
#' ## The following lines are now commented because the elapsed time is too long!!
#' ## Please uncomment to run the following lines to run the function.
#' # climdex_annual <- climdex.data.frame(data=realizations, station=stations,
#' # realization_TN=realizations_TN,realization_TX=realizations_TX,realization_PREC=NULL,
#' # start_date= start_date, end_date = end_date ,climate_index = climate_indices,
#' # frequency = "yearly",date.series = date.series,base.range = base.range,
#' # n = n, prefix = prefix)
#' #
#' # str(climdex_annual)
#'
#'
#' # Wilcoxon test between observed and generated climate indices
#'
#' observed <- "T0129__Tn_mes__climdex.tx90p"
Expand Down Expand Up @@ -95,14 +131,30 @@ climdex.data.frame <- function(data,
realization_TX,
realization_PREC,
start_date="1981-01-01",
end_date="2010-12-31",climate_index="climdex.gsl",frequency=c("yearly","monthly","daily"),
date.series=seq(as.PCICt(start_date, cal="gregorian"), as.PCICt(end_date, cal="gregorian"), by="days"),base.range=c(1990, 2002),n=5,prefix=NULL){
end_date="2010-12-31",climate_index="climdex.gsl",
frequency=c("yearly","monthly","daily"),
freq=c("default","monthly", "annual"),
date.series=
seq(as.PCICt(start_date, cal="gregorian"),
as.PCICt(end_date, cal="gregorian"),
by="days"),
base.range=c(1990, 2002),n=5,prefix=NULL,...){

out <- NULL

daily=FALSE
monthly=FALSE
yearly=FALSE


frequency <- frequency[1]
freq <- freq[1]

if (freq!="default") frequency <- freq
if (freq=="default") freq <- frequency
if (frequency=="annual") frequency <- "yearly"
if (freq=="yearly") freq <- "annual"

if (frequency=="daily") daily=TRUE
if (frequency=="monthy") monthly=TRUE
if (frequency=="yearly") yearly=TRUE
Expand All @@ -121,34 +173,66 @@ climdex.data.frame <- function(data,


temp <- climdexInput.raw(tx,tn,prec, date.series, date.series, date.series,base.range,n)

###str(temp)

if(frequency=="yearly"){
## UNCOMMENTED BY EC ON 2014-02-01
if (frequency=="yearly"){

years <- unique(as.character(temp@annual.factor))
years <- unique(as.character(temp@date.factors$annual))

out <- as.data.frame(array(NA,c(length(years),length(climate_index))))

}
else if (frequency=="monthly") {

months <- unique(as.character(temp@monthly.factor))
months <- unique(as.character(temp@date.factors$monthly))

out <- as.data.frame(array(NA,c(length(months),length(climate_index))))
} else if (frequency=="daily") {

out <- array(NA,c(nrow(tx),length(climate_index)))
}

## END UNCOMMENTED BY EC ON 2014-02-01
names(out) <- paste(prefix,climate_index,sep="__")


for (f in climate_index){


call <- call(f,temp)


# list <- list(ci=temp,...)




names_args <- names(formals(f))
nargs <- formals("climdex.data.frame")
nargs <- nargs[names(nargs) %in% names_args]

names <- names(nargs)
nargs <- lapply(X=names,FUN=function(x) {get(x)})
names(nargs) <- names



args <- list(ci=temp,...)
args[names] <- nargs





name <- names(out)[climate_index==f]
out[,name] <- as.vector(eval(call))


## print("out")
## str(out)
## str(as.vector(eval(call)))
## print("end out")

out[,name] <- as.vector(do.call(f,args))
}

} else {
Expand All @@ -162,8 +246,8 @@ climdex.data.frame <- function(data,
name <- paste(it,realization_TN[r],sep="__")

temp0 <- climdex.data.frame(data,station=it,realization_TN=realization_TN[r],
realization_TX=realization_TX[r],realization_PREC=realization_PREC[r],frequency=frequency,
date.series=date.series,base.range=base.range,n=n,prefix=name,climate_index=climate_index)
realization_TX=realization_TX[r],realization_PREC=realization_PREC[r],frequency=frequency,freq=freq,
date.series=date.series,base.range=base.range,n=n,prefix=name,climate_index=climate_index,...)



Expand Down
Binary file modified data/generation_p1.rda
Binary file not shown.
Binary file modified data/trentino_1958_2010.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/RClimMAWGEN-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
\details{
\tabular{ll}{ Package: \tab RClimMAWGEN\cr Type: \tab
Package\cr Version: \tab 1.0\cr Date: \tab 2013-02-21\cr
Package\cr Version: \tab 1.1\cr Date: \tab 2014-01-04\cr
License: \tab GPL (>= 2) \cr LazyLoad: \tab yes\cr
Depends: climdex.pcic,RMAWGEN \cr }
}
Expand Down

0 comments on commit 5e2ea6c

Please sign in to comment.