From aff21eb0a294746e2b8b21ea36541d81e0b534f4 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 21 Jan 2020 10:59:16 +0100 Subject: [PATCH 1/2] previous version Extremes function with working examples --- R/Extremes.R | 9 +++++---- man/Extremes.Rd | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/Extremes.R b/R/Extremes.R index a609340..8fc5ca2 100644 --- a/R/Extremes.R +++ b/R/Extremes.R @@ -91,9 +91,9 @@ Extremes <- function(data, threshold, op = ">", min.length = 6, spells.can.span. if (!any(class(dates) %in% c('POSIXct'))) { dates <- try( { if (is.character(dates)) { - as.POSIXct(dates, format = "%Y%m%d", tz = "CET") + as.POSIXct(dates, format = "%Y%m%d") } else { - as.POSIXct(dates, format = "%Y%m%d", tz = "CET") + as.POSIXct(dates) } }) if ('try-error' %in% class(dates) | sum(is.na(dates)) == length(dates)) { @@ -113,8 +113,8 @@ Extremes <- function(data, threshold, op = ">", min.length = 6, spells.can.span. if (stop_error) { stop("Parameter 'dates' must be of the same length as the 'time' dimension of the parameter 'data'.") } - dates <- as.PCICt(dates, cal = calendar, format = "%Y%m%d") -# dates = as.character(dates) + dates <- as.PCICt(dates, cal = calendar) + dates = as.character(dates) jdays <- as.numeric(strftime(dates, format = "%j")) if (calendar == "gregorian" | calendar == "standard" | calendar == "proleptic_gregorian") { year <- as.numeric(strftime(dates, format = "%Y")) @@ -215,3 +215,4 @@ Extremes <- function(data, threshold, op = ">", min.length = 6, spells.can.span. threshold,op, min.length, spells.can.span.years, max.missing.days) } + diff --git a/man/Extremes.Rd b/man/Extremes.Rd index 61b312a..0939fa6 100644 --- a/man/Extremes.Rd +++ b/man/Extremes.Rd @@ -46,8 +46,7 @@ This routine compares data to the thresholds using the given operator, generatin ##Example synthetic data: data <- 1:(2 * 3 * 372 * 1) dim(data) <- c(time = 372, lon = 2, lat = 3, model = 1) -time <- as.POSIXct(paste(sort(rep(1900:1911, 31)), 1, 1:31, sep = "-"), tz = "CET", - format = "\%Y-\%m-\%d") +time <- as.POSIXct(paste(sort(rep(1900:1911, 31)), 1, 1:31, sep = "-"), tz = "CET") metadata <- list(time = list(standard_name = 'time', long_name = 'time', calendar = 'noleap', units = 'days since 1970-01-01 00:00:00', prec = 'double', dim = list(list(name = 'time', unlim = FALSE)))) -- GitLab From 4d85a6564b1133e3a3f3f388619935bddaacefcc Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 21 Jan 2020 13:16:16 +0100 Subject: [PATCH 2/2] reference to climdex.pcic and bumped version number --- DESCRIPTION | 6 +++--- R/Climdex.R | 5 ++++- man/Climdex.Rd | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8293274..3259032 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,11 @@ Package: ClimProjDiags Title: Set of Tools to Compute Various Climate Indices -Version: 0.0.4 +Version: 0.1.0 Authors@R: c( person("BSC-CNS", role = c("aut", "cph")), - person("Alasdair", "Hunter", , "alasdair.hunter@bsc.es", role = "aut"), - person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("aut", "cre")), + person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-8568-3071")), person("Nicolau", "Manubens", , "nicolau.manubens@bsc.es", role = "ctb"), + person("Alasdair", "Hunter", , "alasdair.hunter@bsc.es", role = "aut"), person("Louis-Philippe", "Caron", , "louis-philippe.caron@bsc.es", role = "ctb")) Description: Set of tools to compute metrics and indices for climate analysis. The package provides functions to compute extreme indices, evaluate the diff --git a/R/Climdex.R b/R/Climdex.R index 20c3e43..e8203fb 100644 --- a/R/Climdex.R +++ b/R/Climdex.R @@ -47,6 +47,9 @@ #' #'clim <- Climdex(data, metric = "t90p", threshold = thres) #'str(clim) +#'@references David Bronaugh for the Pacific Climate Impacts Consortium (2015). +#' climdex.pcic: PCIC Implementation of Climdex Routines. R package +#' version 1.1-6. http://CRAN.R-project.org/package=climdex.pcic #'@export Climdex <- function(data, metric, threshold = NULL, base.range = NULL, dates = NULL, timedim = NULL, calendar = NULL, ncores = NULL) { @@ -285,7 +288,7 @@ Climdex <- function(data, metric, threshold = NULL, base.range = NULL, dates = N if(spells.can.span.years) { all.true <- .tapply.fast(bools, date.factor, all) - max.spell <- .tapply.fast(get.series.lengths.at.ends(bools), date.factor, max) + max.spell <- .tapply.fast(.get.series.lengths.at.ends(bools), date.factor, max) ## Mask out values which are in the middle of a spell with NA na.mask <- c(1, NA)[as.integer((max.spell == 0) & all.true) + 1] diff --git a/man/Climdex.Rd b/man/Climdex.Rd index 3ff6bb7..669570a 100644 --- a/man/Climdex.Rd +++ b/man/Climdex.Rd @@ -63,4 +63,9 @@ str(thres) clim <- Climdex(data, metric = "t90p", threshold = thres) str(clim) } +\references{ +David Bronaugh for the Pacific Climate Impacts Consortium (2015). + climdex.pcic: PCIC Implementation of Climdex Routines. R package + version 1.1-6. http://CRAN.R-project.org/package=climdex.pcic +} -- GitLab