From 81316b0f146b30ef8d0acec6a71108238516ecce Mon Sep 17 00:00:00 2001 From: aho Date: Thu, 15 Apr 2021 15:33:47 +0200 Subject: [PATCH 1/3] Transform StatSeasAtlHurr.R --- NAMESPACE | 1 + R/StatSeasAtlHurr.R | 225 ++++++++++++++++++++++++++ man/StatSeasAtlHurr.Rd | 65 ++++++++ tests/testthat/test-StatSeasAtlHurr.R | 110 +++++++++++++ 4 files changed, 401 insertions(+) create mode 100644 R/StatSeasAtlHurr.R create mode 100644 man/StatSeasAtlHurr.Rd create mode 100644 tests/testthat/test-StatSeasAtlHurr.R diff --git a/NAMESPACE b/NAMESPACE index 87937e2..a19a297 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,6 +47,7 @@ export(Reorder) export(SPOD) export(Season) export(Smoothing) +export(StatSeasAtlHurr) export(TPI) export(ToyModel) export(Trend) diff --git a/R/StatSeasAtlHurr.R b/R/StatSeasAtlHurr.R new file mode 100644 index 0000000..358849d --- /dev/null +++ b/R/StatSeasAtlHurr.R @@ -0,0 +1,225 @@ +#'Compute estimate of seasonal mean of Atlantic hurricane activity +#' +#'Compute one of G. Villarini's statistically downscaled measure of mean +#'Atlantic hurricane activity and its variance. The hurricane activity is +#'estimated using seasonal averages of sea surface temperature anomalies over +#'the tropical Atlantic (bounded by 10N-25N and 80W-20W) and the tropics at +#'large (bounded by 30N-30S). The anomalies are for the JJASON season.\cr +#'The estimated seasonal average is either 1) number of hurricanes, 2) number +#'of tropical cyclones with lifetime >=48h or 3) power dissipation index +#'(PDI; in 10^11 m^3 s^{-2}).\cr +#'The statistical models used in this function are described in references. +#' +#'@param atlano A numeric array with named dimensions of Atlantic sea surface +#' temperature anomalies. It must have the same dimensions as 'tropano'. +#'@param tropano A numeric array with named dimensions of tropical sea surface +#' temperature anomalies. It must have the same dimensions as 'atlano'. +#'@param hrvar A character string of the seasonal average to be estimated. The +#' options are either "HR" (hurricanes), "TC" (tropical cyclones with lifetime +#' >=48h), or "PDI" (power dissipation index). The default value is 'HR'. +#'@param ncores An integer indicating the number of cores to use for parallel +#' computation. The default value is NULL. +#' +#'@return A list composed of two arrays with the same dimensions as 'atlano' +#' and 'tropano'. +#'\item{ +#' A matrix (mean) with the seasonal average values of the desired quantity.\cr +#'} +#'\item{ +#' A matrix (var) of the variance of that quantity.\cr +#'} +#' +#'@references +#'Villarini et al. (2010) Mon Wea Rev, 138, 2681-2705.\cr +#'Villarini et al. (2012) Mon Wea Rev, 140, 44-65.\cr +#'Villarini et al. (2012) J Clim, 25, 625-637.\cr +#'An example of how the function can be used in hurricane forecast studies +#' is given in\cr +#'Caron, L.-P. et al. (2014) Multi-year prediction skill of Atlantic hurricane +#' activity in CMIP5 decadal hindcasts. Climate Dynamics, 42, 2675-2690. +#' doi:10.1007/s00382-013-1773-1. +#' +#'@examples +#'# Let AtlAno represents 5 different 5-year forecasts of seasonally averaged +#'# Atlantic sea surface temperature anomalies. +#'AtlAno <- array(runif(25, -1, 1), dim = c(sdate = 5, ftime = 5)) +#'# Let TropAno represents 5 corresponding 5-year forecasts of seasonally +#'# averaged tropical sea surface temperature anomalies. +#'TropAno <- array(runif(25, -1, 1), dim = c(sdate = 5, ftime = 5)) +#'# The seasonal average of hurricanes for each of the five forecasted years, +#'# for each forecast, would then be given by. +#'hr_count <- StatSeasAtlHurr(atlano = AtlAno, tropano = TropAno, hrvar = 'HR') +#' +#'@import multiApply +#'@export +StatSeasAtlHurr <- function(atlano, tropano, hrvar = "HR", ncores = NULL) { + + # Check inputs + ## atlano and tropano + if (is.null(atlano) | is.null(tropano)) { + stop("Parameter 'atlano' and 'tropano' cannot be NULL.") + } + if (!is.numeric(atlano) | !is.numeric(tropano)) { + stop("Parameter 'atlano' and 'tropano' must be a numeric array.") + } + if (is.null(dim(atlano))) { #is vector + dim(atlano) <- c(length(atlano)) + names(dim(atlano)) <- 'dim1' + } + if (is.null(dim(tropano))) { #is vector + dim(tropano) <- c(length(tropano)) + names(dim(tropano)) <- 'dim1' + } + if(any(is.null(names(dim(atlano))))| any(nchar(names(dim(atlano))) == 0) | + any(is.null(names(dim(tropano))))| any(nchar(names(dim(tropano))) == 0)) { + stop("Parameter 'atlano' and 'tropano' must have dimension names.") + } + if(!all(names(dim(atlano)) %in% names(dim(tropano))) | + !all(names(dim(tropano)) %in% names(dim(atlano)))) { + stop("Parameter 'atlano' and 'tropano' must have same dimension names.") + } + name_1 <- sort(names(dim(atlano))) + name_2 <- sort(names(dim(tropano))) + if (!all(dim(atlano)[name_1] == dim(tropano)[name_2])) { + stop(paste0("Parameter 'atlano' and 'tropano' must have the same length of ", + "all the dimensions.")) + } + ## hrvar + if (hrvar != "HR" & hrvar != "TC" & hrvar != "PDI") { + stop("The parameter 'hrvar' must be either 'HR', 'TC', or 'PDI'.") + } + ## ncores + if (!is.null(ncores)) { + if (!is.numeric(ncores) | ncores %% 1 != 0 | ncores <= 0 | + length(ncores) > 1) { + stop("Parameter 'ncores' must be a positive integer.") + } + } + + + ############################### + # Calculate StatSeasAtlHurr + if (is.null(ncores)) { + use_Apply <- FALSE + } else if (ncores == 1) { + use_Apply <- FALSE + } else { + use_Apply <- TRUE + } + + if (use_Apply) { + res <- Apply(list(atlano, tropano), + target_dims = list(c(names(which.max(dim(AtlAno)))), + c(names(which.max(dim(AtlAno))))), + fun = .StatSeasAtlHurr, + hrvar = hrvar, + ncores = ncores) + } else { + + # Get the values of the betas according to the hurricane + # activity measure we specified. + # ------------------------------------------------------ + if (hrvar == "HR") { + # beta's are derived from Villarini et al. (2012), Mon Wea + # Rev, 140, 44-65. beta's are for corrected hurricane data + + # ERSST with SBC criteria (table 2) + beta0 <- 1.85 + betaAtl <- 1.05 + betaTrop <- -1.17 + } else if (hrvar == "TC") { + # beta's are from Villarini et al. (2010), Mon Wea Rev, 138, + # 2681-2705. beta's are for corrected TC data (lifetime >= + # 48h) + ERSST (table 5) + beta0 <- 2.1 + betaAtl <- 1.02 + betaTrop <- -1.05 + } else if (hrvar == "PDI") { + # beta's are from Villarini et al. (2012), J Clim, 25, + # 625-637. beta's are from ERSST, with SBC penalty criterion + # (table 1) + beta0 <- 0.76 + betaAtl <- 1.94 + betaTrop <- -1.78 + } + # Create matrix of similar dimension as atlano for beta0. + # ------------------------------------------------------- + intercept <- array(beta0, dim(atlano)) + # Compute statistical relationship b/w SSTAs and mean + # hurricane activity. + # --------------------------------------------------- + atl <- betaAtl * atlano + trop <- betaTrop * tropano + # + temp <- intercept + atl + trop + # + res <- list(mean = array(NA, dim(atl)), var = array(NA, dim(atl))) + res$mean[] <- vapply(X = temp, FUN = exp, numeric(1)) + # Compute the variance of the distribution. TC and HR follow + # a Poisson distribution, so the variance is equal to the + # mean. PDI follows a gamma distribution, with sigma = + # -0.57. (variance = sigma^2 * mean^2). + # ----------------------------------------------------------- + if (hrvar == "HR" | hrvar == "TC") { + res$var <- res$mean + } else { + sigma <- -0.57 + res$var[] <- sigma^2 * vapply(X = res$mean, FUN = function(x) x^2, numeric(1)) + } + + } + + return(res) +} + +.StatSeasAtlHurr <- function(atlano, tropano, hrvar = "HR") { + + # atlano and tropano: a vector with same length + + # Get the values of the betas according to the hurricane activity measure we + # specified. + # ------------------------------------------------------ + if (hrvar == "HR") { + # beta's are derived from Villarini et al. (2012), Mon Wea + # Rev, 140, 44-65. beta's are for corrected hurricane data + + # ERSST with SBC criteria (table 2) + beta0 <- 1.85 + betaAtl <- 1.05 + betaTrop <- -1.17 + } else if (hrvar == "TC") { + # beta's are from Villarini et al. (2010), Mon Wea Rev, 138, + # 2681-2705. beta's are for corrected TC data (lifetime >= + # 48h) + ERSST (table 5) + beta0 <- 2.1 + betaAtl <- 1.02 + betaTrop <- -1.05 + } else if (hrvar == "PDI") { + # beta's are from Villarini et al. (2012), J Clim, 25, + # 625-637. beta's are from ERSST, with SBC penalty criterion + # (table 1) + beta0 <- 0.76 + betaAtl <- 1.94 + betaTrop <- -1.78 + } + + # Compute statistical relationship b/w SSTAs and mean + # hurricane activity. + # --------------------------------------------------- + atl <- betaAtl * atlano + trop <- betaTrop * tropano + temp <- beta0 + atl + trop + stat_mean <- exp(temp) + + # Compute the variance of the distribution. TC and HR follow + # a Poisson distribution, so the variance is equal to the + # mean. PDI follows a gamma distribution, with sigma = + # -0.57. (variance = sigma^2 * mean^2). + # ----------------------------------------------------------- + if (hrvar == "HR" | hrvar == "TC") { + stat_var <- stat_mean + } else { + sigma <- -0.57 + stat_var <- sigma^2 * stat_mean^2 + } + + return(invisible(list(mean = stat_mean, var = stat_var))) +} diff --git a/man/StatSeasAtlHurr.Rd b/man/StatSeasAtlHurr.Rd new file mode 100644 index 0000000..dd7dd8f --- /dev/null +++ b/man/StatSeasAtlHurr.Rd @@ -0,0 +1,65 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/StatSeasAtlHurr.R +\name{StatSeasAtlHurr} +\alias{StatSeasAtlHurr} +\title{Compute estimate of seasonal mean of Atlantic hurricane activity} +\usage{ +StatSeasAtlHurr(atlano, tropano, hrvar = "HR", ncores = NULL) +} +\arguments{ +\item{atlano}{A numeric array with named dimensions of Atlantic sea surface +temperature anomalies. It must have the same dimensions as 'tropano'.} + +\item{tropano}{A numeric array with named dimensions of tropical sea surface +temperature anomalies. It must have the same dimensions as 'atlano'.} + +\item{hrvar}{A character string of the seasonal average to be estimated. The +options are either "HR" (hurricanes), "TC" (tropical cyclones with lifetime +>=48h), or "PDI" (power dissipation index). The default value is 'HR'.} + +\item{ncores}{An integer indicating the number of cores to use for parallel +computation. The default value is NULL.} +} +\value{ +A list composed of two arrays with the same dimensions as 'atlano' + and 'tropano'. +\item{ + A matrix (mean) with the seasonal average values of the desired quantity.\cr +} +\item{ + A matrix (var) of the variance of that quantity.\cr +} +} +\description{ +Compute one of G. Villarini's statistically downscaled measure of mean +Atlantic hurricane activity and its variance. The hurricane activity is +estimated using seasonal averages of sea surface temperature anomalies over +the tropical Atlantic (bounded by 10N-25N and 80W-20W) and the tropics at +large (bounded by 30N-30S). The anomalies are for the JJASON season.\cr +The estimated seasonal average is either 1) number of hurricanes, 2) number +of tropical cyclones with lifetime >=48h or 3) power dissipation index +(PDI; in 10^11 m^3 s^{-2}).\cr +The statistical models used in this function are described in references. +} +\examples{ +# Let AtlAno represents 5 different 5-year forecasts of seasonally averaged +# Atlantic sea surface temperature anomalies. +AtlAno <- array(runif(25, -1, 1), dim = c(sdate = 5, ftime = 5)) +# Let TropAno represents 5 corresponding 5-year forecasts of seasonally +# averaged tropical sea surface temperature anomalies. +TropAno <- array(runif(25, -1, 1), dim = c(sdate = 5, ftime = 5)) +# The seasonal average of hurricanes for each of the five forecasted years, +# for each forecast, would then be given by. +hr_count <- StatSeasAtlHurr(atlano = AtlAno, tropano = TropAno, hrvar = 'HR') + +} +\references{ +Villarini et al. (2010) Mon Wea Rev, 138, 2681-2705.\cr +Villarini et al. (2012) Mon Wea Rev, 140, 44-65.\cr +Villarini et al. (2012) J Clim, 25, 625-637.\cr +An example of how the function can be used in hurricane forecast studies + is given in\cr +Caron, L.-P. et al. (2014) Multi-year prediction skill of Atlantic hurricane + activity in CMIP5 decadal hindcasts. Climate Dynamics, 42, 2675-2690. + doi:10.1007/s00382-013-1773-1. +} diff --git a/tests/testthat/test-StatSeasAtlHurr.R b/tests/testthat/test-StatSeasAtlHurr.R new file mode 100644 index 0000000..82ef308 --- /dev/null +++ b/tests/testthat/test-StatSeasAtlHurr.R @@ -0,0 +1,110 @@ +context("s2dv::StatSeaAtlHurr tests") + +############################################## + # dat1 + set.seed(1) + atlano1 <- array(runif(30, -1, 1), + dim = c(dat = 2, sdate = 5, ftime = 3)) + + set.seed(2) + tropano1 <- array(runif(30, -1, 1), + dim = c(dat = 2, sdate = 5, ftime = 3)) + + # dat2 + atlano2 <- atlano1 + tropano2 <- tropano1 + atlano2[1, 1, 1] <- NA + tropano2[1, 1, 1:2] <- NA + +############################################## +test_that("1. Input checks", { + + expect_error( + StatSeasAtlHurr(c(), c()), + "Parameter 'atlano' and 'tropano' cannot be NULL." + ) + expect_error( + StatSeasAtlHurr(c('b'), c('a')), + "Parameter 'atlano' and 'tropano' must be a numeric array." + ) + expect_error( + StatSeasAtlHurr(atlano1, array(1:4, dim = c(2, 2))), + "Parameter 'atlano' and 'tropano' must have dimension names." + ) + expect_error( + StatSeasAtlHurr(array(1:10, dim = c(a = 2, c = 5)), array(1:4, dim = c(a = 2, b = 2))), + "Parameter 'atlano' and 'tropano' must have same dimension names." + ) + expect_error( + StatSeasAtlHurr(array(1:10, dim = c(a = 2, c = 5)), array(1:4, dim = c(c = 5, a = 3))), + "Parameter 'atlano' and 'tropano' must have the same length of all the dimensions." + ) + expect_error( + StatSeasAtlHurr(atlano1, tropano1, hrvar = 1), + "The parameter 'hrvar' must be either 'HR', 'TC', or 'PDI'." + ) + expect_error( + StatSeasAtlHurr(atlano1, tropano1, ncores = 1.5), + "Parameter 'ncores' must be a positive integer." + ) + + +}) + +############################################## +test_that("2. Output checks: dat1", { + +expect_equal( +names(StatSeasAtlHurr(atlano1, tropano1)), +c('mean', 'var') +) +expect_equal( +dim(StatSeasAtlHurr(atlano1, tropano1)$mean), +c(dat = 2, sdate = 5, ftime = 3) +) +expect_equal( +dim(StatSeasAtlHurr(atlano1, tropano1)$var), +c(dat = 2, sdate = 5, ftime = 3) +) +expect_equal( +StatSeasAtlHurr(atlano1, tropano1)$mean, +StatSeasAtlHurr(atlano1, tropano1)$var +) +expect_equal( +StatSeasAtlHurr(atlano1, tropano1)$mean[1, 1:2, 2], +c(3.032203, 5.119961), +tolerance = 0.0001 +) +expect_equal( +StatSeasAtlHurr(atlano1, tropano1, hrvar = 'TC')$mean, +StatSeasAtlHurr(atlano1, tropano1, hrvar = 'TC')$var +) +expect_equal( +StatSeasAtlHurr(atlano1, tropano1, hrvar = 'PDI')$mean[1, 1:2, 2], +c(0.5664659, 1.7475613), +tolerance = 0.0001 +) +expect_equal( +StatSeasAtlHurr(atlano1, tropano1, hrvar = 'PDI')$var[1, 1:2, 2], +c(0.1042551, 0.9922350), +tolerance = 0.0001 +) + +}) + +############################################## +test_that("3. Output checks: dat2", { + +expect_equal( +StatSeasAtlHurr(atlano2, tropano2)$mean[1, 1:2, 2], +c(NA, 5.119961), +tolerance = 0.0001 +) +expect_equal( +StatSeasAtlHurr(atlano2, tropano2)$mean[1, 1, ], +c(NA, NA, 10.84862), +tolerance = 0.0001 +) + + +}) -- GitLab From f6cafa13692485045173f8121685c4e8f230c472 Mon Sep 17 00:00:00 2001 From: aho Date: Thu, 15 Apr 2021 15:35:35 +0200 Subject: [PATCH 2/3] Update indices Rd file --- man/AMV.Rd | 29 ++++++++++++++--------------- man/GMST.Rd | 51 ++++++++++++++++++++++++--------------------------- man/GSAT.Rd | 30 +++++++++++++++--------------- man/SPOD.Rd | 30 +++++++++++++++--------------- man/TPI.Rd | 30 +++++++++++++++--------------- 5 files changed, 83 insertions(+), 87 deletions(-) diff --git a/man/AMV.Rd b/man/AMV.Rd index 0f81652..3cc4113 100644 --- a/man/AMV.Rd +++ b/man/AMV.Rd @@ -18,16 +18,15 @@ AMV( indices_for_clim = NULL, year_dim = "year", month_dim = "month", - member_dim = "member", + na.rm = TRUE, ncores = NULL ) } \arguments{ -\item{data}{A numerical array to be used for the index computation with the -dimensions: 1) latitude, longitude, start date, forecast month, and member -(in case of decadal predictions), 2) latitude, longitude, year, month and -member (in case of historical simulations), or 3) latitude, longitude, year -and month (in case of observations or reanalyses). This data has to be +\item{data}{A numerical array to be used for the index computation with, at least, the +dimensions: 1) latitude, longitude, start date and forecast month +(in case of decadal predictions), 2) latitude, longitude, year and month +(in case of historical simulations or observations). This data has to be provided, at least, over the whole region needed to compute the index.} \item{data_lats}{A numeric vector indicating the latitudes of the data.} @@ -70,7 +69,7 @@ climatology is calculated over the whole period. If the data are already anomalies, set it to FALSE. The default value is NULL.\cr In case of parameter 'type' is 'dcpp', 'indices_for_clim' must be relative to the first forecast year, and the climatology is automatically computed -over the actual common period for the different forecast years.} +over the common calendar period for the different forecast years.} \item{year_dim}{A character string indicating the name of the year dimension The default value is 'year'. Only used if parameter 'type' is 'hist' or @@ -80,18 +79,17 @@ The default value is 'year'. Only used if parameter 'type' is 'hist' or dimension. The default value is 'month'. Only used if parameter 'type' is 'hist' or 'obs'.} -\item{member_dim}{A character string indicating the name of the member -dimension. The default value is 'member'. Only used if parameter 'type' is -'dcpp' or 'hist'.} +\item{na.rm}{A logical value indicanting whether to remove NA values. The default +value is TRUE.} \item{ncores}{An integer indicating the number of cores to use for parallel computation. The default value is NULL.} } \value{ -A numerical array of the AMV index with the dimensions of: - 1) sdate, forecast year, and member (in case of decadal predictions); - 2) year and member (in case of historical simulations); or - 3) year (in case of observations or reanalyses). +A numerical array with the AMV index with the same dimensions as data except + the lat_dim, lon_dim and fmonth_dim (month_dim) in case of decadal predictions + (historical simulations or observations). In case of decadal predictions, a new dimension + 'fyear' is added. } \description{ The Atlantic Multidecadal Variability (AMV), also known as Atlantic @@ -100,7 +98,8 @@ surface temperatures (SST) over the North Atlantic Ocean on multi-decadal time scales. The AMV index is computed as the difference of weighted-averaged SST anomalies over the North Atlantic region (0ºN-60ºN, 280ºE-360ºE) and the weighted-averaged SST anomalies over 60ºS-60ºN, 0ºE-360ºE (Trenberth & -Dennis, 2005; Doblas-Reyes et al., 2013). +Dennis, 2005; Doblas-Reyes et al., 2013). If different members and/or datasets are provided, +the climatology (used to calculate the anomalies) is computed individually for all of them. } \examples{ ## Observations or reanalyses diff --git a/man/GMST.Rd b/man/GMST.Rd index 8021943..f23e60d 100644 --- a/man/GMST.Rd +++ b/man/GMST.Rd @@ -21,28 +21,25 @@ GMST( indices_for_clim = NULL, year_dim = "year", month_dim = "month", - member_dim = "member", + na.rm = TRUE, ncores = NULL ) } \arguments{ -\item{data_tas}{A numerical array indicating the surface air temperature data -to be used for the index computation with the dimensions: 1) latitude, -longitude, start date, forecast month, and member (in case of decadal -predictions), 2) latitude, longitude, year, month and member (in case of -historical simulations), or 3) latitude, longitude, year and month (in case -of observations or reanalyses). This data has to be provided, at least, -over the whole region needed to compute the index. The dimensions must be -identical to those of data_tos.} - -\item{data_tos}{A numerical array indicating the sea surface temperature data -to be used for the index computation with the dimensions: 1) latitude, -longitude, start date, forecast month, and member (in case of decadal -predictions), 2) latitude, longitude, year, month and member (in case of -historical simulations), or 3) latitude, longitude, year and month (in case -of observations or reanalyses). This data has to be provided, at least, -over the whole region needed to compute the index. The dimensions must be -identical to those of data_tas.} +\item{data_tas}{A numerical array with the surface air temperature data +to be used for the index computation with, at least, the +dimensions: 1) latitude, longitude, start date and forecast month +(in case of decadal predictions), 2) latitude, longitude, year and month +(in case of historical simulations or observations). This data has to be +provided, at least, over the whole region needed to compute the index. +The dimensions must be identical to thos of data_tos. +#'@param data_tos A numerical array with the sea surface temperature data +to be used for the index computation with, at least, the +dimensions: 1) latitude, longitude, start date and forecast month +(in case of decadal predictions), 2) latitude, longitude, year and month +(in case of historical simulations or observations). This data has to be +provided, at least, over the whole region needed to compute the index. +The dimensions must be identical to thos of data_tas.} \item{data_lats}{A numeric vector indicating the latitudes of the data.} @@ -90,7 +87,7 @@ climatology is calculated over the whole period. If the data are already anomalies, set it to FALSE. The default value is NULL.\cr In case of parameter 'type' is 'dcpp', 'indices_for_clim' must be relative to the first forecast year, and the climatology is automatically computed -over the actual common period for the different forecast years.} +over the common calendar period for the different forecast years.} \item{year_dim}{A character string indicating the name of the year dimension The default value is 'year'. Only used if parameter 'type' is 'hist' or @@ -100,23 +97,23 @@ The default value is 'year'. Only used if parameter 'type' is 'hist' or dimension. The default value is 'month'. Only used if parameter 'type' is 'hist' or 'obs'.} -\item{member_dim}{A character string indicating the name of the member -dimension. The default value is 'member'. Only used if parameter 'type' is -'dcpp' or 'hist'.} +\item{na.rm}{A logical value indicanting whether to remove NA values. The default +value is TRUE.} \item{ncores}{An integer indicating the number of cores to use for parallel computation. The default value is NULL.} } \value{ -A numerical array of the GMST anomalies with the dimensions of: - 1) sdate, forecast year, and member (in case of decadal predictions); - 2) year and member (in case of historical simulations); or - 3) year (in case of observations or reanalyses). +A numerical array with the GMST anomalies with the same dimensions as data_tas except + the lat_dim, lon_dim and fmonth_dim (month_dim) in case of decadal predictions + (historical simulations or observations). In case of decadal predictions, a new dimension + 'fyear' is added. } \description{ The Global Mean Surface Temperature (GMST) anomalies are computed as the weighted-averaged surface air temperature anomalies over land and sea surface -temperature anomalies over the ocean. +temperature anomalies over the ocean. If different members and/or datasets are provided, +the climatology (used to calculate the anomalies) is computed individually for all of them. } \examples{ ## Observations or reanalyses diff --git a/man/GSAT.Rd b/man/GSAT.Rd index d7fe3cf..9f03ff2 100644 --- a/man/GSAT.Rd +++ b/man/GSAT.Rd @@ -18,16 +18,15 @@ GSAT( indices_for_clim = NULL, year_dim = "year", month_dim = "month", - member_dim = "member", + na.rm = TRUE, ncores = NULL ) } \arguments{ -\item{data}{A numerical array to be used for the index computation with the -dimensions: 1) latitude, longitude, start date, forecast month, and member -(in case of decadal predictions), 2) latitude, longitude, year, month and -member (in case of historical simulations), or 3) latitude, longitude, year -and month (in case of observations or reanalyses). This data has to be +\item{data}{A numerical array to be used for the index computation with, at least, the +dimensions: 1) latitude, longitude, start date and forecast month +(in case of decadal predictions), 2) latitude, longitude, year and month +(in case of historical simulations or observations). This data has to be provided, at least, over the whole region needed to compute the index.} \item{data_lats}{A numeric vector indicating the latitudes of the data.} @@ -70,7 +69,7 @@ climatology is calculated over the whole period. If the data are already anomalies, set it to FALSE. The default value is NULL.\cr In case of parameter 'type' is 'dcpp', 'indices_for_clim' must be relative to the first forecast year, and the climatology is automatically computed -over the actual common period for the different forecast years.} +over the common calendar period for the different forecast years.} \item{year_dim}{A character string indicating the name of the year dimension The default value is 'year'. Only used if parameter 'type' is 'hist' or @@ -80,22 +79,23 @@ The default value is 'year'. Only used if parameter 'type' is 'hist' or dimension. The default value is 'month'. Only used if parameter 'type' is 'hist' or 'obs'.} -\item{member_dim}{A character string indicating the name of the member -dimension. The default value is 'member'. Only used if parameter 'type' is -'dcpp' or 'hist'.} +\item{na.rm}{A logical value indicanting whether to remove NA values. The default +value is TRUE.} \item{ncores}{An integer indicating the number of cores to use for parallel computation. The default value is NULL.} } \value{ -A numerical array of the GSAT anomalies with the dimensions of: - 1) sdate, forecast year, and member (in case of decadal predictions); - 2) year and member (in case of historical simulations); or - 3) year (in case of observations or reanalyses). +A numerical array with the GSAT anomalies with the same dimensions as data except + the lat_dim, lon_dim and fmonth_dim (month_dim) in case of decadal predictions + (historical simulations or observations). In case of decadal predictions, a new dimension + 'fyear' is added. } \description{ The Global Surface Air Temperature (GSAT) anomalies are computed as the -weighted-averaged surface air temperature anomalies over the global region. +weighted-averaged surface air temperature anomalies over the global region. +If different members and/or datasets are provided, the climatology (used to +calculate the anomalies) is computed individually for all of them. } \examples{ ## Observations or reanalyses diff --git a/man/SPOD.Rd b/man/SPOD.Rd index 0491739..4c4ed29 100644 --- a/man/SPOD.Rd +++ b/man/SPOD.Rd @@ -18,16 +18,15 @@ SPOD( indices_for_clim = NULL, year_dim = "year", month_dim = "month", - member_dim = "member", + na.rm = TRUE, ncores = NULL ) } \arguments{ -\item{data}{A numerical array to be used for the index computation with the -dimensions: 1) latitude, longitude, start date, forecast month, and member -(in case of decadal predictions), 2) latitude, longitude, year, month and -member (in case of historical simulations), or 3) latitude, longitude, year -and month (in case of observations or reanalyses). This data has to be +\item{data}{A numerical array to be used for the index computation with, at least, the +dimensions: 1) latitude, longitude, start date and forecast month +(in case of decadal predictions), 2) latitude, longitude, year and month +(in case of historical simulations or observations). This data has to be provided, at least, over the whole region needed to compute the index.} \item{data_lats}{A numeric vector indicating the latitudes of the data.} @@ -70,7 +69,7 @@ climatology is calculated over the whole period. If the data are already anomalies, set it to FALSE. The default value is NULL.\cr In case of parameter 'type' is 'dcpp', 'indices_for_clim' must be relative to the first forecast year, and the climatology is automatically computed -over the actual common period for the different forecast years.} +over the common calendar period for the different forecast years.} \item{year_dim}{A character string indicating the name of the year dimension The default value is 'year'. Only used if parameter 'type' is 'hist' or @@ -80,25 +79,26 @@ The default value is 'year'. Only used if parameter 'type' is 'hist' or dimension. The default value is 'month'. Only used if parameter 'type' is 'hist' or 'obs'.} -\item{member_dim}{A character string indicating the name of the member -dimension. The default value is 'member'. Only used if parameter 'type' is -'dcpp' or 'hist'.} +\item{na.rm}{A logical value indicanting whether to remove NA values. The default +value is TRUE.} \item{ncores}{An integer indicating the number of cores to use for parallel computation. The default value is NULL.} } \value{ -A numerical array of the SPOD index with the dimensions of: - 1) sdate, forecast year, and member (in case of decadal predictions); - 2) year and member (in case of historical simulations); or - 3) year (in case of observations or reanalyses). +A numerical array with the SPOD index with the same dimensions as data except + the lat_dim, lon_dim and fmonth_dim (month_dim) in case of decadal predictions + (historical simulations or observations). In case of decadal predictions, a new dimension + 'fyear' is added. } \description{ The South Pacific Ocean Dipole (SPOD) index is related to the El Nino-Southern Oscillation (ENSO) and the Inderdecadal Pacific Oscillation (IPO). The SPOD index is computed as the difference of weighted-averaged SST anomalies over 20ºS-48ºS, 165ºE-190ºE (NW pole) and the weighted-averaged SST -anomalies over 44ºS-65ºS, 220ºE-260ºE (SE pole) (Saurral et al., 2020). +anomalies over 44ºS-65ºS, 220ºE-260ºE (SE pole) (Saurral et al., 2020). +If different members and/or datasets are provided, the climatology (used to +calculate the anomalies) is computed individually for all of them. } \examples{ ## Observations or reanalyses diff --git a/man/TPI.Rd b/man/TPI.Rd index 3bdc17c..5e8f716 100644 --- a/man/TPI.Rd +++ b/man/TPI.Rd @@ -18,16 +18,15 @@ TPI( indices_for_clim = NULL, year_dim = "year", month_dim = "month", - member_dim = "member", + na.rm = TRUE, ncores = NULL ) } \arguments{ -\item{data}{A numerical array to be used for the index computation with the -dimensions: 1) latitude, longitude, start date, forecast month, and member -(in case of decadal predictions), 2) latitude, longitude, year, month and -member (in case of historical simulations), or 3) latitude, longitude, year -and month (in case of observations or reanalyses). This data has to be +\item{data}{A numerical array to be used for the index computation with, at least, the +dimensions: 1) latitude, longitude, start date and forecast month +(in case of decadal predictions), 2) latitude, longitude, year and month +(in case of historical simulations or observations). This data has to be provided, at least, over the whole region needed to compute the index.} \item{data_lats}{A numeric vector indicating the latitudes of the data.} @@ -70,7 +69,7 @@ climatology is calculated over the whole period. If the data are already anomalies, set it to FALSE. The default value is NULL.\cr In case of parameter 'type' is 'dcpp', 'indices_for_clim' must be relative to the first forecast year, and the climatology is automatically computed -over the actual common period for the different forecast years.} +over the common calendar period for the different forecast years.} \item{year_dim}{A character string indicating the name of the year dimension The default value is 'year'. Only used if parameter 'type' is 'hist' or @@ -80,24 +79,25 @@ The default value is 'year'. Only used if parameter 'type' is 'hist' or dimension. The default value is 'month'. Only used if parameter 'type' is 'hist' or 'obs'.} -\item{member_dim}{A character string indicating the name of the member -dimension. The default value is 'member'. Only used if parameter 'type' is -'dcpp' or 'hist'.} +\item{na.rm}{A logical value indicanting whether to remove NA values. The default +value is TRUE.} \item{ncores}{An integer indicating the number of cores to use for parallel computation. The default value is NULL.} } \value{ -A numerical array of the TPI index with the dimensions of: - 1) sdate, forecast year, and member (in case of decadal predictions); - 2) year and member (in case of historical simulations); or - 3) year (in case of observations or reanalyses). +A numerical array with the TPI index with the same dimensions as data except + the lat_dim, lon_dim and fmonth_dim (month_dim) in case of decadal predictions + (historical simulations or observations). In case of decadal predictions, a new dimension + 'fyear' is added. } \description{ The Tripole Index (TPI) for the Interdecadal Pacific Oscillation (IPO) is computed as the difference of weighted-averaged SST anomalies over 10ºS-10ºN, 170ºE-270ºE minus the mean of the weighted-averaged SST anomalies over -25ºN-45ºN, 140ºE-215ºE and 50ºS-15ºS, 150ºE-200ºE (Henley et al., 2015). +25ºN-45ºN, 140ºE-215ºE and 50ºS-15ºS, 150ºE-200ºE (Henley et al., 2015). +If different members and/or datasets are provided, the climatology (used to +calculate the anomalies) is computed individually for all of them. } \examples{ ## Observations or reanalyses -- GitLab From 17cf7d302b3aa2fafb9475ca9cd19b5258f5a712 Mon Sep 17 00:00:00 2001 From: aho Date: Thu, 15 Apr 2021 16:40:52 +0200 Subject: [PATCH 3/3] Fix document format and typo in function --- R/StatSeasAtlHurr.R | 12 ++++++------ man/StatSeasAtlHurr.Rd | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/StatSeasAtlHurr.R b/R/StatSeasAtlHurr.R index 358849d..9d0ec38 100644 --- a/R/StatSeasAtlHurr.R +++ b/R/StatSeasAtlHurr.R @@ -22,11 +22,11 @@ #' #'@return A list composed of two arrays with the same dimensions as 'atlano' #' and 'tropano'. -#'\item{ -#' A matrix (mean) with the seasonal average values of the desired quantity.\cr +#'\item{$mean}{ +#' The mean of the desired quantity. #'} -#'\item{ -#' A matrix (var) of the variance of that quantity.\cr +#'\item{$var}{ +#' The variance of that quantity. #'} #' #'@references @@ -109,8 +109,8 @@ StatSeasAtlHurr <- function(atlano, tropano, hrvar = "HR", ncores = NULL) { if (use_Apply) { res <- Apply(list(atlano, tropano), - target_dims = list(c(names(which.max(dim(AtlAno)))), - c(names(which.max(dim(AtlAno))))), + target_dims = list(c(names(which.max(dim(atlano)))), + c(names(which.max(dim(atlano))))), fun = .StatSeasAtlHurr, hrvar = hrvar, ncores = ncores) diff --git a/man/StatSeasAtlHurr.Rd b/man/StatSeasAtlHurr.Rd index dd7dd8f..9657322 100644 --- a/man/StatSeasAtlHurr.Rd +++ b/man/StatSeasAtlHurr.Rd @@ -23,11 +23,11 @@ computation. The default value is NULL.} \value{ A list composed of two arrays with the same dimensions as 'atlano' and 'tropano'. -\item{ - A matrix (mean) with the seasonal average values of the desired quantity.\cr +\item{$mean}{ + The mean of the desired quantity. } -\item{ - A matrix (var) of the variance of that quantity.\cr +\item{$var}{ + The variance of that quantity. } } \description{ -- GitLab