diff --git a/.Rbuildignore b/.Rbuildignore index e817c8bfbfcf40c9315972a5fd5cd8c7986ffeb3..c823928bab44a9986e15f81a90e38f246efb52dd 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -17,3 +17,6 @@ vignettes # but test-CDORemap.R and test-Load.R needs to be hidden #tests/testthat/test-CDORemap.R #tests/testthat/test-Load.R +^.*\.Rproj$ +^\.Rproj\.user$ +^CONTRIBUTING\.md$ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 26a2200ce258f2658c2328e321b49be5d8935268..985765ba834a25d3c8501206e5a7f7345e9c78fa 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ README.Rmd *.ps Rplots.pdf .nfs* +.Rproj.user diff --git a/DESCRIPTION b/DESCRIPTION index aa79da2dade329a233747e6729878cd0990af740..6e031594dbc384f2fa1be279dad389d9afd24cb4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: s2dv -Title: A Set of Common Tools for Seasonal to Decadal Verification -Version: 2.1.0 +Title: Seasonal to Decadal Verification +Version: 2.2.0 Authors@R: c( person("BSC-CNS", role = c("aut", "cph")), person("An-Chi", "Ho", , "an.ho@bsc.es", role = c("aut")), @@ -15,16 +15,20 @@ Authors@R: c( person("Victòria", "Agudetse", , "victoria.agudetse@bsc.es", role = "ctb"), person("Nadia", "Milders", , "nadia.milders@bsc.es", role = "ctb"), person("Ariadna", "Batalla", , "ariadna.batalla@bsc.es", role = c("ctb", "cre"))) -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 observation, - to visualization. Compared to 's2dverification', 's2dv' is more compatible - with the package 'startR', able to use multiple cores for computation and - handle multi-dimensional arrays with a higher flexibility. The CDO version used - in development is 1.9.8. +Description: An advanced version of package 's2dverification'. Intended for + seasonal to decadal (s2d) climate forecast verification, but also applicable + to other types of forecasts or general climate analysis. This package is + specifically designed for comparing experimental and observational datasets. + It provides functionality for data retrieval, post-processing, skill score + computation against observations, and visualization. Compared to + 's2dverification', 's2dv' is more compatible with the package 'startR', able + to use multiple cores for computation and handle multi-dimensional arrays + with a higher flexibility. The Climate Data Operators (CDO) version used in + development is 1.9.8. Implements methods described in Wilks (2011) + , DelSole and Tippett + (2016) , Kharin et al. (2012) + , Doblas-Reyes et al. (2003) + . Depends: R (>= 3.6.0) Imports: @@ -53,5 +57,5 @@ BugReports: https://earth.bsc.es/gitlab/es/s2dv/-/issues LazyData: true SystemRequirements: cdo Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 587aec211d4a7bb13e0ef6e9e7dd9a4a99f6eadd..a94059fc864b2cb163b73d0a2c4104dc11695d57 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,6 +41,7 @@ export(Histo2Hindcast) export(InsertDim) export(LeapYear) export(Load) +export(LoadSampleData) export(MSE) export(MSSS) export(MeanDims) diff --git a/NEWS.md b/NEWS.md index 75e33f9e8f1c916da8132f583cb86865063a05ba..e1f9753d0ee6995dff3a8da4fa95a733d1b8b3d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,17 @@ +# s2dv 2.2.0 (Release date: 2025-09-05) + +**Bugfixes** +- RandomWalkTest(): Fix error when 'A_better' or 'B_better' is NA +- test-Load(): Remove deleted experiment +- RandomWalkTest(): Relax dimensions check to accept dimensions in different order + +**Development** +- RMSSS(): calculate the climatological forecast from the average of 'obs' if 'ref' is NULL +- Accept probabilities as inputs for Fair RPS() and Fair RPSS() + +**Other** +- Add CONTRIBUTING.md + # s2dv 2.1.0 (Release date: 2024-09-26) **Bugfixes** diff --git a/R/ACC.R b/R/ACC.R index ee9d3812ff82b526dc2499c1f710453b36b8e50e..8d6cb8620ae19924f91a0753765df0cd38c67ad1 100644 --- a/R/ACC.R +++ b/R/ACC.R @@ -102,13 +102,10 @@ #'@examples #' \dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #' } #'sampleData$mod <- Season(sampleData$mod, monini = 11, moninf = 12, monsup = 2) #'sampleData$obs <- Season(sampleData$obs, monini = 11, moninf = 12, monsup = 2) diff --git a/R/AnimateMap.R b/R/AnimateMap.R index 1cd1ffe079ce77b04d68bf8433c4573c9635799c..917b9b5e645c6ad2300b3d746fa2424c5bb3da9b 100644 --- a/R/AnimateMap.R +++ b/R/AnimateMap.R @@ -89,33 +89,13 @@ #' } #'} #' -#'@examples -#'# See ?Load for explanations on the first part of this example -#' \dontrun{ -#'data_path <- system.file('sample_data', package = 's2dv') -#'expA <- list(name = 'experiment', path = file.path(data_path, -#' 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', -#' '$VAR_NAME$_$START_DATE$.nc')) -#'obsX <- list(name = 'observation', path = file.path(data_path, -#' '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', -#' '$VAR_NAME$_$YEAR$$MONTH$.nc')) +#'@return No return value, called for side effects. #' -#'# Now we are ready to use Load(). -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- Load('tos', list(expA), list(obsX), startDates, -#' output = 'lonlat', latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } -#' \dontshow{ +#'@examples #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#'sampleData <- LoadSampleData(startDates, output = 'lonlat') #'clim <- Clim(sampleData$mod, sampleData$obs, memb = FALSE) -#' \dontrun{ +#' \donttest{ #'AnimateMap(clim$clim_exp, sampleData$lon, sampleData$lat, #' toptitle = "climatology of decadal prediction", sizetit = 1, #' units = "degree", brks = seq(270, 300, 3), monini = 11, freq = 12, @@ -218,6 +198,8 @@ AnimateMap <- function(var, lon, lat, toptitle = rep("", 11), sizetit = 1, ".png", sep = ""), width = 550, height = 300, bg = "white") # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) for (jt in 1:nleadtime) { title <- paste(toptitle[(jexp - 1) * nobs + jobs], diff --git a/R/Ano.R b/R/Ano.R index ccb41e0a98e41fe51c9873618cdf3dcd9231daaf..bb7c45b4e6cf1b6c89527151f4ae777426333755 100644 --- a/R/Ano.R +++ b/R/Ano.R @@ -17,11 +17,11 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) -#'\dontrun{ +#'\donttest{ #'PlotAno(ano_exp, ano_obs, startDates, #' toptitle = 'Anomaly', ytitle = c('K', 'K', 'K'), #' legends = 'ERSST', biglab = FALSE) diff --git a/R/Ano_CrossValid.R b/R/Ano_CrossValid.R index e083fc90701b97a0db106c034bffd93e67b01b24..772e438ed139c49ab492ae5979f3a908d0aea0ff 100644 --- a/R/Ano_CrossValid.R +++ b/R/Ano_CrossValid.R @@ -43,10 +43,12 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'anomalies <- Ano_CrossValid(sampleData$mod, sampleData$obs) -#'\dontrun{ -#'PlotAno(anomalies$exp, anomalies$obs, startDates, +#'ano_exp <- Reorder(anomalies$exp, c(2, 3, 1, 4)) +#'ano_obs <- Reorder(anomalies$obs, c(2, 3, 1, 4)) +#'\donttest{ +#'PlotAno(ano_exp, ano_obs, startDates, #' toptitle = paste('anomalies'), ytitle = c('K', 'K', 'K'), #' legends = 'ERSST', biglab = FALSE) #'} diff --git a/R/BrierScore.R b/R/BrierScore.R index 82526c03fe97195d961ff91ccfccde5ad5571e3e..672e54775d4e9a1a8be4f739acc32e1446f914df 100644 --- a/R/BrierScore.R +++ b/R/BrierScore.R @@ -79,7 +79,7 @@ #'x <- BrierScore(exp, obs) #' #'# Inputs are arrays -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/CDORemap.R b/R/CDORemap.R index 0933d113507fa04453a557e1552ba377d14f8346..acda5d9559996e0cc5e026080c672d6c6e9a249c 100644 --- a/R/CDORemap.R +++ b/R/CDORemap.R @@ -87,8 +87,9 @@ #' is provided at all, NULL otherwise).} #' \item{'lons'}{The longitudes of the data on the destination grid.} #' \item{'lats'}{The latitudes of the data on the destination grid.} +#' #'@examples -#' \dontrun{ +#' \donttest{ #'# Interpolating only vectors of longitudes and latitudes #'lon <- seq(0, 360 - 360/50, length.out = 50) #'lat <- seq(-90, 90, length.out = 25) @@ -219,9 +220,11 @@ #'names(dim(lat)) <- c('i', 'j') #'tas2 <- CDORemap(tas, lon, lat, 't17grid', 'bil') #'tas2 <- CDORemap(tas, lon, lat, 't17grid', 'bil', FALSE) -#'# It is ossible to specify an external NetCDF file as target grid reference +#' } +#' \dontrun{ +#'# It is possible to specify an external NetCDF file as target grid reference #'tas2 <- CDORemap(tas, lon, lat, 'external_file.nc', 'bil') -#'} +#' } #'@import ncdf4 #'@importFrom easyNCDF ArrayToNc #'@importFrom stats lm predict setNames diff --git a/R/Clim.R b/R/Clim.R index d3dde13d3b0dbf94c68b8ccf2c4dc96505eb53dd..b56f2bcf6394dd0ddba6325da02032fd007fcc65 100644 --- a/R/Clim.R +++ b/R/Clim.R @@ -61,15 +61,16 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'clim2 <- Clim(sampleData$mod, sampleData$obs, method = 'kharin', memb = FALSE) -#'\dontrun{ +#'\donttest{ #'PlotClim(clim$clim_exp, clim$clim_obs, #' toptitle = paste('sea surface temperature climatologies'), #' ytitle = 'K', monini = 11, listexp = c('CMIP5 IC3'), #' listobs = c('ERSST'), biglab = FALSE) #'} +#' #'@importFrom abind adrop #'@importFrom ClimProjDiags Subset #'@import multiApply diff --git a/R/ColorBar.R b/R/ColorBar.R index b6da2bb32820cbfd9bcce4f5aef2f661bfc289c3..fd71df214a03aba19dfcd609cb2a7b77a55452d5 100644 --- a/R/ColorBar.R +++ b/R/ColorBar.R @@ -139,6 +139,7 @@ #' "white", "yellow", "orange", "red", "saddlebrown") #'lims <- seq(-1, 1, 0.2) #'ColorBar(lims, cols) +#' #'@importFrom grDevices col2rgb rgb #'@export ColorBar <- function(brks = NULL, cols = NULL, vertical = TRUE, @@ -435,6 +436,8 @@ ColorBar <- function(brks = NULL, cols = NULL, vertical = TRUE, # ~~~~~~~~~~~~~~~~~~~ # if (plot) { + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) pars_to_save <- c('mar', 'cex', names(userArgs), 'mai', 'mgp', 'las', 'xpd') saved_pars <- par(pars_to_save) par(mar = c(0, 0, 0, 0), cex = 1) diff --git a/R/ConfigApplyMatchingEntries.R b/R/ConfigApplyMatchingEntries.R index 21a304bb2bbd638335b0a552b091aaa806c51711..7cec76c54a62fe0ad2215fbf926714a58d054f60 100644 --- a/R/ConfigApplyMatchingEntries.R +++ b/R/ConfigApplyMatchingEntries.R @@ -25,9 +25,11 @@ #' #'@return A list with the information resulting of applying the matching #' entries is returned. +#' #'@seealso ConfigApplyMatchingEntries, ConfigEditDefinition, #' ConfigEditEntry, ConfigFileOpen, ConfigShowSimilarEntries, #' ConfigShowTable +#' #'@examples #'# Create an empty configuration file #'config_file <- paste0(tempdir(), "/example.conf") @@ -49,6 +51,7 @@ #'# result #'match_info <- ConfigApplyMatchingEntries(configuration, 'tas', #' exp = c('ExampleExperiment2'), show_result = TRUE) +#' #'@export ConfigApplyMatchingEntries <- function(configuration, var, exp = NULL, obs = NULL, show_entries = FALSE, show_result = TRUE) { ## Function to tell if a regexpr() match is a complete match to a specified name diff --git a/R/ConfigEditDefinition.R b/R/ConfigEditDefinition.R index e0cf1a0da01ac06e3ccccd6e9c95a25d77db426a..001e01c094069c3ed17745dbcdc0d24eb9b82653 100644 --- a/R/ConfigEditDefinition.R +++ b/R/ConfigEditDefinition.R @@ -13,9 +13,11 @@ #' variable is being modified. Takes by default TRUE. #' #'@return A modified configuration object is returned. +#' #'@seealso [ConfigApplyMatchingEntries()], [ConfigEditDefinition()], #' [ConfigEditEntry()], [ConfigFileOpen()], [ConfigShowSimilarEntries()], #' [ConfigShowTable()]. +#' #'@examples #'# Create an empty configuration file #'config_file <- paste0(tempdir(), "/example.conf") diff --git a/R/ConfigEditEntry.R b/R/ConfigEditEntry.R index d625c1a65507ce0ea48b8bfff8ff175d0326825a..e6c1482d72628df116307cdc5ba852ed85075024 100644 --- a/R/ConfigEditEntry.R +++ b/R/ConfigEditEntry.R @@ -44,6 +44,7 @@ #' #'@seealso ConfigApplyMatchingEntries, ConfigEditDefinition, ConfigEditEntry, #' ConfigFileOpen, ConfigShowSimilarEntries, ConfigShowTable +#' #'@examples #'# Create an empty configuration file #'config_file <- paste0(tempdir(), "/example.conf") @@ -73,6 +74,7 @@ #'ConfigShowTable(configuration, "experiments") #'# Save the configuration #'ConfigFileSave(configuration, config_file, confirm = FALSE) +#' #'@rdname ConfigEditEntry #'@export ConfigEditEntry <- function(configuration, dataset_type, position, dataset_name = NULL, var_name = NULL, main_path = NULL, file_path = NULL, nc_var_name = NULL, suffix = NULL, varmin = NULL, varmax = NULL) { diff --git a/R/ConfigFileOpen.R b/R/ConfigFileOpen.R index 7d1fd96ec317967cacb75453cab53553198429cc..43a12aa110cddfb9c46f9890e1f2b3b24177e5e4 100644 --- a/R/ConfigFileOpen.R +++ b/R/ConfigFileOpen.R @@ -145,9 +145,11 @@ #' #'@seealso ConfigApplyMatchingEntries, ConfigEditDefinition, #' ConfigEditEntry, ConfigFileOpen, ConfigShowSimilarEntries, ConfigShowTable +#' #'@references #'[1] \url{https://stat.ethz.ch/R-manual/R-devel/library/base/html/regex.html}\cr #'[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/ConfigShowSimilarEntries.R b/R/ConfigShowSimilarEntries.R index ccad3f3229e2d9480d8a44af5f025b3b7464085a..06066ec3a48c1fddad613715d908ce01520af584 100644 --- a/R/ConfigShowSimilarEntries.R +++ b/R/ConfigShowSimilarEntries.R @@ -30,9 +30,11 @@ #' #'@seealso ConfigApplyMatchingEntries, ConfigEditDefinition, #' ConfigEditEntry, ConfigFileOpen, ConfigShowSimilarEntries, ConfigShowTable +#' #'@references #'[1] Simon White, string seamness: #' \url{http://www.catalysoft.com/articles/StrikeAMatch.html} +#' #'@examples #'# Create an empty configuration file #'config_file <- paste0(tempdir(), "/example.conf") diff --git a/R/Consist_Trend.R b/R/Consist_Trend.R index 8289168c437233c7c85e56d0f7d9cc861f2efc92..fb161fd2046fdb8bd0c2b2687c1a09b938c355e8 100644 --- a/R/Consist_Trend.R +++ b/R/Consist_Trend.R @@ -51,8 +51,8 @@ #'} #' #'@examples -#'#'# Load sample data as in Load() example: -#'example(Load) +#'# Load sample data as in Load() example: +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/Corr.R b/R/Corr.R index 28d166eaf8e0f4a09b409de870602acaeeb06476..667c128e67cf8a75832f1bba1fefdbf408283eec 100644 --- a/R/Corr.R +++ b/R/Corr.R @@ -77,7 +77,7 @@ #' #'@examples #'# Case 1: Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/EOF.R b/R/EOF.R index 38c3fae0970f3e487441d64bea40311fbf02e37c..5ab552699af6886ac58a5c799e0c22098fdc42f8 100644 --- a/R/EOF.R +++ b/R/EOF.R @@ -62,27 +62,25 @@ #'} #' #'@seealso ProjectField, NAO, PlotBoxWhisker +#' #'@examples #'# This example computes the EOFs along forecast horizons and plots the one #'# that explains the greatest amount of variability. The example data has low #'# resolution so the result may not be explanatory, but it displays how to #'# use this function. -#'\dontshow{ +#' #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#'} +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') +#' #'ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) #'tmp <- MeanDims(ano$exp, c('dataset', 'member')) #'ano <- tmp[1, , ,] #'names(dim(ano)) <- names(dim(tmp))[-2] -#'eof <- EOF(ano, sampleData$lat, sampleData$lon) -#'\dontrun{ +#'eof <- EOF(ano, sampleData$lat, sampleData$lon, neofs = 4) +#'\donttest{ #'PlotEquiMap(eof$EOFs[1, , ], sampleData$lon, sampleData$lat) #'} #' diff --git a/R/EuroAtlanticTC.R b/R/EuroAtlanticTC.R index a18e6fbc722e8f74e5b48a9c05c3a6e87193ff35..b38fcbd0adc5ca698797972b48fce96a10250f4b 100644 --- a/R/EuroAtlanticTC.R +++ b/R/EuroAtlanticTC.R @@ -51,6 +51,7 @@ #' by the square root of cosine of 'lat' and used to compute the fraction of #' variance explained by each REOFs. #'} +#' #'@examples #'# Use synthetic data #'set.seed(1) diff --git a/R/Filter.R b/R/Filter.R index e7043e2714caf5b8c69b380f1742c2f76291656e..156e62fe21163cfce34399ae6cbe7ee8a2a210d4 100644 --- a/R/Filter.R +++ b/R/Filter.R @@ -21,7 +21,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'ensmod <- MeanDims(sampleData$mod, 2) #'spectrum <- Spectrum(ensmod) #' diff --git a/R/Histo2Hindcast.R b/R/Histo2Hindcast.R index 649b75bb6349497bbe4247ef72dbc746d33aa803..d3de1ac24cb79f8f792b766cfdc1f4b1bf6f7cd7 100644 --- a/R/Histo2Hindcast.R +++ b/R/Histo2Hindcast.R @@ -23,16 +23,11 @@ #' of sdate_dim is 'sdatesout' and the length of ftime_dim is nleadtimesout. #' #'@examples -#' \dontshow{ #'startDates <- c('19901101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 60, -#' output = 'areave', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 60, +#' output = 'areave') #' #'sdates_out <- c('19901101', '19911101', '19921101', '19931101', '19941101') #'leadtimes_per_startdate <- 12 @@ -40,7 +35,7 @@ #' sdates_out, leadtimes_per_startdate) #'obs_data <- Histo2Hindcast(sampleData$obs, startDates, #' sdates_out, leadtimes_per_startdate) -#' \dontrun{ +#' \donttest{ #'exp_data <- Reorder(exp_data, c(3, 4, 1, 2)) #'obs_data <- Reorder(obs_data, c(3, 4, 1, 2)) #'PlotAno(exp_data, obs_data, sdates_out, diff --git a/R/Load.R b/R/Load.R index 47da2b32138902c1ba6ffadb6d8a35df9386b4b5..fecc464094c5e77acae9b3c2768887c2c1556a2d 100644 --- a/R/Load.R +++ b/R/Load.R @@ -756,35 +756,14 @@ #'# Instead, the code in 'dontshow' is run, which loads the equivalent #'# already processed data in R. #'# -#'# Example 1: Providing lists of lists to 'exp' and 'obs': -#'# -#' \dontrun{ -#'data_path <- system.file('sample_data', package = 's2dv') -#'exp <- list( -#' name = 'experiment', -#' path = file.path(data_path, 'model/$EXP_NAME$/monthly_mean', -#' '$VAR_NAME$_3hourly/$VAR_NAME$_$START_DATES$.nc') -#' ) -#'obs <- list( -#' name = 'observation', -#' path = file.path(data_path, 'observation/$OBS_NAME$/monthly_mean', -#' '$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$.nc') -#' ) -#'# Now we are ready to use Load(). -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- Load('tos', list(exp), list(obs), startDates, -#' output = 'areave', latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } -#'# -#'# Example 2: Providing vectors of character strings to 'exp' and 'obs' +#'# Example 1: Providing vectors of character strings to 'exp' and 'obs' #'# and using a configuration file. #'# #'# The configuration file 'sample.conf' that we will create in the example #'# has the proper entries to load these (see ?LoadConfigFile for details on #'# writing a configuration file). #'# -#' \dontrun{ +#' \donttest{ #'data_path <- system.file('sample_data', package = 's2dv') #'expA <- list(name = 'experiment', path = file.path(data_path, #' 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', @@ -799,8 +778,9 @@ #' output = 'areave', latmin = 27, latmax = 48, #' lonmin = -12, lonmax = 40) #'# -#'# Example 3: providing character strings in 'exp' and 'obs', and providing -#'# a configuration file. +#'# Example 2: providing character strings in 'exp' and 'obs', and providing +#'# a configuration file. +#'# #'# The configuration file 'sample.conf' that we will create in the example #'# has the proper entries to load these (see ?LoadConfigFile for details on #'# writing a configuration file). @@ -827,14 +807,7 @@ #' output = 'areave', latmin = 27, latmax = 48, #' lonmin = -12, lonmax = 40, configfile = configfile) #' } -#' \dontshow{ -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' output = 'areave', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#' #'@import parallel bigmemory methods #'@importFrom stats ts window na.omit #'@importFrom abind abind diff --git a/R/LoadSampleData.R b/R/LoadSampleData.R new file mode 100644 index 0000000000000000000000000000000000000000..475de178eec86430aab286961118d4c231178943 --- /dev/null +++ b/R/LoadSampleData.R @@ -0,0 +1,80 @@ +#' Load Sample Data for Package Examples +#' +#' Loads and subsets sample data stored in the internal datasets +#' \code{sampleMap} and \code{sampleTimeSeries}, included with the package. +#' Intended for use in documentation examples instead of \code{Load()}, in order +#' to avoid reliance on external system dependencies like 'nco' and 'cdo' and +#' to reduce computation time during CRAN checks. +#' +#' @param sdates Character vector of start dates to include (e.g., +#' \code{c("19851101", "19901101")}). Must match one or more of the available +#' dates in the internal sample datasets: "19851101", "19901101", "19951101", +#' "20001101" or "20051101". +#' @param leadtimemin Integer specifying the first lead time to include. Default +#' is 1. +#' @param leadtimemax Integer specifying the last lead time to include. If NULL, +#' the full lead time range is included. Default is NULL. +#' @param output Character string indicating the type of output: \code{"areave"} +#' for area-averaged time series data, or \code{"lonlat"} for gridded spatial +#' data. Default is \code{"areave"}. +#' +#' @return A named list with the following elements: +#' \item{mod}{Array of model data with the selected start dates and lead times.} +#' \item{obs}{Array of observational data with the selected start dates and lead +#' times.} +#' \item{lat}{Vector of latitudes.} +#' \item{lon}{Vector of longitudes.} +#' +#' @details +#' This function is designed for use in examples and tests within the +#' 's2dv' package. It provides quick access to precomputed datasets, helping to +#' avoid slow or system-dependent operations during automated checks. +#' +#' @examples +#' startDates <- c("19851101", "19901101", "19951101", "20001101", "20051101") +#' sampleData <- LoadSampleData(sdates = startDates, output = "areave") +#' +#' @export +LoadSampleData <- function(sdates, leadtimemin = 1, leadtimemax = NULL, + output = 'areave') { + + selected_start_dates <- match(sdates, c('19851101', '19901101', '19951101', + '20001101', '20051101')) + start_dates_position <- 3 + lead_times_position <- 4 + + if (output == 'lonlat') { + sampleData <- s2dv::sampleMap + if (is.null(leadtimemax)) { + leadtimemax <- dim(sampleData$mod)[lead_times_position] + } + selected_lead_times <- leadtimemin:leadtimemax + + dataOut <- sampleData + dataOut$mod <- sampleData$mod[, , selected_start_dates, selected_lead_times, , ] + dataOut$obs <- sampleData$obs[, , selected_start_dates, selected_lead_times, , ] + } else if (output == 'areave') { + sampleData <- s2dv::sampleTimeSeries + if (is.null(leadtimemax)) { + leadtimemax <- dim(sampleData$mod)[lead_times_position] + } + selected_lead_times <- leadtimemin:leadtimemax + + dataOut <- sampleData + dataOut$mod <- sampleData$mod[, , selected_start_dates, selected_lead_times] + dataOut$obs <- sampleData$obs[, , selected_start_dates, selected_lead_times] + } + + dims_out <- dim(sampleData$mod) + dims_out[start_dates_position] <- length(selected_start_dates) + dims_out[lead_times_position] <- length(selected_lead_times) + dim(dataOut$mod) <- dims_out + + dims_out <- dim(sampleData$obs) + dims_out[start_dates_position] <- length(selected_start_dates) + dims_out[lead_times_position] <- length(selected_lead_times) + dim(dataOut$obs) <- dims_out + + return(list(mod = dataOut$mod, obs = dataOut$obs, + lat = dataOut$lat, lon = dataOut$lon)) +} diff --git a/R/MSE.R b/R/MSE.R index 5c502baed41a12e8fb118a91d457724d2c8ef97c..2fa5bbe2bf53503f08127d51424af4f21da4d93b 100644 --- a/R/MSE.R +++ b/R/MSE.R @@ -52,7 +52,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/MSSS.R b/R/MSSS.R index ca854f30f8b18b3e8db3e82a1cb6d4487d9783c5..fe05cb2da3c7f4fe29e569d764ff03c8b1caff40 100644 --- a/R/MSSS.R +++ b/R/MSSS.R @@ -77,7 +77,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/MeanDims.R b/R/MeanDims.R index 45fd6f6c5dfd298cb21e988d091503234a11a84e..eb65d477466950780381cbc97a2216a96db6abfd 100644 --- a/R/MeanDims.R +++ b/R/MeanDims.R @@ -21,6 +21,7 @@ #'dim(ens_mean) #'ens_time_mean <- MeanDims(a, c(2, 3), drop = FALSE) #'dim(ens_time_mean) +#' #'@import multiApply #'@export MeanDims <- function(data, dims, na.rm = FALSE, drop = TRUE) { diff --git a/R/NAO.R b/R/NAO.R index 2f562d3d33f2ec7cc6f85e01794b135657d7e535..8934ce7752155a5afeba88161c9fa5fc799d1011 100644 --- a/R/NAO.R +++ b/R/NAO.R @@ -90,7 +90,7 @@ #'exp_cor <- array(rnorm(540), dim = c(member = 2, sdate = 1, ftime = 5, lat = 6, lon = 9)) #'nao <- NAO(exp = exp, obs = obs, exp_cor = exp_cor, lat = lat, lon = lon, obsproj = TRUE) #'# plot the NAO index -#' \dontrun{ +#' \donttest{ #'nao$exp <- Reorder(nao$exp, c(2, 1)) #'nao$obs <- Reorder(nao$obs, c(2, 1)) #'PlotBoxWhisker(nao$exp, nao$obs, "NAO index, DJF", "NAO index (PC1) TOS", diff --git a/R/Plot2VarsVsLTime.R b/R/Plot2VarsVsLTime.R index 12e04ae22d676c670d8fde7afd188f61292316b0..6343fcbf231e02033b23a810bec1c76d9b960e9b 100644 --- a/R/Plot2VarsVsLTime.R +++ b/R/Plot2VarsVsLTime.R @@ -49,9 +49,12 @@ #'------------------\cr\cr #'RMSE error for a number of experiments and along lead-time: (nexp, nltime) #' +#'@return +#'No return value, called for side effects. +#' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) @@ -110,11 +113,11 @@ Plot2VarsVsLTime <- function(var1, var2, toptitle = '', ytitle = '', monini = 1, nvars <- 2 if (length(dim(var1)) != length(dim(var2))) { - print("the two input variables should have the same dimensions") + message("the two input variables should have the same dimensions") stop() } if (length(dim(var1)) >= 4) { - print("dimensions of input variables should be 3") + message("dimensions of input variables should be 3") stop() } nleadtime <- dim(var1)[3] @@ -193,6 +196,8 @@ Plot2VarsVsLTime <- function(var1, var2, toptitle = '', ytitle = '', monini = 1, } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) if (biglab) { diff --git a/R/PlotACC.R b/R/PlotACC.R index 6ea518203dd07520ca52392c857bd0e65f671928..48f6a1f66c0f09f7944e6f07462d1b9d708dde79 100644 --- a/R/PlotACC.R +++ b/R/PlotACC.R @@ -47,18 +47,17 @@ #' lend lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page #' plt smo srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog\cr #' For more information about the parameters see `par`. +#' +#'@return +#'No return value, called for side effects. #' #'@examples -#' \dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') +#' #'sampleData$mod <- Season(sampleData$mod, monini = 11, moninf = 12, monsup = 2) #'sampleData$obs <- Season(sampleData$obs, monini = 11, moninf = 12, monsup = 2) #'clim <- Clim(sampleData$mod, sampleData$obs) @@ -77,6 +76,7 @@ #'PlotACC(res, startDates) #'PlotACC(res_bootstrap, startDates) #' } +#' #'@importFrom grDevices dev.cur dev.new dev.off #'@importFrom stats ts #'@export @@ -142,6 +142,8 @@ PlotACC <- function(ACC, sdates, toptitle = "", sizetit = 1, ytitle = "", } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) if (biglab) { diff --git a/R/PlotAno.R b/R/PlotAno.R index 9a4a97141268bde9e6c80c985e7342dbeb9898f2..042069fa247fac03345315518eb38e2396aef0ea 100644 --- a/R/PlotAno.R +++ b/R/PlotAno.R @@ -51,9 +51,12 @@ #' srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr #' For more information about the parameters see `par`. #' +#'@return +#'No return value, called for side effects. +#' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) @@ -105,7 +108,7 @@ PlotAno <- function(exp_ano, obs_ano = NULL, sdates, toptitle = rep('', 15), stop("4 dim needed : c(nexp/nobs, nmemb, nsdates, nltime)") } if (dim(obs_ano)[3] != nsdates | dim(obs_ano)[4] != nleadtime ) { - stop("obs and exp must have same number of sdates & ltimes") + stop("obs and exp must have the same number of sdates & ltimes") } } else { nobs <- 0 @@ -180,6 +183,8 @@ PlotAno <- function(exp_ano, obs_ano = NULL, sdates, toptitle = rep('', 15), # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) if (biglab) { diff --git a/R/PlotBoxWhisker.R b/R/PlotBoxWhisker.R index 9b4c88e02836f68d32c98d4b92cc0c1d4f1f24cd..81bcea846a6a1a6dc1407c06ed37d2750d7968f2 100644 --- a/R/PlotBoxWhisker.R +++ b/R/PlotBoxWhisker.R @@ -53,38 +53,19 @@ #'0.2 - 2015-03 (L. Batte, \email{lauriane.batte@@ic3.cat}) - Removed all\cr #' normalization for sake of clarity. #'1.0 - 2016-03 (N. Manubens, \email{nicolau.manubens@@bsc.es}) - Formatting to R CRAN -#'@examples -#'# See examples on Load() to understand the first lines in this example -#' \dontrun{ -#'data_path <- system.file('sample_data', package = 's2dverification') -#'expA <- list(name = 'experiment', path = file.path(data_path, -#' 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', -#' '$VAR_NAME$_$START_DATE$.nc')) -#'obsX <- list(name = 'observation', path = file.path(data_path, -#' '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', -#' '$VAR_NAME$_$YEAR$$MONTH$.nc')) #' -#'# Now we are ready to use Load(). -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- Load('tos', list(expA), list(obsX), startDates, -#' leadtimemin = 1, leadtimemax = 4, output = 'lonlat', -#' latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) -#' } -#' \dontshow{ +#'@examples #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 20, latmax = 80, -#' lonmin = -80, lonmax = 40) +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #'# No example data is available over NAO region, so in this example we will #'# tweak the available data. In a real use case, one can Load() the data over #'# NAO region directly. #'sampleData$lon[] <- c(40, 280, 340) #'sampleData$lat[] <- c(20, 80) -#' } +#' #'# Now ready to compute the EOFs and project on, for example, the first #'# variability mode. #'ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) @@ -92,12 +73,10 @@ #'ano_obs <- array(ano$obs, dim = dim(ano$obs)[-2]) #'nao <- NAO(exp = ano_exp, obs = ano_obs, lat = sampleData$lat, lon = sampleData$lon) #'# Finally plot the nao index -#' \dontrun{ #'nao$exp <- Reorder(nao$exp, c(2, 1)) #'nao$obs <- Reorder(nao$obs, c(2, 1)) #'PlotBoxWhisker(nao$exp, nao$obs, "NAO index, DJF", "NAO index (PC1) TOS", #' monini = 12, yearini = 1985, freq = 1, "Exp. A", "Obs. X") -#' } #' #'@importFrom grDevices dev.cur dev.new dev.off #'@importFrom stats cor @@ -203,6 +182,8 @@ PlotBoxWhisker <- function(exp, obs, toptitle = '', ytitle = '', monini = 1, } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) ## Observed time series. diff --git a/R/PlotClim.R b/R/PlotClim.R index aff96e40d1a6addd91f0573be83e456ae44144c6..6aa3b9ebafeb987635f364cc8248ec48df6cae72 100644 --- a/R/PlotClim.R +++ b/R/PlotClim.R @@ -40,10 +40,13 @@ #' lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page pch plt #' smo srt tck usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr #' For more information about the parameters see `par`. +#' +#'@return +#'No return value, called for side effects. #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'PlotClim(clim$clim_exp, clim$clim_obs, toptitle = paste('climatologies'), #' ytitle = 'K', monini = 11, listexp = c('CMIP5 IC3'), @@ -151,6 +154,8 @@ PlotClim <- function(exp_clim, obs_clim = NULL, toptitle = '', ytitle = '', } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) if (biglab) { diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index a2a7e3d4328285bb69e9d45a839107b683221e38..825883c8fa3f124341e654e898a30eeab420579e 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -225,35 +225,15 @@ #'} #' #'@examples -#'# See examples on Load() to understand the first lines in this example -#' \dontrun{ -#'data_path <- system.file('sample_data', package = 's2dv') -#'expA <- list(name = 'experiment', path = file.path(data_path, -#' 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', -#' '$VAR_NAME$_$START_DATE$.nc')) -#'obsX <- list(name = 'observation', path = file.path(data_path, -#' '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', -#' '$VAR_NAME$_$YEAR$$MONTH$.nc')) -#' -#'# Now we are ready to use Load(). -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- Load('tos', list(expA), list(obsX), startDates, -#' leadtimemin = 1, leadtimemax = 4, output = 'lonlat', -#' latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) -#' } -#' \dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #'PlotEquiMap(sampleData$mod[1, 1, 1, 1, , ], sampleData$lon, sampleData$lat, #' toptitle = 'Predicted sea surface temperature for Nov 1960 from 1st Nov', #' title_scale = 0.5) +#' #'@import graphics maps #'@importFrom grDevices dev.cur dev.new dev.off gray #'@importFrom stats cor @@ -1058,6 +1038,8 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, } plot.new() # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) par(mar = margins, cex.main = cex_title, cex.axis = cex_axes_labels, mgp = c(0, spaceticklab, 0), las = 0) diff --git a/R/PlotLayout.R b/R/PlotLayout.R index c77b25a405d3b40535606870899711ad0cda77bd..b515e5fc61f481f85d69cf195b8dc782bf7cc9b9 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -179,32 +179,11 @@ #'} #' #'@examples -#'# See examples on Load() to understand the first lines in this example -#' \dontrun{ -#'data_path <- system.file('sample_data', package = 's2dv') -#'expA <- list(name = 'experiment', path = file.path(data_path, -#' 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', -#' '$VAR_NAME$_$START_DATE$.nc')) -#'obsX <- list(name = 'observation', path = file.path(data_path, -#' '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', -#' '$VAR_NAME$_$YEAR$$MONTH$.nc')) -#' -#'# Now we are ready to use Load(). -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- Load('tos', list(expA), list(obsX), startDates, -#' leadtimemin = 1, leadtimemax = 4, output = 'lonlat', -#' latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) -#' } -#' \dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #'PlotLayout(PlotEquiMap, c('lat', 'lon'), sampleData$mod[1, , 1, 1, , ], #' sampleData$lon, sampleData$lat, #' toptitle = 'Predicted tos for Nov 1960 from 1st Nov', @@ -517,6 +496,8 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, vertical <- drawleg %in% c('E', 'W') # Open connection to graphical device + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) if (!is.null(fileout)) { saveToFile(fileout) } else if (names(dev.cur()) == 'null device') { diff --git a/R/PlotMatrix.R b/R/PlotMatrix.R index 269d059c33802b67af32b064b129eef600f7d104..5f01049c1a41e876a6fb58a0c5a7f3d8a1776140 100644 --- a/R/PlotMatrix.R +++ b/R/PlotMatrix.R @@ -58,6 +58,7 @@ #' xtitle = "Forecast time (month)", ytitle = "Start date", #' xlabels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", #' "Aug", "Sep", "Oct", "Nov", "Dec")) +#' #'@importFrom grDevices dev.new dev.off dev.cur #'@export PlotMatrix <- function(var, brks = NULL, cols = NULL, @@ -120,7 +121,10 @@ PlotMatrix <- function(var, brks = NULL, cols = NULL, dev.new(units = size_units, res = res, width = 8 * figure.width, height = 5) } - + + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) + if (!is.null(fileout)) { # Draw empty plot: diff --git a/R/PlotSection.R b/R/PlotSection.R index 29bdd4929e2495b40830ec70dd663c101be47c11..d0cb060f024a9405ed1ecb07943d5481860e95a3 100644 --- a/R/PlotSection.R +++ b/R/PlotSection.R @@ -36,10 +36,14 @@ #' yaxt ylbias ylog \cr #' For more information about the parameters see `par`. #' +#'@return +#'No return value, called for side effects. +#' #'@examples #'sampleData <- s2dv::sampleDepthData #'PlotSection(sampleData$mod[1, 1, 1, 1, , ], sampleData$lat, sampleData$depth, #' toptitle = 'temperature 1995-11 member 0') +#' #'@importFrom grDevices dev.cur dev.new dev.off rainbow #'@export PlotSection <- function(var, horiz, depth, toptitle = '', sizetit = 1, @@ -119,6 +123,8 @@ PlotSection <- function(var, horiz, depth, toptitle = '', sizetit = 1, } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) xmargin <- 0.5 diff --git a/R/PlotStereoMap.R b/R/PlotStereoMap.R index a2fdb85d27cc0faf2fd8d21160bfdfe9d1a3a6c0..fb4e117b324c96335f53dc81d7370f691a7947a1 100644 --- a/R/PlotStereoMap.R +++ b/R/PlotStereoMap.R @@ -170,10 +170,9 @@ #'data <- matrix(rnorm(100 * 50), 100, 50) #'x <- seq(from = 0, to = 360, length.out = 100) #'y <- seq(from = -90, to = 90, length.out = 50) -#' \dontrun{ #'PlotStereoMap(data, x, y, latlims = c(60, 90), brks = 50, #' toptitle = "This is the title") -#' } +#' #'@import mapproj #'@importFrom grDevices dev.cur dev.new dev.off gray #'@importFrom stats median @@ -603,6 +602,8 @@ PlotStereoMap <- function(var, lon, lat, varu = NULL, varv = NULL, latlims = c(6 layout(matrix(1:2, ncol = 2, nrow = 1), widths = c(8, 2)) } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) par(mar = margins, las = 0) coast <- map("world", interior = FALSE, projection = "stereographic", diff --git a/R/PlotVsLTime.R b/R/PlotVsLTime.R index c51e31b3c04cb2d302e282a14d9b22f7a83be47b..434f5115304b720a5a291936fe97198a841e70e6 100644 --- a/R/PlotVsLTime.R +++ b/R/PlotVsLTime.R @@ -65,9 +65,12 @@ #'would plot the correlations or RMS between each exp & each obs as a function #'of the forecast time. #' +#'@return +#'No return value, called for side effects. +#' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) @@ -197,6 +200,8 @@ PlotVsLTime <- function(var, toptitle = '', ytitle = '', monini = 1, freq = 12, } # Load the user parameters + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) par(userArgs) if (biglab) { diff --git a/R/ProbBins.R b/R/ProbBins.R index adc889093fac343104834af7e6b81993f3c26bc3..78c193796be8786a1915002cd545e3b04cacb185 100644 --- a/R/ProbBins.R +++ b/R/ProbBins.R @@ -40,14 +40,8 @@ #' grid point, time step, member and start date belongs to. #' #'@examples -#'\dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#'} +#'sampleData <- LoadSampleData(startDates, output = 'lonlat') #'clim <- Clim(sampleMap$mod, sampleMap$obs) #'ano_exp <- Ano(sampleMap$mod, clim$clim_exp) #'PB <- ProbBins(ano_exp, fcyr = 3, thr = c(1/3, 2/3), quantile = TRUE) diff --git a/R/ProjectField.R b/R/ProjectField.R index 70c8552c934becbcc2f2b365139bc1f2aa178543..9b4a3ed22a50b8c88fb52789bb5663c2212889b9 100644 --- a/R/ProjectField.R +++ b/R/ProjectField.R @@ -28,24 +28,20 @@ #' format. The dimensions are the same as 'ano' except 'space_dim'. #' #'@seealso EOF, NAO, PlotBoxWhisker +#' #'@examples -#'\dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#'} +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #'ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) -#'eof_exp <- EOF(ano$exp, sampleData$lat, sampleData$lon) -#'eof_obs <- EOF(ano$obs, sampleData$lat, sampleData$lon) +#'eof_exp <- EOF(ano$exp, sampleData$lat, sampleData$lon, neofs = 5) +#'eof_obs <- EOF(ano$obs, sampleData$lat, sampleData$lon, neofs = 5) #'mode1_exp <- ProjectField(ano$exp, eof_exp, mode = 1) #'mode1_obs <- ProjectField(ano$obs, eof_obs, mode = 1) #' -#'\dontrun{ +#'\donttest{ #' # Plot the forecast and the observation of the first mode for the last year #' # of forecast #' sdate_dim_length <- dim(mode1_obs)['sdate'] diff --git a/R/REOF.R b/R/REOF.R index 1135332978782d8cdec5c92f67a2a3b63b29c034..27fcfdc91d79111e11dba1902d3b1401d3138f2a 100644 --- a/R/REOF.R +++ b/R/REOF.R @@ -49,6 +49,7 @@ #'} #' #'@seealso EOF +#' #'@examples #'# This example computes the REOFs along forecast horizons and plots the one #'# that explains the greatest amount of variability. The example data has low @@ -56,19 +57,19 @@ #'# use this function. #'\dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) +#'sampleData <- LoadSampleData(sdates = startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #'} #'ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) #'ano <- MeanDims(ano$exp, c('dataset', 'member')) #'res <- REOF(ano, lat = sampleData$lat, lon = sampleData$lon, ntrunc = 5) -#'\dontrun{ -#'PlotEquiMap(eof$EOFs[1, , , 1], sampleData$lat, sampleData$lon) +#'eof_to_plot <- array(res$REOFs[1, , , 1], +#' dim = c(length(sampleData$lat), length(sampleData$lon)), +#' dimnames = list(lat = sampleData$lat, lon = sampleData$lon)) +#'\donttest{ +#'PlotEquiMap(eof_to_plot, sampleData$lat, sampleData$lon) #'} #' #'@import multiApply diff --git a/R/RMS.R b/R/RMS.R index a08af1271ac8338b78a32c6ad8d6e2741419e6cd..a96fd233c988b58c3804d9a1e41c1d80e05b3431 100644 --- a/R/RMS.R +++ b/R/RMS.R @@ -53,7 +53,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/RMSSS.R b/R/RMSSS.R index 7bf97dd7657e52372a63628c962a7760be821608..e8bdd53167798d0ca27147cddb68103bdec5c465 100644 --- a/R/RMSSS.R +++ b/R/RMSSS.R @@ -77,7 +77,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/R/RatioRMS.R b/R/RatioRMS.R index d09fc0fbac57cccfe8a76b992ce25f0eaca4412a..17fbe3812c96c87e76a3c78ec51fa42dd7c13d06 100644 --- a/R/RatioRMS.R +++ b/R/RatioRMS.R @@ -31,14 +31,9 @@ #'} #' #'@examples -#'\dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#'} +#'sampleData <- LoadSampleData(startDates, output = 'lonlat') +#' #'# Compute DJF seasonal means and anomalies. #'initial_month <- 11 #'mean_start_month <- 12 diff --git a/R/RatioSDRMS.R b/R/RatioSDRMS.R index f7e848f3648869b5d52c6a683f9f677219d5d745..159d829881e54cb408b26367d709c9b5f14fed1a 100644 --- a/R/RatioSDRMS.R +++ b/R/RatioSDRMS.R @@ -36,17 +36,17 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'rsdrms <- RatioSDRMS(sampleData$mod, sampleData$obs, dat_dim = 'dataset') #'# Reorder the data in order to plot it with PlotVsLTime #'rsdrms_plot <- array(dim = c(dim(rsdrms$ratio)[1:2], 4, dim(rsdrms$ratio)[3])) #'rsdrms_plot[, , 2, ] <- rsdrms$ratio #'rsdrms_plot[, , 4, ] <- rsdrms$p.val -#'\dontrun{ +#' \donttest{ #'PlotVsLTime(rsdrms_plot, toptitle = "Ratio ensemble spread / RMSE", ytitle = "", #' monini = 11, limits = c(-1, 1.3), listexp = c('CMIP5 IC3'), #' listobs = c('ERSST'), biglab = FALSE, siglev = TRUE) -#'} +#' } #' #'@import multiApply #'@export diff --git a/R/Regression.R b/R/Regression.R index ef92fc4e3011291b0678b1bc137025fd1f95eb06..0001d578c3e617bb2465a2fca0207c7a31156a35 100644 --- a/R/Regression.R +++ b/R/Regression.R @@ -74,7 +74,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'datay <- sampleData$mod[, 1, , ] #'names(dim(datay)) <- c('sdate', 'ftime') #'datax <- sampleData$obs[, 1, , ] diff --git a/R/Reorder.R b/R/Reorder.R index 2809a00eab1860723acbe051222a6d7691cde61a..30309d8b45a70b49b848cd8699b93ff28246a9f1 100644 --- a/R/Reorder.R +++ b/R/Reorder.R @@ -24,6 +24,7 @@ #' # A character array #' dat3 <- array(paste0('a', 1:24), dim = c(b = 2, c = 3, d = 4)) #' dat3_reorder <- Reorder(dat3, c('d', 'c', 'b')) +#' #'@export Reorder <- function(data, order) { diff --git a/R/Season.R b/R/Season.R index 46dcc489994f91920316eb759437ec78a06a41cc..f9c1ec0d2943cf07b0e6f1a045bbf47492866d6d 100644 --- a/R/Season.R +++ b/R/Season.R @@ -36,6 +36,7 @@ #'dat2[na] <- NA #'res <- Season(data = dat2, monini = 3, moninf = 1, monsup = 2) #'res <- Season(data = dat2, monini = 3, moninf = 1, monsup = 2, na.rm = FALSE) +#' #'@import multiApply #'@export Season <- function(data, monini, moninf, monsup, time_dim = 'ftime', diff --git a/R/Smoothing.R b/R/Smoothing.R index f1efa449c09ab1d0edbae06cd69fc0543e3772c5..f320dd882e11646cd0a2fa85ad75762853ed0cf7 100644 --- a/R/Smoothing.R +++ b/R/Smoothing.R @@ -17,7 +17,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'ano_obs <- Ano(sampleData$obs, clim$clim_obs) @@ -25,10 +25,11 @@ #'smooth_ano_obs <- Smoothing(ano_obs, time_dim = 'ftime', runmeanlen = 12) #'smooth_ano_exp <- Reorder(smooth_ano_exp, c(2, 3, 4, 1)) #'smooth_ano_obs <- Reorder(smooth_ano_obs, c(2, 3, 4, 1)) -#' \dontrun{ +#' \donttest{ #'PlotAno(smooth_ano_exp, smooth_ano_obs, startDates, #' toptitle = "Smoothed Mediterranean mean SST", ytitle = "K") #' } +#' #'@import plyr multiApply #'@export Smoothing <- function(data, time_dim = 'ftime', runmeanlen = 12, ncores = NULL) { diff --git a/R/Spectrum.R b/R/Spectrum.R index cbaf135946fdb5c35000319bf248d3efd51775b8..0f73cf599839ea210131aca730af877636a58dd8 100644 --- a/R/Spectrum.R +++ b/R/Spectrum.R @@ -27,7 +27,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'ensmod <- MeanDims(sampleData$mod, 2) #'spectrum <- Spectrum(ensmod) #' diff --git a/R/Spread.R b/R/Spread.R index 88ead15b78a454d144a58e0cd0fb6e6efdd6d697..ad141c501d9883a9f276fcdc6f229304ba15b509 100644 --- a/R/Spread.R +++ b/R/Spread.R @@ -42,7 +42,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'clim <- Clim(sampleData$mod, sampleData$obs) #'ano_exp <- Ano(sampleData$mod, clim$clim_exp) #'runmean_months <- 12 @@ -56,7 +56,7 @@ #'spread <- Spread(smooth_ano_exp_m_sub, compute_dim = c('member', 'sdate')) #'}) #' -#'\dontrun{ +#' \donttest{ #'PlotVsLTime(Reorder(spread$iqr, c('dataset', 'stats', 'ftime')), #' toptitle = "Inter-Quartile Range between ensemble members", #' ytitle = "K", monini = 11, limits = NULL, @@ -77,7 +77,7 @@ #' ytitle = "K", monini = 11, limits = NULL, #' listexp = c('CMIP5 IC3'), listobs = c('ERSST'), biglab = FALSE, #' hlines = c(0)) -#'} +#' } #' #'@import multiApply #'@importFrom stats IQR sd mad runif quantile diff --git a/R/ToyModel.R b/R/ToyModel.R index 2a0a47f5e001b489d01b5724b4f90d155f0b2247..fc7c67f756bb6d4bf1481bd8f7dadff18145fbff 100644 --- a/R/ToyModel.R +++ b/R/ToyModel.R @@ -62,29 +62,8 @@ #' #'# Example 2: Generate forecast from loaded observations #'# Decadal prediction example -#' \dontrun{ -#'data_path <- system.file('sample_data', package = 's2dv') -#'expA <- list(name = 'experiment', path = file.path(data_path, -#' 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', -#' '$VAR_NAME$_$START_DATE$.nc')) -#'obsX <- list(name = 'observation', path = file.path(data_path, -#' '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', -#' '$VAR_NAME$_$YEAR$$MONTH$.nc')) -#' -#'# Now we are ready to use Load(). -#'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- Load('tos', list(expA), list(obsX), startDates, -#' output = 'areave', latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } -#' \dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' output = 'areave', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) -#' } +#'sampleData <- LoadSampleData(startDates, output = 'areave') #' #'a <- 0.1 #'b <- 0.3 @@ -93,12 +72,12 @@ #' #'toyforecast <- ToyModel(alpha = a, beta = b, gamma = g, nmemb = nm, #' obsini = sampleData$obs, nstartd = 5, nleadt = 60) -#'## 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") -#'# } +#' +#'\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/Trend.R b/R/Trend.R index 883bcdf42ef3024bb3d0a95636d45c26bf6d356d..68287583ad614d78fab7d0f95c0397cae0744c6e 100644 --- a/R/Trend.R +++ b/R/Trend.R @@ -66,7 +66,7 @@ #' #'@examples #'# Load sample data as in Load() example: -#'example(Load) +#'example(LoadSampleData) #'months_between_startdates <- 60 #'trend <- Trend(sampleData$obs, polydeg = 2, interval = months_between_startdates) #' diff --git a/R/UltimateBrier.R b/R/UltimateBrier.R index 79b9864574cbc35724d509aa0f92da2ba4e5c56b..f69a5ebdfff85678c1eb63b5ee3fdaef9c0a54b8 100644 --- a/R/UltimateBrier.R +++ b/R/UltimateBrier.R @@ -68,13 +68,10 @@ #'@examples #' \dontshow{ #'startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -#'sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), -#' c('observation'), startDates, -#' leadtimemin = 1, -#' leadtimemax = 4, -#' output = 'lonlat', -#' latmin = 27, latmax = 48, -#' lonmin = -12, lonmax = 40) +#'sampleData <- LoadSampleData(startDates, +#' leadtimemin = 1, +#' leadtimemax = 4, +#' output = 'lonlat') #' } #'sampleData$mod <- Season(sampleData$mod, monini = 11, moninf = 12, monsup = 2) #'sampleData$obs <- Season(sampleData$obs, monini = 11, moninf = 12, monsup = 2) diff --git a/R/Utils.R b/R/Utils.R index c6e233c00ca1c532c7bcd7224b62411e5585e209..67d73eb20043206e9006ad47d6881a325ee59fdb 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -997,63 +997,6 @@ } } -.LoadSampleData <- function(var, exp = NULL, obs = NULL, sdates, - nmember = NULL, nmemberobs = NULL, - nleadtime = NULL, leadtimemin = 1, - leadtimemax = NULL, storefreq = 'monthly', - sampleperiod = 1, lonmin = 0, lonmax = 360, - latmin = -90, latmax = 90, output = 'areave', - method = 'conservative', grid = NULL, - maskmod = vector("list", 15), - maskobs = vector("list", 15), - configfile = NULL, suffixexp = NULL, - suffixobs = NULL, varmin = NULL, varmax = NULL, - silent = FALSE, nprocs = NULL) { - ## This function loads and selects sample data stored in sampleMap and - ## sampleTimeSeries and is used in the examples instead of Load() so as - ## to avoid nco and cdo system calls and computation time in the stage - ## of running examples in the CHECK process on CRAN. - selected_start_dates <- match(sdates, c('19851101', '19901101', '19951101', - '20001101', '20051101')) - start_dates_position <- 3 - lead_times_position <- 4 - - if (output == 'lonlat') { - sampleData <- s2dv::sampleMap - if (is.null(leadtimemax)) { - leadtimemax <- dim(sampleData$mod)[lead_times_position] - } - selected_lead_times <- leadtimemin:leadtimemax - - dataOut <- sampleData - dataOut$mod <- sampleData$mod[, , selected_start_dates, selected_lead_times, , ] - dataOut$obs <- sampleData$obs[, , selected_start_dates, selected_lead_times, , ] - } else if (output == 'areave') { - sampleData <- s2dv::sampleTimeSeries - if (is.null(leadtimemax)) { - leadtimemax <- dim(sampleData$mod)[lead_times_position] - } - selected_lead_times <- leadtimemin:leadtimemax - - dataOut <- sampleData - dataOut$mod <- sampleData$mod[, , selected_start_dates, selected_lead_times] - dataOut$obs <- sampleData$obs[, , selected_start_dates, selected_lead_times] - } - - dims_out <- dim(sampleData$mod) - dims_out[start_dates_position] <- length(selected_start_dates) - dims_out[lead_times_position] <- length(selected_lead_times) - dim(dataOut$mod) <- dims_out - - dims_out <- dim(sampleData$obs) - dims_out[start_dates_position] <- length(selected_start_dates) - dims_out[lead_times_position] <- length(selected_lead_times) - dim(dataOut$obs) <- dims_out - - invisible(list(mod = dataOut$mod, obs = dataOut$obs, - lat = dataOut$lat, lon = dataOut$lon)) -} - .ConfigGetDatasetInfo <- function(matching_entries, table_name) { # This function obtains the information of a dataset and variable pair, # applying all the entries that match in the configuration file. diff --git a/R/clim.palette.R b/R/clim.palette.R index b23ff8428f201dbe4cb129e5f202ab2f1924532f..7d1cb10f935e53d303b7ae38901386e7c2489a07 100644 --- a/R/clim.palette.R +++ b/R/clim.palette.R @@ -10,6 +10,11 @@ #' and from orange through white to purple ('orangepurple'). #'@param n Number of colors to generate. #' +#'@return +#'A function that generates a vector of \code{n} color hex codes when +#'called. The returned function has an optional attribute \code{"na_color"} +#'specifying the color used for missing values. +#' #'@examples #'lims <- seq(-1, 1, length.out = 21) #' diff --git a/README.md b/README.md index baba3c395489f10b2ea68a18bd140573c7f999c7..87dfa8ae95b1a934d942cd5fcf64692e638318e0 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,9 @@ data input of the functions should have names for all the dimensions. It should not be a problem since the data retrieved by s2dv::Load or startR::Start have named dimension inherently. Take the sample data in s2dv as an example: ```r -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), c('observation'), - '19901101', leadtimemin = 1, leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) +sampleData <- LoadSampleData('19901101', leadtimemin = 1, leadtimemax = 4, + output = 'lonlat') + # It returns an object 'sampleData' dim(sampleData$mod) dataset member sdate ftime lat lon diff --git a/man/ACC.Rd b/man/ACC.Rd index f733f74181780f00938449d2a44f573dcb767e93..33d661e6da08952723b3d5f35da9ca03965d8416 100644 --- a/man/ACC.Rd +++ b/man/ACC.Rd @@ -142,13 +142,10 @@ Wilks (2011; section 7.6.4; https://doi.org/10.1016/B978-0-12-385022-5.00008-7). \examples{ \dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') } sampleData$mod <- Season(sampleData$mod, monini = 11, moninf = 12, monsup = 2) sampleData$obs <- Season(sampleData$obs, monini = 11, moninf = 12, monsup = 2) diff --git a/man/AnimateMap.Rd b/man/AnimateMap.Rd index 2ec930d5c964189f4c3e39ce167037c9cbe1d6fd..009e1fe612ff0bed727aa2c4d9db7b18100982cc 100644 --- a/man/AnimateMap.Rd +++ b/man/AnimateMap.Rd @@ -106,6 +106,9 @@ lwd mai mar mex mfcol mfrow mfg mgp mkh oma omd omi page pch plt pty smo srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog. \cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Create animations of maps in an equi-rectangular or stereographic projection, showing the anomalies, the climatologies, the mean InterQuartile @@ -147,32 +150,10 @@ Examples of input: } } \examples{ -# See ?Load for explanations on the first part of this example - \dontrun{ -data_path <- system.file('sample_data', package = 's2dv') -expA <- list(name = 'experiment', path = file.path(data_path, - 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', - '$VAR_NAME$_$START_DATE$.nc')) -obsX <- list(name = 'observation', path = file.path(data_path, - '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', - '$VAR_NAME$_$YEAR$$MONTH$.nc')) - -# Now we are ready to use Load(). -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- Load('tos', list(expA), list(obsX), startDates, - output = 'lonlat', latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } - \dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } +sampleData <- LoadSampleData(startDates, output = 'lonlat') clim <- Clim(sampleData$mod, sampleData$obs, memb = FALSE) - \dontrun{ + \donttest{ AnimateMap(clim$clim_exp, sampleData$lon, sampleData$lat, toptitle = "climatology of decadal prediction", sizetit = 1, units = "degree", brks = seq(270, 300, 3), monini = 11, freq = 12, diff --git a/man/Ano.Rd b/man/Ano.Rd index e30467e0f3070aacae112aa9086322f3320f2903..2bacf58819c9271dc628faa22cba10921057f017 100644 --- a/man/Ano.Rd +++ b/man/Ano.Rd @@ -28,11 +28,11 @@ climatology array. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) -\dontrun{ +\donttest{ PlotAno(ano_exp, ano_obs, startDates, toptitle = 'Anomaly', ytitle = c('K', 'K', 'K'), legends = 'ERSST', biglab = FALSE) diff --git a/man/Ano_CrossValid.Rd b/man/Ano_CrossValid.Rd index 2a82713159b5d3357904e190a88486aadea52d1b..532cdee45a31064f85715a3472055932486cc85b 100644 --- a/man/Ano_CrossValid.Rd +++ b/man/Ano_CrossValid.Rd @@ -65,10 +65,12 @@ the 'exp' and 'obs' are excluded when computing the climatologies. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) anomalies <- Ano_CrossValid(sampleData$mod, sampleData$obs) -\dontrun{ -PlotAno(anomalies$exp, anomalies$obs, startDates, +ano_exp <- Reorder(anomalies$exp, c(2, 3, 1, 4)) +ano_obs <- Reorder(anomalies$obs, c(2, 3, 1, 4)) +\donttest{ +PlotAno(ano_exp, ano_obs, startDates, toptitle = paste('anomalies'), ytitle = c('K', 'K', 'K'), legends = 'ERSST', biglab = FALSE) } diff --git a/man/BrierScore.Rd b/man/BrierScore.Rd index 76fb27eb0106b2a38a4222af784b268abcaa45a2..41cf8d6c936b7675352519cbf3dc2541de5a5b82 100644 --- a/man/BrierScore.Rd +++ b/man/BrierScore.Rd @@ -94,7 +94,7 @@ obs <- round(exp) x <- BrierScore(exp, obs) # Inputs are arrays -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/CDORemap.Rd b/man/CDORemap.Rd index 9bfeaa557bfce79400e4b1959e1e0c555157c0b3..a211ce617deb213cc2d6280e2a8c7224344ba5a5 100644 --- a/man/CDORemap.Rd +++ b/man/CDORemap.Rd @@ -120,7 +120,7 @@ Any metadata attached to the input data array, longitudes or latitudes will be preserved or accordingly modified. } \examples{ - \dontrun{ + \donttest{ # Interpolating only vectors of longitudes and latitudes lon <- seq(0, 360 - 360/50, length.out = 50) lat <- seq(-90, 90, length.out = 25) @@ -251,7 +251,9 @@ lat <- t(array(seq(-90, 90, length.out = num_lats), names(dim(lat)) <- c('i', 'j') tas2 <- CDORemap(tas, lon, lat, 't17grid', 'bil') tas2 <- CDORemap(tas, lon, lat, 't17grid', 'bil', FALSE) -# It is ossible to specify an external NetCDF file as target grid reference + } + \dontrun{ +# It is possible to specify an external NetCDF file as target grid reference tas2 <- CDORemap(tas, lon, lat, 'external_file.nc', 'bil') -} + } } diff --git a/man/Clim.Rd b/man/Clim.Rd index c3bd96fa0165213f4399ff94156912321ed21f2f..4ee2a9fbfb21baffc426fef44452b9e75567e08a 100644 --- a/man/Clim.Rd +++ b/man/Clim.Rd @@ -89,13 +89,14 @@ per-pair correction beforehand. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) clim2 <- Clim(sampleData$mod, sampleData$obs, method = 'kharin', memb = FALSE) -\dontrun{ +\donttest{ PlotClim(clim$clim_exp, clim$clim_obs, toptitle = paste('sea surface temperature climatologies'), ytitle = 'K', monini = 11, listexp = c('CMIP5 IC3'), listobs = c('ERSST'), biglab = FALSE) } + } diff --git a/man/ColorBar.Rd b/man/ColorBar.Rd index 6d62f153d89f73aae9cffea2e2ead04a66d894f2..d661892f6fbed9355a2f6d94d494e2744ac6f37d 100644 --- a/man/ColorBar.Rd +++ b/man/ColorBar.Rd @@ -191,4 +191,5 @@ cols <- c("dodgerblue4", "dodgerblue1", "forestgreen", "yellowgreen", "white", "white", "yellow", "orange", "red", "saddlebrown") lims <- seq(-1, 1, 0.2) ColorBar(lims, cols) + } diff --git a/man/ConfigApplyMatchingEntries.Rd b/man/ConfigApplyMatchingEntries.Rd index ee4cb5a40bf6cc8c44ff82fff0cfecb4279ce298..694861f10fdd7203104e7f3be5412c45d615a45b 100644 --- a/man/ConfigApplyMatchingEntries.Rd +++ b/man/ConfigApplyMatchingEntries.Rd @@ -68,6 +68,7 @@ configuration <- ConfigEditEntry(configuration, "experiments", 1, # result match_info <- ConfigApplyMatchingEntries(configuration, 'tas', exp = c('ExampleExperiment2'), show_result = TRUE) + } \seealso{ ConfigApplyMatchingEntries, ConfigEditDefinition, diff --git a/man/ConfigEditEntry.Rd b/man/ConfigEditEntry.Rd index e597709dfa2c7a8683a716c0dad12cf4faf7c82c..204e5fb05fb60262278aa0e58a0339dd7a27b22d 100644 --- a/man/ConfigEditEntry.Rd +++ b/man/ConfigEditEntry.Rd @@ -118,6 +118,7 @@ configuration <- ConfigRemoveEntry(configuration, "experiments", ConfigShowTable(configuration, "experiments") # Save the configuration ConfigFileSave(configuration, config_file, confirm = FALSE) + } \seealso{ ConfigApplyMatchingEntries, ConfigEditDefinition, ConfigEditEntry, diff --git a/man/Consist_Trend.Rd b/man/Consist_Trend.Rd index 2ac7d42655c91de8713d5a2ff7a865b6e5da5aa9..0463370e9b0cc6a7c82f144e936824c3e9633ee9 100644 --- a/man/Consist_Trend.Rd +++ b/man/Consist_Trend.Rd @@ -71,8 +71,8 @@ The function doesn't do the ensemble mean, so if the input data have the member dimension, ensemble mean needs to be computed beforehand. } \examples{ -#'# Load sample data as in Load() example: -example(Load) +# Load sample data as in Load() example: +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/Corr.Rd b/man/Corr.Rd index 38d5c6469bebd1d668741ee450b8cd5a23e5353a..99779c7e2368d36cb261c81565f517312fbb87db 100644 --- a/man/Corr.Rd +++ b/man/Corr.Rd @@ -113,7 +113,7 @@ compute the correlation. } \examples{ # Case 1: Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/EOF.Rd b/man/EOF.Rd index 3d67308965fbb463092acee4cae2534e7e0e2740..ddd5d654e89954a6651a0bc59885a81c38be9c26 100644 --- a/man/EOF.Rd +++ b/man/EOF.Rd @@ -90,22 +90,19 @@ set to TRUE. # that explains the greatest amount of variability. The example data has low # resolution so the result may not be explanatory, but it displays how to # use this function. -\dontshow{ + startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) -} +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') + ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) tmp <- MeanDims(ano$exp, c('dataset', 'member')) ano <- tmp[1, , ,] names(dim(ano)) <- names(dim(tmp))[-2] -eof <- EOF(ano, sampleData$lat, sampleData$lon) -\dontrun{ +eof <- EOF(ano, sampleData$lat, sampleData$lon, neofs = 4) +\donttest{ PlotEquiMap(eof$EOFs[1, , ], sampleData$lon, sampleData$lat) } diff --git a/man/Filter.Rd b/man/Filter.Rd index f98fe0acbcff6bf4b9e1bd6f716fc7227930006f..f7dc4fde4be85779fe64077398c2d83f8378a334 100644 --- a/man/Filter.Rd +++ b/man/Filter.Rd @@ -33,7 +33,7 @@ the specified frequency and phase. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) ensmod <- MeanDims(sampleData$mod, 2) spectrum <- Spectrum(ensmod) diff --git a/man/Histo2Hindcast.Rd b/man/Histo2Hindcast.Rd index a2bc5cac3a7ff241d3912edd6b0123f2f890d3d5..e09f6a68e369934835035f919e7524008830d1eb 100644 --- a/man/Histo2Hindcast.Rd +++ b/man/Histo2Hindcast.Rd @@ -46,16 +46,11 @@ chunks corresponding to a set of start dates. The time frequency of the data should be monthly. } \examples{ - \dontshow{ startDates <- c('19901101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 60, - output = 'areave', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 60, + output = 'areave') sdates_out <- c('19901101', '19911101', '19921101', '19931101', '19941101') leadtimes_per_startdate <- 12 @@ -63,7 +58,7 @@ exp_data <- Histo2Hindcast(sampleData$mod, startDates, sdates_out, leadtimes_per_startdate) obs_data <- Histo2Hindcast(sampleData$obs, startDates, sdates_out, leadtimes_per_startdate) - \dontrun{ + \donttest{ exp_data <- Reorder(exp_data, c(3, 4, 1, 2)) obs_data <- Reorder(obs_data, c(3, 4, 1, 2)) PlotAno(exp_data, obs_data, sdates_out, diff --git a/man/Load.Rd b/man/Load.Rd index f91c315ca645c6c2af2aca2d3dd99242835909aa..7b2b039359f86ca1c0ea988580a11813479f5e0d 100644 --- a/man/Load.Rd +++ b/man/Load.Rd @@ -819,35 +819,14 @@ to the package or check the comments in the code. # Instead, the code in 'dontshow' is run, which loads the equivalent # already processed data in R. # -# Example 1: Providing lists of lists to 'exp' and 'obs': -# - \dontrun{ -data_path <- system.file('sample_data', package = 's2dv') -exp <- list( - name = 'experiment', - path = file.path(data_path, 'model/$EXP_NAME$/monthly_mean', - '$VAR_NAME$_3hourly/$VAR_NAME$_$START_DATES$.nc') - ) -obs <- list( - name = 'observation', - path = file.path(data_path, 'observation/$OBS_NAME$/monthly_mean', - '$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$.nc') - ) -# Now we are ready to use Load(). -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- Load('tos', list(exp), list(obs), startDates, - output = 'areave', latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } -# -# Example 2: Providing vectors of character strings to 'exp' and 'obs' +# Example 1: Providing vectors of character strings to 'exp' and 'obs' # and using a configuration file. # # The configuration file 'sample.conf' that we will create in the example # has the proper entries to load these (see ?LoadConfigFile for details on # writing a configuration file). # - \dontrun{ + \donttest{ data_path <- system.file('sample_data', package = 's2dv') expA <- list(name = 'experiment', path = file.path(data_path, 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', @@ -862,8 +841,9 @@ sampleData <- Load('tos', list(expA), list(obsX), startDates, output = 'areave', latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) # -# Example 3: providing character strings in 'exp' and 'obs', and providing -# a configuration file. +# Example 2: providing character strings in 'exp' and 'obs', and providing +# a configuration file. +# # The configuration file 'sample.conf' that we will create in the example # has the proper entries to load these (see ?LoadConfigFile for details on # writing a configuration file). @@ -890,12 +870,5 @@ sampleData <- Load('tos', c('experiment'), c('observation'), startDates, output = 'areave', latmin = 27, latmax = 48, lonmin = -12, lonmax = 40, configfile = configfile) } - \dontshow{ -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - output = 'areave', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } + } diff --git a/man/LoadSampleData.Rd b/man/LoadSampleData.Rd new file mode 100644 index 0000000000000000000000000000000000000000..b1e1a7fe3b8a71d3b297c9d703faeaf7ddaa1a03 --- /dev/null +++ b/man/LoadSampleData.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/LoadSampleData.R +\name{LoadSampleData} +\alias{LoadSampleData} +\title{Load Sample Data for Package Examples} +\usage{ +LoadSampleData(sdates, leadtimemin = 1, leadtimemax = NULL, output = "areave") +} +\arguments{ +\item{sdates}{Character vector of start dates to include (e.g., +\code{c("19851101", "19901101")}). Must match one or more of the available +dates in the internal sample datasets: "19851101", "19901101", "19951101", +"20001101" or "20051101".} + +\item{leadtimemin}{Integer specifying the first lead time to include. Default +is 1.} + +\item{leadtimemax}{Integer specifying the last lead time to include. If NULL, +the full lead time range is included. Default is NULL.} + +\item{output}{Character string indicating the type of output: \code{"areave"} +for area-averaged time series data, or \code{"lonlat"} for gridded spatial +data. Default is \code{"areave"}.} +} +\value{ +A named list with the following elements: +\item{mod}{Array of model data with the selected start dates and lead times.} +\item{obs}{Array of observational data with the selected start dates and lead + times.} +\item{lat}{Vector of latitudes.} +\item{lon}{Vector of longitudes.} +} +\description{ +Loads and subsets sample data stored in the internal datasets +\code{sampleMap} and \code{sampleTimeSeries}, included with the package. +Intended for use in documentation examples instead of \code{Load()}, in order +to avoid reliance on external system dependencies like 'nco' and 'cdo' and +to reduce computation time during CRAN checks. +} +\details{ +This function is designed for use in examples and tests within the +'s2dv' package. It provides quick access to precomputed datasets, helping to +avoid slow or system-dependent operations during automated checks. +} +\examples{ +startDates <- c("19851101", "19901101", "19951101", "20001101", "20051101") +sampleData <- LoadSampleData(sdates = startDates, output = "areave") + +} diff --git a/man/MSE.Rd b/man/MSE.Rd index ded3c248a76bc82f3835c6f8fcf1e332c772f96d..6d6b21ce9f53e4399b0d1502140b920488d3a515 100644 --- a/man/MSE.Rd +++ b/man/MSE.Rd @@ -80,7 +80,7 @@ The confidence interval is computed by the chi2 distribution.\cr } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/MSSS.Rd b/man/MSSS.Rd index c3c5662eba72eb242c483961206112dde625badc..cdf97922c796d3a32adf686397d906408aae340d 100644 --- a/man/MSSS.Rd +++ b/man/MSSS.Rd @@ -111,7 +111,7 @@ Fisher test or Random Walk test.\cr } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/MeanDims.Rd b/man/MeanDims.Rd index 94369da0bdd255126766d347ba940a5c1d02a963..9234f9161b703ae32aacf668577c746206a8b27d 100644 --- a/man/MeanDims.Rd +++ b/man/MeanDims.Rd @@ -34,4 +34,5 @@ ens_mean <- MeanDims(a, 'member') dim(ens_mean) ens_time_mean <- MeanDims(a, c(2, 3), drop = FALSE) dim(ens_time_mean) + } diff --git a/man/NAO.Rd b/man/NAO.Rd index 8115fa22ff25b1a8793827ca5c9203bebb7499e1..3788bc68ef850a7f9cbbbe47ad9c16724bd38711 100644 --- a/man/NAO.Rd +++ b/man/NAO.Rd @@ -116,7 +116,7 @@ nao <- NAO(exp = exp, obs = obs, lat = lat, lon = lon) exp_cor <- array(rnorm(540), dim = c(member = 2, sdate = 1, ftime = 5, lat = 6, lon = 9)) nao <- NAO(exp = exp, obs = obs, exp_cor = exp_cor, lat = lat, lon = lon, obsproj = TRUE) # plot the NAO index - \dontrun{ + \donttest{ nao$exp <- Reorder(nao$exp, c(2, 1)) nao$obs <- Reorder(nao$obs, c(2, 1)) PlotBoxWhisker(nao$exp, nao$obs, "NAO index, DJF", "NAO index (PC1) TOS", diff --git a/man/Plot2VarsVsLTime.Rd b/man/Plot2VarsVsLTime.Rd index 9eeb928263365b81e3364e405c4a2ccbfa96e72e..a73c3272f7996be5412fc9beaf8d4e016813b28b 100644 --- a/man/Plot2VarsVsLTime.Rd +++ b/man/Plot2VarsVsLTime.Rd @@ -91,6 +91,9 @@ lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page pch plt smo srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Plot two input variables that have the same dimensions in a common plot. One plot for all experiments. @@ -103,7 +106,7 @@ RMSE error for a number of experiments and along lead-time: (nexp, nltime) } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/PlotACC.Rd b/man/PlotACC.Rd index 9a32f8b841b32b031581510a9299e9b2ab718a2b..c0fbe8f189940e6576cc29941c17d79edd7f8546 100644 --- a/man/PlotACC.Rd +++ b/man/PlotACC.Rd @@ -85,6 +85,9 @@ lend lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page plt smo srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog\cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Plots plumes/timeseries of ACC from an array with dimensions (output from \code{ACC()}): \cr @@ -95,16 +98,12 @@ confidence interval and the 95\% significance level given by a one-sided T-test. } \examples{ - \dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') + sampleData$mod <- Season(sampleData$mod, monini = 11, moninf = 12, monsup = 2) sampleData$obs <- Season(sampleData$obs, monini = 11, moninf = 12, monsup = 2) clim <- Clim(sampleData$mod, sampleData$obs) @@ -122,4 +121,5 @@ res_bootstrap <- array(c(acc$acc_conf.lower, acc$acc, acc$acc_conf.upper, acc$p. PlotACC(res, startDates) PlotACC(res_bootstrap, startDates) } + } diff --git a/man/PlotAno.Rd b/man/PlotAno.Rd index 6591ef19f52879f38d3968450b5cc92b471f0ceb..48a473f532eed20b17c03fa4dec6082efc583505 100644 --- a/man/PlotAno.Rd +++ b/man/PlotAno.Rd @@ -98,6 +98,9 @@ lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page plt smo srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Plots time series of raw or smoothed anomalies of any variable output from \code{Load()} or \code{Ano()} or or \code{Ano_CrossValid()} or @@ -105,7 +108,7 @@ Plots time series of raw or smoothed anomalies of any variable output from } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/PlotBoxWhisker.Rd b/man/PlotBoxWhisker.Rd index e8681607b4b639b9ccfe9b29651f618c2680b699..ab0b05bf42f09534517e7821f787edffb2dc57a6 100644 --- a/man/PlotBoxWhisker.Rd +++ b/man/PlotBoxWhisker.Rd @@ -87,37 +87,17 @@ forecast and observational data is calculated and displayed. Only works for n-monthly to n-yearly time series. } \examples{ -# See examples on Load() to understand the first lines in this example - \dontrun{ -data_path <- system.file('sample_data', package = 's2dverification') -expA <- list(name = 'experiment', path = file.path(data_path, - 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', - '$VAR_NAME$_$START_DATE$.nc')) -obsX <- list(name = 'observation', path = file.path(data_path, - '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', - '$VAR_NAME$_$YEAR$$MONTH$.nc')) - -# Now we are ready to use Load(). startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- Load('tos', list(expA), list(obsX), startDates, - leadtimemin = 1, leadtimemax = 4, output = 'lonlat', - latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) - } - \dontshow{ -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 20, latmax = 80, - lonmin = -80, lonmax = 40) +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') # No example data is available over NAO region, so in this example we will # tweak the available data. In a real use case, one can Load() the data over # NAO region directly. sampleData$lon[] <- c(40, 280, 340) sampleData$lat[] <- c(20, 80) - } + # Now ready to compute the EOFs and project on, for example, the first # variability mode. ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) @@ -125,12 +105,10 @@ ano_exp <- array(ano$exp, dim = dim(ano$exp)[-2]) ano_obs <- array(ano$obs, dim = dim(ano$obs)[-2]) nao <- NAO(exp = ano_exp, obs = ano_obs, lat = sampleData$lat, lon = sampleData$lon) # Finally plot the nao index - \dontrun{ nao$exp <- Reorder(nao$exp, c(2, 1)) nao$obs <- Reorder(nao$obs, c(2, 1)) PlotBoxWhisker(nao$exp, nao$obs, "NAO index, DJF", "NAO index (PC1) TOS", monini = 12, yearini = 1985, freq = 1, "Exp. A", "Obs. X") - } } \seealso{ diff --git a/man/PlotClim.Rd b/man/PlotClim.Rd index 9b3381edb0a11749c28c6da41ed5a0abf9a1ff11..5294d921969b0c743545aebcfb5e32c25b2a6abb 100644 --- a/man/PlotClim.Rd +++ b/man/PlotClim.Rd @@ -78,6 +78,9 @@ lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page pch plt smo srt tck usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Plots climatologies as a function of the forecast time for any index output from \code{Clim()} and organized in matrix with dimensions:\cr @@ -87,7 +90,7 @@ c(nobs, nmemb, nltime) or c(nobs, nltime) for the observational data } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) PlotClim(clim$clim_exp, clim$clim_obs, toptitle = paste('climatologies'), ytitle = 'K', monini = 11, listexp = c('CMIP5 IC3'), diff --git a/man/PlotEquiMap.Rd b/man/PlotEquiMap.Rd index 5d3739a0349323304fcd881a804bda4a0fbf161c..9714602ebd1e5c4ea9c8c4b99ffff6076258567b 100644 --- a/man/PlotEquiMap.Rd +++ b/man/PlotEquiMap.Rd @@ -376,33 +376,13 @@ include continents, oceans, and lakes. This plot function is compatible with figure layouts if colour bar is disabled. } \examples{ -# See examples on Load() to understand the first lines in this example - \dontrun{ -data_path <- system.file('sample_data', package = 's2dv') -expA <- list(name = 'experiment', path = file.path(data_path, - 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', - '$VAR_NAME$_$START_DATE$.nc')) -obsX <- list(name = 'observation', path = file.path(data_path, - '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', - '$VAR_NAME$_$YEAR$$MONTH$.nc')) - -# Now we are ready to use Load(). startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- Load('tos', list(expA), list(obsX), startDates, - leadtimemin = 1, leadtimemax = 4, output = 'lonlat', - latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) - } - \dontshow{ -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') PlotEquiMap(sampleData$mod[1, 1, 1, 1, , ], sampleData$lon, sampleData$lat, toptitle = 'Predicted sea surface temperature for Nov 1960 from 1st Nov', title_scale = 0.5) + } diff --git a/man/PlotLayout.Rd b/man/PlotLayout.Rd index 2a053ad04b0291f71dcf5bee4e946ceb7a6d2034..a040c39f99cd154b5e48c878a8b84ecd9cac642c 100644 --- a/man/PlotLayout.Rd +++ b/man/PlotLayout.Rd @@ -265,32 +265,11 @@ This function pops up a blank new device and fills it in, so it cannot be nested in complex layouts. } \examples{ -# See examples on Load() to understand the first lines in this example - \dontrun{ -data_path <- system.file('sample_data', package = 's2dv') -expA <- list(name = 'experiment', path = file.path(data_path, - 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', - '$VAR_NAME$_$START_DATE$.nc')) -obsX <- list(name = 'observation', path = file.path(data_path, - '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', - '$VAR_NAME$_$YEAR$$MONTH$.nc')) - -# Now we are ready to use Load(). startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- Load('tos', list(expA), list(obsX), startDates, - leadtimemin = 1, leadtimemax = 4, output = 'lonlat', - latmin = 27, latmax = 48, lonmin = -12, lonmax = 40) - } - \dontshow{ -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') PlotLayout(PlotEquiMap, c('lat', 'lon'), sampleData$mod[1, , 1, 1, , ], sampleData$lon, sampleData$lat, toptitle = 'Predicted tos for Nov 1960 from 1st Nov', diff --git a/man/PlotMatrix.Rd b/man/PlotMatrix.Rd index 5275df031e1d329fc3da932e5bd93ab19d5f45a7..61623a0cbcfda6a09aff7e703e505d0e2895db30 100644 --- a/man/PlotMatrix.Rd +++ b/man/PlotMatrix.Rd @@ -108,4 +108,5 @@ PlotMatrix(var = matrix(rnorm(n = 120, mean = 0.3), 10, 12), xtitle = "Forecast time (month)", ytitle = "Start date", xlabels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) + } diff --git a/man/PlotSection.Rd b/man/PlotSection.Rd index 1627339847efecf53cac6c798208eb744c2ec4af..3bf154b9e90e53c96593e1b555f2ccbb2522c085 100644 --- a/man/PlotSection.Rd +++ b/man/PlotSection.Rd @@ -77,6 +77,9 @@ omi page pch pin plt pty smo srt tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Plot a (longitude,depth) or (latitude,depth) section. } @@ -84,4 +87,5 @@ Plot a (longitude,depth) or (latitude,depth) section. sampleData <- s2dv::sampleDepthData PlotSection(sampleData$mod[1, 1, 1, 1, , ], sampleData$lat, sampleData$depth, toptitle = 'temperature 1995-11 member 0') + } diff --git a/man/PlotStereoMap.Rd b/man/PlotStereoMap.Rd index 10e7503e3332b49deb233530a8a670118e313ddd..957eab0092c62bb3be3b5b73a0479f9498b98f28 100644 --- a/man/PlotStereoMap.Rd +++ b/man/PlotStereoMap.Rd @@ -283,8 +283,7 @@ compatible with figure layouts if colour bar is disabled. data <- matrix(rnorm(100 * 50), 100, 50) x <- seq(from = 0, to = 360, length.out = 100) y <- seq(from = -90, to = 90, length.out = 50) - \dontrun{ PlotStereoMap(data, x, y, latlims = c(60, 90), brks = 50, toptitle = "This is the title") -} + } diff --git a/man/PlotVsLTime.Rd b/man/PlotVsLTime.Rd index 21cfe5301919296c2fdacdb9d5b84c17acf39673..0f05caf2687590edccd17c5b0a3a33ea01148cca 100644 --- a/man/PlotVsLTime.Rd +++ b/man/PlotVsLTime.Rd @@ -90,6 +90,9 @@ lheight ljoin lmitre mar mex mfcol mfrow mfg mkh oma omd omi page pch plt smo srt tck tcl usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylbias ylog \cr For more information about the parameters see `par`.} } +\value{ +No return value, called for side effects. +} \description{ Plot the correlation (\code{Corr()}), the root mean square error (\code{RMS()}) between the forecast values and their observational @@ -117,7 +120,7 @@ of the forecast time. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/ProbBins.Rd b/man/ProbBins.Rd index cfd7affed05b4ac98400ff9f6c51973ca798a995..88e0851bf4348c0cc7ab10d099334a75cd3ff082 100644 --- a/man/ProbBins.Rd +++ b/man/ProbBins.Rd @@ -65,14 +65,8 @@ the selected forecast years ('fcyr') or the forecast year for which the probabilistic bins are being computed (see 'compPeriod'). } \examples{ -\dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) -} +sampleData <- LoadSampleData(startDates, output = 'lonlat') clim <- Clim(sampleMap$mod, sampleMap$obs) ano_exp <- Ano(sampleMap$mod, clim$clim_exp) PB <- ProbBins(ano_exp, fcyr = 3, thr = c(1/3, 2/3), quantile = TRUE) diff --git a/man/ProjectField.Rd b/man/ProjectField.Rd index 358f4ee86e8aefaebb4e6cac23eaae6b9e4f8b1e..0901f353f32e315a544b1729cd7df4f1da50d6c6 100644 --- a/man/ProjectField.Rd +++ b/man/ProjectField.Rd @@ -49,23 +49,18 @@ projection onto EOF pattern (from \code{EOF()}) or REOF pattern (from returns NA if the whole spatial pattern is NA. } \examples{ -\dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) -} +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) -eof_exp <- EOF(ano$exp, sampleData$lat, sampleData$lon) -eof_obs <- EOF(ano$obs, sampleData$lat, sampleData$lon) +eof_exp <- EOF(ano$exp, sampleData$lat, sampleData$lon, neofs = 5) +eof_obs <- EOF(ano$obs, sampleData$lat, sampleData$lon, neofs = 5) mode1_exp <- ProjectField(ano$exp, eof_exp, mode = 1) mode1_obs <- ProjectField(ano$obs, eof_obs, mode = 1) -\dontrun{ +\donttest{ # Plot the forecast and the observation of the first mode for the last year # of forecast sdate_dim_length <- dim(mode1_obs)['sdate'] diff --git a/man/REOF.Rd b/man/REOF.Rd index a5d416c22e132b96125b18738ecf7330d9ce7d2f..ff85572d76e7636f51b114215b86c359e7a74a4b 100644 --- a/man/REOF.Rd +++ b/man/REOF.Rd @@ -79,19 +79,19 @@ internally. # use this function. \dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) +sampleData <- LoadSampleData(sdates = startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') } ano <- Ano_CrossValid(sampleData$mod, sampleData$obs) ano <- MeanDims(ano$exp, c('dataset', 'member')) res <- REOF(ano, lat = sampleData$lat, lon = sampleData$lon, ntrunc = 5) -\dontrun{ -PlotEquiMap(eof$EOFs[1, , , 1], sampleData$lat, sampleData$lon) +eof_to_plot <- array(res$REOFs[1, , , 1], + dim = c(length(sampleData$lat), length(sampleData$lon)), + dimnames = list(lat = sampleData$lat, lon = sampleData$lon)) +\donttest{ +PlotEquiMap(eof_to_plot, sampleData$lat, sampleData$lon) } } diff --git a/man/RMS.Rd b/man/RMS.Rd index 57473544cacaaa0f10629dd331dd830d2de79b38..1a974c6b1825da80fb2188e55f0e572643cea07c 100644 --- a/man/RMS.Rd +++ b/man/RMS.Rd @@ -81,7 +81,7 @@ The confidence interval is computed by the chi2 distribution.\cr } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/RMSSS.Rd b/man/RMSSS.Rd index 706788c11c297310deb6900948035ac8675a99e2..d7722f07953f33a2d5f10af6d2b7aef393d22fc6 100644 --- a/man/RMSSS.Rd +++ b/man/RMSSS.Rd @@ -111,7 +111,7 @@ Fisher test or Random Walk test.\cr } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) diff --git a/man/RPSS.Rd b/man/RPSS.Rd index f6c80460aa8877f7b270f3ab452828e4815ae60b..14cf158a74718d5675f45bc0291e5eb74b91f82e 100644 --- a/man/RPSS.Rd +++ b/man/RPSS.Rd @@ -65,7 +65,12 @@ The default value is NULL.} \item{prob_thresholds}{A numeric vector of the relative thresholds (from 0 to 1) between the categories. The default value is c(1/3, 2/3), which -corresponds to tercile equiprobable categories.} +corresponds to tercile equiprobable categories. When the inputs are +ensemble members ('cat_dim' is NULL), these thresholds are used to compute +category probabilities. If 'ref' is NULL, the thresholds are also used to +compute the reference forecast ('clim_probs'), even when 'exp' and 'obs' are +already given as probabilities. If 'ref' is provided and the inputs are +probabilities, 'prob_thresholds' is ignored.} \item{indices_for_clim}{A vector of the indices to be taken along 'time_dim' for computing the thresholds between the probabilistic categories. If NULL, diff --git a/man/RatioRMS.Rd b/man/RatioRMS.Rd index 4e834ad3d9cf58f6eecd97438e3c62a285911dfa..6b541a32ede6b9446d7028d6dfda7489cf915e9f 100644 --- a/man/RatioRMS.Rd +++ b/man/RatioRMS.Rd @@ -45,14 +45,9 @@ that is, RMSE(ens, obs) / RMSE(ens.ref, obs). The p-value is provided by a two-sided Fischer test. } \examples{ -\dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) -} +sampleData <- LoadSampleData(startDates, output = 'lonlat') + # Compute DJF seasonal means and anomalies. initial_month <- 11 mean_start_month <- 12 diff --git a/man/RatioSDRMS.Rd b/man/RatioSDRMS.Rd index 07afc461c64a380bc0bea9e1eb9fe297a39c7082..caac08063b5f178e4ae27fc646fccd0cac2bd74e 100644 --- a/man/RatioSDRMS.Rd +++ b/man/RatioSDRMS.Rd @@ -59,13 +59,13 @@ Fisher's test. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) rsdrms <- RatioSDRMS(sampleData$mod, sampleData$obs, dat_dim = 'dataset') # Reorder the data in order to plot it with PlotVsLTime rsdrms_plot <- array(dim = c(dim(rsdrms$ratio)[1:2], 4, dim(rsdrms$ratio)[3])) rsdrms_plot[, , 2, ] <- rsdrms$ratio rsdrms_plot[, , 4, ] <- rsdrms$p.val -\dontrun{ + \donttest{ PlotVsLTime(rsdrms_plot, toptitle = "Ratio ensemble spread / RMSE", ytitle = "", monini = 11, limits = c(-1, 1.3), listexp = c('CMIP5 IC3'), listobs = c('ERSST'), biglab = FALSE, siglev = TRUE) diff --git a/man/Regression.Rd b/man/Regression.Rd index 9ac0c9460a910722d0b1b86584ac39f24ee3b955..fdae1f9ec65d008383512315d4bdde094405903e 100644 --- a/man/Regression.Rd +++ b/man/Regression.Rd @@ -100,7 +100,7 @@ on the student-T distribution. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) datay <- sampleData$mod[, 1, , ] names(dim(datay)) <- c('sdate', 'ftime') datax <- sampleData$obs[, 1, , ] diff --git a/man/Reorder.Rd b/man/Reorder.Rd index c4e4a2312fc342e6e54ebd36c92c8d19eec3f7d2..4ce0aa32d8c77bb0f117972a81cb121a41197ef4 100644 --- a/man/Reorder.Rd +++ b/man/Reorder.Rd @@ -34,4 +34,5 @@ by Load(). # A character array dat3 <- array(paste0('a', 1:24), dim = c(b = 2, c = 3, d = 4)) dat3_reorder <- Reorder(dat3, c('d', 'c', 'b')) + } diff --git a/man/Season.Rd b/man/Season.Rd index 60fbbbc6f12b1b633f90c70be9eff905cf542fec..aa9e65b8947b2baece5808f4f1e14f61782d10f8 100644 --- a/man/Season.Rd +++ b/man/Season.Rd @@ -61,4 +61,5 @@ na <- floor(runif(30, min = 1, max = 144 * 3)) dat2[na] <- NA res <- Season(data = dat2, monini = 3, moninf = 1, monsup = 2) res <- Season(data = dat2, monini = 3, moninf = 1, monsup = 2, na.rm = FALSE) + } diff --git a/man/Smoothing.Rd b/man/Smoothing.Rd index 5769aa2b3763834651398bbecbd1268236264967..3fc48c2696788c3ee5e7e4613ede40bcc453d08f 100644 --- a/man/Smoothing.Rd +++ b/man/Smoothing.Rd @@ -29,7 +29,7 @@ Smooth an array of any number of dimensions along one dimension. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) ano_obs <- Ano(sampleData$obs, clim$clim_obs) @@ -37,8 +37,9 @@ smooth_ano_exp <- Smoothing(ano_exp, time_dim = 'ftime', runmeanlen = 12) smooth_ano_obs <- Smoothing(ano_obs, time_dim = 'ftime', runmeanlen = 12) smooth_ano_exp <- Reorder(smooth_ano_exp, c(2, 3, 4, 1)) smooth_ano_obs <- Reorder(smooth_ano_obs, c(2, 3, 4, 1)) - \dontrun{ + \donttest{ PlotAno(smooth_ano_exp, smooth_ano_obs, startDates, toptitle = "Smoothed Mediterranean mean SST", ytitle = "K") } + } diff --git a/man/Spectrum.Rd b/man/Spectrum.Rd index 18671e5cb1defc78f69817388f2f1e8ccd2e35dc..caf2979c4a5b5d34ffb7eb89e4164345c9de1da0 100644 --- a/man/Spectrum.Rd +++ b/man/Spectrum.Rd @@ -39,7 +39,7 @@ and the confidence interval is estimated by the Monte-Carlo method. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) ensmod <- MeanDims(sampleData$mod, 2) spectrum <- Spectrum(ensmod) diff --git a/man/Spread.Rd b/man/Spread.Rd index d3f93bbb229cafcac4235025fe11a93a52fd68b3..27af61eb00c8d9c69460893ef9980a2180994983 100644 --- a/man/Spread.Rd +++ b/man/Spread.Rd @@ -62,7 +62,7 @@ data can be the output of \code{Load()}, \code{Ano()}, or } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) clim <- Clim(sampleData$mod, sampleData$obs) ano_exp <- Ano(sampleData$mod, clim$clim_exp) runmean_months <- 12 @@ -76,7 +76,7 @@ suppressWarnings({ spread <- Spread(smooth_ano_exp_m_sub, compute_dim = c('member', 'sdate')) }) -\dontrun{ + \donttest{ PlotVsLTime(Reorder(spread$iqr, c('dataset', 'stats', 'ftime')), toptitle = "Inter-Quartile Range between ensemble members", ytitle = "K", monini = 11, limits = NULL, @@ -97,6 +97,6 @@ PlotVsLTime(Reorder(spread$mad, c('dataset', 'stats', 'ftime')), ytitle = "K", monini = 11, limits = NULL, listexp = c('CMIP5 IC3'), listobs = c('ERSST'), biglab = FALSE, hlines = c(0)) -} + } } diff --git a/man/ToyModel.Rd b/man/ToyModel.Rd index ee7a98e93204383f416d1aacec019ead1ea12b66..d7ce1164188e0e2a82ec58d8a7fb1395ba81ae90 100644 --- a/man/ToyModel.Rd +++ b/man/ToyModel.Rd @@ -91,29 +91,8 @@ toyforecast <- ToyModel(alpha = a, beta = b, gamma = g, sig = sig, trend = t, # Example 2: Generate forecast from loaded observations # Decadal prediction example - \dontrun{ -data_path <- system.file('sample_data', package = 's2dv') -expA <- list(name = 'experiment', path = file.path(data_path, - 'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly', - '$VAR_NAME$_$START_DATE$.nc')) -obsX <- list(name = 'observation', path = file.path(data_path, - '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$', - '$VAR_NAME$_$YEAR$$MONTH$.nc')) - -# Now we are ready to use Load(). -startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- Load('tos', list(expA), list(obsX), startDates, - output = 'areave', latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } - \dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - output = 'areave', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) - } +sampleData <- LoadSampleData(startDates, output = 'areave') a <- 0.1 b <- 0.3 @@ -122,11 +101,11 @@ nm <- 10 toyforecast <- ToyModel(alpha = a, beta = b, gamma = g, nmemb = nm, obsini = sampleData$obs, nstartd = 5, nleadt = 60) -## 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") -# } + +\donttest{ +PlotAno(toyforecast$mod, toyforecast$obs, startDates, + toptitle = c("Synthetic decadal temperature prediction"), + fileout = "ex_toymodel.eps") +} } diff --git a/man/Trend.Rd b/man/Trend.Rd index 012474870ccfdd8d0b3777145f9b5df2cfbc9f12..450ec3c9487040b82fa33986703797312a42f607 100644 --- a/man/Trend.Rd +++ b/man/Trend.Rd @@ -92,7 +92,7 @@ is calculated by ANOVA. } \examples{ # Load sample data as in Load() example: -example(Load) +example(LoadSampleData) months_between_startdates <- 60 trend <- Trend(sampleData$obs, polydeg = 2, interval = months_between_startdates) diff --git a/man/UltimateBrier.Rd b/man/UltimateBrier.Rd index a20412e3976fe2aa0afde3d7cef877e8cfd603d9..4744629a57cd46084b61d74d19b06671d6363a11 100644 --- a/man/UltimateBrier.Rd +++ b/man/UltimateBrier.Rd @@ -96,13 +96,10 @@ to choose. \examples{ \dontshow{ startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101') -sampleData <- s2dv:::.LoadSampleData('tos', c('experiment'), - c('observation'), startDates, - leadtimemin = 1, - leadtimemax = 4, - output = 'lonlat', - latmin = 27, latmax = 48, - lonmin = -12, lonmax = 40) +sampleData <- LoadSampleData(startDates, + leadtimemin = 1, + leadtimemax = 4, + output = 'lonlat') } sampleData$mod <- Season(sampleData$mod, monini = 11, moninf = 12, monsup = 2) sampleData$obs <- Season(sampleData$obs, monini = 11, moninf = 12, monsup = 2) diff --git a/man/clim.palette.Rd b/man/clim.palette.Rd index 94c90553881cac83d3ddb5a89d99bf2b24a8cc1b..f97a3b263ed22054a886ebd8a3a33b824ebbc587 100644 --- a/man/clim.palette.Rd +++ b/man/clim.palette.Rd @@ -18,6 +18,11 @@ and from orange through white to purple ('orangepurple').} \item{n}{Number of colors to generate.} } +\value{ +A function that generates a vector of \code{n} color hex codes when +called. The returned function has an optional attribute \code{"na_color"} +specifying the color used for missing values. +} \description{ Generates a colorblind friendly color palette with color ranges useful in climate temperature variable plotting. diff --git a/man/s2dv-package.Rd b/man/s2dv-package.Rd index 24ed0bf802f81c1248d504ca058d81385b3235d9..095b9a3ada675a9ae47d7fbbffa3eb07171ebefc 100644 --- a/man/s2dv-package.Rd +++ b/man/s2dv-package.Rd @@ -4,9 +4,9 @@ \name{s2dv-package} \alias{s2dv} \alias{s2dv-package} -\title{s2dv: A Set of Common Tools for Seasonal to Decadal Verification} +\title{s2dv: 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 observation, to visualization. Compared to 's2dverification', 's2dv' is more compatible with the package 'startR', able to use multiple cores for computation and handle multi-dimensional arrays with a higher flexibility. The CDO version used in development is 1.9.8. +An advanced version of package 's2dverification'. Intended for seasonal to decadal (s2d) climate forecast verification, but also applicable to other types of forecasts or general climate analysis. This package is specifically designed for comparing experimental and observational datasets. It provides functionality for data retrieval, post-processing, skill score computation against observations, and visualization. Compared to 's2dverification', 's2dv' is more compatible with the package 'startR', able to use multiple cores for computation and handle multi-dimensional arrays with a higher flexibility. The Climate Data Operators (CDO) version used in development is 1.9.8. Implements methods described in Wilks (2011) \doi{10.1016/B978-0-12-385022-5.00008-7}, DelSole and Tippett (2016) \doi{10.1175/MWR-D-15-0218.1}, Kharin et al. (2012) \doi{10.1029/2012GL052647}, Doblas-Reyes et al. (2003) \doi{10.1007/s00382-003-0350-4}. } \references{ \url{https://earth.bsc.es/gitlab/es/s2dv/}