diff --git a/DESCRIPTION b/DESCRIPTION index 9d9934751219edac46da063724c718246da94bb0..f6d30e6e5719a4072095e474a7a88f8caef17ef2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: s2dv -Title: Set of Common Tools for Seasonal to Decadal Verification +Title: A Set of Common Tools for Seasonal to Decadal Verification Version: 0.0.1 Authors@R: c( person("BSC-CNS", role = c("aut", "cph")), @@ -10,7 +10,7 @@ Description: The advanced version of package 's2dverification'. It is it can also be used in other kinds of forecasts or general climate analysis. This package is specially designed for the comparison between the experimental and observational datasets. The functionality of the included functions covers - from data retrieval, data post-processing, skill scores against obeservation, + from data retrieval, data post-processing, skill scores against observation, to visualization. Compared to 's2dverification', 's2dv' adopts the regime of package 'multiApply'. Therefore, it can use multi-core for computation and work with multi-dimensional arrays with a higher level of flexibility. diff --git a/NAMESPACE b/NAMESPACE index 8be5ed837de6a0f155362a8141a4fc790ef93b09..627bf51ce445554a9aa98ee491eb9163808fc2dc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -49,15 +49,21 @@ import(parallel) importFrom(ClimProjDiags,Subset) importFrom(abind,abind) importFrom(abind,adrop) +importFrom(grDevices,bmp) importFrom(grDevices,col2rgb) importFrom(grDevices,colorRampPalette) importFrom(grDevices,dev.cur) importFrom(grDevices,dev.new) importFrom(grDevices,dev.off) importFrom(grDevices,gray) +importFrom(grDevices,jpeg) +importFrom(grDevices,pdf) +importFrom(grDevices,png) importFrom(grDevices,postscript) importFrom(grDevices,rainbow) importFrom(grDevices,rgb) +importFrom(grDevices,svg) +importFrom(grDevices,tiff) importFrom(plyr,take) importFrom(stats,acf) importFrom(stats,confint) @@ -67,7 +73,9 @@ importFrom(stats,median) importFrom(stats,na.fail) importFrom(stats,na.omit) importFrom(stats,na.pass) +importFrom(stats,pf) importFrom(stats,pt) +importFrom(stats,qchisq) importFrom(stats,qnorm) importFrom(stats,rnorm) importFrom(stats,ts) diff --git a/NEWS.md b/NEWS.md index c21638265f5de53bf286b8a7fccaf53996e99dff..8290870c7dc6699cee94f9dc5821b085972ccde2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# s2dv 0.0.1 (Release date: 2020-02-) +# s2dv 0.0.1 (Release date: 2020-02-07) - The package is the advanced version of package 's2dverification', adopting the regime of package 'multiApply' for all the analytic functions. Most of the other functions for plotting and data retrieval in 's2dverification' are also preserved in this package. - Because of the adoption of 'multiApply' regime, the functions work well with package 'startR'. - All the packages mentioned above are developed by BSC-CNS. diff --git a/R/InsertDim.R b/R/InsertDim.R index 1ec5b8f8d2eef659b6eba62e9ae5abb8abf82718..cf7866527f9519990d8e36a1b290d0db573f2fd8 100644 --- a/R/InsertDim.R +++ b/R/InsertDim.R @@ -106,7 +106,7 @@ InsertDim <- function(data, posdim, lendim, name = NULL, ncores = NULL) { return(res) } -.InsertDim <- function(x, dat) { +.InsertDim <- function(x, data) { x <- data return(x) } diff --git a/R/RMS.R b/R/RMS.R index cc522f59af5891df72c6db2b972e38a0f276a03b..e9038edc1dc78293d955f359864daf69f87c4c98 100644 --- a/R/RMS.R +++ b/R/RMS.R @@ -60,6 +60,7 @@ #'@rdname RMS #'@import multiApply #'@importFrom ClimProjDiags Subset +#'@importFrom stats qchisq #'@export RMS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', comp_dim = NULL, limits = NULL, @@ -179,7 +180,6 @@ RMS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', return(res) } - .RMS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', conf = TRUE, conf.lev = 0.95) { diff --git a/R/RMSSS.R b/R/RMSSS.R index fa5cca937329d4462f0b2b911c918dc72d306d8a..4f115d3cdb68433e53dcc3a903bbea6e1c1de02d 100644 --- a/R/RMSSS.R +++ b/R/RMSSS.R @@ -49,6 +49,7 @@ #' #'@rdname RMSSS #'@import multiApply +#'@importFrom stats pf #'@export RMSSS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', pval = TRUE, ncores = NULL) { diff --git a/R/Regression.R b/R/Regression.R index 98ef4d2d8f6766d54ef0d7a7c8dc155981c7934c..1e0c79b24c1e34f7d2875bcae03daa170c73d272 100644 --- a/R/Regression.R +++ b/R/Regression.R @@ -30,6 +30,7 @@ #' computation. Default value is NULL. #' #'@import multiApply +#'@importFrom stats pf #'@return #'A list containing: #'\item{$regression}{ diff --git a/R/ToyModel.R b/R/ToyModel.R index 0919a2ef67eb7933f812a41c3aafb0c0e42bbb61..2a0a47f5e001b489d01b5724b4f90d155f0b2247 100644 --- a/R/ToyModel.R +++ b/R/ToyModel.R @@ -93,11 +93,12 @@ #' #'toyforecast <- ToyModel(alpha = a, beta = b, gamma = g, nmemb = nm, #' obsini = sampleData$obs, nstartd = 5, nleadt = 60) -#' \donttest{ -#'PlotAno(toyforecast$mod, toyforecast$obs, startDates, -#' toptitle = c("Synthetic decadal temperature prediction"), -#' fileout = "ex_toymodel.eps") -#' } +#'## Add PlotAno() back when this function is included!! +#'# \donttest{ +#'#PlotAno(toyforecast$mod, toyforecast$obs, startDates, +#'# toptitle = c("Synthetic decadal temperature prediction"), +#'# fileout = "ex_toymodel.eps") +#'# } #' #'@importFrom stats rnorm #'@export diff --git a/R/Utils.R b/R/Utils.R index bb344268f2d5a2640a73e979f641c3e4a7f59cb8..86b2644ff38f872e3d0d5347a6f42ffc7c9dc463 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -1,5 +1,6 @@ #'@importFrom abind abind #'@importFrom plyr take +#'@importFrom grDevices png jpeg pdf svg bmp tiff #'@import ncdf4 ## Function to tell if a regexpr() match is a complete match to a specified name diff --git a/inst/config/BSC.conf b/inst/config/BSC.conf index aca91dbb44fbb0fc2212fbcecfa06ef3cd2a0f0a..1ee7184109fd201d8d5ef3788f9f241d8aa57003 100644 --- a/inst/config/BSC.conf +++ b/inst/config/BSC.conf @@ -1,6 +1,6 @@ -# s2dverification configuration file +# s2dv configuration file # -# Check ?ConfigFileOpen after loading s2dverification for detailed +# Check ?ConfigFileOpen after loading s2dv for detailed # documentation on this configuration file. ############# diff --git a/inst/config/template.conf b/inst/config/template.conf index b6f727eef3235fedd5a31879811e7eac122d2756..e155c8fe9572e88eef6f8393cadc339f0984c18e 100644 --- a/inst/config/template.conf +++ b/inst/config/template.conf @@ -1,6 +1,6 @@ -# s2dverification configuration file +# s2dv configuration file # -# Check ?LoadConfigurationFile after loading s2dverification for detailed +# Check ?LoadConfigurationFile after loading s2dv for detailed # documentation on this configuration file. ################# diff --git a/man/ToyModel.Rd b/man/ToyModel.Rd index 64feac8d0a10d99e1154991197a8337b9a2b4f6b..379ed3bba67e39165ae85a5e41e80ce66313bbf4 100644 --- a/man/ToyModel.Rd +++ b/man/ToyModel.Rd @@ -112,11 +112,12 @@ nm <- 10 toyforecast <- ToyModel(alpha = a, beta = b, gamma = g, nmemb = nm, obsini = sampleData$obs, nstartd = 5, nleadt = 60) - \donttest{ -PlotAno(toyforecast$mod, toyforecast$obs, startDates, - toptitle = c("Synthetic decadal temperature prediction"), - fileout = "ex_toymodel.eps") - } +## Add PlotAno() back when this function is included!! +# \donttest{ +#PlotAno(toyforecast$mod, toyforecast$obs, startDates, +# toptitle = c("Synthetic decadal temperature prediction"), +# fileout = "ex_toymodel.eps") +# } } diff --git a/man/s2dv-package.Rd b/man/s2dv-package.Rd index 7cd54795bcc3cabf8a7aa39492516bfd73b7aff6..fc3eb9450c0682d6104c446b3412df919c4b9010 100644 --- a/man/s2dv-package.Rd +++ b/man/s2dv-package.Rd @@ -4,14 +4,14 @@ \name{s2dv-package} \alias{s2dv} \alias{s2dv-package} -\title{Set of Common Tools for Seasonal to Decadal Verification} +\title{A Set of Common Tools for Seasonal to Decadal Verification} \description{ The advanced version of package 's2dverification'. It is intended for 'seasonal to decadal' (s2d) climate forecast verification, but it can also be used in other kinds of forecasts or general climate analysis. This package is specially designed for the comparison between the experimental and observational datasets. The functionality of the included functions covers -from data retrieval, data post-processing, skill scores against obeservation, +from data retrieval, data post-processing, skill scores against observation, to visualization. Compared to 's2dverification', 's2dv' adopts the regime of package 'multiApply'. Therefore, it can use multi-core for computation and work with multi-dimensional arrays with a higher level of flexibility. diff --git a/tests/testthat/test-Clim.R b/tests/testthat/test-Clim.R index d9617a95272f3d151473c18409229f0b97feb668..835f59f2aaef362617f1083243d4558fa762182a 100644 --- a/tests/testthat/test-Clim.R +++ b/tests/testthat/test-Clim.R @@ -1,4 +1,4 @@ -context("s2dverification::Clim tests") +context("s2dv::Clim tests") ############################################## # dat1 diff --git a/tests/testthat/test-Corr.R b/tests/testthat/test-Corr.R index 490f5e72ec624a938b9ee74920debdf648f4c8ca..d1694f92975500b1060b28db3da7964909ebf9c4 100644 --- a/tests/testthat/test-Corr.R +++ b/tests/testthat/test-Corr.R @@ -1,4 +1,4 @@ -context("s2dverification::Corr tests") +context("s2dv::Corr tests") ############################################## # dat1 @@ -133,8 +133,8 @@ test_that("2. Output checks: dat1", { 2 ) expect_equal( - summary(Corr(exp1, obs1, conf.lev = 0.99)$conf.upper)[1], - c(Min. = 0.2748), + min(Corr(exp1, obs1, conf.lev = 0.99)$conf.upper, na.rm = TRUE), + 0.2747904, tolerance = 0.0001 ) expect_equal( diff --git a/tests/testthat/test-Eno.R b/tests/testthat/test-Eno.R index 1b85092c86c2d436e3d694a227a7097511498713..08fda85e39b82cc160590760b29d31cd9540cf45 100644 --- a/tests/testthat/test-Eno.R +++ b/tests/testthat/test-Eno.R @@ -1,4 +1,4 @@ -context("s2dverification::Eno tests") +context("s2dv::Eno tests") ############################################## set.seed(1) diff --git a/tests/testthat/test-InsertDim.R b/tests/testthat/test-InsertDim.R index eb627fbcde965e4f19609bda69cbc4bd43416195..c4d3226ff66a795cf937fb21431f5158e6835028 100644 --- a/tests/testthat/test-InsertDim.R +++ b/tests/testthat/test-InsertDim.R @@ -1,4 +1,4 @@ -context("s2dverification::InsertDim tests") +context("s2dv::InsertDim tests") ############################################## dat1 <- array(c(1:26), dim = c(dat = 1, sdate = 13, ftime = 2)) diff --git a/tests/testthat/test-MeanDims.R b/tests/testthat/test-MeanDims.R index 7e0f7fbf6242ec81fd5ab4aa78f1a15b76115e6c..9c7c5666a6246759ea7abed3f478bd85f8749f2a 100644 --- a/tests/testthat/test-MeanDims.R +++ b/tests/testthat/test-MeanDims.R @@ -86,14 +86,13 @@ test_that("2. Output checks: dat1", { test_that("3. Output checks: dat2", { expect_equal( - summary(MeanDims(dat2, dims = c(1,3), na.rm = TRUE))[4], - c(Mean = 10), - tolerance = 0.01 + mean(MeanDims(dat2, dims = c(1,3), na.rm = TRUE), na.rm = TRUE), + 10 ) expect_equal( - summary(MeanDims(dat2, dims = c(1,3), na.rm = FALSE))[4], - c(Mean = 11.17), - tolerance = 0.01 + mean(MeanDims(dat2, dims = c(1,3), na.rm = FALSE), na.rm = TRUE), + 11.16667, + tolerance = 0.0001 ) expect_equal( length(which(is.na(MeanDims(dat2, dims = c(1,3), na.rm = FALSE)))), diff --git a/tests/testthat/test-RMS.R b/tests/testthat/test-RMS.R index a0aaff65124bf2898241b2a1d16de98c898c93fc..9394d5ab3d8e5963180b85cd6cd7bded2ce8cf90 100644 --- a/tests/testthat/test-RMS.R +++ b/tests/testthat/test-RMS.R @@ -1,4 +1,4 @@ -context("s2dverification::RMS tests") +context("s2dv::RMS tests") ############################################## # dat1 @@ -133,8 +133,8 @@ test_that("2. Output checks: dat1", { 21 ) expect_equal( - summary(RMS(exp1, obs1, conf.lev = 0.99)$conf.upper)[1], - c(Min. = 1.406), + min(RMS(exp1, obs1, conf.lev = 0.99)$conf.upper, na.rm = TRUE), + 1.406368, tolerance = 0.0001 ) expect_equal( diff --git a/tests/testthat/test-RMSSS.R b/tests/testthat/test-RMSSS.R index a73f90e71ce0ac67b4e9252dadb81d94e1fba9fe..9242d6dd8b1a94332f258c3f2df5f9352a56e565 100644 --- a/tests/testthat/test-RMSSS.R +++ b/tests/testthat/test-RMSSS.R @@ -1,4 +1,4 @@ -context("s2dverification::RMSSS tests") +context("s2dv::RMSSS tests") ############################################## # case 0 diff --git a/tests/testthat/test-Regression.R b/tests/testthat/test-Regression.R index c966fe929a2bc0eff9b96d368602e6f46fc8f050..fd5314222027306166efd56b1b726948f41326fe 100644 --- a/tests/testthat/test-Regression.R +++ b/tests/testthat/test-Regression.R @@ -1,4 +1,4 @@ -context("s2dverification::Regression tests") +context("s2dv::Regression tests") ############################################## # dat1 @@ -136,13 +136,13 @@ test_that("2. Output checks: dat1", { tolerance = 0.001 ) expect_equal( - summary(Regression(datay1, datax1)$p.val)[1], - c(Min. = 0.005335), + min(Regression(datay1, datax1)$p.val, na.rm = TRUE), + 0.005335, tolerance = 0.0001 ) expect_equal( - summary(Regression(datay1, datax1, formula = y~poly(x, 2, raw = T))$p.val)[3], - c(Median = 0.22560), + mean(Regression(datay1, datax1, formula = y~poly(x, 2, raw = T))$p.val, na.rm = TRUE), + 0.3407307, tolerance = 0.0001 ) }) diff --git a/tests/testthat/test-Reorder.R b/tests/testthat/test-Reorder.R index 6cc799b950c1f01b3dcc9b12259a595671b2ec18..0e8e5b5564f2291e13ad614575bf2470e5c26ed0 100644 --- a/tests/testthat/test-Reorder.R +++ b/tests/testthat/test-Reorder.R @@ -71,9 +71,8 @@ test_that("2. Output checks: dat1", { c(sdate = 3, dat = 1, lon = 5, ftime = 2) ) expect_equal( - summary(Reorder(dat1, c(2, 1, 4, 3)))[3], - c(Median = 15.50), - tolerance = 0.01 + max(Reorder(dat1, c(2, 1, 4, 3)), na.rm = TRUE), + 30 ) }) diff --git a/tests/testthat/test-Season.R b/tests/testthat/test-Season.R index b01b242b2bc23f8fc191339e246c5f10b2b14c66..ab9996a26f84fce734315ed037f6e0c57503e600 100644 --- a/tests/testthat/test-Season.R +++ b/tests/testthat/test-Season.R @@ -1,4 +1,4 @@ -context("s2dverification::Season tests") +context("s2dv::Season tests") ############################################## # dat1 @@ -81,13 +81,13 @@ test_that("2. Output checks: dat1", { c(sdate = 3, member = 2, ftime = 2, lon = 3) ) expect_equal( - summary(Season(dat1, monini = 10, moninf = 12, monsup = 2))[3], - c(Median = 0.007925), + median(Season(dat1, monini = 10, moninf = 12, monsup = 2)), + 0.007925, tolerance = 0.0001 ) expect_equal( - summary(Season(dat1, monini = 10, moninf = 2, monsup = 5, method = sum))[3], - c(Median = 0.2732), + median(Season(dat1, monini = 10, moninf = 2, monsup = 5, method = sum)), + 0.2732015, tolerance = 0.0001 ) @@ -97,13 +97,13 @@ test_that("2. Output checks: dat1", { test_that("3. Output checks: dat2", { expect_equal( - summary(Season(dat2, monini = 10, moninf = 12, monsup = 2))[3], - c(Median = -0.01987), + median(Season(dat2, monini = 10, moninf = 12, monsup = 2)), + -0.01986671, tolerance = 0.0001 ) expect_equal( - summary(Season(dat2, monini = 10, moninf = 12, monsup = 2, na.rm = F))[3], - c(Median = 0.06207), + median(Season(dat2, monini = 10, moninf = 12, monsup = 2, na.rm = F), na.rm = TRUE), + 0.06207006, tolerance = 0.0001 ) res <- Season(dat2, monini = 10, moninf = 12, monsup = 2, na.rm = F) diff --git a/tests/testthat/test-Trend.R b/tests/testthat/test-Trend.R index 8843b9ed75bcc651826880ced57d8a4d1010e193..ac9f14a1811ec19feab5913b5d16077610f958f6 100644 --- a/tests/testthat/test-Trend.R +++ b/tests/testthat/test-Trend.R @@ -1,4 +1,4 @@ -context("s2dverification::Trend tests") +context("s2dv::Trend tests") ############################################## # dat1 @@ -87,8 +87,8 @@ test_that("2. Output checks: dat1", { tolerance = 0.0001 ) expect_equal( - summary(Trend(dat1)$detrended)[3], - c(Median = 0.1154), + median(Trend(dat1)$detrended, na.rm = TRUE), + 0.1153846, tolerance = 0.001 ) @@ -130,8 +130,8 @@ test_that("3. Output checks: dat2", { test_that("4. Output checks: dat3", { expect_equal( - summary(Trend(dat3)$trend)[3], - c(Median = 1.3680), + median(Trend(dat3)$trend, na.rm = TRUE), + 1.368071, tolerance = 0.0001 ) expect_equal(