From f6302b31bf1f020b31a030acb3edc41322db20ab Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Tue, 28 Mar 2023 17:28:39 +0200 Subject: [PATCH 1/8] Uncomment tests that depend on new CSTools version --- tests/testthat/test-AbsToProbs.R | 39 ++++++---- .../test-AccumulationExceedingThreshold.R | 78 ++++++++++--------- tests/testthat/test-PeriodAccumulation.R | 46 +++++------ tests/testthat/test-PeriodMean.R | 47 +++++------ tests/testthat/test-QThreshold.R | 67 ++++++++-------- 5 files changed, 150 insertions(+), 127 deletions(-) diff --git a/tests/testthat/test-AbsToProbs.R b/tests/testthat/test-AbsToProbs.R index c448670..902b3f1 100644 --- a/tests/testthat/test-AbsToProbs.R +++ b/tests/testthat/test-AbsToProbs.R @@ -81,17 +81,30 @@ test_that("1. Sanity checks", { }) ############################################## +library(CSTools) +library(s2dv) -# test_that("2. Seasonal forecasts", { -# exp <- CSTools::lonlat_temp$exp$data[1,1:3,1:3,,1:5,1:5] -# exp_probs <- AbsToProbs(exp) -# expect_equal(dim(exp)[3:5], dim(exp_probs)[3:5]) -# expect_equal(round(exp_probs[1,,1,1,1]), c(1, 0, 1)) -# exp <- exp[,1,,,] # one sdate -# expect_error(exp1_probs <- AbsToProbs(exp), -# "Could not find dimension 'sdate' in 1th object provided in 'data'.") -# library(s2dv) -# exp1 <- InsertDim(exp, 2, 1, name = 'sdate') -# exp1_probs <- AbsToProbs(exp1) -# expect_equal(round(exp1_probs[,1,2,2,2]), c(1, 0, 1)) -# }) +test_that("2. Seasonal forecasts", { + exp <- CSTools::lonlat_temp$exp$data[1,1:3,1:3,,1:5,1:5] + exp_probs <- AbsToProbs(exp) + expect_equal( + dim(exp)[3:5], + dim(exp_probs)[3:5] + ) + expect_equal( + round(exp_probs[1,,1,1,1]), + c(1, 0, 1) + ) + exp <- exp[,1,,,] # one sdate + expect_error( + exp1_probs <- AbsToProbs(exp), + "Could not find dimension 'sdate' in 1th object provided in 'data'." + ) + + exp1 <- InsertDim(exp, 2, 1, name = 'sdate') + exp1_probs <- AbsToProbs(exp1) + expect_equal( + round(exp1_probs[,1,2,2,2]), + c(1, 0, 1) + ) +}) diff --git a/tests/testthat/test-AccumulationExceedingThreshold.R b/tests/testthat/test-AccumulationExceedingThreshold.R index dda5c42..a6b598e 100644 --- a/tests/testthat/test-AccumulationExceedingThreshold.R +++ b/tests/testthat/test-AccumulationExceedingThreshold.R @@ -235,49 +235,51 @@ test_that("4. Output checks", { }) ############################################## +library(CSTools) + test_that("5. Seasonal forecasts", { - # exp <- CSTools::lonlat_temp$exp - # exp$data <- exp$data[ , 1:4, 1:2, , , ] - # res <- CST_AccumulationExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') + exp <- CSTools::lonlat_temp$exp + exp$data <- exp$data[ , 1:4, 1:2, , , ] + res <- CST_AccumulationExceedingThreshold(exp, threshold = 280, time_dim = 'ftime') - # expect_equal( - # round(res$data[, 2, 2, 2]), - # c(0, 280, 281, 281) - # ) + expect_equal( + round(res$data[, 2, 2, 2]), + c(0, 280, 281, 281) + ) - # # GDD - # exp <- array(NA, dim = c(member = 6, sdate = 3, ftime = 214, lat = 4, lon = 4)) - # exp1 <- drop(CSTools::lonlat_prec$data) * 86400000 - # exp[, , 1:31, , ] <- exp1 + 10; exp[, , 32:62, , ] <- exp1 + 11 - # exp[, , 63:93, , ] <- exp1 + 12; exp[, , 94:124, , ] <- exp1 + 13 - # exp[, , 125:155, , ] <- exp1 + 14; exp[, , 156:186, , ] <- exp1 + 15 - # exp[, , 187:214, , ] <- exp1[, , 1:28, , ] + 16 + # GDD + exp <- array(NA, dim = c(member = 6, sdate = 3, ftime = 214, lat = 4, lon = 4)) + exp1 <- drop(CSTools::lonlat_prec$data) * 86400000 + exp[, , 1:31, , ] <- exp1 + 10; exp[, , 32:62, , ] <- exp1 + 11 + exp[, , 63:93, , ] <- exp1 + 12; exp[, , 94:124, , ] <- exp1 + 13 + exp[, , 125:155, , ] <- exp1 + 14; exp[, , 156:186, , ] <- exp1 + 15 + exp[, , 187:214, , ] <- exp1[, , 1:28, , ] + 16 - # Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), - # as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), - # seq(as.Date("01-05-2001", format = "%d-%m-%Y"), - # as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), - # seq(as.Date("01-05-2002", format = "%d-%m-%Y"), - # as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) - # GDD <- AccumulationExceedingThreshold(exp - 17, threshold = 0, dates = Dates, time_dim = 'ftime', - # start = list(1, 4), end = list(31, 10), na.rm = TRUE) + Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), + as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'), + seq(as.Date("01-05-2001", format = "%d-%m-%Y"), + as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'), + seq(as.Date("01-05-2002", format = "%d-%m-%Y"), + as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) + GDD <- AccumulationExceedingThreshold(exp - 17, threshold = 0, dates = Dates, time_dim = 'ftime', + start = list(1, 4), end = list(31, 10), na.rm = TRUE) - # expect_equal( - # round(GDD[,1,1,1]), - # c(538, 367, 116, 519, 219, 282) - # ) - # expect_equal( - # dim(GDD), - # c(member = 6, sdate = 3, lat =4, lon = 4) - # ) - # expect_error( - # AccumulationExceedingThreshold(exp - 17, threshold = 0, dates = Dates, start = list(1, 4), end = list(31, 10), time_dim = 'time'), - # "Parameter 'time_dim' is not found in 'data' dimension." - # ) - # expect_equal( - # all(is.na(AccumulationExceedingThreshold(exp - 17, threshold = 0, dates = Dates, time_dim = 'ftime',start = list(1, 4), end = list(31, 10)))), - # all(is.na(c(NA, NA))) - # ) + expect_equal( + round(GDD[,1,1,1]), + c(538, 367, 116, 519, 219, 282) + ) + expect_equal( + dim(GDD), + c(member = 6, sdate = 3, lat =4, lon = 4) + ) + expect_error( + AccumulationExceedingThreshold(exp - 17, threshold = 0, dates = Dates, start = list(1, 4), end = list(31, 10), time_dim = 'time'), + "Parameter 'time_dim' is not found in 'data' dimension." + ) + expect_equal( + all(is.na(AccumulationExceedingThreshold(exp - 17, threshold = 0, dates = Dates, time_dim = 'ftime',start = list(1, 4), end = list(31, 10)))), + all(is.na(c(NA, NA))) + ) # test the 'diff' input_1 <- c(1:20) diff --git a/tests/testthat/test-PeriodAccumulation.R b/tests/testthat/test-PeriodAccumulation.R index f79d00c..777dc30 100644 --- a/tests/testthat/test-PeriodAccumulation.R +++ b/tests/testthat/test-PeriodAccumulation.R @@ -33,27 +33,29 @@ test_that("Sanity Checks", { ) }) +############################################## +library(CSTools) -# test_that("seasonal", { -# exp <- CSTools::lonlat_prec -# exp$data <- array(1:(1 * 3 * 214 * 2), -# c(memb = 1, sdate = 3, ftime = 214, lon = 2)) -# exp$dims <- dim(exp$data) -# exp$attrs$Dates <- c(seq(as.Date("01-04-2000", format = "%d-%m-%Y"), -# as.Date("31-10-2000", format = "%d-%m-%Y"), by = 'day'), -# seq(as.Date("01-04-2001", format = "%d-%m-%Y"), -# as.Date("31-10-2001", format = "%d-%m-%Y"), by = 'day'), -# seq(as.Date("01-04-2002", format = "%d-%m-%Y"), -# as.Date("31-10-2002", format = "%d-%m-%Y"), by = 'day')) -# dim(exp$attrs$Dates) <- c(ftime = 214, sdate = 3) -# output <- exp -# output$data <- array(c(sum(exp$data[1,1,21:82,1]), sum(exp$data[1,2,21:82,1]), -# sum(exp$data[1,3,21:82,1]), sum(exp$data[1,1,21:82,2]), -# sum(exp$data[1,2,21:82,2]), sum(exp$data[1,3,21:82,2])), -# c(memb = 1, sdate = 3, lon = 2)) +test_that("seasonal", { + exp <- CSTools::lonlat_prec + exp$data <- array(1:(1 * 3 * 214 * 2), + c(memb = 1, sdate = 3, ftime = 214, lon = 2)) + exp$dims <- dim(exp$data) + exp$attrs$Dates <- c(seq(as.Date("01-04-2000", format = "%d-%m-%Y"), + as.Date("31-10-2000", format = "%d-%m-%Y"), by = 'day'), + seq(as.Date("01-04-2001", format = "%d-%m-%Y"), + as.Date("31-10-2001", format = "%d-%m-%Y"), by = 'day'), + seq(as.Date("01-04-2002", format = "%d-%m-%Y"), + as.Date("31-10-2002", format = "%d-%m-%Y"), by = 'day')) + dim(exp$attrs$Dates) <- c(ftime = 214, sdate = 3) + output <- exp + output$data <- array(c(sum(exp$data[1,1,21:82,1]), sum(exp$data[1,2,21:82,1]), + sum(exp$data[1,3,21:82,1]), sum(exp$data[1,1,21:82,2]), + sum(exp$data[1,2,21:82,2]), sum(exp$data[1,3,21:82,2])), + c(memb = 1, sdate = 3, lon = 2)) -# expect_equal( -# CST_PeriodAccumulation(exp, start = list(21, 4), end = list(21, 6))$data, -# output$data -# ) -# }) + expect_equal( + CST_PeriodAccumulation(exp, start = list(21, 4), end = list(21, 6))$data, + output$data + ) +}) diff --git a/tests/testthat/test-PeriodMean.R b/tests/testthat/test-PeriodMean.R index 3cd6365..7576b11 100644 --- a/tests/testthat/test-PeriodMean.R +++ b/tests/testthat/test-PeriodMean.R @@ -34,25 +34,28 @@ test_that("Sanity Checks", { ) }) -# test_that("seasonal", { -# exp <- CSTools::lonlat_prec -# exp$data <- array(1:(1 * 3 * 214 * 2), -# c(memb = 1, sdate = 3, ftime = 214, lon = 2)) -# exp$dims <- dim(exp$data) -# exp$attrs$Dates <- c(seq(as.Date("01-04-2000", format = "%d-%m-%Y"), -# as.Date("31-10-2000", format = "%d-%m-%Y"), by = 'day'), -# seq(as.Date("01-04-2001", format = "%d-%m-%Y"), -# as.Date("31-10-2001", format = "%d-%m-%Y"), by = 'day'), -# seq(as.Date("01-04-2002", format = "%d-%m-%Y"), -# as.Date("31-10-2002", format = "%d-%m-%Y"), by = 'day')) -# dim(exp$attrs$Dates) <- c(ftime = 214, sdate = 3) -# output <- exp -# output$data <- array(c(mean(exp$data[1,1,21:82,1]), mean(exp$data[1,2,21:82,1]), -# mean(exp$data[1,3,21:82,1]), mean(exp$data[1,1,21:82,2]), -# mean(exp$data[1,2,21:82,2]), mean(exp$data[1,3,21:82,2])), -# c(memb = 1, sdate = 3, lon = 2)) -# expect_equal( -# CST_PeriodMean(exp, start = list(21, 4), end = list(21, 6))$data, -# output$data -# ) -# }) +############################################## +library(CSTools) + +test_that("seasonal", { + exp <- CSTools::lonlat_prec + exp$data <- array(1:(1 * 3 * 214 * 2), + c(memb = 1, sdate = 3, ftime = 214, lon = 2)) + exp$dims <- dim(exp$data) + exp$attrs$Dates <- c(seq(as.Date("01-04-2000", format = "%d-%m-%Y"), + as.Date("31-10-2000", format = "%d-%m-%Y"), by = 'day'), + seq(as.Date("01-04-2001", format = "%d-%m-%Y"), + as.Date("31-10-2001", format = "%d-%m-%Y"), by = 'day'), + seq(as.Date("01-04-2002", format = "%d-%m-%Y"), + as.Date("31-10-2002", format = "%d-%m-%Y"), by = 'day')) + dim(exp$attrs$Dates) <- c(ftime = 214, sdate = 3) + output <- exp + output$data <- array(c(mean(exp$data[1,1,21:82,1]), mean(exp$data[1,2,21:82,1]), + mean(exp$data[1,3,21:82,1]), mean(exp$data[1,1,21:82,2]), + mean(exp$data[1,2,21:82,2]), mean(exp$data[1,3,21:82,2])), + c(memb = 1, sdate = 3, lon = 2)) + expect_equal( + CST_PeriodMean(exp, start = list(21, 4), end = list(21, 6))$data, + output$data + ) +}) diff --git a/tests/testthat/test-QThreshold.R b/tests/testthat/test-QThreshold.R index 1dc6c65..7572bd0 100644 --- a/tests/testthat/test-QThreshold.R +++ b/tests/testthat/test-QThreshold.R @@ -89,35 +89,38 @@ test_that("Sanity checks", { }) -# test_that("Seasonal forecasts", { -# obs <- CSTools::lonlat_temp$obs$data - 248 -# obs_percentile <- QThreshold(obs, threshold = 35) -# expect_equal( -# dim(obs)[4:6], -# dim(obs_percentile)[4:6] -# ) -# expect_equal( -# obs_percentile[, 1, 1, 3, 20, 53], -# c(rep(0.4, 4), rep(0.2, 2)) -# ) -# obs1 <- obs[,,2,,,] # no sdate -# expect_error( -# obs1_percentile <- QThreshold(obs1, threshold = 35), -# "Could not find dimension 'sdate' in 1th object provided in 'data'." -# ) -# obs1 <- s2dv::InsertDim(obs1, 1, 1, name = 'sdate') # one sdate -# expect_error( -# obs1_percentile <- QThreshold(obs1, threshold = 35), -# "'x' must have 1 or more non-missing values" -# ) -# obs2 <- obs[,,,2,,] # one ftime -# obs2_percentile <- QThreshold(obs2, threshold = 35) -# expect_equal( -# dim(obs2), -# dim(obs2_percentile) -# ) -# expect_equal( -# obs2_percentile[,14,53], -# c(0.6, 0.4, 0.6, 0.6, 0.4, 0.4) -# ) -# }) +############################################## +library(CSTools) + +test_that("Seasonal forecasts", { + obs <- CSTools::lonlat_temp$obs$data - 248 + obs_percentile <- QThreshold(obs, threshold = 35) + expect_equal( + dim(obs)[4:6], + dim(obs_percentile)[4:6] + ) + expect_equal( + obs_percentile[, 1, 1, 3, 20, 53], + c(rep(0.4, 4), rep(0.2, 2)) + ) + obs1 <- obs[,,2,,,] # no sdate + expect_error( + obs1_percentile <- QThreshold(obs1, threshold = 35), + "Could not find dimension 'sdate' in 1th object provided in 'data'." + ) + obs1 <- s2dv::InsertDim(obs1, 1, 1, name = 'sdate') # one sdate + expect_error( + obs1_percentile <- QThreshold(obs1, threshold = 35), + "'x' must have 1 or more non-missing values" + ) + obs2 <- obs[,,,2,,] # one ftime + obs2_percentile <- QThreshold(obs2, threshold = 35) + expect_equal( + dim(obs2), + dim(obs2_percentile) + ) + expect_equal( + obs2_percentile[,14,53], + c(0.6, 0.4, 0.6, 0.6, 0.4, 0.4) + ) +}) -- GitLab From d2d5f47fce4ec920c927f9e0db83031cdd4d945a Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Tue, 28 Mar 2023 17:34:59 +0200 Subject: [PATCH 2/8] Update NEWS --- NEWS.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.md b/NEWS.md index fa2bb87..415e494 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# CSIndicators 1.0.0 (Release date: 2023-03-30) +**Fixes** +- Correct vignettes figures links +**New features** +- Exceeding Threshold functions to allow between thresholds or equal threshold options. +- New s2dv_cube object development for all the functions, unit tests, examples and vignettes + # CSIndicators 0.0.2 (Release date: 2022-10-21) - Correct figures of EnergyIndicators vignette. - Sanity check correction in functions CST_PeriodAccumulation, CST_AbsToProbs, CST_AccumulationExceedingThreshold, CST_MergeRefToExp, CST_PeriodMean, CST_QThreshold, CST_SelectPeriodOnData, CST_Threshold, TotalSpellTimeExceedingThreshold, CST_TotalTimeExceedingThreshold, CST_WindCapacityFactor and CST_WindPowerDensity. -- GitLab From a0ae3a6427416e007a3a8521048318e143243086 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 29 Mar 2023 10:42:03 +0200 Subject: [PATCH 3/8] Update NEWS, License, .Rbuildignore --- .Rbuildignore | 1 + DESCRIPTION | 4 ++-- NEWS.md | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index ba637f5..c0e2736 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,4 @@ ./.nfs* ^cran-comments\.md$ ./vignettes/*.md +^inst/doc/paper-figure-PlotForecastPDF\.R$ diff --git a/DESCRIPTION b/DESCRIPTION index d855559..7fcf115 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: CSIndicators Title: Climate Services' Indicators Based on Sub-Seasonal to Decadal Predictions -Version: 0.0.2 +Version: 1.0.0 Authors@R: c( person("Eva", "Rifà", , "eva.rifarovira@bsc.es", role = c("cre")), person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("aut"), comment = c(ORCID = "0000-0001-8568-3071")), @@ -37,7 +37,7 @@ Suggests: markdown, rmarkdown VignetteBuilder: knitr -License: Apache License 2.0 +License: GPL-3 URL: https://earth.bsc.es/gitlab/es/csindicators/ BugReports: https://earth.bsc.es/gitlab/es/csindicators/-/issues Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index 415e494..fa22663 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,13 @@ # CSIndicators 1.0.0 (Release date: 2023-03-30) -**Fixes** +**Fixes** - Correct vignettes figures links -**New features** + +**New features** - Exceeding Threshold functions to allow between thresholds or equal threshold options. - New s2dv_cube object development for all the functions, unit tests, examples and vignettes # CSIndicators 0.0.2 (Release date: 2022-10-21) +**Fixes** - Correct figures of EnergyIndicators vignette. - Sanity check correction in functions CST_PeriodAccumulation, CST_AbsToProbs, CST_AccumulationExceedingThreshold, CST_MergeRefToExp, CST_PeriodMean, CST_QThreshold, CST_SelectPeriodOnData, CST_Threshold, TotalSpellTimeExceedingThreshold, CST_TotalTimeExceedingThreshold, CST_WindCapacityFactor and CST_WindPowerDensity. - Revise examples using s2dv::InsertDim in MergeRefToExp(). -- GitLab From d068c18cda8b53588280f4d6511947924626068c Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 29 Mar 2023 11:14:07 +0200 Subject: [PATCH 4/8] Update README --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2ed5fde..59f5b73 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,27 @@ CSIndicators #### Sectoral Indicators for Climate Services Based on Sub-Seasonal to Decadal Climate Predictions -## Description -Set of generalised tools for the flexible computation of climate related -indicators defined by the user. Each method represents a specific mathematical -approach which is combined with the possibility to select an arbitrary time -period to define the indicator. This enables a wide range of possibilities to -tailor the most suitable indicator for each particular climate service -application (agriculture, food security, energy, water management…). This package -is intended for sub-seasonal, seasonal and decadal climate predictions, but its -methods are also applicable to other time-scales, provided the dimensional -structure of the input is maintained. Additionally, the outputs of the functions -in this package are compatible with CSTools. - -## Functions and documentation +Set of generalised tools for the flexible computation of climate related indicators defined by the user. Each method represents a specific mathematical approach which is combined with the possibility to select an arbitrary time period to define the indicator. This enables a wide range of possibilities to tailor the most suitable indicator for each particular climate service application (agriculture, food security, energy, water management…). + +This package is intended for sub-seasonal, seasonal and decadal climate predictions, but its methods are also applicable to other time-scales, provided the dimensional structure of the input is maintained. Additionally, the outputs of the functions in this package are compatible with [CSTools](https://earth.bsc.es/gitlab/external/cstools). + +This package can be found in CRAN: [CSIndicators](https://cran.r-project.org/web/packages/CSIndicators/index.html). + +Installation +------------ + +You can then install the public released version of CSIndicators from CRAN: +```r +install.packages("CSIndicators") +``` +Or the development version from the GitLab repository: +```r +# install.packages("devtools") +devtools::install_git("https://earth.bsc.es/gitlab/es/csindicators.git") +``` + +Overview +-------- To learn how to use the package see: @@ -50,8 +58,36 @@ Find the current status of each function in this link: https://docs.google.com/s *Note: All functions computing indicators allows to subset a time period if required, although this temporal subsetting can also be done with functions `SelectPeriodOnData` in a separated step.* +This package is designed to be compatible with other R packages such as [CSTools](https://cran.r-project.org/web/packages/CSTools/index.html) through a common object structure: `s2dv_cube` object class. Functions with the prefix **CST_** operate with the `s2dv_cube` object class. This object can be created from Start ([startR](https://cran.r-project.org/web/packages/startR/index.html) package) and from Load ([s2dv](https://cran.r-project.org/web/packages/s2dv/index.html) package) directly. + +The class `s2dv_cube` is mainly a list of named elements to keep data and metadata in a single object. Basic structure of the object class `s2dv_cube`: + +```r +$data: A multidimensional array +$dims: Dimensions vector +$coords: Named list of coordinates vector + $sdate + $time + $lon + [...] +$attrs: Named list containing the metadata + $Variable + $Datasets + $source_files + $when + $Dates + $load_parameters +``` + +More information about the `s2dv_cube` object class can be found here: [Description of the s2dv_cube object structure document](https://docs.google.com/document/d/1ko37JFl_h6mOjDKM5QSQGikfLBKZq1naL11RkJIwtMM/edit?usp=sharing). + +The current `s2dv_cube` object (CSIndicators 1.0.0 and CSTools 5.0.0) differs from the original object used in the previous versions of the packages. If you have **questions** on this change you can follow some of the points below: + +- [New s2dv_cube object discussion in CSTools](https://earth.bsc.es/gitlab/external/cstools/-/issues/94) +- [How to deal with the compatibility break in CSIndicators](https://earth.bsc.es/gitlab/es/csindicators/-/issues/25) -### How to contribute +Contribute +---------- 1. Open an issue to ask for help or describe a function to be integrated 2. Agree with maintainers (@ngonzal2, @rmarcos, @nperez and @erifarov) on the requirements @@ -60,14 +96,15 @@ Find the current status of each function in this link: https://docs.google.com/s *Note: Remember to work with multidimensionals arrays with named dimensions when possible and use multiApply (https://earth.bsc.es/gitlab/ces/multiApply)* -### Add a function +Add a function +---------- To add a new function in this R package, follow this considerations: 1. Each function exposed to the users should be in separate files in the R folder -2. The name of the function should match the name of the file (e.g.: `Function()` included in file **Function.R** +2. The name of the function should match the name of the file (e.g.: `Function()` included in file **Function.R**) 3. The documentation should be in roxygen2 format as a header of the function 4. Once, the function and the documentation is finished, run the command `devtools::document()` in your R terminal to automatically generate the **Function.Rd** file -5. Remember to use R 3.6.1 when doing the development -6. Code format: include spaces between operators (e.g. +, -, &), before { and after ','. The maximum length of lines is of 100 characters (hard limit 80 characters). Number of indentation spaces is 2. +5. Remember to use R 4.1.2 when doing the development +6. Code format: include spaces between operators (e.g. +, -, &), before and after ','. The maximum length of lines is of 100 characters (hard limit 80 characters). Number of indentation spaces is 2. 7. Functions computing Climate indicators should include a temporal subsetting option. Use the already existing functions to adapt your code. -- GitLab From 12a4461434ccf56d6c844a4b14e323daae648309 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 29 Mar 2023 11:16:09 +0200 Subject: [PATCH 5/8] Udate README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59f5b73..f77131a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ Find the current status of each function in this link: https://docs.google.com/s *Note: All functions computing indicators allows to subset a time period if required, although this temporal subsetting can also be done with functions `SelectPeriodOnData` in a separated step.* +## Object class `s2dv_cube` + This package is designed to be compatible with other R packages such as [CSTools](https://cran.r-project.org/web/packages/CSTools/index.html) through a common object structure: `s2dv_cube` object class. Functions with the prefix **CST_** operate with the `s2dv_cube` object class. This object can be created from Start ([startR](https://cran.r-project.org/web/packages/startR/index.html) package) and from Load ([s2dv](https://cran.r-project.org/web/packages/s2dv/index.html) package) directly. The class `s2dv_cube` is mainly a list of named elements to keep data and metadata in a single object. Basic structure of the object class `s2dv_cube`: @@ -96,8 +98,7 @@ Contribute *Note: Remember to work with multidimensionals arrays with named dimensions when possible and use multiApply (https://earth.bsc.es/gitlab/ces/multiApply)* -Add a function ----------- +## Add a function To add a new function in this R package, follow this considerations: -- GitLab From 311fd80dd2df15efb2afb7d961cc3519f0f4ded8 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 29 Mar 2023 11:17:37 +0200 Subject: [PATCH 6/8] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f77131a..d282870 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Find the current status of each function in this link: https://docs.google.com/s *Note: All functions computing indicators allows to subset a time period if required, although this temporal subsetting can also be done with functions `SelectPeriodOnData` in a separated step.* -## Object class `s2dv_cube` +#### Object class 's2dv_cube' This package is designed to be compatible with other R packages such as [CSTools](https://cran.r-project.org/web/packages/CSTools/index.html) through a common object structure: `s2dv_cube` object class. Functions with the prefix **CST_** operate with the `s2dv_cube` object class. This object can be created from Start ([startR](https://cran.r-project.org/web/packages/startR/index.html) package) and from Load ([s2dv](https://cran.r-project.org/web/packages/s2dv/index.html) package) directly. @@ -98,7 +98,7 @@ Contribute *Note: Remember to work with multidimensionals arrays with named dimensions when possible and use multiApply (https://earth.bsc.es/gitlab/ces/multiApply)* -## Add a function +#### Add a function To add a new function in this R package, follow this considerations: -- GitLab From 7c9241d0b82387b71c88807b811f30e273155d10 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 29 Mar 2023 11:38:09 +0200 Subject: [PATCH 7/8] Update readme --- README.md | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d282870..712ecb8 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,7 @@ CSIndicators #### Sectoral Indicators for Climate Services Based on Sub-Seasonal to Decadal Climate Predictions -Set of generalised tools for the flexible computation of climate related indicators defined by the user. Each method represents a specific mathematical approach which is combined with the possibility to select an arbitrary time period to define the indicator. This enables a wide range of possibilities to tailor the most suitable indicator for each particular climate service application (agriculture, food security, energy, water management…). - -This package is intended for sub-seasonal, seasonal and decadal climate predictions, but its methods are also applicable to other time-scales, provided the dimensional structure of the input is maintained. Additionally, the outputs of the functions in this package are compatible with [CSTools](https://earth.bsc.es/gitlab/external/cstools). - -This package can be found in CRAN: [CSIndicators](https://cran.r-project.org/web/packages/CSIndicators/index.html). +Set of generalised tools for the flexible computation of climate related indicators defined by the user. Each method represents a specific mathematical approach which is combined with the possibility to select an arbitrary time period to define the indicator. This enables a wide range of possibilities to tailor the most suitable indicator for each particular climate service application (agriculture, food security, energy, water management…). This package is intended for sub-seasonal, seasonal and decadal climate predictions, but its methods are also applicable to other time-scales, provided the dimensional structure of the input is maintained. Additionally, the outputs of the functions in this package are compatible with [CSTools](https://earth.bsc.es/gitlab/external/cstools). Installation ------------ @@ -30,7 +26,7 @@ To learn how to use the package see: - [**Agricultural Indicators**](https://CRAN.R-project.org/package=CSIndicators/vignettes/AgriculturalIndicators.html) - [**Wind Energy Indicators**](https://CRAN.R-project.org/package=CSIndicators/vignettes/EnergyIndicators.html) -Functions documentation can be found [here](https://CRAN.R-project.org/package=CSIndicators/CSIndicators.pdf) +Functions documentation can be found [here](https://CRAN.R-project.org/package=CSIndicators/CSIndicators.pdf). | Function | CST version | Indicators | |--------------------------------|------------------------------------|---------------------------------| @@ -52,7 +48,7 @@ Functions documentation can be found [here](https://CRAN.R-project.org/package=C |SelectPeriodOnData |CST_SelectPeriodOnData| |SelectPeriodOnDates| | -Find the current status of each function in this link: https://docs.google.com/spreadsheets/d/1arqgw-etNPs-XRyMTJ4ekF5YjQxAZBzssxxr2GMXp3c/edit#gid=0. +Find the current status of each function in [this link](https://docs.google.com/spreadsheets/d/1arqgw-etNPs-XRyMTJ4ekF5YjQxAZBzssxxr2GMXp3c/edit#gid=0). *Note: the CST version uses 's2dv_cube' objects as inputs and outputs while the former version uses multidimensional arrays with named dimensions as inputs and outputs* @@ -60,25 +56,27 @@ Find the current status of each function in this link: https://docs.google.com/s #### Object class 's2dv_cube' -This package is designed to be compatible with other R packages such as [CSTools](https://cran.r-project.org/web/packages/CSTools/index.html) through a common object structure: `s2dv_cube` object class. Functions with the prefix **CST_** operate with the `s2dv_cube` object class. This object can be created from Start ([startR](https://cran.r-project.org/web/packages/startR/index.html) package) and from Load ([s2dv](https://cran.r-project.org/web/packages/s2dv/index.html) package) directly. +This package is designed to be compatible with other R packages such as [CSTools](https://cran.r-project.org/web/packages/CSTools/index.html) through a common object: the `s2dv_cube` object class, used in functions with the prefix **CST_**. This object can be created from Start ([startR](https://cran.r-project.org/web/packages/startR/index.html) package) and from Load ([s2dv](https://cran.r-project.org/web/packages/s2dv/index.html) package) directly. -The class `s2dv_cube` is mainly a list of named elements to keep data and metadata in a single object. Basic structure of the object class `s2dv_cube`: +The class `s2dv_cube` is mainly a list of named elements to keep data and metadata in a single object. Basic structure is`: ```r -$data: A multidimensional array -$dims: Dimensions vector -$coords: Named list of coordinates vector - $sdate - $time - $lon +$ data: [data array] +$ dims: [dimensions vector] +$ coords: [List of coordinates vectors] + $ sdate + $ time + $ lon [...] -$attrs: Named list containing the metadata - $Variable - $Datasets - $source_files - $when - $Dates - $load_parameters +$ attrs: [List of the attributes] + $ Variable: + $ varName + $ metadata + $ Datasets + $ Dates + $ source_files + $ when + $ load_parameters ``` More information about the `s2dv_cube` object class can be found here: [Description of the s2dv_cube object structure document](https://docs.google.com/document/d/1ko37JFl_h6mOjDKM5QSQGikfLBKZq1naL11RkJIwtMM/edit?usp=sharing). -- GitLab From e0d80348241d21058135b82636ce73416625faf1 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 29 Mar 2023 16:05:44 +0200 Subject: [PATCH 8/8] Improve README --- NEWS.md | 4 ++-- README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index fa22663..488e2b6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,10 @@ # CSIndicators 1.0.0 (Release date: 2023-03-30) **Fixes** -- Correct vignettes figures links +- Correct vignettes figures links. **New features** - Exceeding Threshold functions to allow between thresholds or equal threshold options. -- New s2dv_cube object development for all the functions, unit tests, examples and vignettes +- New s2dv_cube object development for all the functions, unit tests, examples and vignettes. # CSIndicators 0.0.2 (Release date: 2022-10-21) **Fixes** diff --git a/README.md b/README.md index 712ecb8..555cf39 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Find the current status of each function in [this link](https://docs.google.com/ This package is designed to be compatible with other R packages such as [CSTools](https://cran.r-project.org/web/packages/CSTools/index.html) through a common object: the `s2dv_cube` object class, used in functions with the prefix **CST_**. This object can be created from Start ([startR](https://cran.r-project.org/web/packages/startR/index.html) package) and from Load ([s2dv](https://cran.r-project.org/web/packages/s2dv/index.html) package) directly. -The class `s2dv_cube` is mainly a list of named elements to keep data and metadata in a single object. Basic structure is`: +The class `s2dv_cube` is mainly a list of named elements to keep data and metadata in a single object. Basic structure of the object: ```r $ data: [data array] @@ -79,7 +79,7 @@ $ attrs: [List of the attributes] $ load_parameters ``` -More information about the `s2dv_cube` object class can be found here: [Description of the s2dv_cube object structure document](https://docs.google.com/document/d/1ko37JFl_h6mOjDKM5QSQGikfLBKZq1naL11RkJIwtMM/edit?usp=sharing). +More information about the `s2dv_cube` object class can be found here: [description of the s2dv_cube object structure document](https://docs.google.com/document/d/1ko37JFl_h6mOjDKM5QSQGikfLBKZq1naL11RkJIwtMM/edit?usp=sharing). The current `s2dv_cube` object (CSIndicators 1.0.0 and CSTools 5.0.0) differs from the original object used in the previous versions of the packages. If you have **questions** on this change you can follow some of the points below: @@ -94,7 +94,7 @@ Contribute 3. Create a new branch from master with a meaningful name 4. Once the development is finished, open a merge request to merge the branch on master -*Note: Remember to work with multidimensionals arrays with named dimensions when possible and use multiApply (https://earth.bsc.es/gitlab/ces/multiApply)* +*Note: Remember to work with multidimensionals arrays with named dimensions when possible and use [multiApply](https://earth.bsc.es/gitlab/ces/multiApply).* #### Add a function -- GitLab