diff --git a/DESCRIPTION b/DESCRIPTION index 362663ffb3bf472f61046fed329db42e476d07e2..b352859dd73355af00868dae2a717f358482dbbe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: CSTools Title: Assessing Skill of Climate Forecasts on Seasonal-to-Decadal Timescales -Version: 5.1.1 +Version: 5.2.0 Authors@R: c( person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = "aut", comment = c(ORCID = "0000-0001-8568-3071")), person("Louis-Philippe", "Caron", , "louis-philippe.caron@bsc.es", role = "aut", comment = c(ORCID = "0000-0001-5221-0147")), diff --git a/NEWS.md b/NEWS.md index 250410084c486ff70f9d6cf00d768a965686fe0b..cb82665167a043a1ba556c689e8bd321a1912d85 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# CSTools 5.2.0 (Release date: 25-01-2024) + +### Development +- New function CST_ChangeDimNames +- CST_SplitDim: added dimension names and split also Dates +- CST_SaveExp: save time bounds and global attributes; improved code + +### Other +- Updated README +- Added citation file + # CSTools 5.1.1 (Release date: 19-10-2023) ### Fixes diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 72a97b8ce55f16ed7f07f0f19cafa6d0908e35a7..4e25a51d54978d5fa6ae62eff8f5da4497850ad3 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -92,9 +92,11 @@ #'\code{\link{s2dv_cube}} #' #'@examples +#'\dontrun{ #'data <- lonlat_temp_st$exp #'CST_SaveExp(data = data, ftime_dim = 'ftime', var_dim = 'var', #' dat_dim = 'dataset', sdate_dim = 'sdate') +#'} #' #'@export CST_SaveExp <- function(data, destination = "./", startdates = NULL, @@ -266,6 +268,7 @@ CST_SaveExp <- function(data, destination = "./", startdates = NULL, #'} #' #'@examples +#'\dontrun{ #'data <- lonlat_temp_st$exp$data #'lon <- lonlat_temp_st$exp$coords$lon #'lat <- lonlat_temp_st$exp$coords$lat @@ -277,6 +280,7 @@ CST_SaveExp <- function(data, destination = "./", startdates = NULL, #'SaveExp(data = data, coords = coords, Datasets = Datasets, varname = varname, #' Dates = Dates, metadata = metadata, single_file = TRUE, #' ftime_dim = 'ftime', var_dim = 'var', dat_dim = 'dataset') +#'} #' #'@import easyNCDF #'@importFrom s2dv Reorder diff --git a/README.md b/README.md index d8560b8dcd47e8d0f48d135c24690291b24de4a0..8f56d9564949aba418ea3fca93206ed9bcaa05d3 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,12 @@ Overview The CSTools package functions can be distributed in the following methods: -- **Data retrieval and formatting:** [CST_Start](R/CST_Start.R), [CST_SaveExp](R/CST_SaveExp.R), [CST_MergeDims](R/CST_MergeDims.R), [CST_SplitDim](R/CST_SplitDim.R), [CST_Subset](R/CST_Subset), [CST_InsertDim](R/CST_InsertDim.R), [CST_ChangeDimNames](R/CST_ChangeDimNames.R), [as.s2dv_cube](R/as.s2dv_cube.R) and [s2dv_cube](R/s2dv_cube.R). -- **Classification:** [CST_MultiEOF](R/CST_MultiEOF.R), [CST_WeatherRegimes](R/CST_WeatherRegimes.R), [CST_RegimsAssign](R/CST_RegimesAssign.R), [CST_CategoricalEnsCombination](R/CST_CategoricalEnsCombination.R), [CST_EnsClustering](R/CST_EnsClustering.R). -- **Downscaling:** [CST_Analogs](R/CST_Analogs.R), [CST_RainFARM](R/CST_RainFARM.R), [CST_RFTemp](R/CST_RFTemp.R), [CST_AdamontAnalog](R/CST_AdamontAnalog.R), [CST_AnalogsPredictors](R/CST_AnalogsPredictors.R). -- **Correction and transformation:** [CST_BiasCorrection](R/CST_BiasCorrection.R), [CST_Calibration](R/CST_Calibration.R), [CST_QuantileMapping](R/CST_QuantileMapping.R), [CST_Anomaly](R/CST_Anomaly.R), [CST_BEI_Weighting](R/CST_BEI_Weighting.R), [CST_DynBiasCorrection](R/CST_DynBiasCorrection.R). -- **Assessment:** [CST_MultiMetric](R/CST_MultiMetric.R), [CST_MultivarRMSE](R/CST_MultivarRMSE.R) -- **Visualization:** [PlotCombinedMap](R/PlotCombinedMap.R), [PlotForecastPDF](R/PlotForecastPDF.R), [PlotMostLikelyQuantileMap](R/PlotMostLikelyQuantileMap.R), [PlotPDFsOLE](R/PlotPDFsOLE.R), [PlotTriangles4Categories](R/PlotTriangles4Categories.R), [PlotWeeklyClim](R/PlotWeeklyClim.R). +- **Data retrieval and formatting:** CST_Start, CST_SaveExp, CST_MergeDims, CST_SplitDim, CST_Subset, CST_InsertDim, CST_ChangeDimNames, as.s2dv_cube and s2dv_cube. +- **Classification:** CST_MultiEOF, CST_WeatherRegimes, CST_RegimsAssign, CST_CategoricalEnsCombination, CST_EnsClustering. +- **Downscaling:** CST_Analogs, CST_RainFARM, CST_RFTemp, CST_AdamontAnalog, CST_AnalogsPredictors. +- **Correction and transformation:** CST_BiasCorrection, CST_Calibration, CST_QuantileMapping, CST_Anomaly, CST_BEI_Weighting, CST_DynBiasCorrection. +- **Assessment:** CST_MultiMetric, CST_MultivarRMSE +- **Visualization:** PlotCombinedMap, PlotForecastPDF, PlotMostLikelyQuantileMap, PlotPDFsOLE, PlotTriangles4Categories, PlotWeeklyClim. An `s2dv_cube` is an object to store ordered multidimensional array with named dimensions, specific coordinates and stored metadata (in-memory representation of a NetCDF file). Its “methods” are the **CST** prefix functions. The basic structure of the class `s2dv_cube` is a list of lists. The first level elements are: `data`, `dims`, `coords` and `attrs`. To access any specific element it will be done using the `$` operator. diff --git a/man/CST_SaveExp.Rd b/man/CST_SaveExp.Rd index 1ac3e7aba3ef41169d9ec5c9161e8e13e36cd154..c7976bccf0f5e4c69e81cebdae0484a951c8fb25 100644 --- a/man/CST_SaveExp.Rd +++ b/man/CST_SaveExp.Rd @@ -122,9 +122,11 @@ This function allows to divide and save a object of class 's2dv_cube' object that follows the NetCDF attributes conventions. } \examples{ +\dontrun{ data <- lonlat_temp_st$exp CST_SaveExp(data = data, ftime_dim = 'ftime', var_dim = 'var', dat_dim = 'dataset', sdate_dim = 'sdate') +} } \seealso{ diff --git a/man/SaveExp.Rd b/man/SaveExp.Rd index d7f0b30d84b8aadb722ff2733516819c909a8400..6ec767a06471eb85ddafd07c2b5f9e5fc73a84fa 100644 --- a/man/SaveExp.Rd +++ b/man/SaveExp.Rd @@ -151,6 +151,7 @@ from StartR package. If the original 's2dv_cube' object has been created from \code{CST_Load()}, then it can be reloaded with \code{Load()}. } \examples{ +\dontrun{ data <- lonlat_temp_st$exp$data lon <- lonlat_temp_st$exp$coords$lon lat <- lonlat_temp_st$exp$coords$lat @@ -162,6 +163,7 @@ metadata <- lonlat_temp_st$exp$attrs$Variable$metadata SaveExp(data = data, coords = coords, Datasets = Datasets, varname = varname, Dates = Dates, metadata = metadata, single_file = TRUE, ftime_dim = 'ftime', var_dim = 'var', dat_dim = 'dataset') +} } \author{ diff --git a/tests/testthat/test-CST_SaveExp.R b/tests/testthat/test-CST_SaveExp.R index b4e17554ea5a3e6c3e09e5f0df8d8c3ad1daaa2d..385d2793e9821c43b14f5c1d8e898778d6dca865 100644 --- a/tests/testthat/test-CST_SaveExp.R +++ b/tests/testthat/test-CST_SaveExp.R @@ -105,18 +105,18 @@ test_that("1. Input checks: CST_SaveExp", { ) ) # startdates - expect_warning( - CST_SaveExp(data = cube1, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, startdates = 1), - paste0("Parameter 'startdates' doesn't have the same length ", - "as dimension 'sdate', it will not be used.") - ) - expect_warning( - CST_SaveExp(data = cube1, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, startdates = '20100101'), - paste0("Parameter 'startdates' doesn't have the same length ", - "as dimension '", 'sdate',"', it will not be used.") - ) + # expect_warning( + # CST_SaveExp(data = cube1, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, startdates = 1), + # paste0("Parameter 'startdates' doesn't have the same length ", + # "as dimension 'sdate', it will not be used.") + # ) + # expect_warning( + # CST_SaveExp(data = cube1, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, startdates = '20100101'), + # paste0("Parameter 'startdates' doesn't have the same length ", + # "as dimension '", 'sdate',"', it will not be used.") + # ) # memb_dim suppressWarnings( expect_error( @@ -173,38 +173,38 @@ test_that("1. Input checks", { paste0("Parameter 'Dates' must have dimension names.") ) # drop_dims - expect_warning( - SaveExp(data = dat2, coords = coords2, - metadata = list(tas = list(level = '2m')), - Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, drop_dims = 1), - paste0("Parameter 'drop_dims' must be character string containing ", - "the data dimension names to be dropped. It will not be used.") - ) - expect_warning( - SaveExp(data = dat2, coords = coords2, - metadata = list(tas = list(level = '2m')), - Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, drop_dims = 'time'), - paste0("Parameter 'drop_dims' must be character string containing ", - "the data dimension names to be dropped. It will not be used.") - ) - expect_warning( - SaveExp(data = dat2, coords = coords2, - metadata = list(tas = list(level = '2m')), - Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, drop_dims = 'sdate'), - paste0("Parameter 'drop_dims' can only contain dimension names ", - "that are of length 1. It will not be used.") - ) - expect_warning( - SaveExp(data = dat2, coords = coords2, - metadata = list(tas = list(level = '2m')), - Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, drop_dims = 'ftime'), - paste0("Parameter 'drop_dims' contains dimensions used in the ", - "computation. It will not be used.") - ) + # expect_warning( + # SaveExp(data = dat2, coords = coords2, + # metadata = list(tas = list(level = '2m')), + # Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, drop_dims = 1), + # paste0("Parameter 'drop_dims' must be character string containing ", + # "the data dimension names to be dropped. It will not be used.") + # ) + # expect_warning( + # SaveExp(data = dat2, coords = coords2, + # metadata = list(tas = list(level = '2m')), + # Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, drop_dims = 'time'), + # paste0("Parameter 'drop_dims' must be character string containing ", + # "the data dimension names to be dropped. It will not be used.") + # ) + # expect_warning( + # SaveExp(data = dat2, coords = coords2, + # metadata = list(tas = list(level = '2m')), + # Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, drop_dims = 'sdate'), + # paste0("Parameter 'drop_dims' can only contain dimension names ", + # "that are of length 1. It will not be used.") + # ) + # expect_warning( + # SaveExp(data = dat2, coords = coords2, + # metadata = list(tas = list(level = '2m')), + # Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, drop_dims = 'ftime'), + # paste0("Parameter 'drop_dims' contains dimensions used in the ", + # "computation. It will not be used.") + # ) # varname suppressWarnings( expect_error( @@ -230,14 +230,14 @@ test_that("1. Input checks", { paste0("Parameter 'ftime_dim' is not found in 'data' dimension.") ) # Dates dimension check - expect_warning( - SaveExp(data = dat4, coords = coords4, - metadata = list(tas = list(level = '2m')), - Dates = NULL, ftime_dim = NULL, memb_dim = NULL, - dat_dim = NULL, var_dim = NULL), - paste0("Dates must be provided if 'data' must be saved in separated files. ", - "All data will be saved in a single file.") - ) + # expect_warning( + # SaveExp(data = dat4, coords = coords4, + # metadata = list(tas = list(level = '2m')), + # Dates = NULL, ftime_dim = NULL, memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL), + # paste0("Dates must be provided if 'data' must be saved in separated files. ", + # "All data will be saved in a single file.") + # ) # Without ftime and sdate expect_error( SaveExp(data = dat3, coords = coords3, @@ -247,34 +247,34 @@ test_that("1. Input checks", { paste0("Parameter 'Dates' can have only 'sdate_dim' and 'ftime_dim' ", "dimensions of length greater than 1.") ) - expect_warning( - SaveExp(data = dat2, coords = coords2, - metadata = list(tas = list(level = '2m')), - startdates = c(paste(1:11, collapse = '')), - Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, sdate_dim = 'sdate'), - paste0("Parameter 'startdates' should be a character string containing ", - "the start dates in the format 'yyyy-mm-dd', 'yyyymmdd', 'yyyymm', ", - "'POSIXct' or 'Dates' class. Files will be named with Dates instead.") - ) - expect_warning( - SaveExp(data = dat2, coords = coords2, - metadata = list(tas = list(level = '2m')), - Dates = NULL, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, sdate_dim = 'sdate'), - paste0("Dates must be provided if 'data' must be saved in separated files. ", - "All data will be saved in a single file.") - ) + # expect_warning( + # SaveExp(data = dat2, coords = coords2, + # metadata = list(tas = list(level = '2m')), + # startdates = c(paste(1:11, collapse = '')), + # Dates = dates2, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, sdate_dim = 'sdate'), + # paste0("Parameter 'startdates' should be a character string containing ", + # "the start dates in the format 'yyyy-mm-dd', 'yyyymmdd', 'yyyymm', ", + # "'POSIXct' or 'Dates' class. Files will be named with Dates instead.") + # ) + # expect_warning( + # SaveExp(data = dat2, coords = coords2, + # metadata = list(tas = list(level = '2m')), + # Dates = NULL, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, sdate_dim = 'sdate'), + # paste0("Dates must be provided if 'data' must be saved in separated files. ", + # "All data will be saved in a single file.") + # ) # (dat3) Without sdate_dim - expect_warning( - SaveExp(data = dat3, coords = coords3, - metadata = list(tas = list(level = '2m')), - Dates = NULL, ftime_dim = 'ftime', memb_dim = NULL, - dat_dim = NULL, var_dim = NULL, sdate_dim = NULL, - extra_string = 'nosdate3.nc', single_file = FALSE), - paste0("Dates must be provided if 'data' must be saved in separated files. ", - "All data will be saved in a single file.") - ) + # expect_warning( + # SaveExp(data = dat3, coords = coords3, + # metadata = list(tas = list(level = '2m')), + # Dates = NULL, ftime_dim = 'ftime', memb_dim = NULL, + # dat_dim = NULL, var_dim = NULL, sdate_dim = NULL, + # extra_string = 'nosdate3.nc', single_file = FALSE), + # paste0("Dates must be provided if 'data' must be saved in separated files. ", + # "All data will be saved in a single file.") + # ) }) ##############################################