diff --git a/.Rbuildignore b/.Rbuildignore index aa8227b142f77c731283cc23cb40abe0e7fdc490..19a1af65ac5ae3e96e68397e9d01cc76b0c9e8ac 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,4 @@ README\.md$ \..*\.RData$ vignettes .gitlab-ci.yml +^tests$ diff --git a/DESCRIPTION b/DESCRIPTION index 6aff1bc732b7f31178c69fe6c1872cbad280ab81..126179a2af69c234ead2c12cf6d6e562cfdd91e8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: s2dv Title: A Set of Common Tools for Seasonal to Decadal Verification -Version: 0.1.0 +Version: 0.1.1 Authors@R: c( person("BSC-CNS", role = c("aut", "cph")), person("An-Chi", "Ho", , "an.ho@bsc.es", role = c("aut", "cre")), @@ -39,9 +39,9 @@ Imports: Suggests: easyVerification, testthat -License: LGPL-3 +License: Apache License 2.0 URL: https://earth.bsc.es/gitlab/es/s2dv/ -BugReports: https://earth.bsc.es/gitlab/es/s2dv/issues +BugReports: https://earth.bsc.es/gitlab/es/s2dv/-/issues LazyData: true SystemRequirements: cdo Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index bcb14884e8864502cddac59d8bef98cb13aafd03..6da8d0c7ee74b297aab584a94a5431777f714d19 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -78,8 +78,8 @@ importFrom(grDevices,rainbow) importFrom(grDevices,rgb) importFrom(grDevices,svg) importFrom(grDevices,tiff) -importFrom(plyr,take) importFrom(stats,acf) +importFrom(stats,anova) importFrom(stats,confint) importFrom(stats,cor) importFrom(stats,lm) diff --git a/NEWS.md b/NEWS.md index 463a6cad31a74c8af44908b5649c39a4e2221eae..567b9e0d4060b6e584c959aa4868691d3eab15f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# s2dv 0.1.1 (Release date: 2020-11-16) +- Change the lincense to Apache License 2.0. + # s2dv 0.1.0 (Release date: 2020-11-12) - New functions: Ano(), Composite(), PlotAno(), Smoothing(), AMV(), GSAT(), SPOD(), TPI(), GMST(), Persistence(). - Change the default value of PlotClim() parameter 'fileout' to NULL. diff --git a/R/Composite.R b/R/Composite.R index c79ef2434449716ed126727b614bdba2704eb3fa..ebab24750a9bdf98e977ab914c134ac2f6fb0ac9 100644 --- a/R/Composite.R +++ b/R/Composite.R @@ -27,6 +27,8 @@ #' used. #'@param fileout A character string indicating the name of the .sav output file #' The default value is NULL, which means not to save the output. +#'@param ncores An integer indicating the number of cores to use for parallel +#' computation. The default value is NULL. #' #'@return #'A list containing: diff --git a/R/ConfigFileOpen.R b/R/ConfigFileOpen.R index c442f1f0c5e7a1b39717309cb6736067e5163c8e..7d1fd96ec317967cacb75453cab53553198429cc 100644 --- a/R/ConfigFileOpen.R +++ b/R/ConfigFileOpen.R @@ -147,7 +147,7 @@ #' ConfigEditEntry, ConfigFileOpen, ConfigShowSimilarEntries, ConfigShowTable #'@references #'[1] \url{https://stat.ethz.ch/R-manual/R-devel/library/base/html/regex.html}\cr -#'[2] \url{http://tldp.org/LDP/abs/html/globbingref.html} +#'[2] \url{https://tldp.org/LDP/abs/html/globbingref.html} #'@examples #'# Create an empty configuration file #'config_file <- paste0(tempdir(), "/example.conf") diff --git a/R/Persistence.R b/R/Persistence.R index e8865c2f2cd5dcf5ae1392963918029a8d6e4756..3aa0636caf7b502e913927cd8d14bd4dd5efbd18 100644 --- a/R/Persistence.R +++ b/R/Persistence.R @@ -70,9 +70,10 @@ #' #'@examples #'#Building an example dataset with yearly start dates from 1920 to 2009 -#'obs1 <- 1 : (1 * 90 * 6 * 7) -#'dim(obs1) <- c(member = 1, time = 90, lat = 6, lon = 7) -#'dates <- seq(1920, 2009, 1) +#'set.seed(1) +#'obs1 <- rnorm(1 * 70 * 6 * 7) +#'dim(obs1) <- c(member = 1, time = 70, lat = 6, lon = 7) +#'dates <- seq(1940, 2009, 1) #'persist <- Persistence(obs1, dates = dates, start = 1961, end = 2005, ft_start = 1, #' nmemb = 40) #' diff --git a/R/TPI.R b/R/TPI.R index d5be6da57b742bcf55a5bfbe61c78c2d38e0fef0..a041c69c9be9e8ee7ef97910d25d79967bc5a334 100644 --- a/R/TPI.R +++ b/R/TPI.R @@ -13,7 +13,7 @@ #' provided, at least, over the whole region needed to compute the index. #'@param data_lats A numeric vector indicating the latitudes of the data. #'@param data_lons A numeric vector indicating the longitudes of the data. -#'@param A character string indicating the type of data ('dcpp' for +#'@param type A character string indicating the type of data ('dcpp' for #' decadal predictions, 'hist' for historical simulations, or 'obs' for #' observations or reanalyses). #'@param lat_dim A character string of the name of the latitude dimension. The @@ -80,7 +80,7 @@ #'@importFrom ClimProjDiags WeightedMean CombineIndices #'@import multiApply #'@export -TPI <- function(data, data_lats, data_lons, index, type, lat_dim = 'lat', lon_dim = 'lon', +TPI <- function(data, data_lats, data_lons, type, lat_dim = 'lat', lon_dim = 'lon', mask = NULL, monini = 11, fmonth_dim = 'fmonth', sdate_dim = 'sdate', indices_for_clim = NULL, year_dim = 'year', month_dim = 'month', member_dim = 'member') { diff --git a/R/Trend.R b/R/Trend.R index 1f6664a07d049ebcfdd6e77605138809db912143..4afb5237abb47ab5c7ec0e20f9ee2b9bb142fa77 100644 --- a/R/Trend.R +++ b/R/Trend.R @@ -65,6 +65,7 @@ #' #'@rdname Trend #'@import multiApply +#'@importFrom stats anova #'@export Trend <- function(data, time_dim = 'ftime', interval = 1, polydeg = 1, conf = TRUE, conf.lev = 0.95, pval = TRUE, ncores = NULL) { @@ -171,7 +172,7 @@ Trend <- function(data, time_dim = 'ftime', interval = 1, polydeg = 1, } if (pval) { - p.val <- as.array(anova(lm.out)$'Pr(>F)'[1]) + p.val <- as.array(stats::anova(lm.out)$'Pr(>F)'[1]) } detrended <- c() diff --git a/R/Utils.R b/R/Utils.R index b815bc5525eb4f7fd816cddb37779f8f98454290..6e781e1a9d0d527db76b5bea8f3a875e7e686c15 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -1,5 +1,5 @@ #'@importFrom abind abind -#'@importFrom plyr take +#'@import plyr #'@importFrom grDevices png jpeg pdf svg bmp tiff #'@import ncdf4 diff --git a/R/s2dv-package.R b/R/s2dv-package.R index 28b1493975bcf6533e939cefb37eb2b5454f7e44..97827a76974854fc741922b6ddfe3f8d26523a7a 100644 --- a/R/s2dv-package.R +++ b/R/s2dv-package.R @@ -1,3 +1,3 @@ -#'@references \url{https://earth.bsc.es/gitlab/es/s2dverification/} +#'@references \url{https://earth.bsc.es/gitlab/es/s2dv/} #'@keywords internal "_PACKAGE" diff --git a/man/Composite.Rd b/man/Composite.Rd index 25c64aa5b35e9c253799ea9aaf11697a592644f0..64d5bfcc5f97ee75516a75fe3a5bc6937790fed2 100644 --- a/man/Composite.Rd +++ b/man/Composite.Rd @@ -38,6 +38,9 @@ used.} \item{fileout}{A character string indicating the name of the .sav output file The default value is NULL, which means not to save the output.} + +\item{ncores}{An integer indicating the number of cores to use for parallel +computation. The default value is NULL.} } \value{ A list containing: diff --git a/man/ConfigFileOpen.Rd b/man/ConfigFileOpen.Rd index cf40e0011faba312b0661906b2ab2fe3a14c427d..eee183f0f87335a6404c1c0f8e975a0252c4d6d6 100644 --- a/man/ConfigFileOpen.Rd +++ b/man/ConfigFileOpen.Rd @@ -188,7 +188,7 @@ ConfigFileSave(configuration, config_file, confirm = FALSE) } \references{ [1] \url{https://stat.ethz.ch/R-manual/R-devel/library/base/html/regex.html}\cr -[2] \url{http://tldp.org/LDP/abs/html/globbingref.html} +[2] \url{https://tldp.org/LDP/abs/html/globbingref.html} } \seealso{ ConfigApplyMatchingEntries, ConfigEditDefinition, diff --git a/man/Persistence.Rd b/man/Persistence.Rd index 9514788411345b05e569b99098568bef2d1ae026..33d48682db86cecb1e87f9263bb78b34d7e1c68c 100644 --- a/man/Persistence.Rd +++ b/man/Persistence.Rd @@ -90,9 +90,10 @@ uncertainty (prediction interval) based on Coelho et al., 2004.\cr\cr } \examples{ #Building an example dataset with yearly start dates from 1920 to 2009 -obs1 <- 1 : (1 * 90 * 6 * 7) -dim(obs1) <- c(member = 1, time = 90, lat = 6, lon = 7) -dates <- seq(1920, 2009, 1) +set.seed(1) +obs1 <- rnorm(1 * 70 * 6 * 7) +dim(obs1) <- c(member = 1, time = 70, lat = 6, lon = 7) +dates <- seq(1940, 2009, 1) persist <- Persistence(obs1, dates = dates, start = 1961, end = 2005, ft_start = 1, nmemb = 40) diff --git a/man/TPI.Rd b/man/TPI.Rd index e0d62b1efbf293e0382462ee3f3fccc78f9e227b..6968f22e6cc4502755093ff012f39647c6561e13 100644 --- a/man/TPI.Rd +++ b/man/TPI.Rd @@ -4,10 +4,10 @@ \alias{TPI} \title{Compute the Tripole Index (TPI) for the Interdecadal Pacific Oscillation (IPO)} \usage{ -TPI(data, data_lats, data_lons, index, type, lat_dim = "lat", - lon_dim = "lon", mask = NULL, monini = 11, fmonth_dim = "fmonth", - sdate_dim = "sdate", indices_for_clim = NULL, year_dim = "year", - month_dim = "month", member_dim = "member") +TPI(data, data_lats, data_lons, type, lat_dim = "lat", lon_dim = "lon", + mask = NULL, monini = 11, fmonth_dim = "fmonth", sdate_dim = "sdate", + indices_for_clim = NULL, year_dim = "year", month_dim = "month", + member_dim = "member") } \arguments{ \item{data}{A numerical array to be used for the index computation with the @@ -21,6 +21,10 @@ provided, at least, over the whole region needed to compute the index.} \item{data_lons}{A numeric vector indicating the longitudes of the data.} +\item{type}{A character string indicating the type of data ('dcpp' for +decadal predictions, 'hist' for historical simulations, or 'obs' for +observations or reanalyses).} + \item{lat_dim}{A character string of the name of the latitude dimension. The default value is 'lat'.} @@ -66,10 +70,6 @@ dimension. The default value is 'month'. Only used if parameter 'type' is \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{A}{character string indicating the type of data ('dcpp' for -decadal predictions, 'hist' for historical simulations, or 'obs' for -observations or reanalyses).} } \value{ A numerical array of the TPI index with the dimensions of: diff --git a/man/s2dv-package.Rd b/man/s2dv-package.Rd index 71e5d16a00c1bb64c5213335ece11a5f6e888f84..cb522141db9a5c9aa5fa068ba61e4b65c80a5bc7 100644 --- a/man/s2dv-package.Rd +++ b/man/s2dv-package.Rd @@ -17,7 +17,7 @@ with the package 'startR', able to use multiple cores for computation and handle multi-dimensional arrays with a higher flexibility. } \references{ -\url{https://earth.bsc.es/gitlab/es/s2dverification/} +\url{https://earth.bsc.es/gitlab/es/s2dv/} } \keyword{internal} diff --git a/s2dv-manual.pdf b/s2dv-manual.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8c9d1cac06d9fffc9d59bc28e9427d11643c27f3 Binary files /dev/null and b/s2dv-manual.pdf differ diff --git a/tests/testthat/test-Composite.R b/tests/testthat/test-Composite.R index 338abf3d7ffd7a7e8c2896d54a90ebb5c6c77c85..acc7fe64e975b3c41bfa986b36a18a7347d72715 100644 --- a/tests/testthat/test-Composite.R +++ b/tests/testthat/test-Composite.R @@ -181,7 +181,7 @@ test_that("3. dat2", { expect_equal( mean(Composite(dat2, occ2, time_dim = 'sdate')$composite[, , 2, 1])*10^17, -3.908599, - tolerance = 0.00001 + tolerance = 0.001 ) expect_equal( mean(Composite(dat2, occ2, time_dim = 'sdate')$composite[, , 1, 2]), diff --git a/tests/testthat/test-RMS.R b/tests/testthat/test-RMS.R index 35ea4e9da46c735dbec28ba59f9412f60cfffb08..6e18bee447b4397a471350b89a12cf3c1b663f67 100644 --- a/tests/testthat/test-RMS.R +++ b/tests/testthat/test-RMS.R @@ -103,51 +103,69 @@ test_that("1. Input checks", { ############################################## test_that("2. Output checks: dat1", { - +suppressWarnings( expect_equal( dim(RMS(exp1, obs1)$rms), c(nexp = 3, nobs = 2, ftime = 2, lon = 1, lat = 4) ) +) +suppressWarnings( expect_equal( RMS(exp1, obs1)$rms[1:6], c(1.2815677, 2.0832803, 1.1894637, 1.3000403, 1.4053807, 0.8157563), tolerance = 0.001 ) +) +suppressWarnings( expect_equal( length(which(is.na(RMS(exp1, obs1)$conf.lower))), 4 ) +) +suppressWarnings( expect_equal( max(RMS(exp1, obs1)$conf.lower, na.rm = T), 1.399509, tolerance = 0.001 ) +) +suppressWarnings( expect_equal( length(which(is.na(RMS(exp1, obs1, comp_dim = 'ftime')$rms))), 0 ) +) +suppressWarnings( expect_equal( length(which(is.na(RMS(exp1, obs1, comp_dim = 'ftime')$conf.upper))), 8 ) +) +suppressWarnings( expect_equal( length(which(is.na(RMS(exp1, obs1, comp_dim = 'lat')$conf.lower))), 36 ) +) +suppressWarnings( expect_equal( length(which(is.na(RMS(exp1, obs1, comp_dim = 'lat', limits = c(1, 2))$conf.lower))), 21 ) +) +suppressWarnings( expect_equal( min(RMS(exp1, obs1, conf.lev = 0.99)$conf.upper, na.rm = TRUE), 1.406368, tolerance = 0.0001 ) +) +suppressWarnings( expect_equal( length(RMS(exp1, obs1, conf = FALSE)), 1 ) - +) })