From 338571a4c6e81cf465f324a50f0adb85f2cae280 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Tue, 23 Jan 2024 16:29:12 +0100 Subject: [PATCH 1/6] Version bump 5.2.0 --- DESCRIPTION | 2 +- NEWS.md | 11 +++++++++++ README.md | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 362663ff..b352859d 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 25041008..0f3602fd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# CSTools 5.2.0 (Release date: 24-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/README.md b/README.md index d8560b8d..9be3c57c 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ 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). +- **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.R), [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). -- GitLab From 382aa29bea487ba7eef871e3f6ad850ae6780800 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Tue, 23 Jan 2024 17:02:01 +0100 Subject: [PATCH 2/6] Add inst/doc to .gitignore and .Rbuildignore --- .Rbuildignore | 2 +- .gitignore | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index 6cd6d8c8..df7a1177 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,7 +8,7 @@ .*\.gitlab-ci.yml$ .lintr ^tests$ -#^inst/doc$ +^inst/doc$ ^inst/doc/usecase/UseCase2_PrecipitationDownscaling_RainFARM_RF100\.R$ ^inst/doc/usecase/UseCase1_WindEvent_March2018\.R$ ^inst/doc/usecase/UseCase2_PrecipitationDownscaling_RainFARM_RF4\.R$ diff --git a/.gitignore b/.gitignore index 2f6c062a..4b9792d6 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ Rplots.pdf .nfs* *.RData !data/*.RData +inst/doc -- GitLab From 3d6acfb8ef47e50daca2863a489a44d74412c804 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Tue, 23 Jan 2024 17:10:10 +0100 Subject: [PATCH 3/6] Correct .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4b9792d6..9e03b0a3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ Rplots.pdf .nfs* *.RData !data/*.RData -inst/doc +inst/doc/* -- GitLab From 6b3bfd94eef644d899876ab088effca9fc7e2fa5 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 24 Jan 2024 10:23:45 +0100 Subject: [PATCH 4/6] Add dontrun in CST_SaveExp examples, comment some tests in CST_SaveExp to avoid creating files, remove some changes in -gitignore, .Rbuildignore --- .Rbuildignore | 2 +- .gitignore | 1 - R/CST_SaveExp.R | 4 + man/CST_SaveExp.Rd | 2 + man/SaveExp.Rd | 2 + tests/testthat/test-CST_SaveExp.R | 158 +++++++++++++++--------------- 6 files changed, 88 insertions(+), 81 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index df7a1177..6cd6d8c8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,7 +8,7 @@ .*\.gitlab-ci.yml$ .lintr ^tests$ -^inst/doc$ +#^inst/doc$ ^inst/doc/usecase/UseCase2_PrecipitationDownscaling_RainFARM_RF100\.R$ ^inst/doc/usecase/UseCase1_WindEvent_March2018\.R$ ^inst/doc/usecase/UseCase2_PrecipitationDownscaling_RainFARM_RF4\.R$ diff --git a/.gitignore b/.gitignore index 9e03b0a3..2f6c062a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,3 @@ Rplots.pdf .nfs* *.RData !data/*.RData -inst/doc/* diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 72a97b8c..4e25a51d 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/man/CST_SaveExp.Rd b/man/CST_SaveExp.Rd index 1ac3e7ab..c7976bcc 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 d7f0b30d..6ec767a0 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 b4e17554..385d2793 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.") + # ) }) ############################################## -- GitLab From ab18f5173e7eb48cc98a71b3884760c54b710a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eva=20Rif=C3=A0?= Date: Thu, 25 Jan 2024 15:56:20 +0100 Subject: [PATCH 5/6] Update README.md without gitlab short links --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9be3c57c..8f56d956 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.R), [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. -- GitLab From 21dd81ef4b5bba38a87acbb930f8f15bf2cb2668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eva=20Rif=C3=A0?= Date: Thu, 25 Jan 2024 15:57:11 +0100 Subject: [PATCH 6/6] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 0f3602fd..cb826651 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# CSTools 5.2.0 (Release date: 24-01-2024) +# CSTools 5.2.0 (Release date: 25-01-2024) ### Development - New function CST_ChangeDimNames -- GitLab