From 0cf613e4e65c4f549f9778466a99d19be4dfbadc Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 4 May 2021 12:26:27 +0200 Subject: [PATCH 01/26] improve Readme file --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be122f6..c12acb8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,63 @@ -# CSIndicators +CSIndicators +----- -Sectorial Indicators for Climate Services: from sub-seasonal forecast to Decadal Predictions \ No newline at end of file +#### 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 + +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) + +| Function | CST version | Indicators | +|--------------------------------|------------------------------------|---------------------------------| +|PeriodMean |CST_PeriodMean |GST, SprTX, DTR | +|PeriodAccumulation |CST_PeriodAccumulation |SprR, HarR, PRCPTOT | +|AccumulationExceedingThreshold |CST_AccumulationExceedingThreshold |GDD, R95pTOT, R99pTOT | +|TotalTimeExceedingThreshold |CST_TotalTimeExceedingThreshold |SU35, SU, FD, ID, TR, R10mm, Rnmm| +|TotalSpellTimeExceedingThreshold|CST_TotalSpellTimeExceedingThreshold|WSDI, CSDI | +|WindCapacityFactor |CST_WindCapacityFactor |Wind Capacity Factor | +|WindPowerDensity |CST_WindPowerDensity |Wind Power Density | + + +| Auxiliar function | CST version | +|-------------------|----------------------| +|AbsToProbs |CST_AbsToProbs | +|QThreshold |CST_QThreshold | +|Threshold |CST_Threshold | +|MergeRefToExp |CST_MergeRefToExp | +|SelectPeriodOnData |CST_SelectPeriodOnData| +|SelectPeriodOnDates| | + + +*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* + +*Note: All functions computing indicators allows to subset a time period if required, although this temporal subsetting can also be done with funcitons `SelectPeriodOnData` in a separated step.* + + +### How to contribute + +1. Open an issue to ask for help or describe a function to be integrated +2. Agree with maintainers (@ngonzal2, @rmarcos and @nperez) on the requirements +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)* + +### 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** +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. -- GitLab From ff8a1678eb80d3b5d1eaaf97a2ba69f9c15c8a83 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 4 May 2021 15:30:49 +0200 Subject: [PATCH 02/26] Mention temporal subsetting --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c12acb8..24069b7 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,5 @@ To add a new function in this R package, follow this considerations: 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. +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 275e431fcd3a8be3a99dc64ff2f75d0e25514ac7 Mon Sep 17 00:00:00 2001 From: nperez Date: Mon, 10 May 2021 16:08:43 +0200 Subject: [PATCH 03/26] Fix link plots in vignettes --- vignettes/AgriculturalIndicators.Rmd | 16 ++++++++-------- vignettes/EnergyIndicators.Rmd | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/vignettes/AgriculturalIndicators.Rmd b/vignettes/AgriculturalIndicators.Rmd index 3d9300d..c8d52b2 100644 --- a/vignettes/AgriculturalIndicators.Rmd +++ b/vignettes/AgriculturalIndicators.Rmd @@ -170,7 +170,7 @@ PlotEquiMap(Bias[1,,], lon = prlr_obs$lon, lat = prlr_obs$lat, ``` You will see the following maps of HarvestR bias in 2013. - +![](.figures/HarvestR_Bias_2013-1.png) In 2013, the ensemble-mean SEAS5 seasonal forecast of HarvestR is underestimated by up to 60 mm over Douro Valley region (the central four grid points). @@ -270,7 +270,7 @@ PlotEquiMap(GST_Clim, lon = tas_obs$lon, lat = tas_obs$lat, The ERA5 GST climatology is shown as below. - +![](./figures/GST_ERA5_Climatology-1.png) ERA5 GST ranges from 17-18.5°C over the Douro Valley region for the period from 2013-2016 as shown in the figure. @@ -395,9 +395,9 @@ PlotEquiMap(SU35_exp_BC_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, You can see the figure as below. - - - +![](./figures/SU35_ERA5_Y2016-1.png) +![](./figures/SU35_SEAS5_Y2016-1.png) +![](./figures/SU35_SEAS5_BC_Y2016-1.png) As seen above, the bias-adjusted SU35 forecasts are much closer to the ERA5 results, although differences remain. @@ -454,7 +454,7 @@ PlotEquiMap(SU35_exp_per_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, ``` - +![](./figures/SU35_Percentile_SEAS5_Y2016-1.png) As seen in the figure above, applying the percentile adjustment seems to implicitly adjust certain extent of bias which was observed in the non-bias-adjusted SEAS5 forecast. @@ -512,7 +512,7 @@ PlotEquiMap(GDD_Corr, lon = tas_obs$lon, lat = tas_obs$lat, The map of correlation coefficient for the 2013-2016 period is shown as below. - +![](./figures/GDD_SEAS5_Corr_Y13-16-1.png) The 2013-2016 correlation coefficients of the SEAS5 forecasts of GDD in reference with ERA5 reanalysis over Douro Valley range between 0.6 and 0.8. @@ -583,7 +583,7 @@ PlotEquiMap(WSDI_FRPSS, lon = tasmax_obs$lon, lat = tasmax_obs$lat, The FRPSS map for 2013-2016 SEAS WSDI is shown as below. - +![](./figures/WSDI_SEAS5_FRPSS_Y13-16-1.png) As seen in the map, the FRPSS in the eastern part of Douro Valley falls in 0.6-0.9, which are good enough to be useful when compared to observational climatology. diff --git a/vignettes/EnergyIndicators.Rmd b/vignettes/EnergyIndicators.Rmd index 222ba38..f656f56 100644 --- a/vignettes/EnergyIndicators.Rmd +++ b/vignettes/EnergyIndicators.Rmd @@ -42,7 +42,6 @@ par(mfrow=c(1, 2)) hist(wind, breaks = seq(0, 20)) hist(WPD, breaks = seq(0, 4000, 200)) ``` - As you can see the histogram of the WPD is highly skewed, even if the wind speed was only a little skewed! @@ -72,7 +71,6 @@ hist(WCFIII, breaks = seq(0, 1, 0.05), ylim = c(0, 500)) par(oldpar) ``` - From the CF histograms we can see that, for this particular wind speed distribution, the IEC I turbine (designed for high winds) producess less energy than the IEC III turbine, which is more suitable for this range of wind speed values. -- GitLab From c1569bcdd0e7313e83440e812b901c4366ecabbc Mon Sep 17 00:00:00 2001 From: nperez Date: Mon, 10 May 2021 17:21:20 +0200 Subject: [PATCH 04/26] NEWS file --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..7aefb00 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,6 @@ +### CSIndicators 0.0.2 +**Submission date to CRAN: XX-YY-2021** + +- New features: +- Fixes: + + Vignettes figures -- GitLab From 85f622c0b1f0cfc1905f7421b5dea91d2d60a747 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 11 May 2021 09:19:20 +0200 Subject: [PATCH 05/26] vignettes md version --- vignettes/AgriculturalIndicators.md | 595 ++++++++++++++++++++++++++++ 1 file changed, 595 insertions(+) create mode 100644 vignettes/AgriculturalIndicators.md diff --git a/vignettes/AgriculturalIndicators.md b/vignettes/AgriculturalIndicators.md new file mode 100644 index 0000000..c8d52b2 --- /dev/null +++ b/vignettes/AgriculturalIndicators.md @@ -0,0 +1,595 @@ +--- +title: "Agricultural Indicators" +author: "Earth Sciences department, Barcelona Supercomputing Center (BSC)" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteEngine{knitr::knitr} + %\VignetteIndexEntry{Agricultural Indicators} + %\usepackage[utf8]{inputenc} +--- + +Agricultural Indicators +----------------------------- + + +## Introduction + +Apart from forecasts of Essential Climate Variables, Climate Services also provide a variety of the sectoral indicators that are often required for Climate Services people, including researchers, decision-makers, farmers, etc. + +In the MEDGOLD project, 10 indicators which were identified as critical indices for the three agricultural sectors - grape/wine, olive/olive oil and wheat/pasta - have been considered in this CSIndicators package. + +The computing functions and the corresponding indicators are listed as follows: + +1. **PeriodAccumulation -** Spring Total Precipitation (SprR) and Harvest Total Precipitation (HarvestR) +2. **PeriodMean -** Growing Season Temperature (GST) and Spring Mean Temperature Maximum (SPRTX) +3. **TotalTimeExceedingThreshold -** Number of Heat Stress Days - 35°C (SU35), 36°C (SU36), 40°C (SU40) and Spring Heat Stress Days - 32°C (Spr32) +4. **AccumulationExceedingThreshold -** Growing Degree Days (GDD) +5. **TotalSpellTimeExceedingThreshold -** Warm Spell Duration Index (WSDI) + +The above functions can take both multidimensional arrays and the s2dv_cube objects (see note below). Taking PeriodAccumulation as example, **CST_**PeriodAccumulation handles the latter and PeriodAccumulation without the prefix can compute multidimensional arrays. + +*Note: s2dv_cube and array classes can be handled by the functions in CSIndicators. See Section 2 in vignette [Data retrieval and storage](https://cran.r-project.org/package=CSTools/vignettes/Data_Considerations.html) from CSTools package for more information.* + +There are some supplementary functions which must be called to smoothly run the above functions. + +1. **SelectPeriodOnData -** to select the data in the requested period +2. **SelectPeriodOnDates -** to select the time dimension in the requested period +3. **Threshold -** to convert absolute value/variable to its percentile, e.g., Warm Spell Duration Index uses the 90th percentile corresponding to each day instead of a fixed threshold. See how this function is applied in Section 5. + +When the period selection is required, the `start` and `end` parameters have to be provided to cut out the portion in `time_dim`. Otherwise, the function will take the **entire** `time_dim`. + +The examples of computing the aforementioned indicators are given by functions as follows. + +### 1. PeriodAccumulation + +`PeriodAccumulation` (and `CST_PeriodAccumulation`) computes the sum of a given variable in a period. + +Here, two indicators are used to show how this function works: Spring Total Precipitation (SprR) and Harvest Total Precipitation (HarvestR). Both indices represent the total precipitation but in different periods, 21st April - 21st June for SprR and 21st August - 21st October for HarvestR. + +First, load the required libraries, CSIndicators, CSTools, etc by running + +``` +library(CSIndicators) +library(CSTools) +library(zeallot) +library(s2dv) +``` + +To obtain the precipitation forecast and observation, we load the daily precipitation (**prlr** given in `var`) data sets of ECMWF SEAS5 seasonal forecast and ERA5 reanalysis for the four starting dates 20130401-20160401 (provided in `sdates`) with the entire 7-month forecast time, April-October (214 days in total given in parameter `leadtimemax`). + +The pathways of SEAS5 and ERA5 are given in the lists with some **whitecards (inside two dollar signs)** used to replace the variable name and iterative items such as year and month. See details of requirements in Section 4 in vignette [Data retrieval and storage](https://cran.r-project.org/package=CSTools/vignettes/Data_Considerations.html) from CSTools package. + +The spatial domain covers part of Douro Valley of Northern Portugal lon=[352.25, 353], lat=[41, 41.75]. These four values are provided in `lonmin`, `lonmax`, `latmin` and `latmax`. + +With `grid` set to **r1440x721**, the SEAS5 forecast would be interpolated to the 0.25-degree ERA5 grid by using the **bicubic** method given in `method`. + + +``` +S5path_prlr <- list(path = '/esarchive/exp/ecmwf/system5c3s/original_files/chou/daily_mean/$VAR_NAME$_s0-24h/$VAR_NAME$_$YEAR$$MONTH$01.nc') + +path_ERA5prlr_CDS <- list(path = '/esarchive/recon/ecmwf/era5/daily_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') + +sdates <- paste0(2013:2016, '04', '01') + +c(prlr_exp, prlr_obs) %<-% CST_Load(var = 'prlr', + exp = list(S5path_prlr), + obs = list(path_ERA5prlr_CDS), + sdates = sdates, + lonmax = 353, lonmin = 352.25, + latmax = 41.75, latmin = 41, + storefreq = 'daily', + leadtimemin = 1, leadtimemax = 214, + nmember = 3, output = "lonlat", + grid = "r1440x721", method = 'bicubic') +``` + + +The output contains data and metadata for the experiment and the observations. The elements `prlr_exp$data` and `prlr_obs$data` have dimensions: + + +``` +dim(prlr_exp$data) +#dataset member sdate ftime lat lon +# 1 3 4 214 4 4 +dim(prlr_obs$data) +#dataset member sdate ftime lat lon +# 1 1 4 214 4 4 +``` + + +To compute **SprR** of forecast and observation, we can run: + + +``` +SprR_exp <- CST_PeriodAccumulation(prlr_exp, start = list(21, 4), end = list(21, 6)) +SprR_obs <- CST_PeriodAccumulation(prlr_obs, start = list(21, 4), end = list(21, 6)) +``` + +The `start` and `end` are the initial and final dates and the day must be given before the month as above. They will be applied along the dimension `time_dim` (it is set to 'ftime' by default). + +As mentioned, these parameters are optional, the function will take the entire timeseries when the period is not specified in `start` and `end`. + +The dimensions of SprR forecasts and observations are: + +``` +dim(SprR_exp$data) +#dataset member sdate lat lon +# 1 3 4 4 4 +dim(SprR_obs$data) +#dataset member sdate lat lon +# 1 1 4 4 4 +``` + +The forecast SprR for the 1st member from 2013-2016 of the 1st grid point in mm are: + +``` +SprR_exp$data[1,1,,1,1] * 86400 * 1000 +#[1] 93.23205 230.41904 194.01412 226.52614 +``` + +Dry springs will delay vegetative growth and reduce vigour and leaf area total surface. Fungal disease pressure will be lower and therefore there will be less need for protective and / or curative treatments, translating as less costs. Wet springs will promote higher vigour, increase the risk of fungal disease and disrupt vineyard operations as it may prevent machinery from getting in the vineyard due to mud. They are usually associated with higher costs. + +On the other hand, another moisture-related indicators, **HarvestR**, can be computed by using `PeriodAccumulation` as well, with the defined period as the following lines. + +``` +HarvestR_exp <- CST_PeriodAccumulation(prlr_exp, start = list(21, 8), end = list(21, 10)) +HarvestR_obs <- CST_PeriodAccumulation(prlr_obs, start = list(21, 8), end = list(21, 10)) +``` + +The forecast HarvestR for the 1st member from 2013-2016 of the 1st grid point in mm are: + +``` +HarvestR_exp$data[1,1,,1,1] * 86400 * 1000 +#[1] 52.30026 42.88068 156.87961 32.18579 +``` + +To compute the 2013-2016 ensemble-mean bias of forecast HarvestR, run + +``` +fcst <- drop(HarvestR_exp$data) * 86400 * 1000 +obs <- drop(HarvestR_obs$data) * 86400 * 1000 + +Bias <- MeanDims((fcst - InsertDim(obs, 1, dim(fcst)['member'])), 'member') +``` + +To plot the map of ensemble-mean bias of HarvestR forecast, run + +``` +cols <- c('#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#d1e5f0', + '#92c5de', '#4393c3', '#2166ac') + +PlotEquiMap(Bias[1,,], lon = prlr_obs$lon, lat = prlr_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'mm', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, col_inf = cols[1], + margin_scale = c(1, 1, 1, 1), cols = cols[2:7], col_sup = cols[8], + brks = seq(-60, 60, 20), colNA = 'white', + toptitle = 'Ensemble-mean bias of HarvestR in 2013', + bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) +``` +You will see the following maps of HarvestR bias in 2013. + +![](.figures/HarvestR_Bias_2013-1.png) + +In 2013, the ensemble-mean SEAS5 seasonal forecast of HarvestR is underestimated by up to 60 mm over Douro Valley region (the central four grid points). + + +### 2. PeriodMean + +For the function `PeriodMean`, we use Growing Season Temperature (**GST**) as an example. GST is defined as the average of daily average temperatures between April 1st to October 31st in the Northern Hemisphere. It provides information onto which are the best suited varieties for a given site or, inversely, which are the best places to grow a specific variety. For existing vineyards, GST also informs on the suitability of its varieties for the climate of specific years, explaining quality and production variation. Many grapevine varieties across the world have been characterized in function of their GST optimum. + +Firstly, we prepare a sample data of daily mean temperature of SEAS5 and ERA5 data sets with the same starting dates, spatial domain, interpolation grid and method by running + +``` +S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/daily_mean/$VAR_NAME$_f6h/$VAR_NAME$_$YEAR$$MONTH$01.nc') +ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/daily_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') + +c(tas_exp, tas_obs) %<-% CST_Load(var = 'tas', exp = list(S5path), obs = list(ERA5path), + sdates = sdates, lonmax = 353, lonmin = 352.25, + latmax = 41.75, latmin = 41, + storefreq = 'daily', + leadtimemin = 1, leadtimemax = 214, + nmember = 3, output = "lonlat", + grid = "r1440x721", method = 'bicubic') +``` + +The output contains observations `tas_dv$obs$data` and forecast `tas_dv$exp$data`, and their dimensions and summaries are like + +``` +dim(tas_obs$data) +#dataset member sdate ftime lat lon +# 1 1 4 214 4 4 + +dim(tas_exp$data) +#dataset member sdate ftime lat lon +# 1 3 4 214 4 4 + +summary(tas_obs$data - 273.15) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 3.63 14.38 17.89 17.65 21.24 30.21 + +summary(tas_exp$data - 273.15) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 0.54 11.65 16.56 16.50 21.25 31.41 + +``` +To compute the GST for both observation and forecast, run the following lines + +``` +# change the unit of temperature from °C to K + +tas_exp$data <- tas_exp$data - 273.15 +tas_obs$data <- tas_obs$data - 273.15 + +# compute GST + +GST_exp <- CST_PeriodMean(tas_exp, start = list(1, 4), end = list(31, 10)) +GST_obs <- CST_PeriodMean(tas_obs, start = list(1, 4), end = list(31, 10)) + +``` + +Since the period considered for GST is the entire period for starting month of April, in this case the `start` and `end` parameters could be ignored. + +The summaries and dimensions of the output are as follows: + +``` +summary(GST_exp$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 14.23 15.78 16.50 16.50 17.17 18.70 + +summary(GST_obs$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 15.34 16.85 17.72 17.65 18.41 19.60 + +dim(GST_exp$data) +#dataset member sdate lat lon +# 1 3 4 4 4 + +dim(GST_obs$data) +#dataset member sdate lat lon +# 1 1 4 4 4 +``` + +Here, we plot the 2013-2016 mean climatology of ERA5 GST by running + +``` +# compute ERA5 GST climatology +GST_Clim <- MeanDims(drop(GST_obs$data), 'sdate') + +cols <- c('#ffffd4','#fee391','#fec44f','#fe9929','#ec7014','#cc4c02','#8c2d04') +PlotEquiMap(GST_Clim, lon = tas_obs$lon, lat = tas_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = '°C', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, col_inf = cols[1], + margin_scale = c(1, 1, 1, 1), cols = cols[2:6], col_sup = cols[7], + brks = seq(16, 18.5, 0.5), colNA = 'white', bar_label_scale = 1.5, + toptitle = '2013-2016 mean ERA5 GST', + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) +``` + +The ERA5 GST climatology is shown as below. + +![](./figures/GST_ERA5_Climatology-1.png) + +ERA5 GST ranges from 17-18.5°C over the Douro Valley region for the period from 2013-2016 as shown in the figure. + + +### 3. TotalTimeExceedingThreshold + +For the function `TotalTimeExceedingThreshold`, **SU35** (Number of Heat Stress Days - 35°C) is taken as an example here. 35°C is the average established threshold for photosynthesis to occur in the grapevine. Above this temperature, the plant closes its stomata. If this situation occurs after veraison, maturation will be arrested for as long as the situation holds, decreasing sugar, polyphenol and aroma precursor levels, all essential for grape and wine quality. The higher the index, the lower will be the berry quality and aptitude to produce quality grapes. + +SU35 is defined as the Total count of days when daily maximum temperatures exceed 35°C in the seven months into the future. There are three indicators sharing the similar definition as SU35: SU36, SU40 and Spr32. Their definition are listed as follows. + +1. **SU36**: Total count of days when daily maximum temperatures exceed 36°C between June 21st and September 21st +2. **SU40**: Total count of days when daily maximum temperatures exceed 40°C between June 21st and September 21st +3. **Spr32**: Total count of days when daily maximum temperatures exceed 32°C between April 21st and June 21st + +These indicators can be computed as well by using the function `TotalTimeExceedingThreshold` with different thresholds and periods indicated. + +Here, we take SU35 as example, therefore the daily temperature maximum of the entire 7-month forecast period is needed for the computation of this indicator. + +Load SEAS5 and ERA5 daily temperature maximum by running + +``` +S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/daily/$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$01.nc') +ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/daily/$VAR_NAME$-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') + +c(tasmax_exp, tasmax_obs) %<-% CST_Load(var = 'tasmax', exp = list(S5path), + obs = list(ERA5path), sdates = sdates, + lonmax = 353, lonmin = 352.25, + latmax = 41.75, latmin = 41, storefreq = 'daily', + leadtimemin = 1, leadtimemax = 214, nmember = 3, + output = "lonlat", grid = "r1440x721", + method = 'bicubic', nprocs = 1) +``` + +Check the unit of temperature to from °C to K for the comparison with the threshold defined (for example 35°C here). + +``` +tasmax_exp$data <- tasmax_exp$data - 273.15 +tasmax_obs$data <- tasmax_obs$data - 273.15 +``` + +Computing SU35 for forecast and observation by running + +``` +threshold <- 35 +SU35_exp <- CST_TotalTimeExceedingThreshold(tasmax_exp, threshold = threshold, + start = list(1, 4), end = list(31, 10)) +SU35_obs <- CST_TotalTimeExceedingThreshold(tasmax_obs, threshold = threshold, + start = list(1, 4), end = list(31, 10)) +``` + +The summaries of SU35 forecasts and observations are given below. + +``` +summary(SU35_exp$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 0.00 2.00 5.00 7.12 12.00 26.00 + +summary(SU35_obs$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 0.000 0.000 1.000 2.609 5.000 10.000 + +``` +As shown in the summaries, SEAS5 SU35 forecasts are overestimated by 5 days in terms of mean value. + +Therefore, `CST_BiasCorrection` is used to bias adjust the SU35 forecasts. + +``` +res <- CST_BiasCorrection(obs = SU35_obs, exp = SU35_exp) +SU35_exp_BC <- drop(res$data) +summary(SU35_exp_BC) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# -1.419 0.000 1.613 2.831 4.756 17.768 +``` + +Since there are negative values after bias adjustment, all negative data is converted to zero. + +``` +SU35_exp_BC[SU35_exp_BC < 0] <- 0 +summary(SU35_exp_BC) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 0.000 0.000 1.613 2.943 4.756 17.768 +``` + +Plot the bias-adjusted SU35 forecast in 2016 by running + +``` +SU35_obs_Y2016 <- drop(SU35_obs$data)[4, , ] +SU35_exp_Y2016 <- MeanDims(drop(SU35_exp$data)[, 4, , ], 'member') +SU35_exp_BC_Y2016 <- MeanDims(SU35_exp_BC[, 4, , ], 'member') +cols <- c("#fee5d9", "#fcae91", "#fb6a4a", "#de2d26","#a50f15") + +toptitle <- 'ERA5 SU35 forecast in 2016' +PlotEquiMap(SU35_obs_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'day', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), + cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), + toptitle = toptitle, + colNA = cols[1], bar_label_scale = 1.5, + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) + +toptitle <- 'SU35 forecast in 2016' +PlotEquiMap(SU35_exp_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'day', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), + cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), + toptitle = toptitle, + colNA = cols[1], bar_label_scale = 1.5, + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) + +toptitle <- 'Bias-adjusted SU35 forecast in 2016' +PlotEquiMap(SU35_exp_BC_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'day', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), + cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), + toptitle = toptitle, + colNA = cols[1], bar_label_scale = 1.5, + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) +``` +You can see the figure as below. + + +![](./figures/SU35_ERA5_Y2016-1.png) +![](./figures/SU35_SEAS5_Y2016-1.png) +![](./figures/SU35_SEAS5_BC_Y2016-1.png) + +As seen above, the bias-adjusted SU35 forecasts are much closer to the ERA5 results, although differences remain. + +Beside of the original definition of SU35, here two supplementary functions in the package `CSIndicators` are demonstrated by computing its another definition with the percentile adjustment. + +--- +1. **AbsToProbs -**: to transform ensemble forecast into probabilities by using the Cumulative Distribution Function +2. **QThreshold -**: to transform an absolute threshold into probabilities. +--- + +The above two supplementary functions are required to compute SU35 with the percentile adjustment. The function `AbsToProbs` would be applied to forecast and the `QThreshold` would be used to convert the observations to its percentile based on the given threshold. + +The revised definition of SU35 is to reduce the potential influence induced by the fixed threshold of temperature defined for the index, instead of using the absolute value, the percentile corresponding to 35°C for observation is compared to the percentile corresponding to the predicted daily maximum temperature before being considered as a ‘heat stress’ day. + +As mentioned, the forecast is translated to its percentile by using the function `ABsToProbs` by running + +``` +exp_percentile <- AbsToProbs(tasmax_exp$data) +S5txP <- aperm(drop(exp_percentile), c(2, 1, 3, 4, 5)) +``` + +After that, based on 35 of threshold, the percentile corresponding to each observational value can be calculated as follows. + +``` +obs_percentile <- QThreshold(tasmax_obs$data, threshold = 35) +obs_percentile <- drop(obs_percentile) +``` + +After translating both forecasts and observations into probabilities, the comparison can then be done by running + +``` +SU35_exp_Percentile <- TotalTimeExceedingThreshold(S5txP, threshold = obs_percentile, time_dim = 'ftime') +``` + +Compute the same ensemble-mean SU35 **with percentile adjustment** in 2016 by running + +``` +SU35_exp_per_Y2016 <- MeanDims(SU35_exp_Percentile[, 4, , ], 'member') +``` + +Plot the same map for comparison + +``` +toptitle <- 'SU35 forecast with percentile adjustment in 2016' +PlotEquiMap(SU35_exp_per_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'day', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), + cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), + toptitle = toptitle, + colNA = cols[1], bar_label_scale = 1.5, + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) + +``` + + +![](./figures/SU35_Percentile_SEAS5_Y2016-1.png) + +As seen in the figure above, applying the percentile adjustment seems to implicitly adjust certain extent of bias which was observed in the non-bias-adjusted SEAS5 forecast. + +The performance of comparison of skills between two definitions requires further analysis such as the application of more skill metrics. + +### 4. AccumulationExceedingThreshold + +The function ´AccumulationExceedingThreshold´ can compute GDD (Growing Degree Days). + +The definition of GDD is the summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st. Here, the tas (daily average temperature) used above (in Section 2. PeriodMean) is loaded again (Please re-use the section of loading tas in Section 2). As per the definition, `threshold` is set to 10 with `diff` set to TRUE so that the function will compute the differences between daily temperature and the threshold given before calculating summation. + +*Note: The data is in degrees Celsiusi at this point* + +``` +GDD_exp <- CST_AccumulationExceedingThreshold(tas_exp, threshold = 10, diff = TRUE) +GDD_obs <- CST_AccumulationExceedingThreshold(tas_obs, threshold = 10, diff = TRUE) +``` + +The summaries of GDD are + +``` +summary(GDD_exp$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 1021 1331 1480 1469 1596 1873 + +summary(GDD_obs$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 1195 1504 1687 1660 1804 2055 +``` + +To compute the correlation coefficient for the period from 2013-2016, run the following lines + +``` +# reorder the dimension +fcst <- Reorder(drop(GDD_exp$data), c(4, 3, 2, 1)) +obs <- Reorder(drop(GDD_obs$data), c(3, 2, 1)) + +EnsCorr <- veriApply('EnsCorr', fcst = fcst, obs = obs, ensdim = 4, tdim = 3) +GDD_Corr <- Reorder(EnsCorr, c(2, 1)) +``` + +To plot the map of correlation coefficient of GDD for the 2013-2016 period. + +``` +cols <- c("#f7fcf5", "#e5f5e0", "#c7e9c0", "#a1d99b", "#74c476") +toptitle <- '2013-2016 correlation coefficient of GDD' +PlotEquiMap(GDD_Corr, lon = tas_obs$lon, lat = tas_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'correlation', + title_scale = .8, axes_label_scale = 1, axes_tick_scale = 1, + margin_scale = c(1, 1, 1, 1), cols = cols, brks = seq(0.5, 1, 0.1), + toptitle = toptitle, bar_label_scale = 1.5, + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) +``` + +The map of correlation coefficient for the 2013-2016 period is shown as below. + +![](./figures/GDD_SEAS5_Corr_Y13-16-1.png) + +The 2013-2016 correlation coefficients of the SEAS5 forecasts of GDD in reference with ERA5 reanalysis over Douro Valley range between 0.6 and 0.8. + +### 5. TotalSpellTimeExceedingThreshold + +One of the critical agricultural indicators related to dry spell is the **Warm Spell Duration Index (WSDI)**, which is defined as the total count of days with at least 6 consecutive days when the daily maximum temperature exceeds its 90th percentile in the seven months into the future. + +The maximum temperature data used in Section 3. Since the daily maximum temperature needs to compare to its 90th percentile, the function `Threshold` in the `CSIndicators` package is required to compute the percentile of observations used for each day. Here the same period (2013-2016) is considered. + +``` +tx_p <- CST_Threshold(tasmax_obs, threshold = 0.9) +``` + +The output will be the 90th percentile of each day of each grid point derived by using all the years in the data.See the dimension and summary as below. + +``` +dim(tx_p$data) +#dataset ftime lat lon +# 1 214 4 4 + +summary(tx_p$data) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 287.0 295.2 299.2 299.4 303.9 309.9 +``` + +With the prepared threshold (90th percentile), the WSDI can be computed by running + +``` +WSDI_exp <- CST_TotalSpellTimeExceedingThreshold(tasmax_exp, threshold = tx_p, spell = 6) +WSDI_obs <- CST_TotalSpellTimeExceedingThreshold(tasmax_obs, threshold = tx_p, spell = 6) +``` + +After checking the summaries, compute the Fair Ranked Probability Skill Score (FRPSS) of WSDI by running the following lines + +``` +# Reorder the data +fcst <- Reorder(drop(WSDI_exp$data), c(4, 3, 2, 1)) +obs <- Reorder(drop(WSDI_obs$data), c(3, 2, 1)) + +# summaries of WSDI +summary(fcst) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 0.00 13.00 28.00 30.65 42.25 82.00 + +summary(obs) +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 9.00 19.00 22.50 22.91 25.25 33.00 + +# compute FRPSS +f <- veriApply('FairRpss', fcst = fcst, obs = obs, ensdim = 4, tdim = 3, prob = 1:2/3)$skillscore +WSDI_FRPSS <- Reorder(f, c(2,1)) +``` + +Plot the map of WSDI FRPSS for the period from 2013-2016 + +``` +cols <- c("#edf8fb", "#ccece6", "#99d8c9", "#66c2a4") +toptitle <- 'SEAS5 WSDI FRPSS (2013-2016)' + +PlotEquiMap(WSDI_FRPSS, lon = tasmax_obs$lon, lat = tasmax_obs$lat, + intylat = 1, intxlon = 1, width = 6, height = 6, + filled.continents = FALSE, units = 'FRPSS', title_scale = .8, + axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), + cols = cols[1:3], col_inf = 'white', col_sup = cols[4], + brks = seq(0, 0.9, 0.3), toptitle = toptitle, bar_label_scale = 1.5, + bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) +``` + +The FRPSS map for 2013-2016 SEAS WSDI is shown as below. + +![](./figures/WSDI_SEAS5_FRPSS_Y13-16-1.png) + +As seen in the map, the FRPSS in the eastern part of Douro Valley falls in 0.6-0.9, which are good enough to be useful when compared to observational climatology. + + +In addition to the grape/wine sector focused here, the MEDGOLD project also works on the other two sectors: olive/olive oil and durum wheat/pasta. Furthermore, the climate services are also provided at the longer term (up to 30 years) by other project partners. + +Click on [MEDGOLD](https://www.med-gold.eu/climate-services/) for more information. + + -- GitLab From 01d04a5fbae79e1df00d435abb930a17d00b39b2 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 11 May 2021 09:20:41 +0200 Subject: [PATCH 06/26] buildignore vignette md --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index 1ed837b..e8159e2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,4 @@ #^tests$ ./.nfs* ^cran-comments\.md$ +./vignettes/*.md -- GitLab From e504ff7d0c0b5dac0527930879270d641a944f31 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 1 Jun 2021 10:21:27 +0200 Subject: [PATCH 07/26] Fix SelectPeriodOnData and test MergeRefToExp --- R/SelectPeriodOnData.R | 5 ++++ tests/testthat/test-MergeRefToExp.R | 40 +++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index a6f9c29..85b7ff3 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -121,6 +121,11 @@ SelectPeriodOnData <- function(data, dates, start, end, res <- Apply(list(data, res), target_dims = time_dim, fun = function(x, y) { res <- x[y] + if (is.null(dim(res))) { + dim(res) <- 1 + names(dim(res)) <- time_dim + } + return(res) }, output_dims = time_dim, ncores = ncores)$output1 } return(res) diff --git a/tests/testthat/test-MergeRefToExp.R b/tests/testthat/test-MergeRefToExp.R index a74df90..aed1964 100644 --- a/tests/testthat/test-MergeRefToExp.R +++ b/tests/testthat/test-MergeRefToExp.R @@ -11,7 +11,7 @@ test_that("Sanity checks", { as.Date("01-12-1994", "%d-%m-%Y", tz = 'UTC'), "day") dim(ref_dates) <- c(ftime = 350, sdate = 2) ref <- array(1001:1700, c(ftime = 350, sdate = 2)) - data <- array(1:(2*154*2), c(ftime = 154, sdate = 2, member= 2)) + data <- array(1:(2 * 154 * 2), c(ftime = 154, sdate = 2, member= 2)) ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = ref_dates, end = ref_dates)) data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, @@ -29,7 +29,43 @@ test_that("Sanity checks", { end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9))$data, output) - }) + + # issue 13: One lead time + data_dates <- c(as.Date("01-06-1993", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-07-1993", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-06-1994", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-07-1994","%d-%m-%Y", tz = 'UTC')) + + dim(data_dates) <- c(ftime = 2, sdate = 2) + ref_dates <- c(as.Date("01-05-1993", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-05-1994", "%d-%m-%Y", tz = 'UTC')) + dim(ref_dates) <- c(ftime = 1, sdate = 2) + ref <- array(1:2, c(ftime = 1, sdate = 2)) + data <- array(1:(2 * 3 * 2), c(ftime = 2, sdate = 2, member = 3)) + ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = ref_dates, + end = ref_dates)) + data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, + end = data_dates)) + res_dates <- c(as.Date("01-05-1993", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-06-1993", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-07-1993", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-05-1994", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-06-1994", "%d-%m-%Y", tz = 'UTC'), + as.Date("01-07-1994","%d-%m-%Y", tz = 'UTC')) + dim(res_dates) <- c(ftime = 3, sdate = 2) + expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(1, 5), + end1 = list(31, 5), start2 = list(1, 6), + end2 = list(31, 7))$Dates, + res_dates) + output <- abind::abind(t(matrix(rep(1:2, 3), ncol = 2, nrow = 3, byrow = T)), + data$data, along = 1) + names(dim(output)) <- c('ftime', 'sdate', 'member') + expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(1, 5), + end1 = list(31, 5), start2 = list(1, 6), + end2 = list(31, 7))$data, + output) + +}) test_that("Seasonal", { -- GitLab From c5a2dd1bfd04caa9bb14ed83521d22d9a487c0a5 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 10 Jun 2022 16:22:33 +0200 Subject: [PATCH 08/26] Correct path of the experimental dataset. --- vignettes/AgriculturalIndicators.Rmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vignettes/AgriculturalIndicators.Rmd b/vignettes/AgriculturalIndicators.Rmd index 3d9300d..b155d3d 100644 --- a/vignettes/AgriculturalIndicators.Rmd +++ b/vignettes/AgriculturalIndicators.Rmd @@ -66,9 +66,9 @@ With `grid` set to **r1440x721**, the SEAS5 forecast would be interpolated to th ``` -S5path_prlr <- list(path = '/esarchive/exp/ecmwf/system5c3s/original_files/chou/daily_mean/$VAR_NAME$_s0-24h/$VAR_NAME$_$YEAR$$MONTH$01.nc') +S5path_prlr <- list(path = '/esarchive/exp/ecmwf/system5c3s/$STORE_FREQ$_mean/$VAR_NAME$_s0-24h/$VAR_NAME$_$START_DATE$.nc') -path_ERA5prlr_CDS <- list(path = '/esarchive/recon/ecmwf/era5/daily_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') +path_ERA5prlr_CDS <- list(path = '/esarchive/recon/ecmwf/era5/$STORE_FREQ$_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') sdates <- paste0(2013:2016, '04', '01') @@ -182,8 +182,8 @@ For the function `PeriodMean`, we use Growing Season Temperature (**GST**) as an Firstly, we prepare a sample data of daily mean temperature of SEAS5 and ERA5 data sets with the same starting dates, spatial domain, interpolation grid and method by running ``` -S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/daily_mean/$VAR_NAME$_f6h/$VAR_NAME$_$YEAR$$MONTH$01.nc') -ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/daily_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') +S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/$STORE_FREQ$_mean/$VAR_NAME$_f6h/$VAR_NAME$_$YEAR$$MONTH$01.nc') +ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/$STORE_FREQ$_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') c(tas_exp, tas_obs) %<-% CST_Load(var = 'tas', exp = list(S5path), obs = list(ERA5path), sdates = sdates, lonmax = 353, lonmin = 352.25, @@ -292,8 +292,8 @@ Here, we take SU35 as example, therefore the daily temperature maximum of the en Load SEAS5 and ERA5 daily temperature maximum by running ``` -S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/daily/$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$01.nc') -ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/daily/$VAR_NAME$-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') +S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/$STORE_FREQ$/$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$01.nc') +ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/$STORE_FREQ$/$VAR_NAME$-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') c(tasmax_exp, tasmax_obs) %<-% CST_Load(var = 'tasmax', exp = list(S5path), obs = list(ERA5path), sdates = sdates, -- GitLab From b79a3c96e9145ccbb0111c5335f9bee69c381557 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Tue, 14 Jun 2022 12:45:34 +0200 Subject: [PATCH 09/26] Parameter ncores deleted in InsertDim --- R/MergeRefToExp.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 365ceb5..155dee3 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -171,7 +171,7 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, en if (length(dif_dims) > 0) { for (i in dif_dims) { data1 <- s2dv::InsertDim(data1, posdim = i, lendim = dim(data2)[i], - name = names(dim(data2))[i], ncores = ncores) + name = names(dim(data2))[i]) } } } @@ -181,7 +181,7 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, en if (length(dif_dims) > 0) { for (i in dif_dims) { data2 <- s2dv::InsertDim(data2, posdim = i, lendim = dim(data1)[i], - name = names(dim(data1))[i], ncores = ncores) + name = names(dim(data1))[i]) } } } -- GitLab From 6c928c5cb9c334207ca8896a98108cd78156613a Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Thu, 16 Jun 2022 13:07:04 +0200 Subject: [PATCH 10/26] Update with correct results and images --- vignettes/AgriculturalIndicators.Rmd | 26 +++++++++--------- vignettes/figures/GDD_SEAS5_Corr_Y13-16-1.png | Bin 9961 -> 16049 bytes vignettes/figures/GST_ERA5_Climatology-1.png | Bin 8885 -> 14335 bytes 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/vignettes/AgriculturalIndicators.Rmd b/vignettes/AgriculturalIndicators.Rmd index b155d3d..50df881 100644 --- a/vignettes/AgriculturalIndicators.Rmd +++ b/vignettes/AgriculturalIndicators.Rmd @@ -206,8 +206,8 @@ dim(tas_exp$data) # 1 3 4 214 4 4 summary(tas_obs$data - 273.15) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 3.63 14.38 17.89 17.65 21.24 30.21 +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 3.63 13.97 17.25 17.29 20.75 30.21 summary(tas_exp$data - 273.15) # Min. 1st Qu. Median Mean 3rd Qu. Max. @@ -235,12 +235,12 @@ The summaries and dimensions of the output are as follows: ``` summary(GST_exp$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. +# Min. 1st Qu. Median Mean 3rd Qu. Max. # 14.23 15.78 16.50 16.50 17.17 18.70 summary(GST_obs$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 15.34 16.85 17.72 17.65 18.41 19.60 +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 15.34 16.77 17.22 17.29 18.00 18.75 dim(GST_exp$data) #dataset member sdate lat lon @@ -482,7 +482,7 @@ summary(GDD_exp$data) summary(GDD_obs$data) # Min. 1st Qu. Median Mean 3rd Qu. Max. -# 1195 1504 1687 1660 1804 2055 +# 1195 1483 1569 1583 1730 1874 ``` To compute the correlation coefficient for the period from 2013-2016, run the following lines @@ -534,8 +534,8 @@ dim(tx_p$data) # 1 214 4 4 summary(tx_p$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 287.0 295.2 299.2 299.4 303.9 309.9 +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 13.83 22.08 26.08 26.22 30.72 36.72 ``` With the prepared threshold (90th percentile), the WSDI can be computed by running @@ -554,12 +554,12 @@ obs <- Reorder(drop(WSDI_obs$data), c(3, 2, 1)) # summaries of WSDI summary(fcst) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 0.00 13.00 28.00 30.65 42.25 82.00 - +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 0.00 13.00 28.00 31.22 46.00 82.00 + summary(obs) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 9.00 19.00 22.50 22.91 25.25 33.00 +# Min. 1st Qu. Median Mean 3rd Qu. Max. +# 9.00 19.00 22.50 23.16 26.00 33.00 # compute FRPSS f <- veriApply('FairRpss', fcst = fcst, obs = obs, ensdim = 4, tdim = 3, prob = 1:2/3)$skillscore diff --git a/vignettes/figures/GDD_SEAS5_Corr_Y13-16-1.png b/vignettes/figures/GDD_SEAS5_Corr_Y13-16-1.png index 43e291cfa9295e5011912f10b02326cdb4762795..5d05be945f1dc68da843d2b67436a05a23315cee 100644 GIT binary patch literal 16049 zcmeIZcTkjR+b7yaP!TX8f`I4%k`<5~6ck5LKynZe5y?u90*&vWO^Aat0G3 zAW3qToO90m>)BJ^cm6r2cB{@-ZSDEGYIx^mn(pVh@9VyaKsb2q z@5{;r!cI-nKjb^{oAbM=eDOc~tp3)rB@n0#NdN5kAeCTBAe!Vm^3#7aD~G1>buY_F?didM;msc}Ud-dG1BMl+<8tv(#XgkRbWo zEP)HzzZ;YCrt>^~PG?a3+Sn2fsF5f&xJNX2YOqlf<#DiQUcy*%SnONTaB>`fcr`9a zYqU!j*E4mQdMDwX?Ej)4(&Xue<&<6etk+-v>3lNXQ>w4K^7G}H$U>`trH%)s_EViA zTwK38I>dy9oob^b^(?lH~QP?yZ52><>}lD^1&QxcFn3O+S%@#YwYao z@}WH392_=%&v}fO1hllY0@)O&+Oy47RaNmu?Hr4?H2u;W;euL|5rKj8Q-#wx<}Ez9 zu$C4fQPBd$XvrK=^Tp{N{S(o@eqB#uNYyJAb(m=NXApbpO z+O2fg)_HUbf?mD4!%1f+sv9loh6_@+k@X$UNW>o`C`8&cKTjPpxRht!k~%YEmGrG8 z_d!p%&;v8EXi@vbYk{olVu}&M^);CjU4<>T&z+S>VJ%NoOOlq6k>^oQYYAYI>h4!B zw-Dsj%J^Pen>O&OzrQ~-GgH1)HmZvKQfs0br_sKqM74&To|jA|gF?1L*X=ba_R3gT zOkj6@-ODU%zJC4suLu#_Ur{HCIo-51cg+8q6n2`qt*RQ-RC^?a?t&TVo9}f09tfj8 z&B0OG*YK_Pgl@Icn+%R;U%!6c+FaK!u&WqrAB@)T1uulBua_t}a9CAzIp%Kb}+^0fvT#T{_nXt^2<3Tbvzh zN-DG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-- GitLab From 5a51593be55a372fc3bddfea82374db5d7127bd9 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 13 Jul 2022 16:06:17 +0200 Subject: [PATCH 11/26] Added warnings for NULL dates dimensions --- R/MergeRefToExp.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 365ceb5..a5cfc20 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -143,10 +143,14 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, en names(dim(data2)) <- time_dim } if (is.null(dim(dates1))) { + warning("Dimensions in 'dates1' element are missed and ", + "all data would be used.") dim(dates1) <- length(dates1) names(dim(dates1)) <- time_dim } if (is.null(dim(dates2))) { + warning("Dimensions in 'dates2' element are missed and ", + "all data would be used.") dim(dates2) <- length(dates2) names(dim(dates2)) <- time_dim } -- GitLab From 341bf54b3673f2467716b71e5ef59592f315ba6b Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 13 Jul 2022 16:07:43 +0200 Subject: [PATCH 12/26] Supressed warnings from test-MergeRefToExp --- tests/testthat/test-MergeRefToExp.R | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-MergeRefToExp.R b/tests/testthat/test-MergeRefToExp.R index aed1964..b4503d8 100644 --- a/tests/testthat/test-MergeRefToExp.R +++ b/tests/testthat/test-MergeRefToExp.R @@ -12,23 +12,31 @@ test_that("Sanity checks", { dim(ref_dates) <- c(ftime = 350, sdate = 2) ref <- array(1001:1700, c(ftime = 350, sdate = 2)) data <- array(1:(2 * 154 * 2), c(ftime = 154, sdate = 2, member= 2)) + +suppressWarnings( ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = ref_dates, end = ref_dates)) +) +suppressWarnings( data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, end = data_dates)) - +) +suppressWarnings( expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(21, 6), end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9))$Dates, SelectPeriodOnDates(ref_dates, start = list(21, 6), end = list(21,9))) +) output <- array(c(1172:1181, 1:83, 1537:1546, 155:237, 1172:1181, 309:391, 1537:1546, 463:545), c(ftime = 93, sdate = 2, member = 2)) +suppressWarnings( expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(21, 6), end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9))$data, output) +) # issue 13: One lead time data_dates <- c(as.Date("01-06-1993", "%d-%m-%Y", tz = 'UTC'), @@ -42,10 +50,15 @@ test_that("Sanity checks", { dim(ref_dates) <- c(ftime = 1, sdate = 2) ref <- array(1:2, c(ftime = 1, sdate = 2)) data <- array(1:(2 * 3 * 2), c(ftime = 2, sdate = 2, member = 3)) + +suppressWarnings( ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = ref_dates, end = ref_dates)) +) +suppressWarnings( data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, end = data_dates)) +) res_dates <- c(as.Date("01-05-1993", "%d-%m-%Y", tz = 'UTC'), as.Date("01-06-1993", "%d-%m-%Y", tz = 'UTC'), as.Date("01-07-1993", "%d-%m-%Y", tz = 'UTC'), @@ -53,17 +66,24 @@ test_that("Sanity checks", { as.Date("01-06-1994", "%d-%m-%Y", tz = 'UTC'), as.Date("01-07-1994","%d-%m-%Y", tz = 'UTC')) dim(res_dates) <- c(ftime = 3, sdate = 2) + +suppressWarnings( expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(1, 5), end1 = list(31, 5), start2 = list(1, 6), end2 = list(31, 7))$Dates, res_dates) +) + output <- abind::abind(t(matrix(rep(1:2, 3), ncol = 2, nrow = 3, byrow = T)), data$data, along = 1) names(dim(output)) <- c('ftime', 'sdate', 'member') + +suppressWarnings( expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(1, 5), end1 = list(31, 5), start2 = list(1, 6), end2 = list(31, 7))$data, output) +) }) @@ -85,22 +105,32 @@ test_that("Seasonal", { dim(dates) <- dim.dates ref <- array(1:(215*25), c(ftime = 215, sdate = 25)) + +suppressWarnings( ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = dates, end = dates)) +) data <- array(1:(215*25*3), c(ftime = 215, sdate = 25, member=3)) + +suppressWarnings( data <- CSTools::s2dv_cube(data = data, Dates = list(start = dates, end = dates)) +) +suppressWarnings( expect_equal(CST_MergeRefToExp(data1 = data, data2 = ref, start1 = list(21, 6), end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9))$Dates, SelectPeriodOnDates(dates, start = list(21, 6), end = list(21,9))) +) +suppressWarnings( expect_equal(CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(21, 6), end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9))$Dates, SelectPeriodOnDates(dates, start = list(21, 6), end = list(21,9))) +) }) -- GitLab From f35a19123d8ed68f8bc32ca67da21e0befb284c8 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Thu, 22 Sep 2022 18:28:48 +0200 Subject: [PATCH 13/26] Correct documentation and formatting --- DESCRIPTION | 2 +- R/QThreshold.R | 155 +++++++++++++++++++++++++++++------------- R/Threshold.R | 109 ++++++++++++++++++++--------- man/CST_QThreshold.Rd | 67 +++++++++++++----- man/CST_Threshold.Rd | 46 +++++++++---- man/QThreshold.Rd | 68 ++++++++++++------ man/Threshold.Rd | 49 +++++++++---- 7 files changed, 352 insertions(+), 144 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 28a2634..6dae74d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,4 +28,4 @@ License: Apache License 2.0 URL: https://earth.bsc.es/gitlab/es/csindicators/ BugReports: https://earth.bsc.es/gitlab/es/csindicators/-/issues Encoding: UTF-8 -RoxygenNote: 7.0.1 +RoxygenNote: 7.2.0 diff --git a/R/QThreshold.R b/R/QThreshold.R index 067c495..f0bb736 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -1,29 +1,55 @@ #'Transform an absolute threshold into probabilities #' -#'From a user perspective, an absolute threshold can be very useful for a specific needs (e.g.: grape variety). -#' However, this absolute threshold could be transform to a relative threshold in order to get its frequency in a given dataset. -#'Therefore, the function \code{QThreshold} returns the probability of an absolute threshold. -#'This is done by computing the Cumulative Distribution Function of a sample and leaving-one-ot. -#' The sample used will depend on the dimensions of the data provided and the dimension names provided in sdate_dim and memb_dim parameters: +#'From the user's perspective, an absolute threshold can be very useful for a +#'specific needs (e.g.: grape variety). However, this absolute threshold could +#'be transformed to a relative threshold in order to get its frequency in a given +#'dataset. Therefore, the function \code{QThreshold} returns the probability of +#'an absolute threshold. This is done by computing the Cumulative Distribution +#'Function of a sample and leaving one out. The sample used will depend on the +#'dimensions of the data provided and the dimension names provided in sdate_dim +#'and memb_dim parameters: +#' #'\itemize{ -#' \item{Wheter a forecast (hindcast) has dimensions member and start date, and both must be used in the sample, their names should be passed in sdate_dim and memb_dim.} -#' \item{Wheter a forecast (hindcast) has dimensions member and start date, and only start date must be used in the sample (the calculation is done in each separate member), memb_dim can be set to NULL.} -#' \item{Wheter a reference (observations) has start date dimension, the sample used is the start date dimension.} -#' \item{Wheter a reference (observations) doesn't have start date dimension, the sample used must be especified in sdate_dim parameter.}} +#' \item{If a forecast (hindcast) has dimensions member and start date, and +#' both must be used in the sample, their names should be passed in +#' sdate_dim and memb_dim.} +#' \item{If a forecast (hindcast) has dimensions member and start date, and +#' only start date must be used in the sample (the calculation is done in +#' each separate member), memb_dim can be set to NULL.} +#' \item{If a reference (observations) has start date dimension, the sample +#' used is the start date dimension.} +#' \item{If a reference (observations) doesn't have start date dimension, +#' the sample used must be especified in sdate_dim parameter.} +#'} #' -#'@param data an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param threshold an 's2dv_cube' object as output of a 'CST_' function in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. A single scalar is also possible. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param memb_dim a character string indicating the name of the dimension in which the ensemble members are stored. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param threshold An 's2dv_cube' object as output of a 'CST_' function in the +#' same units as parameter 'data' and with the common dimensions of the element +#' 'data' of the same length. A single scalar is also possible. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested +#' period. +#'@param memb_dim A character string indicating the name of the dimension in +#' which the ensemble members are stored. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the probabilites in the element \code{data}. -#' -#'@import multiApply -#'@importFrom ClimProjDiags Subset +#'@return An 's2dv_cube' object containing the probability of an absolute +#'threshold in the element \code{data}. #' #'@examples #'threshold <- 26 @@ -38,6 +64,9 @@ #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'exp_probs <- CST_QThreshold(exp, threshold, start = list(21, 4), end = list(21, 6)) +#' +#'@import multiApply +#'@importFrom ClimProjDiags Subset #'@export CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, time_dim = 'ftime', memb_dim = 'member', sdate_dim = 'sdate', @@ -77,36 +106,66 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, } #'Transform an absolute threshold into probabilities #' -#'From a user perspective, an absolute threshold can be very useful for a specific needs (e.g.: grape variety). -#' However, this absolute threshold could be transform to a relative threshold in order to get its frequency in a given dataset. -#'Therefore, the function \code{QThreshold} returns the probability of an absolute threshold. -#'This is done by computing the Cumulative Distribution Function of a sample and leaving-one-ot. -#' The sample used will depend on the dimensions of the data provided and the dimension names provided in sdate_dim and memb_dim parameters: +#'From the user's perspective, an absolute threshold can be very useful for a +#'specific needs (e.g.: grape variety). However, this absolute threshold could +#'be transformed to a relative threshold in order to get its frequency in a given +#'dataset. Therefore, the function \code{QThreshold} returns the probability of +#'an absolute threshold. This is done by computing the Cumulative Distribution +#'Function of a sample and leaving-one-ot. The sample used will depend on the +#'dimensions of the data provided and the dimension names provided in sdate_dim +#'and memb_dim parameters: #'\itemize{ -#' \item{Wheter a forecast (hindcast) has dimensions member and start date, and both must be used in the sample, their names should be passed in sdate_dim and memb_dim.} -#' \item{Wheter a forecast (hindcast) has dimensions member and start date, and only start date must be used in the sample (the calculation is done in each separate member), memb_dim can be set to NULL.} -#' \item{Wheter a reference (observations) has start date dimension, the sample used is the start date dimension.} -#' \item{Wheter a reference (observations) doesn't have start date dimension, the sample used must be especified in sdate_dim parameter.}} +#' \item{If a forecast (hindcast) has dimensions member and start date, and +#' both must be used in the sample, their names should be passed in +#' sdate_dim and memb_dim.} +#' \item{If a forecast (hindcast) has dimensions member and start date, and +#' only start date must be used in the sample (the calculation is done in +#' each separate member), memb_dim can be set to NULL.} +#' \item{If a reference (observations) has start date dimension, the sample +#' used is the start date dimension.} +#' \item{If a reference (observations) doesn't have start date dimension, +#' the sample used must be especified in sdate_dim parameter.} +#'} #' -#'@param data a multidimensional array with named dimensions. -#'@param threshold a multidimensional array with named dimensions in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param memb_dim a character string indicating the name of the dimension in which the ensemble members are stored. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param threshold A multidimensional array with named dimensions in the same +#' units as parameter 'data' and with the common dimensions of the element +#' 'data' of the same length. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested +#' period. +#'@param memb_dim A character string indicating the name of the dimension in +#' which the ensemble members are stored. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. +#'@return A multidimensional array with named dimensions containing the +#'probability of an absolute threshold in the element \code{data}. #' -#'@import multiApply -#'@importFrom ClimProjDiags Subset #'@examples #'threshold = 25 #'data <- array(rnorm(5 * 3 * 20 * 2, mean = 26), #' c(member = 5, sdate = 3, time = 20, lon = 2)) #'thres_q <- QThreshold(data, threshold) +#' +#'@import multiApply +#'@importFrom ClimProjDiags Subset #'@export QThreshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, time_dim = 'time', memb_dim = 'member', sdate_dim = 'sdate', @@ -154,10 +213,10 @@ QThreshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, if (!is.null(dim(dates)) && sdate_dim %in% dim(dates)) { dates_thres <- Subset(dates, along = sdate_dim, indices = 1) threshold <- SelectPeriodOnData(threshold, dates_thres, start, end, - time_dim = time_dim, ncores = ncores) + time_dim = time_dim, ncores = ncores) } else { - threshold <- SelectPeriodOnData(threshold, dates, start, end, - time_dim = time_dim, ncores = ncores) + threshold <- SelectPeriodOnData(threshold, dates, start, end, + time_dim = time_dim, ncores = ncores) } } } @@ -204,7 +263,7 @@ QThreshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, dims <- dim(data) # no 'member' involving qres <- unlist(lapply(1:dims, function(x) { - ecdf(data[-x])(threshold)})) + ecdf(data[-x])(threshold)})) dim(qres) <- c(dims) return(qres) } @@ -212,8 +271,8 @@ QThreshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, qres <- unlist( lapply(1:(dim(data)[1]), function(x) { # dim 1: member lapply(1:(dim(data)[2]), function(y) { # dim 2: sdate - ecdf(as.vector(data[,-y]))(threshold) - }) + ecdf(as.vector(data[,-y]))(threshold) + }) })) dim(qres) <- c(dim(data)[2], dim(data)[1]) return(qres) diff --git a/R/Threshold.R b/R/Threshold.R index c09ebe0..8112cf6 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -1,21 +1,40 @@ #'Absolute value of a relative threshold (percentile) #' -#'Frequently, thresholds are defined by a percentile that may correspond to a different absolute value depending on the variable, gridpoint and also julian day (time). -#' This function calculates the corresponding value of a percentile given a dataset. +#'Frequently, thresholds are defined by a percentile that may correspond to a +#'different absolute value depending on the variable, gridpoint and also julian +#'day (time). This function calculates the corresponding value of a percentile +#'given a dataset. #' -#'@param data an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param threshold a single scalar or vector indicating the relative threshold(s). -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param memb_dim a character string indicating the name of the dimension in which the ensemble members are stored. When set it to NULL, threshold is computed for individual members. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param threshold A single scalar or vector indicating the relative +#' threshold(s). +#'@param start An optional parameter to defined the initial date of the period +#' to selectfrom the data by providing a list of two elements: the initial date +#' of the period and the initial month of the period. By default it is set to +#' NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested +#' period. +#'@param memb_dim A character string indicating the name of the dimension in +#' which the ensemble members are stored. When set it to NULL, threshold is +#' computed for individual members. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the probabilites in the element \code{data}. -#' -#'@import multiApply +#'@return An ’s2dv_cube’ object containing the corresponding values of a +#'percentile in the element \code{data}. #' #'@examples #'threshold <- 0.9 @@ -30,6 +49,8 @@ #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'exp_probs <- CST_Threshold(exp, threshold, start = list(21, 4), end = list(21, 6)) +#' +#'@import multiApply #'@export CST_Threshold <- function(data, threshold, start = NULL, end = NULL, time_dim = 'ftime', memb_dim = 'member', sdate_dim = 'sdate', @@ -66,24 +87,43 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, } #'Absolute value of a relative threshold (percentile) #' -#'Frequently, thresholds are defined by a percentile that may correspond to a different absolute value depending on the variable, gridpoint and also julian day (time). -#' This function calculates the corresponding value of a percentile given a dataset. -#' -#'@param data a multidimensional array with named dimensions. -#'@param threshold a single scalar or vector indicating the relative threshold(s). -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param memb_dim a character string indicating the name of the dimension in which the ensemble members are stored. When set it to NULL, threshold is computed for individual members. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'Frequently, thresholds are defined by a percentile that may correspond to a +#' different absolute value depending on the variable, gridpoint and also julian +#' day (time). This function calculates the corresponding value of a percentile +#' given a dataset. #' -#'@return A multidimensional array with named dimensions. +#'@param data A multidimensional array with named dimensions. +#'@param threshold A single scalar or vector indicating the relative +#' threshold(s). +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested +#' period. +#'@param memb_dim A character string indicating the name of the dimension in +#' which the ensemble members are stored. When set it to NULL, threshold is +#' computed for individual members. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@import multiApply -#'@importFrom stats quantile +#'@return A multidimensional array with named dimensions containing the +#'corresponding values of a percentile in the element \code{data}. #' #'@examples #'threshold <- 0.9 @@ -92,6 +132,9 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, #'thres_q <- Threshold(data, threshold) #'data <- array(rnorm(1 * 3 * 214 * 2), c(member = 1, sdate = 3, time = 214, lon = 2)) #'res <- Threshold(data, threshold) +#' +#'@import multiApply +#'@importFrom stats quantile #'@export Threshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, time_dim = 'time', memb_dim = 'member', sdate_dim = 'sdate', @@ -133,11 +176,11 @@ Threshold <- function(data, threshold, dates = NULL, start = NULL, end = NULL, } if (length(threshold) == 1) { thres <- Apply(data, target_dims = dimensions, - fun = function(x) {quantile(as.vector(x), threshold, na.rm)})$output1 + fun = function(x) {quantile(as.vector(x), threshold, na.rm)})$output1 } else { thres <- Apply(data, target_dims = dimensions, - fun = function(x) {quantile(as.vector(x), threshold, na.rm)}, - output_dims = 'probs')$output1 + fun = function(x) {quantile(as.vector(x), threshold, na.rm)}, + output_dims = 'probs')$output1 } return(thres) } diff --git a/man/CST_QThreshold.Rd b/man/CST_QThreshold.Rd index 744724a..2843999 100644 --- a/man/CST_QThreshold.Rd +++ b/man/CST_QThreshold.Rd @@ -16,36 +16,66 @@ CST_QThreshold( ) } \arguments{ -\item{data}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{threshold}{an 's2dv_cube' object as output of a 'CST_' function in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. A single scalar is also possible.} +\item{threshold}{An 's2dv_cube' object as output of a 'CST_' function in the +same units as parameter 'data' and with the common dimensions of the element +'data' of the same length. A single scalar is also possible.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested +period.} -\item{memb_dim}{a character string indicating the name of the dimension in which the ensemble members are stored.} +\item{memb_dim}{A character string indicating the name of the dimension in +which the ensemble members are stored.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the probabilites in the element \code{data}. +An 's2dv_cube' object containing the probability of an absolute +threshold in the element \code{data}. } \description{ -From a user perspective, an absolute threshold can be very useful for a specific needs (e.g.: grape variety). -However, this absolute threshold could be transform to a relative threshold in order to get its frequency in a given dataset. -Therefore, the function \code{QThreshold} returns the probability of an absolute threshold. -This is done by computing the Cumulative Distribution Function of a sample and leaving-one-ot. -The sample used will depend on the dimensions of the data provided and the dimension names provided in sdate_dim and memb_dim parameters: +From the user's perspective, an absolute threshold can be very useful for a +specific needs (e.g.: grape variety). However, this absolute threshold could +be transformed to a relative threshold in order to get its frequency in a given +dataset. Therefore, the function \code{QThreshold} returns the probability of +an absolute threshold. This is done by computing the Cumulative Distribution +Function of a sample and leaving one out. The sample used will depend on the +dimensions of the data provided and the dimension names provided in sdate_dim +and memb_dim parameters: +} +\details{ \itemize{ - \item{Wheter a forecast (hindcast) has dimensions member and start date, and both must be used in the sample, their names should be passed in sdate_dim and memb_dim.} - \item{Wheter a forecast (hindcast) has dimensions member and start date, and only start date must be used in the sample (the calculation is done in each separate member), memb_dim can be set to NULL.} - \item{Wheter a reference (observations) has start date dimension, the sample used is the start date dimension.} - \item{Wheter a reference (observations) doesn't have start date dimension, the sample used must be especified in sdate_dim parameter.}} + \item{If a forecast (hindcast) has dimensions member and start date, and + both must be used in the sample, their names should be passed in + sdate_dim and memb_dim.} + \item{If a forecast (hindcast) has dimensions member and start date, and + only start date must be used in the sample (the calculation is done in + each separate member), memb_dim can be set to NULL.} + \item{If a reference (observations) has start date dimension, the sample + used is the start date dimension.} + \item{If a reference (observations) doesn't have start date dimension, + the sample used must be especified in sdate_dim parameter.} +} } \examples{ threshold <- 26 @@ -60,4 +90,5 @@ exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- CST_QThreshold(exp, threshold, start = list(21, 4), end = list(21, 6)) + } diff --git a/man/CST_Threshold.Rd b/man/CST_Threshold.Rd index bff93fa..e344ca1 100644 --- a/man/CST_Threshold.Rd +++ b/man/CST_Threshold.Rd @@ -17,30 +17,51 @@ CST_Threshold( ) } \arguments{ -\item{data}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{threshold}{a single scalar or vector indicating the relative threshold(s).} +\item{threshold}{A single scalar or vector indicating the relative +threshold(s).} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to selectfrom the data by providing a list of two elements: the initial date +of the period and the initial month of the period. By default it is set to +NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested +period.} -\item{memb_dim}{a character string indicating the name of the dimension in which the ensemble members are stored. When set it to NULL, threshold is computed for individual members.} +\item{memb_dim}{A character string indicating the name of the dimension in +which the ensemble members are stored. When set it to NULL, threshold is +computed for individual members.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the probabilites in the element \code{data}. +An ’s2dv_cube’ object containing the corresponding values of a +percentile in the element \code{data}. } \description{ -Frequently, thresholds are defined by a percentile that may correspond to a different absolute value depending on the variable, gridpoint and also julian day (time). -This function calculates the corresponding value of a percentile given a dataset. +Frequently, thresholds are defined by a percentile that may correspond to a +different absolute value depending on the variable, gridpoint and also julian +day (time). This function calculates the corresponding value of a percentile +given a dataset. } \examples{ threshold <- 0.9 @@ -55,4 +76,5 @@ exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- CST_Threshold(exp, threshold, start = list(21, 4), end = list(21, 6)) + } diff --git a/man/QThreshold.Rd b/man/QThreshold.Rd index ff4900e..2af6e5f 100644 --- a/man/QThreshold.Rd +++ b/man/QThreshold.Rd @@ -17,42 +17,72 @@ QThreshold( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{threshold}{a multidimensional array with named dimensions in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length.} +\item{threshold}{A multidimensional array with named dimensions in the same +units as parameter 'data' and with the common dimensions of the element +'data' of the same length.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested +period.} -\item{memb_dim}{a character string indicating the name of the dimension in which the ensemble members are stored.} +\item{memb_dim}{A character string indicating the name of the dimension in +which the ensemble members are stored.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +probability of an absolute threshold in the element \code{data}. } \description{ -From a user perspective, an absolute threshold can be very useful for a specific needs (e.g.: grape variety). -However, this absolute threshold could be transform to a relative threshold in order to get its frequency in a given dataset. -Therefore, the function \code{QThreshold} returns the probability of an absolute threshold. -This is done by computing the Cumulative Distribution Function of a sample and leaving-one-ot. -The sample used will depend on the dimensions of the data provided and the dimension names provided in sdate_dim and memb_dim parameters: +From the user's perspective, an absolute threshold can be very useful for a +specific needs (e.g.: grape variety). However, this absolute threshold could +be transformed to a relative threshold in order to get its frequency in a given +dataset. Therefore, the function \code{QThreshold} returns the probability of +an absolute threshold. This is done by computing the Cumulative Distribution +Function of a sample and leaving-one-ot. The sample used will depend on the +dimensions of the data provided and the dimension names provided in sdate_dim +and memb_dim parameters: \itemize{ - \item{Wheter a forecast (hindcast) has dimensions member and start date, and both must be used in the sample, their names should be passed in sdate_dim and memb_dim.} - \item{Wheter a forecast (hindcast) has dimensions member and start date, and only start date must be used in the sample (the calculation is done in each separate member), memb_dim can be set to NULL.} - \item{Wheter a reference (observations) has start date dimension, the sample used is the start date dimension.} - \item{Wheter a reference (observations) doesn't have start date dimension, the sample used must be especified in sdate_dim parameter.}} + \item{If a forecast (hindcast) has dimensions member and start date, and + both must be used in the sample, their names should be passed in + sdate_dim and memb_dim.} + \item{If a forecast (hindcast) has dimensions member and start date, and + only start date must be used in the sample (the calculation is done in + each separate member), memb_dim can be set to NULL.} + \item{If a reference (observations) has start date dimension, the sample + used is the start date dimension.} + \item{If a reference (observations) doesn't have start date dimension, + the sample used must be especified in sdate_dim parameter.} +} } \examples{ threshold = 25 data <- array(rnorm(5 * 3 * 20 * 2, mean = 26), c(member = 5, sdate = 3, time = 20, lon = 2)) thres_q <- QThreshold(data, threshold) + } diff --git a/man/Threshold.Rd b/man/Threshold.Rd index c2f3872..2999439 100644 --- a/man/Threshold.Rd +++ b/man/Threshold.Rd @@ -18,32 +18,54 @@ Threshold( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{threshold}{a single scalar or vector indicating the relative threshold(s).} +\item{threshold}{A single scalar or vector indicating the relative +threshold(s).} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested +period.} -\item{memb_dim}{a character string indicating the name of the dimension in which the ensemble members are stored. When set it to NULL, threshold is computed for individual members.} +\item{memb_dim}{A character string indicating the name of the dimension in +which the ensemble members are stored. When set it to NULL, threshold is +computed for individual members.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +corresponding values of a percentile in the element \code{data}. } \description{ -Frequently, thresholds are defined by a percentile that may correspond to a different absolute value depending on the variable, gridpoint and also julian day (time). -This function calculates the corresponding value of a percentile given a dataset. +Frequently, thresholds are defined by a percentile that may correspond to a +different absolute value depending on the variable, gridpoint and also julian +day (time). This function calculates the corresponding value of a percentile +given a dataset. } \examples{ threshold <- 0.9 @@ -52,4 +74,5 @@ data <- array(rnorm(25 * 3 * 214 * 2, mean = 26), thres_q <- Threshold(data, threshold) data <- array(rnorm(1 * 3 * 214 * 2), c(member = 1, sdate = 3, time = 214, lon = 2)) res <- Threshold(data, threshold) + } -- GitLab From 7c2fa5359bbcfd910f42642a625198e5360113ab Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 23 Sep 2022 12:42:40 +0200 Subject: [PATCH 14/26] Correct documentation and formatting of all functions --- R/AbsToProbs.R | 88 +++++++++---- R/AccumulationExceedingThreshold.R | 136 +++++++++++++------- R/MergeRefToExp.R | 134 ++++++++++++------- R/PeriodAccumulation.R | 95 +++++++++----- R/PeriodMean.R | 86 +++++++++---- R/SelectPeriodOnData.R | 76 +++++++---- R/SelectPeriodOnDates.R | 28 ++-- R/TotalSpellTimeExceedingThreshold.R | 135 +++++++++++++------ R/TotalTimeExceedingThreshold.R | 135 +++++++++++++------ R/WindCapacityFactor.R | 110 +++++++++++----- R/WindPowerDensity.R | 81 ++++++++---- R/zzz.R | 6 +- man/AbsToProbs.Rd | 41 ++++-- man/AccumulationExceedingThreshold.Rd | 55 +++++--- man/CST_AbsToProbs.Rd | 37 ++++-- man/CST_AccumulationExceedingThreshold.Rd | 50 +++++-- man/CST_MergeRefToExp.Rd | 48 +++++-- man/CST_PeriodAccumulation.Rd | 41 ++++-- man/CST_PeriodMean.Rd | 38 ++++-- man/CST_SelectPeriodOnData.Rd | 35 +++-- man/CST_TotalSpellTimeExceedingThreshold.Rd | 55 ++++++-- man/CST_TotalTimeExceedingThreshold.Rd | 64 ++++++--- man/CST_WindCapacityFactor.Rd | 52 ++++++-- man/CST_WindPowerDensity.Rd | 42 ++++-- man/MergeRefToExp.Rd | 45 +++++-- man/PeriodAccumulation.Rd | 44 +++++-- man/PeriodMean.Rd | 42 ++++-- man/SelectPeriodOnData.Rd | 31 +++-- man/SelectPeriodOnDates.Rd | 26 ++-- man/TotalSpellTimeExceedingThreshold.Rd | 59 ++++++--- man/TotalTimeExceedingThreshold.Rd | 65 +++++++--- man/WindCapacityFactor.Rd | 50 +++++-- man/WindPowerDensity.Rd | 39 ++++-- 33 files changed, 1462 insertions(+), 607 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index af7b616..155d745 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -1,19 +1,34 @@ #'Transform ensemble forecast into probabilities #' -#'The Cumulative Distribution Function of a forecast is used to obtain the probabilities of each value in the ensemble. If multiple initializations (start dates) are provided, the function will create the Cumulative Distribution Function excluding the corresponding initialization. +#'The Cumulative Distribution Function of a forecast is used to obtain the +#'probabilities of each value in the ensemble. If multiple initializations +#'(start dates) are provided, the function will create the Cumulative +#'Distribution Function excluding the corresponding initialization. #' -#'@param data an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param memb_dim a character string indicating the name of the dimension in which the ensemble members are stored. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested +#' period. +#'@param memb_dim A character string indicating the name of the dimension in +#' which the ensemble members are stored. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the probabilites in the element \code{data}. -#' -#'@import multiApply -#'@importFrom stats ecdf +#'@return An 's2dv_cube' object containing the probabilites in the element \code{data}. #' #'@examples #'exp <- CSTools::lonlat_prec @@ -27,6 +42,9 @@ #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'exp_probs <- CST_AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) +#' +#'@import multiApply +#'@importFrom stats ecdf #'@export CST_AbsToProbs <- function(data, start = NULL, end = NULL, time_dim = 'ftime', memb_dim = 'member', @@ -63,21 +81,38 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, } #'Transform ensemble forecast into probabilities #' -#'The Cumulative Distribution Function of a forecast is used to obtain the probabilities of each value in the ensemble. If multiple initializations (start dates) are provided, the function will create the Cumulative Distribution Function excluding the corresponding initialization. +#'The Cumulative Distribution Function of a forecast is used to obtain the +#'probabilities of each value in the ensemble. If multiple initializations +#'(start dates) are provided, the function will create the Cumulative +#'Distribution Function excluding the corresponding initialization. #' -#'@param data a multidimensional array with named dimensions. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param memb_dim a character string indicating the name of the dimension in which the ensemble members are stored. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested +#' period. +#'@param memb_dim A character string indicating the name of the dimension in +#' which the ensemble members are stored. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. -#' -#'@import multiApply -#'@importFrom stats ecdf +#'@return A multidimensional array with named dimensions containing the +#'probabilites in the element \code{data}. #' #'@examples #'exp <- CSTools::lonlat_prec$data @@ -91,6 +126,9 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-06-2002", format = "%d-%m-%Y"), by = 'day')) #'exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) +#' +#'@import multiApply +#'@importFrom stats ecdf #'@export AbsToProbs <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', memb_dim = 'member', diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index e953d32..62a4bc4 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -1,35 +1,57 @@ #'Accumulation of a variable when Exceeding (not exceeding) a Threshold #' -#'The accumulation (sum) of a variable in the days (or time steps) that the variable is exceeding (or not exceeding) a threshold during a period. The threshold provided must be -#'in the same units than the variable units, i.e. to use a percentile as a scalar, -#'the function \code{Threshold} or \code{QThreshold} may be needed. -#'Providing mean daily temperature data, the following agriculture indices for heat stress can be obtained by using this function: +#'The accumulation (sum) of a variable in the days (or time steps) that the +#'variable is exceeding (or not exceeding) a threshold during a period. The +#'threshold provided must be in the same units than the variable units, i.e. to +#'use a percentile as a scalar, the function \code{Threshold} or +#'\code{QThreshold} may be needed. Providing mean daily temperature data, the +#'following agriculture indices for heat stress can be obtained by using this +#'function: #'\itemize{ -#' \item\code{GDD}{Summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st}} +#' \item\code{GDD}{Summation of daily differences between daily average +#' temperatures and 10°C between April 1st and October 31st} +#'} #' -#'@param data a 's2dv_cube' object as provided by function \code{CST_Load} in package CSTools. -#'@param threshold a 's2dv_cube' object as output of a 'CST_' function in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. A single scalar is also possible. -#'@param op a opartor '>' (by default), '<', '>=' or '<='. -#'@param diff a logical value indicating whether to accumulate the difference between data and threshold (TRUE) or not (FALSE by default). -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided by function \code{CST_Load} in +#' package CSTools. +#'@param threshold An 's2dv_cube' object as output of a 'CST_' function in the +#' same units as parameter 'data' and with the common dimensions of the element +#' 'data' of the same length. A single scalar is also possible. +#'@param op An operator '>' (by default), '<', '>=' or '<='. +#'@param diff A logical value indicating whether to accumulate the difference +#' between data and threshold (TRUE) or not (FALSE by default). +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' #'@return A 's2dv_cube' object containing the indicator in the element \code{data}. #' -#'@import multiApply #'@examples #'exp <- CSTools::lonlat_data$exp #'exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] #'DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) +#' +#'@import multiApply #'@export CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', - diff = FALSE, - start = NULL, end = NULL, - time_dim = 'ftime', - na.rm = FALSE, ncores = NULL) { + diff = FALSE, + start = NULL, end = NULL, + time_dim = 'ftime', + na.rm = FALSE, ncores = NULL) { if (!inherits(data, 's2dv_cube')) { stop("Parameter 'data' must be of the class 's2dv_cube', ", "as output by CSTools::CST_Load.") @@ -53,9 +75,9 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', threshold <- threshold$data } total <- AccumulationExceedingThreshold(data$data, data$Dates[[1]], - threshold = threshold, op = op, diff = diff, - start = start, end = end, time_dim = time_dim, - na.rm = na.rm, ncores = ncores) + threshold = threshold, op = op, diff = diff, + start = start, end = end, time_dim = time_dim, + na.rm = na.rm, ncores = ncores) data$data <- total if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates$start, @@ -66,25 +88,48 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', } #'Accumulation of a variable when Exceeding (not exceeding) a Threshold #' -#'The accumulation (sum) of a variable in the days (or time steps) that the variable is exceeding (or not exceeding) a threshold during a period. The threshold provided must be -#'in the same units than the variable units, i.e. to use a percentile as a scalar, -#'the function \code{Threshold} or \code{QThreshold} may be needed. -#'Providing mean daily temperature data, the following agriculture indices for heat stress can be obtained by using this function: +#'The accumulation (sum) of a variable in the days (or time steps) that the +#'variable is exceeding (or not exceeding) a threshold during a period. The +#'threshold provided must be in the same units than the variable units, i.e. to +#'use a percentile as a scalar, the function \code{Threshold} or +#'\code{QThreshold} may be needed. Providing mean daily temperature data, the +#'following agriculture indices for heat stress can be obtained by using this +#'function: #'\itemize{ -#' \item\code{GDD}{Summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st}} +#' \item\code{GDD}{Summation of daily differences between daily average +#' temperatures and 10°C between April 1st and October 31st} +#'} #' -#'@param data a multidimensional array with named dimensions. -#'@param threshold a multidimensional array with named dimensions in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. -#'@param op a opartor '>' (by default), '<', '>=' or '<='. -#'@param diff a logical value indicating whether to accumulate the difference between data and threshold (TRUE) or not (FALSE by default). -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param threshold a multidimensional array with named dimensions in the same +#' units as parameter 'data' and with the common dimensions of the element +#' 'data' of the same length. +#'@param op An operator '>' (by default), '<', '>=' or '<='. +#'@param diff A logical value indicating whether to accumulate the difference +#' between data and threshold (TRUE) or not (FALSE by default). +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. +#'@return A multidimensional array with named dimensions containing the +#'indicator in the element \code{data}. #' #'@import multiApply #'@examples @@ -101,10 +146,10 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', #' end = list(31, 10)) #'@export AccumulationExceedingThreshold <- function(data, threshold, op = '>', - diff = FALSE, - dates = NULL, start = NULL, end = NULL, - time_dim = 'time', na.rm = FALSE, - ncores = NULL) { + diff = FALSE, + dates = NULL, start = NULL, end = NULL, + time_dim = 'time', na.rm = FALSE, + ncores = NULL) { if (is.null(data)) { stop("Parameter 'data' cannot be NULL.") } @@ -116,7 +161,7 @@ AccumulationExceedingThreshold <- function(data, threshold, op = '>', names(dim(data)) <- time_dim } if (is.null(threshold)) { - stop("Parameter 'threshold' cannot be NULL.") + stop("Parameter 'threshold' cannot be NULL.") } if (!is.numeric(threshold)) { stop("Parameter 'threshold' must be numeric.") @@ -142,7 +187,7 @@ AccumulationExceedingThreshold <- function(data, threshold, op = '>', if (all(time_dim %in% names(dim(threshold)))) { if (dim(threshold)[time_dim] == dim(data)[time_dim]) { threshold <- SelectPeriodOnData(threshold, dates, start, end, - time_dim = time_dim, ncores = ncores) + time_dim = time_dim, ncores = ncores) } } data <- SelectPeriodOnData(data, dates, start, end, @@ -181,9 +226,6 @@ AccumulationExceedingThreshold <- function(data, threshold, op = '>', return(total) } -#x <- 1:10 -#y <- 3 -#.sumexceedthreshold(x, y, '>', T) .sumexceedthreshold <- function(x, y, op, na.rm) { if (op == '>') { res <- sum(x[x > y], na.rm = na.rm) diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 2dd5af2..3332ffb 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -1,20 +1,42 @@ #'Merge a Reference To Experiments #' -#'Some indicators are defined for specific temporal periods (e.g.: summer from June 21st to September 21st). If the initialization forecast date is later than the one required for the indicator (e.g.: July 1st), the user may want to merge past observations, or other references, to the forecast (or hindcast) to compute the indicator. The function \code{MergeObs2Exp} takes care of this steps. If the forecast simulation doesn't cover the required period because it is initialized too early (e.g.: Initialization on November 1st the forecast covers until the beginning of June next year), a climatology (or other references) could be added at the end of the forecast lead time to cover the desired period (e.g.: until the end of summer). +#'Some indicators are defined for specific temporal periods (e.g.: summer from +#'June 21st to September 21st). If the initialization forecast date is later +#'than the one required for the indicator (e.g.: July 1st), the user may want to +#'merge past observations, or other references, to the forecast (or hindcast) +#'to compute the indicator. The function \code{MergeObs2Exp} takes care of this +#'steps. If the forecast simulation doesn't cover the required period because it +#'is initialized too early (e.g.: Initialization on November 1st the forecast +#'covers until the beginning of June next year), a climatology (or other +#'references) could be added at the end of the forecast lead time to cover the +#'desired period (e.g.: until the end of summer). #' -#'@param data1 an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param data2 an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param start1 a list to defined the initial date of the period to select from data1 by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end1 a list to defined the final date of the period to select from data1 by providing a list of two elements: the final day of the period and the final month of the period. -#'@param start2 a list to defined the initial date of the period to select from data2 by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end2 a list to defined the final date of the period to select from data2 by providing a list of two elements: the final day of the period and the final month of the period. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param ncores an integer indicating the number of cores to use in parallel computation. -#'@return A 's2dv_cube' object containing the indicator in the element \code{data}. -#' -#'@import multiApply -#'@importFrom ClimProjDiags Subset +#'@param data1 An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param data2 An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param start1 A list to defined the initial date of the period to select from +#' data1 by providing a list of two elements: the initial date of the period +#' and the initial month of the period. +#'@param end1 A list to defined the final date of the period to select from +#' data1 by providing a list of two elements: the final day of the period and +#' the final month of the period. +#'@param start2 A list to defined the initial date of the period to select from +#' data2 by providing a list of two elements: the initial date of the period +#' and the initial month of the period. +#'@param end2 A list to defined the final date of the period to select from +#' data2 by providing a list of two elements: the final day of the period and +#' the final month of the period. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested period. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. +#'@return A 's2dv_cube' object containing the indicator in the element +#' \code{data}. #' #'@examples #'data_dates <- c(seq(as.Date("01-07-1993", "%d-%m-%Y", tz = 'UTC'), @@ -34,6 +56,9 @@ #'new_data <- CST_MergeRefToExp(data1 = ref, data2 = data, #' start1 = list(21, 6), end1 = list(30, 6), #' start2 = list(1, 7), end2 = list(21, 9)) +#' +#'@import multiApply +#'@importFrom ClimProjDiags Subset #'@export CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, time_dim = 'ftime', sdate_dim = 'sdate', @@ -73,19 +98,19 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, } } data1$data <- MergeRefToExp(data1 = data1$data, dates1 = data1$Dates[[1]], - start1 = start1, end1 = end1, - data2 = data2$data, dates2 = data2$Dates[[1]], - start2, end2, time_dim = time_dim, - sdate_dim = sdate_dim, ncores = ncores) + start1 = start1, end1 = end1, + data2 = data2$data, dates2 = data2$Dates[[1]], + start2, end2, time_dim = time_dim, + sdate_dim = sdate_dim, ncores = ncores) dates1 <- SelectPeriodOnDates(data1$Dates[[1]], start = start1, - end = end1, - time_dim = time_dim) + end = end1, + time_dim = time_dim) dates2 <- SelectPeriodOnDates(data2$Dates[[1]], - start = start2, - end = end2, time_dim = time_dim) + start = start2, + end = end2, time_dim = time_dim) # TO DO CONCATENATE DATES res <- Apply(list(dates1, dates2), target_dims = time_dim, - c, output_dims = time_dim, ncores = ncores)$output1 + c, output_dims = time_dim, ncores = ncores)$output1 if (class(data1$Dates[[1]]) == 'Date') { data1$Dates <- as.Date(res, origin = '1970-01-01') } else { @@ -96,26 +121,42 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, #'Merge a Reference To Experiments #' -#'Some indicators are defined for specific temporal periods (e.g.: summer from June 21st to September 21st). If the initialization forecast date is later than the one required for the indicator (e.g.: July 1st), the user may want to merge past observations, or other reference, to the forecast (or hindcast) to compute the indicator. The function \code{MergeObs2Exp} takes care of this steps. +#'Some indicators are defined for specific temporal periods (e.g.: summer from +#'June 21st to September 21st). If the initialization forecast date is later +#'than the one required for the indicator (e.g.: July 1st), the user may want to +#'merge past observations, or other reference, to the forecast (or hindcast) to +#'compute the indicator. The function \code{MergeObs2Exp} takes care of this +#'steps. #' -#'@param data1 a multidimensional array with named dimensions. -#'@param dates1 a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data1'. -#'@param data2 a multidimensional array with named dimensions. -#'@param dates2 a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data2'. -#'@param start1 a list to defined the initial date of the period to select from data1 by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end1 a list to defined the final date of the period to select from data1 by providing a list of two elements: the final day of the period and the final month of the period. -#'@param start2 a list to defined the initial date of the period to select from data2 by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end2 a list to defined the final date of the period to select from data2 by providing a list of two elements: the final day of the period and the final month of the period. -#'@param time_dim a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period. -#'@param sdate_dim a character string indicating the name of the dimension in which the initialization dates are stored. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data1 A multidimensional array with named dimensions. +#'@param dates1 a vector of dates or a multidimensional array of dates with +#' named dimensions matching the dimensions on parameter 'data1'. +#'@param data2 A multidimensional array with named dimensions. +#'@param dates2 A vector of dates or a multidimensional array of dates with +#' named dimensions matching the dimensions on parameter 'data2'. +#'@param start1 A list to defined the initial date of the period to select from +#' data1 by providing a list of two elements: the initial date of the period +#' and the initial month of the period. +#'@param end1 A list to defined the final date of the period to select from +#' data1 by providing a list of two elements: the final day of the period and +#' the final month of the period. +#'@param start2 A list to defined the initial date of the period to select from +#' data2 by providing a list of two elements: the initial date of the period +#' and the initial month of the period. +#'@param end2 A list to defined the final date of the period to select from +#' data2 by providing a list of two elements: the final day of the period and +#' the final month of the period. +#'@param time_dim A character string indicating the name of the temporal +#' dimension. By default, it is set to 'ftime'. More than one dimension name +#' matching the dimensions provided in the object \code{data$data} can be +#' specified. This dimension is required to subset the data in a requested period. +#'@param sdate_dim A character string indicating the name of the dimension in +#' which the initialization dates are stored. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' #'@return A multidimensional array with named dimensions. #' -#'@import multiApply -#'@importFrom ClimProjDiags Subset -#'@importFrom s2dv InsertDim -#' #'@examples #'data_dates <- c(seq(as.Date("01-07-1993", "%d-%m-%Y", tz = 'UTC'), #' as.Date("01-12-1993","%d-%m-%Y", tz = 'UTC'), "day"), @@ -130,6 +171,10 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, #'new_data <- MergeRefToExp(data1 = ref, dates1 = ref_dates, start1 = list(21, 6), #' end1 = list(30, 6), data2 = data, dates2 = data_dates, #' start2 = list(1, 7), end = list(21, 9)) +#' +#'@import multiApply +#'@importFrom ClimProjDiags Subset +#'@importFrom s2dv InsertDim #'@export MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, end2, time_dim = 'time', sdate_dim = 'sdate', @@ -155,8 +200,7 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, en names(dim(dates2)) <- time_dim } data1 <- SelectPeriodOnData(data1, dates = dates1, start = start1, - end = end1, - time_dim = time_dim, ncores = ncores) + end = end1, time_dim = time_dim, ncores = ncores) # Check if data2 has dimension sdate_dim and it should be added to data1: if ((sdate_dim %in% names(dim(data2))) && dim(data2)[sdate_dim] > 1 && !sdate_dim %in% names(dim(data1))) { @@ -175,7 +219,7 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, en if (length(dif_dims) > 0) { for (i in dif_dims) { data1 <- s2dv::InsertDim(data1, posdim = i, lendim = dim(data2)[i], - name = names(dim(data2))[i]) + name = names(dim(data2))[i]) } } } @@ -185,14 +229,14 @@ MergeRefToExp <- function(data1, dates1, start1, end1, data2, dates2, start2, en if (length(dif_dims) > 0) { for (i in dif_dims) { data2 <- s2dv::InsertDim(data2, posdim = i, lendim = dim(data1)[i], - name = names(dim(data1))[i]) + name = names(dim(data1))[i]) } } } data2 <- SelectPeriodOnData(data2, dates = dates2, start = start2, - end = end2, time_dim = time_dim, ncores = ncores) + end = end2, time_dim = time_dim, ncores = ncores) data1 <- Apply(list(data1, data2), target_dims = time_dim, fun = 'c', - output_dims = time_dim, ncores = ncores)$output1 + output_dims = time_dim, ncores = ncores)$output1 return(data1) } diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index f9cdb18..2782af3 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -1,21 +1,37 @@ #'Period Accumulation on 's2dv_cube' objects #' -#'Period Accumulation computes the sum (accumulation) of a given variable in a period. -#'Providing precipitation data, two agriculture indices can be obtained by using this function: +#'Period Accumulation computes the sum (accumulation) of a given variable in a +#'period. Providing precipitation data, two agriculture indices can be obtained +#'by using this function: #'\itemize{ -#' \item\code{SprR}{Spring Total Precipitation: The total precipitation from April 21th to June 21st} -#' \item\code{HarR}{Harvest Total Precipitation: The total precipitation from August 21st to October 21st}} +#' \item\code{SprR}{Spring Total Precipitation: The total precipitation from +#' April 21th to June 21st} +#' \item\code{HarR}{Harvest Total Precipitation: The total precipitation from +#' August 21st to October 21st} +#'} #' -#'@param data an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the indicator in the element \code{data}. -#' -#'@import multiApply +#'@return A 's2dv_cube' object containing the indicator in the element +#'\code{data}. #' #'@examples #'exp <- CSTools::lonlat_prec @@ -34,6 +50,8 @@ #'HarR <- CST_PeriodAccumulation(exp, start = list(21, 8), end = list(21, 10)) #'dim(HarR$data) #'head(HarR$Dates) +#' +#'@import multiApply #'@export CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, time_dim = 'ftime', na.rm = FALSE, @@ -62,30 +80,47 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, data$data <- total if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates[[1]], - start = start, end = end, - time_dim = time_dim, ncores = ncores) + start = start, end = end, + time_dim = time_dim, ncores = ncores) } return(data) } #'Period Accumulation on multidimensional array objects #' -#'Period Accumulation computes the sum (accumulation) of a given variable in a period. -#'Providing precipitation data, two agriculture indices can be obtained by using this function: +#'Period Accumulation computes the sum (accumulation) of a given variable in a +#'period. Providing precipitation data, two agriculture indices can be obtained +#'by using this function: #'\itemize{ -#' \item\code{SprR}{Spring Total Precipitation: The total precipitation from April 21th to June 21st} -#' \item\code{HarR}{Harvest Total Precipitation: The total precipitation from August 21st to October 21st}} +#' \item\code{SprR}{Spring Total Precipitation: The total precipitation from +#' April 21th to June 21st} +#' \item\code{HarR}{Harvest Total Precipitation: The total precipitation from +#' August 21st to October 21st} +#'} #' -#'@param data a multidimensional array with named dimensions. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'time'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. -#' -#'@import multiApply +#'@return A multidimensional array with named dimensions containing the +#'indicator in the element \code{data}. #' #'@examples #'exp <- CSTools::lonlat_prec$data @@ -101,6 +136,8 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'SprR <- PeriodAccumulation(data, dates = Dates, start = list(21, 4), end = list(21, 6)) #'HarR <- PeriodAccumulation(data, dates = Dates, start = list(21, 8), end = list(21, 10)) +#' +#'@import multiApply #'@export PeriodAccumulation <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, diff --git a/R/PeriodMean.R b/R/PeriodMean.R index fa3af03..c75cee3 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -1,27 +1,44 @@ #'Period Mean on 's2dv_cube' objects #' #'Period Mean computes the average (mean) of a given variable in a period. -#'Providing temperature data, two agriculture indices can be obtain by using this function: +#'Providing temperature data, two agriculture indices can be obtained by using +#'this function: #'\itemize{ -#' \item\code{GST}{Growing Season average Temperature: The average temperature from April 1st to Octobe 31st} -#' \item\code{SprTX}{Spring Average Maximum Temperature: The average daily maximum temperature from April 1st to May 31st}} +#' \item\code{GST}{Growing Season average Temperature: The average temperature +#' from April 1st to Octobe 31st} +#' \item\code{SprTX}{Spring Average Maximum Temperature: The average daily +#' maximum temperature from April 1st to May 31st} +#'} #' -#'@param data an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the indicator in the element \code{data}. -#' -#'@import multiApply +#'@return An 's2dv_cube' object containing the indicator in the element +#' \code{data}. #' #'@examples #'exp <- CSTools::lonlat_data$exp #'exp$data <- CSTools::lonlat_data$exp$data[1, , 3, , 1, 1] #'SA <- CST_PeriodMean(exp) #' +#'@import multiApply #'@export CST_PeriodMean <- function(data, start = NULL, end = NULL, time_dim = 'ftime', na.rm = FALSE, @@ -59,26 +76,45 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #'Period Mean on multidimensional array objects #' #'Period Mean computes the average (mean) of a given variable in a period. -#'Providing temperature data, two agriculture indices can be obtain by using this function: +#'Providing temperature data, two agriculture indices can be obtained by using +#'this function: #'\itemize{ -#' \item\code{GST}{Growing Season average Temperature: The average temperature from April 1st to Octobe 31st} -#' \item\code{SprTX}{Spring Average Maximum Temperature: The average daily maximum temperature from April 1st to May 31st}} +#' \item\code{GST}{Growing Season average Temperature: The average +#' temperature from April 1st to Octobe 31st} +#' \item\code{SprTX}{Spring Average Maximum Temperature: The average daily +#' maximum temperature from April 1st to May 31st} +#'} #' -#'@param data a multidimensional array with named dimensions. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. -#' -#'@import multiApply +#'@return A multidimensional array with named dimensions containing the +#'indicator in the element \code{data}. #' #'@examples #'exp <- CSTools::lonlat_prec$data #'SA <- PeriodMean(exp, time_dim = 'ftime') +#' +#'@import multiApply #'@export PeriodMean <- function(data, dates = NULL, start = NULL, end = NULL, time_dim = 'time', na.rm = FALSE, ncores = NULL) { diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index 85b7ff3..f15c60e 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -2,27 +2,37 @@ #' #' Auxiliary function to subset data for a specific period. #' -#'@param data an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools. -#'@param start a parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end a parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. -#'@param time_dim a character string indicating the name of the dimension to compute select the dates. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided function \code{CST_Load} in +#' package CSTools. +#'@param start A parameter to defined the initial date of the period to select +#' from the data by providing a list of two elements: the initial date of the +#' period and the initial month of the period. +#'@param end A parameter to defined the final date of the period to select from +#' the data by providing a list of two elements: the final day of the period +#' and the final month of the period. +#'@param time_dim A character string indicating the name of the dimension to +#' compute select the dates. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the subset of the object \code{data$data} during the period requested from \code{start} to \code{end}. -#' -#'@import multiApply +#'@return A 's2dv_cube' object containing the subset of the object +#'\code{data$data} during the period requested from \code{start} to \code{end}. #' #'@examples #'exp <- CSTools::lonlat_prec #'exp$data <- array(rnorm(5 * 3 * 214 * 2), -#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) +#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) #'exp$Dates[[1]] <- 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')) +#' 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')) #'Period <- CST_SelectPeriodOnData(exp, start = list(21, 6), end = list(21, 9)) +#' +#'@import multiApply #'@export CST_SelectPeriodOnData <- function(data, start, end, time_dim = 'ftime', ncores = NULL) { if (!inherits(data, 's2dv_cube')) { @@ -50,8 +60,8 @@ CST_SelectPeriodOnData <- function(data, start, end, time_dim = 'ftime', ncores data$data <- res if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates[[1]], - start = start, end = end, - time_dim = time_dim, ncores = ncores) + start = start, end = end, + time_dim = time_dim, ncores = ncores) } return(data) } @@ -61,29 +71,39 @@ CST_SelectPeriodOnData <- function(data, start, end, time_dim = 'ftime', ncores #' #' Auxiliary function to subset data for a specific period. #' -#'@param data a multidimensional array with named dimensions. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. -#'@param time_dim a character string indicating the name of the dimension to compute select the dates. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. +#'@param time_dim A character string indicating the name of the dimension to +#' compute select the dates. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. -#' -#'@import multiApply +#'@return A multidimensional array with named dimensions containing the subset +#'of the object \code{data} during the period requested from \code{start} to +#'\code{end}. #' #'@examples #'data <- array(rnorm(5 * 3 * 214 * 2), -#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) +#' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) #'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"), +#' 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"), +#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'dim(Dates) <- c(ftime = 214, sdate = 3) #'Period <- SelectPeriodOnData(data, Dates, start = list(21, 6), end = list(21, 9)) #' +#'@import multiApply #'@export SelectPeriodOnData <- function(data, dates, start, end, time_dim = 'ftime', ncores = NULL) { diff --git a/R/SelectPeriodOnDates.R b/R/SelectPeriodOnDates.R index c8444c0..a9c8d9c 100644 --- a/R/SelectPeriodOnDates.R +++ b/R/SelectPeriodOnDates.R @@ -2,13 +2,23 @@ #' #' Auxiliary function to subset dates for a specific period. #' -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. -#'@param time_dim a character string indicating the name of the dimension to compute select the dates. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. +#'@param time_dim A character string indicating the name of the dimension to +#' compute select the dates. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. +#'@return A multidimensional array with named dimensions containing the subset of +#'the vector dates during the period requested from \code{start} to \code{end}. #' #'@import multiApply #'@importFrom s2dv Reorder @@ -16,14 +26,14 @@ #'@examples #'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"), +#' 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"), +#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'Period <- SelectPeriodOnDates(Dates, start = list(21, 6), end = list(21, 9)) #'@export SelectPeriodOnDates <- function(dates, start, end, - time_dim = 'ftime', ncores = NULL) { + time_dim = 'ftime', ncores = NULL) { # TODO: consider NAs if (is.null(dim(dates))) { dim(dates) <- length(dates) diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 0ecbe9e..97981ee 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -1,34 +1,61 @@ #'Total Spell Time Exceeding Threshold #' -#'The number of days (when daily data is provided) that are part of a spell (defined by its minimum length e.g. 6 consecutive days) that exceed (or not exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. -#'This function allows to compute indicators widely used in Climate Services, such as: +#'The number of days (when daily data is provided) that are part of a spell +#'(defined by its minimum length e.g. 6 consecutive days) that exceed (or not +#'exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. +#'This function allows to compute indicators widely used in Climate Services, +#'such as: #'\itemize{ -#' \code{WSDI}{Warm Spell Duration Index that count the total number of days with at least 6 consecutive days when the daily temperature maximum exceeds its 90th percentile.}} -#'This function requires the data and the threshold to be in the same units. The 90th percentile can be translate into absolute values given a reference dataset using function \code{Threshold} or the data can be transform into probabilites by using function \code{AbsToProbs}. See section @examples. +#' \code{WSDI}{Warm Spell Duration Index that count the total number of days +#' with at least 6 consecutive days when the daily temperature +#' maximum exceeds its 90th percentile.} +#'} +#'This function requires the data and the threshold to be in the same units. The +#'90th percentile can be translate into absolute values given a reference dataset +#'using function \code{Threshold} or the data can be transform into probabilites +#'by using function \code{AbsToProbs}. See section @examples. #'@seealso [Threshold()] and [AbsToProbs()]. #' -#'@param data an 's2dv_cube' object as provided by function \code{CST_Load} in package CSTools. -#'@param threshold an 's2dv_cube' object as output of a 'CST_' function in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. A single scalar is also possible. If \code{timd_dim} is in the dimension (with the same length as \code{data}), the comparison will be done day by day. -#'@param spell a scalar indicating the minimum length of the spell. -#'@param op a opartor '>' (by default), '<', '>=' or '<='. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided by function \code{CST_Load} in +#' package CSTools. +#'@param threshold An 's2dv_cube' object as output of a 'CST_' function in the +#' same units as parameter 'data' and with the common dimensions of the element +#' 'data' of the same length. A single scalar is also possible. If +#' \code{timd_dim} is in the dimension (with the same length as \code{data}), +#' the comparison will be done day by day. +#'@param spell A scalar indicating the minimum length of the spell. +#'@param op An operator '>' (by default), '<', '>=' or '<='. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the indicator in the element \code{data}. +#'@return An 's2dv_cube' object containing the indicator in the element +#'\code{data}. #' -#'@import multiApply #'@examples #'exp <- CSTools::lonlat_data$exp #'exp$data <- array(rnorm(5 * 3 * 20 * 2, mean = 25, sd = 3), -#' c(member = 5, sdate = 3, ftime = 20, lon = 2)) +#' c(member = 5, sdate = 3, ftime = 20, lon = 2)) #'TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 23, spell = 3) +#' +#'@import multiApply #'@export CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', - start = NULL, end = NULL, - time_dim = 'ftime', - ncores = NULL) { + start = NULL, end = NULL, + time_dim = 'ftime', + ncores = NULL) { if (!inherits(data, 's2dv_cube')) { stop("Parameter 'data' must be of the class 's2dv_cube', ", "as output by CSTools::CST_Load.") @@ -65,31 +92,61 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> } #'Total Spell Time Exceeding Threshold #' -#'The number of days (when daily data is provided) that are part of a spell (defined by its minimum length e.g. 6 consecutive days) that exceed (or not exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. -#'This function allows to compute indicators widely used in Climate Services, such as: +#'The number of days (when daily data is provided) that are part of a spell +#'(defined by its minimum length e.g. 6 consecutive days) that exceed (or not +#'exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. +#'This function allows to compute indicators widely used in Climate Services, +#'such as: #'\itemize{ -#' \code{WSDI}{Warm Spell Duration Index that count the total number of days with at least 6 consecutive days when the daily temperature maximum exceeds its 90th percentile.}} -#'This function requires the data and the threshold to be in the same units. The 90th percentile can be translate into absolute values given a reference dataset using function \code{Threshold} or the data can be transform into probabilites by using function \code{AbsToProbs}. See section @examples. +#' \code{WSDI}{Warm Spell Duration Index that count the total number of days +#' with at least 6 consecutive days when the daily temperature +#' maximum exceeds its 90th percentile.} +#'} +#'This function requires the data and the threshold to be in the same units. The +#'90th percentile can be translate into absolute values given a reference +#'dataset using function \code{Threshold} or the data can be transform into +#'probabilites by using function \code{AbsToProbs}. See section @examples. #'@seealso [Threshold()] and [AbsToProbs()]. #' -#'@param data a multidimensional array with named dimensions. -#'@param threshold a multidimensional array with named dimensions in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. If \code{timd_dim} is in the dimension (with the same length as \code{data}), the comparison will be done day by day. -#'@param spell a scalar indicating the minimum length of the spell. -#'@param op a opartor '>' (by default), '<', '>=' or '<='. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param threshold A multidimensional array with named dimensions in the same +#' units as parameter 'data' and with the common dimensions of the element +#' 'data' of the same length. If \code{timd_dim} is in the dimension (with the +#' same length as \code{data}), the comparison will be done day by day. +#'@param spell A scalar indicating the minimum length of the spell. +#'@param op An operator '>' (by default), '<', '>=' or '<='. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. +#'@return A multidimensional array with named dimensions containing the indicator +#'in the element \code{data}. #' -#'@details This function considers NA values as the end of the spell. For a different behaviour consider to modify the 'data' input by substituting NA values by values exceeding the threshold. -#'@import multiApply +#'@details This function considers NA values as the end of the spell. For a +#'different behaviour consider to modify the 'data' input by substituting NA +#'values by values exceeding the threshold. + #'@examples #'data <- array(rnorm(120), c(member = 1, sdate = 2, time = 20, lat = 4)) #'threshold <- array(rnorm(4), c(lat = 4)) #'total <- TotalSpellTimeExceedingThreshold(data, threshold, spell = 6) +#' +#'@import multiApply #'@export TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', dates = NULL, start = NULL, end = NULL, time_dim = 'time', @@ -105,7 +162,7 @@ TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', d names(dim(data)) <- time_dim } if (is.null(threshold)) { - stop("Parameter 'threshold' cannot be NULL.") + stop("Parameter 'threshold' cannot be NULL.") } if (!is.numeric(threshold)) { stop("Parameter 'threshold' must be numeric.") @@ -121,8 +178,8 @@ TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', d } if (time_dim %in% names(dim(threshold))) { if (dim(threshold)[time_dim] == dim(data)[time_dim]) { - threshold <- SelectPeriodOnData(threshold, dates, start, end, - time_dim = time_dim, ncores = ncores) + threshold <- SelectPeriodOnData(threshold, dates, start, end, + time_dim = time_dim, ncores = ncores) } } data <- SelectPeriodOnData(data, dates, start, end, @@ -148,9 +205,7 @@ TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '>', d } return(total) } -#data <- c(1,1,3,3,3,3,1,1,3,1,1,3,3,3,3,3) -#spell <- 3 -#threshold <- 2 + .totalspellthres <- function(data, threshold, spell, op = '>') { # data a time serie, threshold single value: if (op == '>') { diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 3792caf..ee0d8ac 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -1,34 +1,60 @@ #'Total Time of a variable Exceeding (not exceeding) a Threshold #' -#'The Total Time of a variable exceeding (or not) a Threshold returns the total number of days -#'(if the data provided is daily, or the corresponding units to the data frequency provided) -#' that a variable is exceeding a threshold during a period. The threshold provided must be -#'in the same units than the variable units, i.e. to use a percentile as a scalar, -#'the function \code{AbsToProbs} or \code{QThreshold} may be needed (see examples). -#'Providing maximum temperature daily data, the following agriculture indices for heat stress can be obtained by using this function: +#'The Total Time of a variable exceeding (or not) a Threshold returns the total +#'number of days (if the data provided is daily, or the corresponding units to +#'the data frequency provided) that a variable is exceeding a threshold during a +#'period. The threshold provided must be in the same units than the variable +#'units, i.e. to use a percentile as a scalar, +#'the function \code{AbsToProbs} or \code{QThreshold} may be needed (see +#'examples). Providing maximum temperature daily data, the following agriculture +#'indices for heat stress can be obtained by using this function: #'\itemize{ -#' \item\code{SU35}{Total count of days when daily maximum temperatures exceed 35°C in the seven months from the start month given (e.g. from April to October for start month of April).} -#' \item\code{SU36}{Total count of days when daily maximum temperatures exceed 36 between June 21st and September 21st} -#' \item\code{SU40}{Total count of days when daily maximum temperatures exceed 40 between June 21st and September 21st} -#' \item\code{Spr32}{Total count of days when daily maximum temperatures exceed 32 between April 21st and June 21st} +#' \item\code{SU35}{Total count of days when daily maximum temperatures exceed +#' 35°C in the seven months from the start month given (e.g. +#' from April to October for start month of April).} +#' \item\code{SU36}{Total count of days when daily maximum temperatures exceed +#' 36 between June 21st and September 21st} +#' \item\code{SU40}{Total count of days when daily maximum temperatures exceed +#' 40 between June 21st and September 21st} +#' \item\code{Spr32}{Total count of days when daily maximum temperatures exceed +#' 32 between April 21st and June 21st} #'} #' -#'@param data a 's2dv_cube' object as provided by function \code{CST_Load} in package CSTools. -#'@param threshold a 's2dv_cube' object as output of a 'CST_' function in the same units as parameter \code{data} and with the common dimensions of the element \code{data} of the same length (e.g. an array with the same lengths of longitude and latitude). A single scalar is also possible (for the case of comparing all grid points with the same scalar). -#'@param op a opartor '>' (by default), '<', '>=' or '<='. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data An 's2dv_cube' object as provided by function \code{CST_Load} in +#' package CSTools. +#'@param threshold An 's2dv_cube' object as output of a 'CST_' function in the +#' same units as parameter \code{data} and with the common dimensions of the +#' element \code{data} of the same length (e.g. an array with the same lengths +#' of longitude and latitude). A single scalar is also possible (for the case +#' of comparing all grid points with the same scalar). +#'@param op An operator '>' (by default), '<', '>=' or '<='. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A 's2dv_cube' object containing the indicator in the element \code{data}. -#' -#'@import multiApply +#'@return An 's2dv_cube' object containing the indicator in the element +#'\code{data}. +#' #'@examples #'exp <- CSTools::lonlat_data$exp #'exp$data <- CSTools::lonlat_data$exp$data[1, 1, 3, 3, 1, 1] #'DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) +#' +#'@import multiApply #'@export CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', start = NULL, end = NULL, @@ -70,36 +96,61 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', } #'Total Time of a variable Exceeding (not exceeding) a Threshold #' -#'The Total Time of a variable exceeding (or not) a Threshold returns the total number of days -#'(if the data provided is daily, or the corresponding units to the data frequency provided) -#' that a variable is exceeding a threshold during a period. The threshold provided must be -#'in the same units than the variable units, i.e. to use a percentile as a threshold, -#'the function \code{Threshold} or \code{QThreshold} may be needed (see examples). -#'Providing maximum temperature daily data, the following agriculture indices for heat stress can be obtained by using this function: +#'The Total Time of a variable exceeding (or not) a Threshold returns the total +#'number of days (if the data provided is daily, or the corresponding units to +#'the data frequency provided) that a variable is exceeding a threshold during a +#'period. The threshold provided must be in the same units than the variable +#'units, i.e. to use a percentile as a threshold, the function \code{Threshold} +#'or \code{QThreshold} may be needed (see examples). Providing maximum +#'temperature daily data, the following agriculture indices for heat stress can +#'be obtained by using this function: #'\itemize{ -#' \item\code{SU35}{Total count of days when daily maximum temperatures exceed 35°C} -#' \item\code{SU36}{Total count of days when daily maximum temperatures exceed 36 between June 21st and September 21st} -#' \item\code{SU40}{Total count of days when daily maximum temperatures exceed 40 between June 21st and September 21st} -#' \item\code{Spr32}{Total count of days when daily maximum temperatures exceed 32 between April 21st and June 21st} +#' \item\code{SU35}{Total count of days when daily maximum temperatures exceed +#' 35°C} +#' \item\code{SU36}{Total count of days when daily maximum temperatures exceed +#' 36 between June 21st and September 21st} +#' \item\code{SU40}{Total count of days when daily maximum temperatures exceed +#' 40 between June 21st and September 21st} +#' \item\code{Spr32}{Total count of days when daily maximum temperatures exceed +#' 32 between April 21st and June 21st} #'} #' -#'@param data a multidimensional array with named dimensions. -#'@param threshold a multidimensional array with named dimensions in the same units as parameter \code{data} and with the common dimensions of the element \code{data} of the same length (e.g. an array with the same lengths of longitude and latitude). A single scalar is also possible (for the case of comparing all grid points with the same scalar). -#'@param op a opartor '>' (by default), '<', '>=' or '<='. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param na.rm a logical value indicating whether to ignore NA values (TRUE) or not (FALSE). -#'@param ncores an integer indicating the number of cores to use in parallel computation. +#'@param data A multidimensional array with named dimensions. +#'@param threshold A multidimensional array with named dimensions in the same +#' units as parameter \code{data} and with the common dimensions of the element +#' \code{data} of the same length (e.g. an array with the same lengths of +#' longitude and latitude). A single scalar is also possible (for the case of +#' comparing all grid points with the same scalar). +#'@param op A operator '>' (by default), '<', '>=' or '<='. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'time'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param na.rm A logical value indicating whether to ignore NA values (TRUE) or +#' not (FALSE). +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation. #' -#'@return A multidimensional array with named dimensions. +#'@return A multidimensional array with named dimensions containing the +#'indicator in the element \code{data}. #' -#'@import multiApply #'@examples #'exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] #'DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') #' +#'@import multiApply #'@export TotalTimeExceedingThreshold <- function(data, threshold, op = '>', dates = NULL, start = NULL, end = NULL, diff --git a/R/WindCapacityFactor.R b/R/WindCapacityFactor.R index 4b9bffb..61565b0 100644 --- a/R/WindCapacityFactor.R +++ b/R/WindCapacityFactor.R @@ -1,26 +1,50 @@ #'Wind capacity factor on s2dv_cube objects #' #'@author Llorenç Lledó, \email{llledo@bsc.es} -#'@description Wind capacity factor computes the wind power generated by a specific wind turbine model under specific wind speed conditions, and expresses it as a fraction of the rated capacity (i.e. maximum power) of the turbine. -#'@description It is computed by means of a tabular power curve that relates wind speed to power output. The tabular values are interpolated with a linear piecewise approximating function to obtain a smooth power curve. Five different power curves that span different IEC classes can be selected (see below). -#'@references Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 +#'@description Wind capacity factor computes the wind power generated by a +#'specific wind turbine model under specific wind speed conditions, and +#'expresses it as a fraction of the rated capacity (i.e. maximum power) of the +#'turbine. +#'@description It is computed by means of a tabular power curve that relates +#'wind speed to power output. The tabular values are interpolated with a linear +#'piecewise approximating function to obtain a smooth power curve. Five +#'different power curves that span different IEC classes can be selected (see +#'below). +#'@references Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). +#'Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 #'@references International Standard IEC 61400-1 (third ed.) (2005) #' -#'@param wind a s2dv_cube object with instantaneous wind speeds expressed in m/s. -#'@param IEC_class a string indicating the IEC wind class (see IEC 61400-1) of the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s respectively. Classes \code{'I/II'} and \code{'II/III'} indicate intermediate turbines that fit both classes. More details of the five turbines and a plot of its power curves can be found in Lledó et al. (2019). -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation for temporal subsetting. -#'@return A s2dv_cube object containing the Wind Capacity Factor (unitless). +#'@param wind An s2dv_cube object with instantaneous wind speeds expressed in m/s. +#'@param IEC_class A string indicating the IEC wind class (see IEC 61400-1) of +#' the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} +#' are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s +#' respectively. Classes \code{'I/II'} and \code{'II/III'} indicate +#' intermediate turbines that fit both classes. More details of the five +#' turbines and a plot of its power curves can be found in Lledó et al. (2019). +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation for temporal subsetting. +#'@return An s2dv_cube object containing the Wind Capacity Factor (unitless). #' #'@examples #'wind <- array(rweibull(n = 100, shape = 2, scale = 6), c(member = 10, lat = 2, lon = 5)) #'wind <- CSTools::s2dv_cube(data = wind, lat = c(40, 41), lon = 1:5, -#' Variable = list(varName = 'sfcWind', level = 'Surface'), -#' Datasets = 'synthetic', when = Sys.time(), -#' Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), -#' source_file = NA) +#' Variable = list(varName = 'sfcWind', level = 'Surface'), +#' Datasets = 'synthetic', when = Sys.time(), +#' Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), +#' source_file = NA) #'WCF <- CST_WindCapacityFactor(wind, IEC_class = "III") #' #'@export @@ -54,35 +78,63 @@ CST_WindCapacityFactor <- function(wind, IEC_class = c("I", "I/II", "II", "II/II } if (!is.null(start) && !is.null(end)) { wind$Dates <- SelectPeriodOnDates(dates = wind$Dates[[1]], - start = start, end = end, - time_dim = time_dim, ncores = ncores) + start = start, end = end, + time_dim = time_dim, ncores = ncores) } return(wind) } #'Wind capacity factor #' #'@author Llorenç Lledó, \email{llledo@bsc.es} -#'@description Wind capacity factor computes the wind power generated by a specific wind turbine model under specific wind speed conditions, and expresses it as a fraction of the rated capacity (i.e. maximum power) of the turbine. -#'@description It is computed by means of a tabular power curve that relates wind speed to power output. The tabular values are interpolated with a linear piecewise approximating function to obtain a smooth power curve. Five different power curves that span different IEC classes can be selected (see below). -#'@references Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 +#'@description Wind capacity factor computes the wind power generated by a +#'specific wind turbine model under specific wind speed conditions, and +#'expresses it as a fraction of the rated capacity (i.e. maximum power) of the +#'turbine. +#'@description It is computed by means of a tabular power curve that relates +#'wind speed to power output. The tabular values are interpolated with a linear +#'piecewise approximating function to obtain a smooth power curve. Five +#'different power curves that span different IEC classes can be selected (see +#'below). +#'@references Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). +#'Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 #'@references International Standard IEC 61400-1 (third ed.) (2005) #' -#'@param wind a multidimensional array, vector or scalar with instantaneous wind speeds expressed in m/s. -#'@param IEC_class a string indicating the IEC wind class (see IEC 61400-1) of the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s respectively. Classes \code{'I/II'} and \code{'II/III'} indicate intermediate turbines that fit both classes. More details of the five turbines and a plot of its power curves can be found in Lledó et al. (2019). -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation for temporal subsetting. +#'@param wind A multidimensional array, vector or scalar with instantaneous wind +#' speeds expressed in m/s. +#'@param IEC_class A string indicating the IEC wind class (see IEC 61400-1) of +#' the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} +#' are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s +#' respectively. Classes \code{'I/II'} and \code{'II/III'} indicate +#' intermediate turbines that fit both classes. More details of the five +#' turbines and a plot of its power curves can be found in Lledó et al. (2019). +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation for temporal subsetting. #' -#'@return An array with the same dimensions as wind, containing the Wind Capacity Factor (unitless). +#'@return An array with the same dimensions as wind, containing the Wind +#' Capacity Factor (unitless). #' -#'@importFrom stats approxfun -#'@importFrom utils read.delim #'@examples #'wind <- rweibull(n = 100, shape = 2, scale = 6) #'WCF <- WindCapacityFactor(wind, IEC_class = "III") #' +#'@importFrom stats approxfun +#'@importFrom utils read.delim #'@export WindCapacityFactor <- function(wind, IEC_class = c("I", "I/II", "II", "II/III", "III"), dates = NULL, start = NULL, end = NULL, diff --git a/R/WindPowerDensity.R b/R/WindPowerDensity.R index 1ecdc30..99d5d80 100644 --- a/R/WindPowerDensity.R +++ b/R/WindPowerDensity.R @@ -1,25 +1,41 @@ #'Wind power density on s2dv_cube objects #' #'@author Llorenç Lledó, \email{llledo@bsc.es} -#'@description Wind Power Density computes the wind power that is available for extraction per square meter of swept area. -#'@description It is computed as 0.5*ro*wspd^3. As this function is non-linear, it will give inaccurate results if used with period means. +#'@description Wind Power Density computes the wind power that is available for +#'extraction per square meter of swept area. +#'@description It is computed as 0.5*ro*wspd^3. As this function is non-linear, +#'it will give inaccurate results if used with period means. #' -#'@param wind a s2dv_cube object with instantaneous wind speeds expressed in m/s obtained from CST_Load or s2dv_cube functions from CSTools pacakge -#'@param ro a scalar, or alternatively a multidimensional array with the same dimensions as wind, with the air density expressed in kg/m^3. By default it takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation for temporal subsetting. +#'@param wind An s2dv_cube object with instantaneous wind speeds expressed in m/s +#' obtained from CST_Load or s2dv_cube functions from CSTools pacakge. +#'@param ro A scalar, or alternatively a multidimensional array with the same +#' dimensions as wind, with the air density expressed in kg/m^3. By default it +#' takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation for temporal subsetting. #' -#'@return A s2dv_cube object containing Wind Power Density expressed in W/m^2. +#'@return An s2dv_cube object containing Wind Power Density expressed in W/m^2. #' #'@examples #'wind <- array(rweibull(n = 100, shape = 2, scale = 6), c(member = 10, lat = 2, lon = 5)) #'wind <- CSTools::s2dv_cube(data = wind, lat = c(40, 41), lon = 1:5, -#' Variable = list(varName = 'sfcWind', level = 'Surface'), -#' Datasets = 'synthetic', when = Sys.time(), -#' Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), -#' source_file = NA) +#' Variable = list(varName = 'sfcWind', level = 'Surface'), +#' Datasets = 'synthetic', when = Sys.time(), +#' Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), +#' source_file = NA) #'WPD <- CST_WindPowerDensity(wind) #' #'@export @@ -61,18 +77,37 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, #'Wind power density on multidimensional array objects #' #'@author Llorenç Lledó, \email{llledo@bsc.es} -#'@description Wind Power Density computes the wind power that is available for extraction per square meter of swept area. -#'@description It is computed as 0.5*ro*wspd^3. As this function is non-linear, it will give inaccurate results if used with period means. +#'@description Wind Power Density computes the wind power that is available for +#'extraction per square meter of swept area. +#'@description It is computed as 0.5*ro*wspd^3. As this function is non-linear, +#'it will give inaccurate results if used with period means. #' -#'@param wind a multidimensional array, vector or scalar with instantaneous wind speeds expressed in m/s. -#'@param ro a scalar, or alternatively a multidimensional array with the same dimensions as wind, with the air density expressed in kg/m^3. By default it takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa. -#'@param dates a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided. -#'@param start an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param end an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. -#'@param ncores an integer indicating the number of cores to use in parallel computation for temporal subsetting. +#'@param wind A multidimensional array, vector or scalar with instantaneous wind +#' speeds expressed in m/s. +#'@param ro A scalar, or alternatively a multidimensional array with the same +#' dimensions as wind, with the air density expressed in kg/m^3. By default it +#' takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa. +#'@param dates A vector of dates or a multidimensional array of dates with named +#' dimensions matching the dimensions on parameter 'data'. By default it is +#' NULL, to select a period this parameter must be provided. +#'@param start An optional parameter to defined the initial date of the period +#' to select from the data by providing a list of two elements: the initial +#' date of the period and the initial month of the period. By default it is set +#' to NULL and the indicator is computed using all the data provided in +#' \code{data}. +#'@param end An optional parameter to defined the final date of the period to +#' select from the data by providing a list of two elements: the final day of +#' the period and the final month of the period. By default it is set to NULL +#' and the indicator is computed using all the data provided in \code{data}. +#'@param time_dim A character string indicating the name of the function to +#' compute the indicator. By default, it is set to 'ftime'. More than one +#' dimension name matching the dimensions provided in the object +#' \code{data$data} can be specified. +#'@param ncores An integer indicating the number of cores to use in parallel +#' computation for temporal subsetting. #' -#'@return An array with the same dimensions as wind, containing Wind Power Density expressed in W/m^2. +#'@return An array with the same dimensions as wind, containing Wind Power +#'Density expressed in W/m^2. #' #'@examples #'wind <- rweibull(n = 100, shape = 2, scale = 6) diff --git a/R/zzz.R b/R/zzz.R index 35cd5a6..52fa2cd 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -5,13 +5,13 @@ position <- logical(length(dates)) if (ini_month != end_month) { pos <- sort(unique(c(pos[months == ini_month & days >= ini_day], - pos[months < end_month & months > ini_month], - pos[months == end_month & days <= end_day]))) + pos[months < end_month & months > ini_month], + pos[months == end_month & days <= end_day]))) position[pos] <- TRUE position[-pos] <- FALSE } else { pos <- sort(unique(c(pos[months == ini_month & - days >= ini_day & days <= end_day]))) + days >= ini_day & days <= end_day]))) position[pos] <- TRUE position[-pos] <- FALSE } diff --git a/man/AbsToProbs.Rd b/man/AbsToProbs.Rd index c4507a2..c3e7c50 100644 --- a/man/AbsToProbs.Rd +++ b/man/AbsToProbs.Rd @@ -16,27 +16,47 @@ AbsToProbs( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested +period.} -\item{memb_dim}{a character string indicating the name of the dimension in which the ensemble members are stored.} +\item{memb_dim}{A character string indicating the name of the dimension in +which the ensemble members are stored.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +probabilites in the element \code{data}. } \description{ -The Cumulative Distribution Function of a forecast is used to obtain the probabilities of each value in the ensemble. If multiple initializations (start dates) are provided, the function will create the Cumulative Distribution Function excluding the corresponding initialization. +The Cumulative Distribution Function of a forecast is used to obtain the +probabilities of each value in the ensemble. If multiple initializations +(start dates) are provided, the function will create the Cumulative +Distribution Function excluding the corresponding initialization. } \examples{ exp <- CSTools::lonlat_prec$data @@ -50,4 +70,5 @@ Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-06-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) + } diff --git a/man/AccumulationExceedingThreshold.Rd b/man/AccumulationExceedingThreshold.Rd index 0dd414f..f7e0982 100644 --- a/man/AccumulationExceedingThreshold.Rd +++ b/man/AccumulationExceedingThreshold.Rd @@ -18,36 +18,59 @@ AccumulationExceedingThreshold( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{threshold}{a multidimensional array with named dimensions in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length.} +\item{threshold}{a multidimensional array with named dimensions in the same +units as parameter 'data' and with the common dimensions of the element +'data' of the same length.} -\item{op}{a opartor '>' (by default), '<', '>=' or '<='.} +\item{op}{An operator '>' (by default), '<', '>=' or '<='.} -\item{diff}{a logical value indicating whether to accumulate the difference between data and threshold (TRUE) or not (FALSE by default).} +\item{diff}{A logical value indicating whether to accumulate the difference +between data and threshold (TRUE) or not (FALSE by default).} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +indicator in the element \code{data}. } \description{ -The accumulation (sum) of a variable in the days (or time steps) that the variable is exceeding (or not exceeding) a threshold during a period. The threshold provided must be -in the same units than the variable units, i.e. to use a percentile as a scalar, -the function \code{Threshold} or \code{QThreshold} may be needed. -Providing mean daily temperature data, the following agriculture indices for heat stress can be obtained by using this function: +The accumulation (sum) of a variable in the days (or time steps) that the +variable is exceeding (or not exceeding) a threshold during a period. The +threshold provided must be in the same units than the variable units, i.e. to +use a percentile as a scalar, the function \code{Threshold} or +\code{QThreshold} may be needed. Providing mean daily temperature data, the +following agriculture indices for heat stress can be obtained by using this +function: \itemize{ - \item\code{GDD}{Summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st}} + \item\code{GDD}{Summation of daily differences between daily average + temperatures and 10°C between April 1st and October 31st} +} } \examples{ # Assuming data is already (tasmax + tasmin)/2 - 10 diff --git a/man/CST_AbsToProbs.Rd b/man/CST_AbsToProbs.Rd index ec1bd8f..8ac3c37 100644 --- a/man/CST_AbsToProbs.Rd +++ b/man/CST_AbsToProbs.Rd @@ -15,25 +15,43 @@ CST_AbsToProbs( ) } \arguments{ -\item{data}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested +period.} -\item{memb_dim}{a character string indicating the name of the dimension in which the ensemble members are stored.} +\item{memb_dim}{A character string indicating the name of the dimension in +which the ensemble members are stored.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the probabilites in the element \code{data}. +An 's2dv_cube' object containing the probabilites in the element \code{data}. } \description{ -The Cumulative Distribution Function of a forecast is used to obtain the probabilities of each value in the ensemble. If multiple initializations (start dates) are provided, the function will create the Cumulative Distribution Function excluding the corresponding initialization. +The Cumulative Distribution Function of a forecast is used to obtain the +probabilities of each value in the ensemble. If multiple initializations +(start dates) are provided, the function will create the Cumulative +Distribution Function excluding the corresponding initialization. } \examples{ exp <- CSTools::lonlat_prec @@ -47,4 +65,5 @@ exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- CST_AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) + } diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 4fbcebc..9785f97 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -17,37 +17,59 @@ CST_AccumulationExceedingThreshold( ) } \arguments{ -\item{data}{a 's2dv_cube' object as provided by function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided by function \code{CST_Load} in +package CSTools.} -\item{threshold}{a 's2dv_cube' object as output of a 'CST_' function in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. A single scalar is also possible.} +\item{threshold}{An 's2dv_cube' object as output of a 'CST_' function in the +same units as parameter 'data' and with the common dimensions of the element +'data' of the same length. A single scalar is also possible.} -\item{op}{a opartor '>' (by default), '<', '>=' or '<='.} +\item{op}{An operator '>' (by default), '<', '>=' or '<='.} -\item{diff}{a logical value indicating whether to accumulate the difference between data and threshold (TRUE) or not (FALSE by default).} +\item{diff}{A logical value indicating whether to accumulate the difference +between data and threshold (TRUE) or not (FALSE by default).} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ A 's2dv_cube' object containing the indicator in the element \code{data}. } \description{ -The accumulation (sum) of a variable in the days (or time steps) that the variable is exceeding (or not exceeding) a threshold during a period. The threshold provided must be -in the same units than the variable units, i.e. to use a percentile as a scalar, -the function \code{Threshold} or \code{QThreshold} may be needed. -Providing mean daily temperature data, the following agriculture indices for heat stress can be obtained by using this function: +The accumulation (sum) of a variable in the days (or time steps) that the +variable is exceeding (or not exceeding) a threshold during a period. The +threshold provided must be in the same units than the variable units, i.e. to +use a percentile as a scalar, the function \code{Threshold} or +\code{QThreshold} may be needed. Providing mean daily temperature data, the +following agriculture indices for heat stress can be obtained by using this +function: \itemize{ - \item\code{GDD}{Summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st}} + \item\code{GDD}{Summation of daily differences between daily average + temperatures and 10°C between April 1st and October 31st} +} } \examples{ exp <- CSTools::lonlat_data$exp exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) + } diff --git a/man/CST_MergeRefToExp.Rd b/man/CST_MergeRefToExp.Rd index 61c1840..961eab9 100644 --- a/man/CST_MergeRefToExp.Rd +++ b/man/CST_MergeRefToExp.Rd @@ -17,29 +17,54 @@ CST_MergeRefToExp( ) } \arguments{ -\item{data1}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data1}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{data2}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data2}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{start1}{a list to defined the initial date of the period to select from data1 by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start1}{A list to defined the initial date of the period to select from +data1 by providing a list of two elements: the initial date of the period +and the initial month of the period.} -\item{end1}{a list to defined the final date of the period to select from data1 by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end1}{A list to defined the final date of the period to select from +data1 by providing a list of two elements: the final day of the period and +the final month of the period.} -\item{start2}{a list to defined the initial date of the period to select from data2 by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start2}{A list to defined the initial date of the period to select from +data2 by providing a list of two elements: the initial date of the period +and the initial month of the period.} -\item{end2}{a list to defined the final date of the period to select from data2 by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end2}{A list to defined the final date of the period to select from +data2 by providing a list of two elements: the final day of the period and +the final month of the period.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested period.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the indicator in the element \code{data}. +A 's2dv_cube' object containing the indicator in the element + \code{data}. } \description{ -Some indicators are defined for specific temporal periods (e.g.: summer from June 21st to September 21st). If the initialization forecast date is later than the one required for the indicator (e.g.: July 1st), the user may want to merge past observations, or other references, to the forecast (or hindcast) to compute the indicator. The function \code{MergeObs2Exp} takes care of this steps. If the forecast simulation doesn't cover the required period because it is initialized too early (e.g.: Initialization on November 1st the forecast covers until the beginning of June next year), a climatology (or other references) could be added at the end of the forecast lead time to cover the desired period (e.g.: until the end of summer). +Some indicators are defined for specific temporal periods (e.g.: summer from +June 21st to September 21st). If the initialization forecast date is later +than the one required for the indicator (e.g.: July 1st), the user may want to +merge past observations, or other references, to the forecast (or hindcast) +to compute the indicator. The function \code{MergeObs2Exp} takes care of this +steps. If the forecast simulation doesn't cover the required period because it +is initialized too early (e.g.: Initialization on November 1st the forecast +covers until the beginning of June next year), a climatology (or other +references) could be added at the end of the forecast lead time to cover the +desired period (e.g.: until the end of summer). } \examples{ data_dates <- c(seq(as.Date("01-07-1993", "\%d-\%m-\%Y", tz = 'UTC'), @@ -59,4 +84,5 @@ data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, new_data <- CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(21, 6), end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9)) + } diff --git a/man/CST_PeriodAccumulation.Rd b/man/CST_PeriodAccumulation.Rd index 0337a13..aea9560 100644 --- a/man/CST_PeriodAccumulation.Rd +++ b/man/CST_PeriodAccumulation.Rd @@ -14,27 +14,45 @@ CST_PeriodAccumulation( ) } \arguments{ -\item{data}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the indicator in the element \code{data}. +A 's2dv_cube' object containing the indicator in the element +\code{data}. } \description{ -Period Accumulation computes the sum (accumulation) of a given variable in a period. -Providing precipitation data, two agriculture indices can be obtained by using this function: +Period Accumulation computes the sum (accumulation) of a given variable in a +period. Providing precipitation data, two agriculture indices can be obtained +by using this function: \itemize{ - \item\code{SprR}{Spring Total Precipitation: The total precipitation from April 21th to June 21st} - \item\code{HarR}{Harvest Total Precipitation: The total precipitation from August 21st to October 21st}} + \item\code{SprR}{Spring Total Precipitation: The total precipitation from + April 21th to June 21st} + \item\code{HarR}{Harvest Total Precipitation: The total precipitation from + August 21st to October 21st} +} } \examples{ exp <- CSTools::lonlat_prec @@ -53,4 +71,5 @@ head(SprR$Dates) HarR <- CST_PeriodAccumulation(exp, start = list(21, 8), end = list(21, 10)) dim(HarR$data) head(HarR$Dates) + } diff --git a/man/CST_PeriodMean.Rd b/man/CST_PeriodMean.Rd index 1beefc5..574e476 100644 --- a/man/CST_PeriodMean.Rd +++ b/man/CST_PeriodMean.Rd @@ -14,27 +14,45 @@ CST_PeriodMean( ) } \arguments{ -\item{data}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the indicator in the element \code{data}. +An 's2dv_cube' object containing the indicator in the element + \code{data}. } \description{ Period Mean computes the average (mean) of a given variable in a period. -Providing temperature data, two agriculture indices can be obtain by using this function: +Providing temperature data, two agriculture indices can be obtained by using +this function: \itemize{ - \item\code{GST}{Growing Season average Temperature: The average temperature from April 1st to Octobe 31st} - \item\code{SprTX}{Spring Average Maximum Temperature: The average daily maximum temperature from April 1st to May 31st}} + \item\code{GST}{Growing Season average Temperature: The average temperature + from April 1st to Octobe 31st} + \item\code{SprTX}{Spring Average Maximum Temperature: The average daily + maximum temperature from April 1st to May 31st} +} } \examples{ exp <- CSTools::lonlat_data$exp diff --git a/man/CST_SelectPeriodOnData.Rd b/man/CST_SelectPeriodOnData.Rd index 2bac418..210fcaa 100644 --- a/man/CST_SelectPeriodOnData.Rd +++ b/man/CST_SelectPeriodOnData.Rd @@ -7,18 +7,28 @@ CST_SelectPeriodOnData(data, start, end, time_dim = "ftime", ncores = NULL) } \arguments{ -\item{data}{an 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in +package CSTools.} -\item{start}{a parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start}{A parameter to defined the initial date of the period to select +from the data by providing a list of two elements: the initial date of the +period and the initial month of the period.} -\item{end}{a parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end}{A parameter to defined the final date of the period to select from +the data by providing a list of two elements: the final day of the period +and the final month of the period.} -\item{time_dim}{a character string indicating the name of the dimension to compute select the dates. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the dimension to +compute select the dates. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the subset of the object \code{data$data} during the period requested from \code{start} to \code{end}. +A 's2dv_cube' object containing the subset of the object +\code{data$data} during the period requested from \code{start} to \code{end}. } \description{ Auxiliary function to subset data for a specific period. @@ -26,12 +36,13 @@ Auxiliary function to subset data for a specific period. \examples{ exp <- CSTools::lonlat_prec exp$data <- array(rnorm(5 * 3 * 214 * 2), - c(memb = 5, sdate = 3, ftime = 214, lon = 2)) + c(memb = 5, sdate = 3, ftime = 214, lon = 2)) exp$Dates[[1]] <- 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')) + 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')) Period <- CST_SelectPeriodOnData(exp, start = list(21, 6), end = list(21, 9)) + } diff --git a/man/CST_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index 8e65e58..d395ae6 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -16,37 +16,64 @@ CST_TotalSpellTimeExceedingThreshold( ) } \arguments{ -\item{data}{an 's2dv_cube' object as provided by function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided by function \code{CST_Load} in +package CSTools.} -\item{threshold}{an 's2dv_cube' object as output of a 'CST_' function in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. A single scalar is also possible. If \code{timd_dim} is in the dimension (with the same length as \code{data}), the comparison will be done day by day.} +\item{threshold}{An 's2dv_cube' object as output of a 'CST_' function in the +same units as parameter 'data' and with the common dimensions of the element +'data' of the same length. A single scalar is also possible. If +\code{timd_dim} is in the dimension (with the same length as \code{data}), +the comparison will be done day by day.} -\item{spell}{a scalar indicating the minimum length of the spell.} +\item{spell}{A scalar indicating the minimum length of the spell.} -\item{op}{a opartor '>' (by default), '<', '>=' or '<='.} +\item{op}{An operator '>' (by default), '<', '>=' or '<='.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the indicator in the element \code{data}. +An 's2dv_cube' object containing the indicator in the element +\code{data}. } \description{ -The number of days (when daily data is provided) that are part of a spell (defined by its minimum length e.g. 6 consecutive days) that exceed (or not exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. -This function allows to compute indicators widely used in Climate Services, such as: +The number of days (when daily data is provided) that are part of a spell +(defined by its minimum length e.g. 6 consecutive days) that exceed (or not +exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. +This function allows to compute indicators widely used in Climate Services, +such as: \itemize{ -\code{WSDI}{Warm Spell Duration Index that count the total number of days with at least 6 consecutive days when the daily temperature maximum exceeds its 90th percentile.}} -This function requires the data and the threshold to be in the same units. The 90th percentile can be translate into absolute values given a reference dataset using function \code{Threshold} or the data can be transform into probabilites by using function \code{AbsToProbs}. See section @examples. +\code{WSDI}{Warm Spell Duration Index that count the total number of days + with at least 6 consecutive days when the daily temperature + maximum exceeds its 90th percentile.} +} +This function requires the data and the threshold to be in the same units. The +90th percentile can be translate into absolute values given a reference dataset +using function \code{Threshold} or the data can be transform into probabilites +by using function \code{AbsToProbs}. See section @examples. } \examples{ exp <- CSTools::lonlat_data$exp exp$data <- array(rnorm(5 * 3 * 20 * 2, mean = 25, sd = 3), - c(member = 5, sdate = 3, ftime = 20, lon = 2)) + c(member = 5, sdate = 3, ftime = 20, lon = 2)) TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 23, spell = 3) + } \seealso{ [Threshold()] and [AbsToProbs()]. diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index e1d3c7d..3c5c11f 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -16,41 +16,67 @@ CST_TotalTimeExceedingThreshold( ) } \arguments{ -\item{data}{a 's2dv_cube' object as provided by function \code{CST_Load} in package CSTools.} +\item{data}{An 's2dv_cube' object as provided by function \code{CST_Load} in +package CSTools.} -\item{threshold}{a 's2dv_cube' object as output of a 'CST_' function in the same units as parameter \code{data} and with the common dimensions of the element \code{data} of the same length (e.g. an array with the same lengths of longitude and latitude). A single scalar is also possible (for the case of comparing all grid points with the same scalar).} +\item{threshold}{An 's2dv_cube' object as output of a 'CST_' function in the +same units as parameter \code{data} and with the common dimensions of the +element \code{data} of the same length (e.g. an array with the same lengths +of longitude and latitude). A single scalar is also possible (for the case +of comparing all grid points with the same scalar).} -\item{op}{a opartor '>' (by default), '<', '>=' or '<='.} +\item{op}{An operator '>' (by default), '<', '>=' or '<='.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A 's2dv_cube' object containing the indicator in the element \code{data}. +An 's2dv_cube' object containing the indicator in the element +\code{data}. } \description{ -The Total Time of a variable exceeding (or not) a Threshold returns the total number of days -(if the data provided is daily, or the corresponding units to the data frequency provided) -that a variable is exceeding a threshold during a period. The threshold provided must be -in the same units than the variable units, i.e. to use a percentile as a scalar, -the function \code{AbsToProbs} or \code{QThreshold} may be needed (see examples). -Providing maximum temperature daily data, the following agriculture indices for heat stress can be obtained by using this function: +The Total Time of a variable exceeding (or not) a Threshold returns the total +number of days (if the data provided is daily, or the corresponding units to +the data frequency provided) that a variable is exceeding a threshold during a +period. The threshold provided must be in the same units than the variable +units, i.e. to use a percentile as a scalar, +the function \code{AbsToProbs} or \code{QThreshold} may be needed (see +examples). Providing maximum temperature daily data, the following agriculture +indices for heat stress can be obtained by using this function: \itemize{ - \item\code{SU35}{Total count of days when daily maximum temperatures exceed 35°C in the seven months from the start month given (e.g. from April to October for start month of April).} - \item\code{SU36}{Total count of days when daily maximum temperatures exceed 36 between June 21st and September 21st} - \item\code{SU40}{Total count of days when daily maximum temperatures exceed 40 between June 21st and September 21st} - \item\code{Spr32}{Total count of days when daily maximum temperatures exceed 32 between April 21st and June 21st} + \item\code{SU35}{Total count of days when daily maximum temperatures exceed + 35°C in the seven months from the start month given (e.g. + from April to October for start month of April).} + \item\code{SU36}{Total count of days when daily maximum temperatures exceed + 36 between June 21st and September 21st} + \item\code{SU40}{Total count of days when daily maximum temperatures exceed + 40 between June 21st and September 21st} + \item\code{Spr32}{Total count of days when daily maximum temperatures exceed + 32 between April 21st and June 21st} } } \examples{ exp <- CSTools::lonlat_data$exp exp$data <- CSTools::lonlat_data$exp$data[1, 1, 3, 3, 1, 1] DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) + } diff --git a/man/CST_WindCapacityFactor.Rd b/man/CST_WindCapacityFactor.Rd index 9e0a46c..28f437f 100644 --- a/man/CST_WindCapacityFactor.Rd +++ b/man/CST_WindCapacityFactor.Rd @@ -14,38 +14,62 @@ CST_WindCapacityFactor( ) } \arguments{ -\item{wind}{a s2dv_cube object with instantaneous wind speeds expressed in m/s.} +\item{wind}{An s2dv_cube object with instantaneous wind speeds expressed in m/s.} -\item{IEC_class}{a string indicating the IEC wind class (see IEC 61400-1) of the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s respectively. Classes \code{'I/II'} and \code{'II/III'} indicate intermediate turbines that fit both classes. More details of the five turbines and a plot of its power curves can be found in Lledó et al. (2019).} +\item{IEC_class}{A string indicating the IEC wind class (see IEC 61400-1) of +the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} +are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s +respectively. Classes \code{'I/II'} and \code{'II/III'} indicate +intermediate turbines that fit both classes. More details of the five +turbines and a plot of its power curves can be found in Lledó et al. (2019).} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation for temporal subsetting.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation for temporal subsetting.} } \value{ -A s2dv_cube object containing the Wind Capacity Factor (unitless). +An s2dv_cube object containing the Wind Capacity Factor (unitless). } \description{ -Wind capacity factor computes the wind power generated by a specific wind turbine model under specific wind speed conditions, and expresses it as a fraction of the rated capacity (i.e. maximum power) of the turbine. +Wind capacity factor computes the wind power generated by a +specific wind turbine model under specific wind speed conditions, and +expresses it as a fraction of the rated capacity (i.e. maximum power) of the +turbine. -It is computed by means of a tabular power curve that relates wind speed to power output. The tabular values are interpolated with a linear piecewise approximating function to obtain a smooth power curve. Five different power curves that span different IEC classes can be selected (see below). +It is computed by means of a tabular power curve that relates +wind speed to power output. The tabular values are interpolated with a linear +piecewise approximating function to obtain a smooth power curve. Five +different power curves that span different IEC classes can be selected (see +below). } \examples{ wind <- array(rweibull(n = 100, shape = 2, scale = 6), c(member = 10, lat = 2, lon = 5)) wind <- CSTools::s2dv_cube(data = wind, lat = c(40, 41), lon = 1:5, - Variable = list(varName = 'sfcWind', level = 'Surface'), - Datasets = 'synthetic', when = Sys.time(), - Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), - source_file = NA) + Variable = list(varName = 'sfcWind', level = 'Surface'), + Datasets = 'synthetic', when = Sys.time(), + Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), + source_file = NA) WCF <- CST_WindCapacityFactor(wind, IEC_class = "III") } \references{ -Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 +Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). +Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 International Standard IEC 61400-1 (third ed.) (2005) } diff --git a/man/CST_WindPowerDensity.Rd b/man/CST_WindPowerDensity.Rd index 8033bfe..9e53457 100644 --- a/man/CST_WindPowerDensity.Rd +++ b/man/CST_WindPowerDensity.Rd @@ -14,33 +14,49 @@ CST_WindPowerDensity( ) } \arguments{ -\item{wind}{a s2dv_cube object with instantaneous wind speeds expressed in m/s obtained from CST_Load or s2dv_cube functions from CSTools pacakge} +\item{wind}{An s2dv_cube object with instantaneous wind speeds expressed in m/s +obtained from CST_Load or s2dv_cube functions from CSTools pacakge.} -\item{ro}{a scalar, or alternatively a multidimensional array with the same dimensions as wind, with the air density expressed in kg/m^3. By default it takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa.} +\item{ro}{A scalar, or alternatively a multidimensional array with the same +dimensions as wind, with the air density expressed in kg/m^3. By default it +takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation for temporal subsetting.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation for temporal subsetting.} } \value{ -A s2dv_cube object containing Wind Power Density expressed in W/m^2. +An s2dv_cube object containing Wind Power Density expressed in W/m^2. } \description{ -Wind Power Density computes the wind power that is available for extraction per square meter of swept area. +Wind Power Density computes the wind power that is available for +extraction per square meter of swept area. -It is computed as 0.5*ro*wspd^3. As this function is non-linear, it will give inaccurate results if used with period means. +It is computed as 0.5*ro*wspd^3. As this function is non-linear, +it will give inaccurate results if used with period means. } \examples{ wind <- array(rweibull(n = 100, shape = 2, scale = 6), c(member = 10, lat = 2, lon = 5)) wind <- CSTools::s2dv_cube(data = wind, lat = c(40, 41), lon = 1:5, - Variable = list(varName = 'sfcWind', level = 'Surface'), - Datasets = 'synthetic', when = Sys.time(), - Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), - source_file = NA) + Variable = list(varName = 'sfcWind', level = 'Surface'), + Datasets = 'synthetic', when = Sys.time(), + Dates = list(start = '1990-01-01 00:00:00', end = '1990-01-01 00:00:00'), + source_file = NA) WPD <- CST_WindPowerDensity(wind) } diff --git a/man/MergeRefToExp.Rd b/man/MergeRefToExp.Rd index 9826df7..32e8627 100644 --- a/man/MergeRefToExp.Rd +++ b/man/MergeRefToExp.Rd @@ -19,33 +19,53 @@ MergeRefToExp( ) } \arguments{ -\item{data1}{a multidimensional array with named dimensions.} +\item{data1}{A multidimensional array with named dimensions.} -\item{dates1}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data1'.} +\item{dates1}{a vector of dates or a multidimensional array of dates with +named dimensions matching the dimensions on parameter 'data1'.} -\item{start1}{a list to defined the initial date of the period to select from data1 by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start1}{A list to defined the initial date of the period to select from +data1 by providing a list of two elements: the initial date of the period +and the initial month of the period.} -\item{end1}{a list to defined the final date of the period to select from data1 by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end1}{A list to defined the final date of the period to select from +data1 by providing a list of two elements: the final day of the period and +the final month of the period.} -\item{data2}{a multidimensional array with named dimensions.} +\item{data2}{A multidimensional array with named dimensions.} -\item{dates2}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data2'.} +\item{dates2}{A vector of dates or a multidimensional array of dates with +named dimensions matching the dimensions on parameter 'data2'.} -\item{start2}{a list to defined the initial date of the period to select from data2 by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start2}{A list to defined the initial date of the period to select from +data2 by providing a list of two elements: the initial date of the period +and the initial month of the period.} -\item{end2}{a list to defined the final date of the period to select from data2 by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end2}{A list to defined the final date of the period to select from +data2 by providing a list of two elements: the final day of the period and +the final month of the period.} -\item{time_dim}{a character string indicating the name of the temporal dimension. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified. This dimension is required to subset the data in a requested period.} +\item{time_dim}{A character string indicating the name of the temporal +dimension. By default, it is set to 'ftime'. More than one dimension name +matching the dimensions provided in the object \code{data$data} can be +specified. This dimension is required to subset the data in a requested period.} -\item{sdate_dim}{a character string indicating the name of the dimension in which the initialization dates are stored.} +\item{sdate_dim}{A character string indicating the name of the dimension in +which the initialization dates are stored.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ A multidimensional array with named dimensions. } \description{ -Some indicators are defined for specific temporal periods (e.g.: summer from June 21st to September 21st). If the initialization forecast date is later than the one required for the indicator (e.g.: July 1st), the user may want to merge past observations, or other reference, to the forecast (or hindcast) to compute the indicator. The function \code{MergeObs2Exp} takes care of this steps. +Some indicators are defined for specific temporal periods (e.g.: summer from +June 21st to September 21st). If the initialization forecast date is later +than the one required for the indicator (e.g.: July 1st), the user may want to +merge past observations, or other reference, to the forecast (or hindcast) to +compute the indicator. The function \code{MergeObs2Exp} takes care of this +steps. } \examples{ data_dates <- c(seq(as.Date("01-07-1993", "\%d-\%m-\%Y", tz = 'UTC'), @@ -61,4 +81,5 @@ data <- array(1:(2*154*2), c(time = 154, sdate = 2, member= 2)) new_data <- MergeRefToExp(data1 = ref, dates1 = ref_dates, start1 = list(21, 6), end1 = list(30, 6), data2 = data, dates2 = data_dates, start2 = list(1, 7), end = list(21, 9)) + } diff --git a/man/PeriodAccumulation.Rd b/man/PeriodAccumulation.Rd index fbc225a..3fa9bb8 100644 --- a/man/PeriodAccumulation.Rd +++ b/man/PeriodAccumulation.Rd @@ -15,29 +15,48 @@ PeriodAccumulation( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'time'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +indicator in the element \code{data}. } \description{ -Period Accumulation computes the sum (accumulation) of a given variable in a period. -Providing precipitation data, two agriculture indices can be obtained by using this function: +Period Accumulation computes the sum (accumulation) of a given variable in a +period. Providing precipitation data, two agriculture indices can be obtained +by using this function: \itemize{ - \item\code{SprR}{Spring Total Precipitation: The total precipitation from April 21th to June 21st} - \item\code{HarR}{Harvest Total Precipitation: The total precipitation from August 21st to October 21st}} + \item\code{SprR}{Spring Total Precipitation: The total precipitation from + April 21th to June 21st} + \item\code{HarR}{Harvest Total Precipitation: The total precipitation from + August 21st to October 21st} +} } \examples{ exp <- CSTools::lonlat_prec$data @@ -53,4 +72,5 @@ Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) SprR <- PeriodAccumulation(data, dates = Dates, start = list(21, 4), end = list(21, 6)) HarR <- PeriodAccumulation(data, dates = Dates, start = list(21, 8), end = list(21, 10)) + } diff --git a/man/PeriodMean.Rd b/man/PeriodMean.Rd index 6062daa..19fb9bf 100644 --- a/man/PeriodMean.Rd +++ b/man/PeriodMean.Rd @@ -15,31 +15,51 @@ PeriodMean( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +indicator in the element \code{data}. } \description{ Period Mean computes the average (mean) of a given variable in a period. -Providing temperature data, two agriculture indices can be obtain by using this function: +Providing temperature data, two agriculture indices can be obtained by using +this function: \itemize{ - \item\code{GST}{Growing Season average Temperature: The average temperature from April 1st to Octobe 31st} - \item\code{SprTX}{Spring Average Maximum Temperature: The average daily maximum temperature from April 1st to May 31st}} + \item\code{GST}{Growing Season average Temperature: The average + temperature from April 1st to Octobe 31st} + \item\code{SprTX}{Spring Average Maximum Temperature: The average daily + maximum temperature from April 1st to May 31st} +} } \examples{ exp <- CSTools::lonlat_prec$data SA <- PeriodMean(exp, time_dim = 'ftime') + } diff --git a/man/SelectPeriodOnData.Rd b/man/SelectPeriodOnData.Rd index dabb190..118cb98 100644 --- a/man/SelectPeriodOnData.Rd +++ b/man/SelectPeriodOnData.Rd @@ -7,32 +7,43 @@ SelectPeriodOnData(data, dates, start, end, time_dim = "ftime", ncores = NULL) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period.} -\item{time_dim}{a character string indicating the name of the dimension to compute select the dates. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the dimension to +compute select the dates. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the subset +of the object \code{data} during the period requested from \code{start} to +\code{end}. } \description{ Auxiliary function to subset data for a specific period. } \examples{ data <- array(rnorm(5 * 3 * 214 * 2), - c(memb = 5, sdate = 3, ftime = 214, lon = 2)) + c(memb = 5, sdate = 3, ftime = 214, lon = 2)) 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"), + 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"), + seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) dim(Dates) <- c(ftime = 214, sdate = 3) Period <- SelectPeriodOnData(data, Dates, start = list(21, 6), end = list(21, 9)) diff --git a/man/SelectPeriodOnDates.Rd b/man/SelectPeriodOnDates.Rd index 2cd553a..cce8e55 100644 --- a/man/SelectPeriodOnDates.Rd +++ b/man/SelectPeriodOnDates.Rd @@ -7,18 +7,28 @@ SelectPeriodOnDates(dates, start, end, time_dim = "ftime", ncores = NULL) } \arguments{ -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period.} -\item{time_dim}{a character string indicating the name of the dimension to compute select the dates. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the dimension to +compute select the dates. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the subset of +the vector dates during the period requested from \code{start} to \code{end}. } \description{ Auxiliary function to subset dates for a specific period. @@ -26,9 +36,9 @@ Auxiliary function to subset dates for a specific period. \examples{ 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"), + 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"), + seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) Period <- SelectPeriodOnDates(Dates, start = list(21, 6), end = list(21, 9)) } diff --git a/man/TotalSpellTimeExceedingThreshold.Rd b/man/TotalSpellTimeExceedingThreshold.Rd index bbbfe35..2bcebfa 100644 --- a/man/TotalSpellTimeExceedingThreshold.Rd +++ b/man/TotalSpellTimeExceedingThreshold.Rd @@ -17,41 +17,70 @@ TotalSpellTimeExceedingThreshold( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{threshold}{a multidimensional array with named dimensions in the same units as parameter 'data' and with the common dimensions of the element 'data' of the same length. If \code{timd_dim} is in the dimension (with the same length as \code{data}), the comparison will be done day by day.} +\item{threshold}{A multidimensional array with named dimensions in the same +units as parameter 'data' and with the common dimensions of the element +'data' of the same length. If \code{timd_dim} is in the dimension (with the +same length as \code{data}), the comparison will be done day by day.} -\item{spell}{a scalar indicating the minimum length of the spell.} +\item{spell}{A scalar indicating the minimum length of the spell.} -\item{op}{a opartor '>' (by default), '<', '>=' or '<='.} +\item{op}{An operator '>' (by default), '<', '>=' or '<='.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the indicator +in the element \code{data}. } \description{ -The number of days (when daily data is provided) that are part of a spell (defined by its minimum length e.g. 6 consecutive days) that exceed (or not exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. -This function allows to compute indicators widely used in Climate Services, such as: +The number of days (when daily data is provided) that are part of a spell +(defined by its minimum length e.g. 6 consecutive days) that exceed (or not +exceed) a threshold are calculated with \code{TotalSpellTimeExceedingThreshold}. +This function allows to compute indicators widely used in Climate Services, +such as: \itemize{ -\code{WSDI}{Warm Spell Duration Index that count the total number of days with at least 6 consecutive days when the daily temperature maximum exceeds its 90th percentile.}} -This function requires the data and the threshold to be in the same units. The 90th percentile can be translate into absolute values given a reference dataset using function \code{Threshold} or the data can be transform into probabilites by using function \code{AbsToProbs}. See section @examples. +\code{WSDI}{Warm Spell Duration Index that count the total number of days + with at least 6 consecutive days when the daily temperature + maximum exceeds its 90th percentile.} +} +This function requires the data and the threshold to be in the same units. The +90th percentile can be translate into absolute values given a reference +dataset using function \code{Threshold} or the data can be transform into +probabilites by using function \code{AbsToProbs}. See section @examples. } \details{ -This function considers NA values as the end of the spell. For a different behaviour consider to modify the 'data' input by substituting NA values by values exceeding the threshold. +This function considers NA values as the end of the spell. For a +different behaviour consider to modify the 'data' input by substituting NA +values by values exceeding the threshold. } \examples{ data <- array(rnorm(120), c(member = 1, sdate = 2, time = 20, lat = 4)) threshold <- array(rnorm(4), c(lat = 4)) total <- TotalSpellTimeExceedingThreshold(data, threshold, spell = 6) + } \seealso{ [Threshold()] and [AbsToProbs()]. diff --git a/man/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 855ef86..119d392 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -17,39 +17,64 @@ TotalTimeExceedingThreshold( ) } \arguments{ -\item{data}{a multidimensional array with named dimensions.} +\item{data}{A multidimensional array with named dimensions.} -\item{threshold}{a multidimensional array with named dimensions in the same units as parameter \code{data} and with the common dimensions of the element \code{data} of the same length (e.g. an array with the same lengths of longitude and latitude). A single scalar is also possible (for the case of comparing all grid points with the same scalar).} +\item{threshold}{A multidimensional array with named dimensions in the same +units as parameter \code{data} and with the common dimensions of the element +\code{data} of the same length (e.g. an array with the same lengths of +longitude and latitude). A single scalar is also possible (for the case of +comparing all grid points with the same scalar).} -\item{op}{a opartor '>' (by default), '<', '>=' or '<='.} +\item{op}{A operator '>' (by default), '<', '>=' or '<='.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'time'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{na.rm}{a logical value indicating whether to ignore NA values (TRUE) or not (FALSE).} +\item{na.rm}{A logical value indicating whether to ignore NA values (TRUE) or +not (FALSE).} -\item{ncores}{an integer indicating the number of cores to use in parallel computation.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation.} } \value{ -A multidimensional array with named dimensions. +A multidimensional array with named dimensions containing the +indicator in the element \code{data}. } \description{ -The Total Time of a variable exceeding (or not) a Threshold returns the total number of days -(if the data provided is daily, or the corresponding units to the data frequency provided) -that a variable is exceeding a threshold during a period. The threshold provided must be -in the same units than the variable units, i.e. to use a percentile as a threshold, -the function \code{Threshold} or \code{QThreshold} may be needed (see examples). -Providing maximum temperature daily data, the following agriculture indices for heat stress can be obtained by using this function: +The Total Time of a variable exceeding (or not) a Threshold returns the total +number of days (if the data provided is daily, or the corresponding units to +the data frequency provided) that a variable is exceeding a threshold during a +period. The threshold provided must be in the same units than the variable +units, i.e. to use a percentile as a threshold, the function \code{Threshold} +or \code{QThreshold} may be needed (see examples). Providing maximum +temperature daily data, the following agriculture indices for heat stress can +be obtained by using this function: \itemize{ - \item\code{SU35}{Total count of days when daily maximum temperatures exceed 35°C} - \item\code{SU36}{Total count of days when daily maximum temperatures exceed 36 between June 21st and September 21st} - \item\code{SU40}{Total count of days when daily maximum temperatures exceed 40 between June 21st and September 21st} - \item\code{Spr32}{Total count of days when daily maximum temperatures exceed 32 between April 21st and June 21st} + \item\code{SU35}{Total count of days when daily maximum temperatures exceed + 35°C} + \item\code{SU36}{Total count of days when daily maximum temperatures exceed + 36 between June 21st and September 21st} + \item\code{SU40}{Total count of days when daily maximum temperatures exceed + 40 between June 21st and September 21st} + \item\code{Spr32}{Total count of days when daily maximum temperatures exceed + 32 between April 21st and June 21st} } } \examples{ diff --git a/man/WindCapacityFactor.Rd b/man/WindCapacityFactor.Rd index 935a3e3..4779ff0 100644 --- a/man/WindCapacityFactor.Rd +++ b/man/WindCapacityFactor.Rd @@ -15,27 +15,54 @@ WindCapacityFactor( ) } \arguments{ -\item{wind}{a multidimensional array, vector or scalar with instantaneous wind speeds expressed in m/s.} +\item{wind}{A multidimensional array, vector or scalar with instantaneous wind +speeds expressed in m/s.} -\item{IEC_class}{a string indicating the IEC wind class (see IEC 61400-1) of the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s respectively. Classes \code{'I/II'} and \code{'II/III'} indicate intermediate turbines that fit both classes. More details of the five turbines and a plot of its power curves can be found in Lledó et al. (2019).} +\item{IEC_class}{A string indicating the IEC wind class (see IEC 61400-1) of +the turbine to be selected. Classes \code{'I'}, \code{'II'} and \code{'III'} +are suitable for sites with an annual mean wind speed of 10, 8.5 and 7.5 m/s +respectively. Classes \code{'I/II'} and \code{'II/III'} indicate +intermediate turbines that fit both classes. More details of the five +turbines and a plot of its power curves can be found in Lledó et al. (2019).} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation for temporal subsetting.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation for temporal subsetting.} } \value{ -An array with the same dimensions as wind, containing the Wind Capacity Factor (unitless). +An array with the same dimensions as wind, containing the Wind + Capacity Factor (unitless). } \description{ -Wind capacity factor computes the wind power generated by a specific wind turbine model under specific wind speed conditions, and expresses it as a fraction of the rated capacity (i.e. maximum power) of the turbine. +Wind capacity factor computes the wind power generated by a +specific wind turbine model under specific wind speed conditions, and +expresses it as a fraction of the rated capacity (i.e. maximum power) of the +turbine. -It is computed by means of a tabular power curve that relates wind speed to power output. The tabular values are interpolated with a linear piecewise approximating function to obtain a smooth power curve. Five different power curves that span different IEC classes can be selected (see below). +It is computed by means of a tabular power curve that relates +wind speed to power output. The tabular values are interpolated with a linear +piecewise approximating function to obtain a smooth power curve. Five +different power curves that span different IEC classes can be selected (see +below). } \examples{ wind <- rweibull(n = 100, shape = 2, scale = 6) @@ -43,7 +70,8 @@ WCF <- WindCapacityFactor(wind, IEC_class = "III") } \references{ -Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 +Lledó, Ll., Torralba, V., Soret, A., Ramon, J., & Doblas-Reyes, F. J. (2019). +Seasonal forecasts of wind power generation. Renewable Energy, 143, 91–100. https://doi.org/10.1016/j.renene.2019.04.135 International Standard IEC 61400-1 (third ed.) (2005) } diff --git a/man/WindPowerDensity.Rd b/man/WindPowerDensity.Rd index 5642edb..af919a6 100644 --- a/man/WindPowerDensity.Rd +++ b/man/WindPowerDensity.Rd @@ -15,27 +15,46 @@ WindPowerDensity( ) } \arguments{ -\item{wind}{a multidimensional array, vector or scalar with instantaneous wind speeds expressed in m/s.} +\item{wind}{A multidimensional array, vector or scalar with instantaneous wind +speeds expressed in m/s.} -\item{ro}{a scalar, or alternatively a multidimensional array with the same dimensions as wind, with the air density expressed in kg/m^3. By default it takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa.} +\item{ro}{A scalar, or alternatively a multidimensional array with the same +dimensions as wind, with the air density expressed in kg/m^3. By default it +takes the value 1.225, the standard density of air at 15ºC and 1013.25 hPa.} -\item{dates}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} +\item{dates}{A vector of dates or a multidimensional array of dates with named +dimensions matching the dimensions on parameter 'data'. By default it is +NULL, to select a period this parameter must be provided.} -\item{start}{an optional parameter to defined the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{start}{An optional parameter to defined the initial date of the period +to select from the data by providing a list of two elements: the initial +date of the period and the initial month of the period. By default it is set +to NULL and the indicator is computed using all the data provided in +\code{data}.} -\item{end}{an optional parameter to defined the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} +\item{end}{An optional parameter to defined the final date of the period to +select from the data by providing a list of two elements: the final day of +the period and the final month of the period. By default it is set to NULL +and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{a character string indicating the name of the function to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} +\item{time_dim}{A character string indicating the name of the function to +compute the indicator. By default, it is set to 'ftime'. More than one +dimension name matching the dimensions provided in the object +\code{data$data} can be specified.} -\item{ncores}{an integer indicating the number of cores to use in parallel computation for temporal subsetting.} +\item{ncores}{An integer indicating the number of cores to use in parallel +computation for temporal subsetting.} } \value{ -An array with the same dimensions as wind, containing Wind Power Density expressed in W/m^2. +An array with the same dimensions as wind, containing Wind Power +Density expressed in W/m^2. } \description{ -Wind Power Density computes the wind power that is available for extraction per square meter of swept area. +Wind Power Density computes the wind power that is available for +extraction per square meter of swept area. -It is computed as 0.5*ro*wspd^3. As this function is non-linear, it will give inaccurate results if used with period means. +It is computed as 0.5*ro*wspd^3. As this function is non-linear, +it will give inaccurate results if used with period means. } \examples{ wind <- rweibull(n = 100, shape = 2, scale = 6) -- GitLab From 74b261f3e044ee24df28aebe76a6b959fd34f9b3 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 23 Sep 2022 12:53:59 +0200 Subject: [PATCH 15/26] Correct formatting --- R/AbsToProbs.R | 32 ++++++++++++++++---------------- R/MergeRefToExp.R | 16 ++++++++-------- R/PeriodAccumulation.R | 14 +++++++------- R/QThreshold.R | 10 +++++----- R/Threshold.R | 32 ++++++++++++++++---------------- man/AbsToProbs.Rd | 16 ++++++++-------- man/CST_AbsToProbs.Rd | 16 ++++++++-------- man/CST_MergeRefToExp.Rd | 8 ++++---- man/CST_PeriodAccumulation.Rd | 10 +++++----- man/CST_QThreshold.Rd | 10 +++++----- man/CST_Threshold.Rd | 10 +++++----- man/MergeRefToExp.Rd | 8 ++++---- man/PeriodAccumulation.Rd | 4 ++-- man/Threshold.Rd | 6 +++--- 14 files changed, 96 insertions(+), 96 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index 155d745..ce5f01a 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -7,12 +7,12 @@ #' #'@param data An 's2dv_cube' object as provided function \code{CST_Load} in #' package CSTools. -#'@param start An optional parameter to defined the initial date of the period +#'@param start An optional parameter to define the initial date of the period #' to select from the data by providing a list of two elements: the initial #' date of the period and the initial month of the period. By default it is set #' to NULL and the indicator is computed using all the data provided in #' \code{data}. -#'@param end An optional parameter to defined the final date of the period to +#'@param end An optional parameter to define the final date of the period to #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. @@ -34,13 +34,13 @@ #'exp <- CSTools::lonlat_prec #'exp_probs <- CST_AbsToProbs(exp) #'exp$data <- array(rnorm(5 * 3 * 214 * 2), -#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) +#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) #'exp$Dates[[1]] <- 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')) +#' 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')) #'exp_probs <- CST_AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) #' #'@import multiApply @@ -90,12 +90,12 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #'@param dates A vector of dates or a multidimensional array of dates with named #' dimensions matching the dimensions on parameter 'data'. By default it is #' NULL, to select a period this parameter must be provided. -#'@param start An optional parameter to defined the initial date of the period +#'@param start An optional parameter to define the initial date of the period #' to select from the data by providing a list of two elements: the initial #' date of the period and the initial month of the period. By default it is set #' to NULL and the indicator is computed using all the data provided in #' \code{data}. -#'@param end An optional parameter to defined the final date of the period to +#'@param end An optional parameter to define the final date of the period to #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. @@ -118,13 +118,13 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #'exp <- CSTools::lonlat_prec$data #'exp_probs <- AbsToProbs(exp) #'data <- array(rnorm(5 * 2 * 61 * 1), -#' c(member = 5, sdate = 2, ftime = 61, lon = 1)) +#' c(member = 5, sdate = 2, ftime = 61, lon = 1)) #'Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), -#' as.Date("30-06-2000", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), -#' as.Date("30-06-2001", format = "%d-%m-%Y"), by = 'day'), -#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), -#' as.Date("30-06-2002", format = "%d-%m-%Y"), by = 'day')) +#' as.Date("30-06-2000", format = "%d-%m-%Y"), by = 'day'), +#' seq(as.Date("01-05-2001", format = "%d-%m-%Y"), +#' as.Date("30-06-2001", format = "%d-%m-%Y"), by = 'day'), +#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), +#' as.Date("30-06-2002", format = "%d-%m-%Y"), by = 'day')) #'exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) #' #'@import multiApply diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 3332ffb..837d304 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -15,16 +15,16 @@ #' package CSTools. #'@param data2 An 's2dv_cube' object as provided function \code{CST_Load} in #' package CSTools. -#'@param start1 A list to defined the initial date of the period to select from +#'@param start1 A list to define the initial date of the period to select from #' data1 by providing a list of two elements: the initial date of the period #' and the initial month of the period. -#'@param end1 A list to defined the final date of the period to select from +#'@param end1 A list to define the final date of the period to select from #' data1 by providing a list of two elements: the final day of the period and #' the final month of the period. -#'@param start2 A list to defined the initial date of the period to select from +#'@param start2 A list to define the initial date of the period to select from #' data2 by providing a list of two elements: the initial date of the period #' and the initial month of the period. -#'@param end2 A list to defined the final date of the period to select from +#'@param end2 A list to define the final date of the period to select from #' data2 by providing a list of two elements: the final day of the period and #' the final month of the period. #'@param time_dim A character string indicating the name of the temporal @@ -134,16 +134,16 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, #'@param data2 A multidimensional array with named dimensions. #'@param dates2 A vector of dates or a multidimensional array of dates with #' named dimensions matching the dimensions on parameter 'data2'. -#'@param start1 A list to defined the initial date of the period to select from +#'@param start1 A list to define the initial date of the period to select from #' data1 by providing a list of two elements: the initial date of the period #' and the initial month of the period. -#'@param end1 A list to defined the final date of the period to select from +#'@param end1 A list to define the final date of the period to select from #' data1 by providing a list of two elements: the final day of the period and #' the final month of the period. -#'@param start2 A list to defined the initial date of the period to select from +#'@param start2 A list to define the initial date of the period to select from #' data2 by providing a list of two elements: the initial date of the period #' and the initial month of the period. -#'@param end2 A list to defined the final date of the period to select from +#'@param end2 A list to define the final date of the period to select from #' data2 by providing a list of two elements: the final day of the period and #' the final month of the period. #'@param time_dim A character string indicating the name of the temporal diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 2782af3..92ec947 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -39,11 +39,11 @@ #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) #'exp$Dates[[1]] <- 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')) +#' 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')) #'SprR <- CST_PeriodAccumulation(exp, start = list(21, 4), end = list(21, 6)) #'dim(SprR$data) #'head(SprR$Dates) @@ -130,9 +130,9 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, #'# ftime tested #'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"), +#' 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"), +#' seq(as.Date("01-05-2002", format = "%d-%m-%Y"), #' as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day')) #'SprR <- PeriodAccumulation(data, dates = Dates, start = list(21, 4), end = list(21, 6)) #'HarR <- PeriodAccumulation(data, dates = Dates, start = list(21, 8), end = list(21, 10)) diff --git a/R/QThreshold.R b/R/QThreshold.R index f0bb736..6b4359d 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -58,11 +58,11 @@ #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) #'exp$Dates[[1]] <- 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')) +#' 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')) #'exp_probs <- CST_QThreshold(exp, threshold, start = list(21, 4), end = list(21, 6)) #' #'@import multiApply diff --git a/R/Threshold.R b/R/Threshold.R index 8112cf6..755c2e6 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -43,19 +43,19 @@ #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) #'exp$Dates[[1]] <- 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')) +#' 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')) #'exp_probs <- CST_Threshold(exp, threshold, start = list(21, 4), end = list(21, 6)) #' #'@import multiApply #'@export CST_Threshold <- function(data, threshold, start = NULL, end = NULL, - time_dim = 'ftime', memb_dim = 'member', sdate_dim = 'sdate', - na.rm = FALSE, ncores = NULL) { - if (!inherits(data, 's2dv_cube')) { + time_dim = 'ftime', memb_dim = 'member', sdate_dim = 'sdate', + na.rm = FALSE, ncores = NULL) { + if (!inherits(data, 's2dv_cube')) { stop("Parameter 'data' must be of the class 's2dv_cube', ", "as output by CSTools::CST_Load.") } @@ -75,22 +75,22 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, } } thres <- Threshold(data$data, threshold, data$Dates[[1]], start, end, - time_dim = time_dim, memb_dim = memb_dim, - sdate_dim = sdate_dim, na.rm = na.rm, ncores = ncores) + time_dim = time_dim, memb_dim = memb_dim, + sdate_dim = sdate_dim, na.rm = na.rm, ncores = ncores) data$data <- thres if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates[[1]], - start = start, end = end, - time_dim = time_dim, ncores = ncores) + start = start, end = end, + time_dim = time_dim, ncores = ncores) } return(data) } #'Absolute value of a relative threshold (percentile) #' -#'Frequently, thresholds are defined by a percentile that may correspond to a -#' different absolute value depending on the variable, gridpoint and also julian -#' day (time). This function calculates the corresponding value of a percentile -#' given a dataset. +#'Frequently, thresholds are defined by a percentile that may correspond to a +#'different absolute value depending on the variable, gridpoint and also julian +#'day (time). This function calculates the corresponding value of a percentile +#'given a dataset. #' #'@param data A multidimensional array with named dimensions. #'@param threshold A single scalar or vector indicating the relative diff --git a/man/AbsToProbs.Rd b/man/AbsToProbs.Rd index c3e7c50..89b1f83 100644 --- a/man/AbsToProbs.Rd +++ b/man/AbsToProbs.Rd @@ -22,13 +22,13 @@ AbsToProbs( dimensions matching the dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.} -\item{start}{An optional parameter to defined the initial date of the period +\item{start}{An optional parameter to define the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{end}{An optional parameter to defined the final date of the period to +\item{end}{An optional parameter to define the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} @@ -62,13 +62,13 @@ Distribution Function excluding the corresponding initialization. exp <- CSTools::lonlat_prec$data exp_probs <- AbsToProbs(exp) data <- array(rnorm(5 * 2 * 61 * 1), - c(member = 5, sdate = 2, ftime = 61, lon = 1)) + c(member = 5, sdate = 2, ftime = 61, lon = 1)) Dates <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), - as.Date("30-06-2000", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), - as.Date("30-06-2001", format = "\%d-\%m-\%Y"), by = 'day'), - seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), - as.Date("30-06-2002", format = "\%d-\%m-\%Y"), by = 'day')) + as.Date("30-06-2000", format = "\%d-\%m-\%Y"), by = 'day'), + seq(as.Date("01-05-2001", format = "\%d-\%m-\%Y"), + as.Date("30-06-2001", format = "\%d-\%m-\%Y"), by = 'day'), + seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), + as.Date("30-06-2002", format = "\%d-\%m-\%Y"), by = 'day')) exp_probs <- AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) } diff --git a/man/CST_AbsToProbs.Rd b/man/CST_AbsToProbs.Rd index 8ac3c37..dcdcef9 100644 --- a/man/CST_AbsToProbs.Rd +++ b/man/CST_AbsToProbs.Rd @@ -18,13 +18,13 @@ CST_AbsToProbs( \item{data}{An 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} -\item{start}{An optional parameter to defined the initial date of the period +\item{start}{An optional parameter to define the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{end}{An optional parameter to defined the final date of the period to +\item{end}{An optional parameter to define the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} @@ -57,13 +57,13 @@ Distribution Function excluding the corresponding initialization. exp <- CSTools::lonlat_prec exp_probs <- CST_AbsToProbs(exp) exp$data <- array(rnorm(5 * 3 * 214 * 2), - c(member = 5, sdate = 3, ftime = 214, lon = 2)) + c(member = 5, sdate = 3, ftime = 214, lon = 2)) exp$Dates[[1]] <- 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')) + 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')) exp_probs <- CST_AbsToProbs(exp, start = list(21, 4), end = list(21, 6)) } diff --git a/man/CST_MergeRefToExp.Rd b/man/CST_MergeRefToExp.Rd index 961eab9..102b062 100644 --- a/man/CST_MergeRefToExp.Rd +++ b/man/CST_MergeRefToExp.Rd @@ -23,19 +23,19 @@ package CSTools.} \item{data2}{An 's2dv_cube' object as provided function \code{CST_Load} in package CSTools.} -\item{start1}{A list to defined the initial date of the period to select from +\item{start1}{A list to define the initial date of the period to select from data1 by providing a list of two elements: the initial date of the period and the initial month of the period.} -\item{end1}{A list to defined the final date of the period to select from +\item{end1}{A list to define the final date of the period to select from data1 by providing a list of two elements: the final day of the period and the final month of the period.} -\item{start2}{A list to defined the initial date of the period to select from +\item{start2}{A list to define the initial date of the period to select from data2 by providing a list of two elements: the initial date of the period and the initial month of the period.} -\item{end2}{A list to defined the final date of the period to select from +\item{end2}{A list to define the final date of the period to select from data2 by providing a list of two elements: the final day of the period and the final month of the period.} diff --git a/man/CST_PeriodAccumulation.Rd b/man/CST_PeriodAccumulation.Rd index aea9560..5a2c3ce 100644 --- a/man/CST_PeriodAccumulation.Rd +++ b/man/CST_PeriodAccumulation.Rd @@ -60,11 +60,11 @@ TP <- CST_PeriodAccumulation(exp) exp$data <- array(rnorm(5 * 3 * 214 * 2), c(memb = 5, sdate = 3, ftime = 214, lon = 2)) exp$Dates[[1]] <- 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')) + 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')) SprR <- CST_PeriodAccumulation(exp, start = list(21, 4), end = list(21, 6)) dim(SprR$data) head(SprR$Dates) diff --git a/man/CST_QThreshold.Rd b/man/CST_QThreshold.Rd index 2843999..a01c5d2 100644 --- a/man/CST_QThreshold.Rd +++ b/man/CST_QThreshold.Rd @@ -84,11 +84,11 @@ exp_probs <- CST_QThreshold(exp, threshold) exp$data <- array(rnorm(5 * 3 * 214 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) exp$Dates[[1]] <- 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')) + 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')) exp_probs <- CST_QThreshold(exp, threshold, start = list(21, 4), end = list(21, 6)) } diff --git a/man/CST_Threshold.Rd b/man/CST_Threshold.Rd index e344ca1..906d1b1 100644 --- a/man/CST_Threshold.Rd +++ b/man/CST_Threshold.Rd @@ -70,11 +70,11 @@ exp_probs <- CST_Threshold(exp, threshold) exp$data <- array(rnorm(5 * 3 * 214 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) exp$Dates[[1]] <- 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')) + 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')) exp_probs <- CST_Threshold(exp, threshold, start = list(21, 4), end = list(21, 6)) } diff --git a/man/MergeRefToExp.Rd b/man/MergeRefToExp.Rd index 32e8627..f5b4958 100644 --- a/man/MergeRefToExp.Rd +++ b/man/MergeRefToExp.Rd @@ -24,11 +24,11 @@ MergeRefToExp( \item{dates1}{a vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data1'.} -\item{start1}{A list to defined the initial date of the period to select from +\item{start1}{A list to define the initial date of the period to select from data1 by providing a list of two elements: the initial date of the period and the initial month of the period.} -\item{end1}{A list to defined the final date of the period to select from +\item{end1}{A list to define the final date of the period to select from data1 by providing a list of two elements: the final day of the period and the final month of the period.} @@ -37,11 +37,11 @@ the final month of the period.} \item{dates2}{A vector of dates or a multidimensional array of dates with named dimensions matching the dimensions on parameter 'data2'.} -\item{start2}{A list to defined the initial date of the period to select from +\item{start2}{A list to define the initial date of the period to select from data2 by providing a list of two elements: the initial date of the period and the initial month of the period.} -\item{end2}{A list to defined the final date of the period to select from +\item{end2}{A list to define the final date of the period to select from data2 by providing a list of two elements: the final day of the period and the final month of the period.} diff --git a/man/PeriodAccumulation.Rd b/man/PeriodAccumulation.Rd index 3fa9bb8..1f23e66 100644 --- a/man/PeriodAccumulation.Rd +++ b/man/PeriodAccumulation.Rd @@ -66,9 +66,9 @@ data <- array(rnorm(5 * 3 * 214 * 2), # ftime tested 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"), + 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"), + seq(as.Date("01-05-2002", format = "\%d-\%m-\%Y"), as.Date("30-11-2002", format = "\%d-\%m-\%Y"), by = 'day')) SprR <- PeriodAccumulation(data, dates = Dates, start = list(21, 4), end = list(21, 6)) HarR <- PeriodAccumulation(data, dates = Dates, start = list(21, 8), end = list(21, 10)) diff --git a/man/Threshold.Rd b/man/Threshold.Rd index 2999439..db59817 100644 --- a/man/Threshold.Rd +++ b/man/Threshold.Rd @@ -62,9 +62,9 @@ A multidimensional array with named dimensions containing the corresponding values of a percentile in the element \code{data}. } \description{ -Frequently, thresholds are defined by a percentile that may correspond to a -different absolute value depending on the variable, gridpoint and also julian -day (time). This function calculates the corresponding value of a percentile +Frequently, thresholds are defined by a percentile that may correspond to a +different absolute value depending on the variable, gridpoint and also julian +day (time). This function calculates the corresponding value of a percentile given a dataset. } \examples{ -- GitLab From f776e17cefeefa047dd2880c347b6ef4a923bcea Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 19 Oct 2022 13:48:52 +0200 Subject: [PATCH 16/26] Correct warning in CST_ Dates initial checks for all functions --- R/AbsToProbs.R | 10 +++++----- R/AccumulationExceedingThreshold.R | 10 +++++----- R/MergeRefToExp.R | 14 +++++++------- R/PeriodAccumulation.R | 6 +++--- R/PeriodMean.R | 4 ++-- R/QThreshold.R | 10 +++++----- R/SelectPeriodOnData.R | 6 +++--- R/Threshold.R | 10 +++++----- R/TotalSpellTimeExceedingThreshold.R | 18 +++++++++--------- R/TotalTimeExceedingThreshold.R | 18 +++++++++--------- R/WindCapacityFactor.R | 4 ++-- R/WindPowerDensity.R | 8 ++++---- tests/testthat/test-PeriodMean.R | 16 +++++++++++----- 13 files changed, 70 insertions(+), 64 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index ce5f01a..89a493b 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -58,13 +58,13 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { if (length(data$Dates$start) == - prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { + prod(dim(data$data)[time_dim] * dim(data$data)[sdate_dim])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], - dim(data$data)['sdate']) + dim(data$data)[sdate_dim]) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 62a4bc4..74a24a9 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -60,17 +60,17 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', if (!is.null(start) && !is.null(end)) { if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { - if (length(data$Dates$start) == + if (length(data$Dates$start) == prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } - } + } if (inherits(threshold, 's2dv_cube')) { threshold <- threshold$data } diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 837d304..ad5bb06 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -77,11 +77,11 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, if (length(data1$Dates$start) == prod(dim(data1$data)[time_dim] * dim(data1$data)['sdate'])) { dim(data1$Dates$start) <- c(dim(data1$data)[time_dim], - dim(data1$data)['sdate']) + dim(data1$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'data$Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'data$Dates$start' are missed and", - "all data would be used.") } } # when subsetting is needed, dimensions are also needed: @@ -91,10 +91,10 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, prod(dim(data2$data)[time_dim] * dim(data2$data)['sdate'])) { dim(data2$Dates$start) <- c(dim(data2$data)[time_dim], dim(data2$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'data$Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'data$Dates$start' are missed and", - "all data would be used.") } } data1$data <- MergeRefToExp(data1 = data1$data, dates1 = data1$Dates[[1]], diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 92ec947..0fcf315 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -68,10 +68,10 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/PeriodMean.R b/R/PeriodMean.R index c75cee3..73700fd 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -56,9 +56,9 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } } } diff --git a/R/QThreshold.R b/R/QThreshold.R index 6b4359d..2b9702a 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -80,13 +80,13 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { if (length(data$Dates$start) == - prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { + prod(dim(data$data)[time_dim] * dim(data$data)[sdate_dim])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], - dim(data$data)['sdate']) + dim(data$data)[sdate_dim]) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index f15c60e..5bd9bb6 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -47,10 +47,10 @@ CST_SelectPeriodOnData <- function(data, start, end, time_dim = 'ftime', ncores prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/Threshold.R b/R/Threshold.R index 755c2e6..933b3fd 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -64,13 +64,13 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, if (is.null(dim(data$Dates$start))) { if (length(data$Dates$start) != dim(data$data)[time_dim]) { if (length(data$Dates$start) == - prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { + prod(dim(data$data)[time_dim] * dim(data$data)[sdate_dim])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], - dim(data$data)['sdate']) + dim(data$data)[sdate_dim]) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } } diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 97981ee..2e56d67 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -68,20 +68,20 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } - } - if (inherits(threshold, 's2dv_cube')) { + } + if (inherits(threshold, 's2dv_cube')) { threshold <- threshold$data } - total <- TotalSpellTimeExceedingThreshold(data$data, data$Dates[[1]], - threshold = threshold, spell = spell, op = op, - start = start, end = end, time_dim = time_dim, - ncores = ncores) + total <- TotalSpellTimeExceedingThreshold(data$data, data$Dates[[1]], + threshold = threshold, spell = spell, op = op, + start = start, end = end, time_dim = time_dim, + ncores = ncores) data$data <- total if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates$start, diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index ee0d8ac..136fd35 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -72,20 +72,20 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) { dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed and", + "all data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", - "all data would be used.") } } - } - if (inherits(threshold, 's2dv_cube')) { + } + if (inherits(threshold, 's2dv_cube')) { threshold <- threshold$data } - total <- TotalTimeExceedingThreshold(data$data, data$Dates[[1]], - threshold = threshold, op = op, - start = start, end = end, time_dim = time_dim, - na.rm = na.rm, ncores = ncores) + total <- TotalTimeExceedingThreshold(data$data, data$Dates[[1]], + threshold = threshold, op = op, + start = start, end = end, time_dim = time_dim, + na.rm = na.rm, ncores = ncores) data$data <- total if (!is.null(start) && !is.null(end)) { data$Dates <- SelectPeriodOnDates(dates = data$Dates$start, diff --git a/R/WindCapacityFactor.R b/R/WindCapacityFactor.R index 61565b0..3b59da7 100644 --- a/R/WindCapacityFactor.R +++ b/R/WindCapacityFactor.R @@ -63,9 +63,9 @@ CST_WindCapacityFactor <- function(wind, IEC_class = c("I", "I/II", "II", "II/II prod(dim(wind$data)[time_dim] * dim(wind$data)['sdate'])) { dim(wind$Dates$start) <- c(dim(wind$data)[time_dim], dim(wind$data)['sdate']) + } else { + warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } - } else { - warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") } } } diff --git a/R/WindPowerDensity.R b/R/WindPowerDensity.R index 99d5d80..15aacf4 100644 --- a/R/WindPowerDensity.R +++ b/R/WindPowerDensity.R @@ -53,9 +53,9 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, prod(dim(wind$data)[time_dim] * dim(wind$data)['sdate'])) { dim(wind$Dates$start) <- c(dim(wind$data)[time_dim], dim(wind$data)['sdate']) + } else { + warning("Dimensions in 'wind' element 'Dates$start' are missed/unmatched. All data would be used.") } - } else { - warning("Dimensions in 'wind' element 'Dates$start' are missed/unmatched. All data would be used.") } } } @@ -68,8 +68,8 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, } if (!is.null(start) && !is.null(end)) { wind$Dates <- SelectPeriodOnDates(dates = wind$Dates[[1]], - start = start, end = end, - time_dim = time_dim, ncores = ncores) + start = start, end = end, + time_dim = time_dim, ncores = ncores) } return(wind) } diff --git a/tests/testthat/test-PeriodMean.R b/tests/testthat/test-PeriodMean.R index c9a0a37..75b6d57 100644 --- a/tests/testthat/test-PeriodMean.R +++ b/tests/testthat/test-PeriodMean.R @@ -2,15 +2,21 @@ context("Generic tests") test_that("Sanity Checks", { #source("csindicators/R/PeriodMean.R") expect_error(PeriodMean('x'), "Parameter 'data' must be numeric.") - expect_equal(PeriodMean(array(1, c(x = 1)), time_dim = 'x'), 1) + suppressWarnings( + expect_equal(PeriodMean(array(1, c(x = 1)), time_dim = 'x'), 1) + ) + expect_error(PeriodMean(data = NULL), "Parameter 'data' cannot be NULL.") expect_error(PeriodMean(1, dates = '2000-01-01', end = 3, start = 4), "Parameter 'start' and 'end' must be lists indicating the day and the month of the period start and end.") - - expect_equal(PeriodMean(array(1:10, c(time = 10))), 5.5) + suppressWarnings( + expect_equal(PeriodMean(array(1:10, c(time = 10))), 5.5) + ) data <- array(1:24, c(sdate = 2, time = 3, lon = 4)) - expect_equal(PeriodMean(data), - array(c(3,4,9,10,15,16,21,22), c(sdate = 2, lon = 4))) + suppressWarnings( + expect_equal(PeriodMean(data), + array(c(3,4,9,10,15,16,21,22), c(sdate = 2, lon = 4))) + ) }) test_that("seasonal", { -- GitLab From 825752111c99036646da55ae206c6771f3aadd33 Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 19 Oct 2022 15:25:12 +0200 Subject: [PATCH 17/26] remove .md file --- vignettes/AgriculturalIndicators.md | 595 ---------------------------- 1 file changed, 595 deletions(-) delete mode 100644 vignettes/AgriculturalIndicators.md diff --git a/vignettes/AgriculturalIndicators.md b/vignettes/AgriculturalIndicators.md deleted file mode 100644 index c8d52b2..0000000 --- a/vignettes/AgriculturalIndicators.md +++ /dev/null @@ -1,595 +0,0 @@ ---- -title: "Agricultural Indicators" -author: "Earth Sciences department, Barcelona Supercomputing Center (BSC)" -date: "`r Sys.Date()`" -output: rmarkdown::html_vignette -vignette: > - %\VignetteEngine{knitr::knitr} - %\VignetteIndexEntry{Agricultural Indicators} - %\usepackage[utf8]{inputenc} ---- - -Agricultural Indicators ------------------------------ - - -## Introduction - -Apart from forecasts of Essential Climate Variables, Climate Services also provide a variety of the sectoral indicators that are often required for Climate Services people, including researchers, decision-makers, farmers, etc. - -In the MEDGOLD project, 10 indicators which were identified as critical indices for the three agricultural sectors - grape/wine, olive/olive oil and wheat/pasta - have been considered in this CSIndicators package. - -The computing functions and the corresponding indicators are listed as follows: - -1. **PeriodAccumulation -** Spring Total Precipitation (SprR) and Harvest Total Precipitation (HarvestR) -2. **PeriodMean -** Growing Season Temperature (GST) and Spring Mean Temperature Maximum (SPRTX) -3. **TotalTimeExceedingThreshold -** Number of Heat Stress Days - 35°C (SU35), 36°C (SU36), 40°C (SU40) and Spring Heat Stress Days - 32°C (Spr32) -4. **AccumulationExceedingThreshold -** Growing Degree Days (GDD) -5. **TotalSpellTimeExceedingThreshold -** Warm Spell Duration Index (WSDI) - -The above functions can take both multidimensional arrays and the s2dv_cube objects (see note below). Taking PeriodAccumulation as example, **CST_**PeriodAccumulation handles the latter and PeriodAccumulation without the prefix can compute multidimensional arrays. - -*Note: s2dv_cube and array classes can be handled by the functions in CSIndicators. See Section 2 in vignette [Data retrieval and storage](https://cran.r-project.org/package=CSTools/vignettes/Data_Considerations.html) from CSTools package for more information.* - -There are some supplementary functions which must be called to smoothly run the above functions. - -1. **SelectPeriodOnData -** to select the data in the requested period -2. **SelectPeriodOnDates -** to select the time dimension in the requested period -3. **Threshold -** to convert absolute value/variable to its percentile, e.g., Warm Spell Duration Index uses the 90th percentile corresponding to each day instead of a fixed threshold. See how this function is applied in Section 5. - -When the period selection is required, the `start` and `end` parameters have to be provided to cut out the portion in `time_dim`. Otherwise, the function will take the **entire** `time_dim`. - -The examples of computing the aforementioned indicators are given by functions as follows. - -### 1. PeriodAccumulation - -`PeriodAccumulation` (and `CST_PeriodAccumulation`) computes the sum of a given variable in a period. - -Here, two indicators are used to show how this function works: Spring Total Precipitation (SprR) and Harvest Total Precipitation (HarvestR). Both indices represent the total precipitation but in different periods, 21st April - 21st June for SprR and 21st August - 21st October for HarvestR. - -First, load the required libraries, CSIndicators, CSTools, etc by running - -``` -library(CSIndicators) -library(CSTools) -library(zeallot) -library(s2dv) -``` - -To obtain the precipitation forecast and observation, we load the daily precipitation (**prlr** given in `var`) data sets of ECMWF SEAS5 seasonal forecast and ERA5 reanalysis for the four starting dates 20130401-20160401 (provided in `sdates`) with the entire 7-month forecast time, April-October (214 days in total given in parameter `leadtimemax`). - -The pathways of SEAS5 and ERA5 are given in the lists with some **whitecards (inside two dollar signs)** used to replace the variable name and iterative items such as year and month. See details of requirements in Section 4 in vignette [Data retrieval and storage](https://cran.r-project.org/package=CSTools/vignettes/Data_Considerations.html) from CSTools package. - -The spatial domain covers part of Douro Valley of Northern Portugal lon=[352.25, 353], lat=[41, 41.75]. These four values are provided in `lonmin`, `lonmax`, `latmin` and `latmax`. - -With `grid` set to **r1440x721**, the SEAS5 forecast would be interpolated to the 0.25-degree ERA5 grid by using the **bicubic** method given in `method`. - - -``` -S5path_prlr <- list(path = '/esarchive/exp/ecmwf/system5c3s/original_files/chou/daily_mean/$VAR_NAME$_s0-24h/$VAR_NAME$_$YEAR$$MONTH$01.nc') - -path_ERA5prlr_CDS <- list(path = '/esarchive/recon/ecmwf/era5/daily_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') - -sdates <- paste0(2013:2016, '04', '01') - -c(prlr_exp, prlr_obs) %<-% CST_Load(var = 'prlr', - exp = list(S5path_prlr), - obs = list(path_ERA5prlr_CDS), - sdates = sdates, - lonmax = 353, lonmin = 352.25, - latmax = 41.75, latmin = 41, - storefreq = 'daily', - leadtimemin = 1, leadtimemax = 214, - nmember = 3, output = "lonlat", - grid = "r1440x721", method = 'bicubic') -``` - - -The output contains data and metadata for the experiment and the observations. The elements `prlr_exp$data` and `prlr_obs$data` have dimensions: - - -``` -dim(prlr_exp$data) -#dataset member sdate ftime lat lon -# 1 3 4 214 4 4 -dim(prlr_obs$data) -#dataset member sdate ftime lat lon -# 1 1 4 214 4 4 -``` - - -To compute **SprR** of forecast and observation, we can run: - - -``` -SprR_exp <- CST_PeriodAccumulation(prlr_exp, start = list(21, 4), end = list(21, 6)) -SprR_obs <- CST_PeriodAccumulation(prlr_obs, start = list(21, 4), end = list(21, 6)) -``` - -The `start` and `end` are the initial and final dates and the day must be given before the month as above. They will be applied along the dimension `time_dim` (it is set to 'ftime' by default). - -As mentioned, these parameters are optional, the function will take the entire timeseries when the period is not specified in `start` and `end`. - -The dimensions of SprR forecasts and observations are: - -``` -dim(SprR_exp$data) -#dataset member sdate lat lon -# 1 3 4 4 4 -dim(SprR_obs$data) -#dataset member sdate lat lon -# 1 1 4 4 4 -``` - -The forecast SprR for the 1st member from 2013-2016 of the 1st grid point in mm are: - -``` -SprR_exp$data[1,1,,1,1] * 86400 * 1000 -#[1] 93.23205 230.41904 194.01412 226.52614 -``` - -Dry springs will delay vegetative growth and reduce vigour and leaf area total surface. Fungal disease pressure will be lower and therefore there will be less need for protective and / or curative treatments, translating as less costs. Wet springs will promote higher vigour, increase the risk of fungal disease and disrupt vineyard operations as it may prevent machinery from getting in the vineyard due to mud. They are usually associated with higher costs. - -On the other hand, another moisture-related indicators, **HarvestR**, can be computed by using `PeriodAccumulation` as well, with the defined period as the following lines. - -``` -HarvestR_exp <- CST_PeriodAccumulation(prlr_exp, start = list(21, 8), end = list(21, 10)) -HarvestR_obs <- CST_PeriodAccumulation(prlr_obs, start = list(21, 8), end = list(21, 10)) -``` - -The forecast HarvestR for the 1st member from 2013-2016 of the 1st grid point in mm are: - -``` -HarvestR_exp$data[1,1,,1,1] * 86400 * 1000 -#[1] 52.30026 42.88068 156.87961 32.18579 -``` - -To compute the 2013-2016 ensemble-mean bias of forecast HarvestR, run - -``` -fcst <- drop(HarvestR_exp$data) * 86400 * 1000 -obs <- drop(HarvestR_obs$data) * 86400 * 1000 - -Bias <- MeanDims((fcst - InsertDim(obs, 1, dim(fcst)['member'])), 'member') -``` - -To plot the map of ensemble-mean bias of HarvestR forecast, run - -``` -cols <- c('#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#d1e5f0', - '#92c5de', '#4393c3', '#2166ac') - -PlotEquiMap(Bias[1,,], lon = prlr_obs$lon, lat = prlr_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'mm', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, col_inf = cols[1], - margin_scale = c(1, 1, 1, 1), cols = cols[2:7], col_sup = cols[8], - brks = seq(-60, 60, 20), colNA = 'white', - toptitle = 'Ensemble-mean bias of HarvestR in 2013', - bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) -``` -You will see the following maps of HarvestR bias in 2013. - -![](.figures/HarvestR_Bias_2013-1.png) - -In 2013, the ensemble-mean SEAS5 seasonal forecast of HarvestR is underestimated by up to 60 mm over Douro Valley region (the central four grid points). - - -### 2. PeriodMean - -For the function `PeriodMean`, we use Growing Season Temperature (**GST**) as an example. GST is defined as the average of daily average temperatures between April 1st to October 31st in the Northern Hemisphere. It provides information onto which are the best suited varieties for a given site or, inversely, which are the best places to grow a specific variety. For existing vineyards, GST also informs on the suitability of its varieties for the climate of specific years, explaining quality and production variation. Many grapevine varieties across the world have been characterized in function of their GST optimum. - -Firstly, we prepare a sample data of daily mean temperature of SEAS5 and ERA5 data sets with the same starting dates, spatial domain, interpolation grid and method by running - -``` -S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/daily_mean/$VAR_NAME$_f6h/$VAR_NAME$_$YEAR$$MONTH$01.nc') -ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/daily_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') - -c(tas_exp, tas_obs) %<-% CST_Load(var = 'tas', exp = list(S5path), obs = list(ERA5path), - sdates = sdates, lonmax = 353, lonmin = 352.25, - latmax = 41.75, latmin = 41, - storefreq = 'daily', - leadtimemin = 1, leadtimemax = 214, - nmember = 3, output = "lonlat", - grid = "r1440x721", method = 'bicubic') -``` - -The output contains observations `tas_dv$obs$data` and forecast `tas_dv$exp$data`, and their dimensions and summaries are like - -``` -dim(tas_obs$data) -#dataset member sdate ftime lat lon -# 1 1 4 214 4 4 - -dim(tas_exp$data) -#dataset member sdate ftime lat lon -# 1 3 4 214 4 4 - -summary(tas_obs$data - 273.15) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 3.63 14.38 17.89 17.65 21.24 30.21 - -summary(tas_exp$data - 273.15) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 0.54 11.65 16.56 16.50 21.25 31.41 - -``` -To compute the GST for both observation and forecast, run the following lines - -``` -# change the unit of temperature from °C to K - -tas_exp$data <- tas_exp$data - 273.15 -tas_obs$data <- tas_obs$data - 273.15 - -# compute GST - -GST_exp <- CST_PeriodMean(tas_exp, start = list(1, 4), end = list(31, 10)) -GST_obs <- CST_PeriodMean(tas_obs, start = list(1, 4), end = list(31, 10)) - -``` - -Since the period considered for GST is the entire period for starting month of April, in this case the `start` and `end` parameters could be ignored. - -The summaries and dimensions of the output are as follows: - -``` -summary(GST_exp$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 14.23 15.78 16.50 16.50 17.17 18.70 - -summary(GST_obs$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 15.34 16.85 17.72 17.65 18.41 19.60 - -dim(GST_exp$data) -#dataset member sdate lat lon -# 1 3 4 4 4 - -dim(GST_obs$data) -#dataset member sdate lat lon -# 1 1 4 4 4 -``` - -Here, we plot the 2013-2016 mean climatology of ERA5 GST by running - -``` -# compute ERA5 GST climatology -GST_Clim <- MeanDims(drop(GST_obs$data), 'sdate') - -cols <- c('#ffffd4','#fee391','#fec44f','#fe9929','#ec7014','#cc4c02','#8c2d04') -PlotEquiMap(GST_Clim, lon = tas_obs$lon, lat = tas_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = '°C', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, col_inf = cols[1], - margin_scale = c(1, 1, 1, 1), cols = cols[2:6], col_sup = cols[7], - brks = seq(16, 18.5, 0.5), colNA = 'white', bar_label_scale = 1.5, - toptitle = '2013-2016 mean ERA5 GST', - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) -``` - -The ERA5 GST climatology is shown as below. - -![](./figures/GST_ERA5_Climatology-1.png) - -ERA5 GST ranges from 17-18.5°C over the Douro Valley region for the period from 2013-2016 as shown in the figure. - - -### 3. TotalTimeExceedingThreshold - -For the function `TotalTimeExceedingThreshold`, **SU35** (Number of Heat Stress Days - 35°C) is taken as an example here. 35°C is the average established threshold for photosynthesis to occur in the grapevine. Above this temperature, the plant closes its stomata. If this situation occurs after veraison, maturation will be arrested for as long as the situation holds, decreasing sugar, polyphenol and aroma precursor levels, all essential for grape and wine quality. The higher the index, the lower will be the berry quality and aptitude to produce quality grapes. - -SU35 is defined as the Total count of days when daily maximum temperatures exceed 35°C in the seven months into the future. There are three indicators sharing the similar definition as SU35: SU36, SU40 and Spr32. Their definition are listed as follows. - -1. **SU36**: Total count of days when daily maximum temperatures exceed 36°C between June 21st and September 21st -2. **SU40**: Total count of days when daily maximum temperatures exceed 40°C between June 21st and September 21st -3. **Spr32**: Total count of days when daily maximum temperatures exceed 32°C between April 21st and June 21st - -These indicators can be computed as well by using the function `TotalTimeExceedingThreshold` with different thresholds and periods indicated. - -Here, we take SU35 as example, therefore the daily temperature maximum of the entire 7-month forecast period is needed for the computation of this indicator. - -Load SEAS5 and ERA5 daily temperature maximum by running - -``` -S5path <- list(path = '/esarchive/exp/ecmwf/system5c3s/daily/$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$01.nc') -ERA5path <- list(path = '/esarchive/recon/ecmwf/era5/daily/$VAR_NAME$-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc') - -c(tasmax_exp, tasmax_obs) %<-% CST_Load(var = 'tasmax', exp = list(S5path), - obs = list(ERA5path), sdates = sdates, - lonmax = 353, lonmin = 352.25, - latmax = 41.75, latmin = 41, storefreq = 'daily', - leadtimemin = 1, leadtimemax = 214, nmember = 3, - output = "lonlat", grid = "r1440x721", - method = 'bicubic', nprocs = 1) -``` - -Check the unit of temperature to from °C to K for the comparison with the threshold defined (for example 35°C here). - -``` -tasmax_exp$data <- tasmax_exp$data - 273.15 -tasmax_obs$data <- tasmax_obs$data - 273.15 -``` - -Computing SU35 for forecast and observation by running - -``` -threshold <- 35 -SU35_exp <- CST_TotalTimeExceedingThreshold(tasmax_exp, threshold = threshold, - start = list(1, 4), end = list(31, 10)) -SU35_obs <- CST_TotalTimeExceedingThreshold(tasmax_obs, threshold = threshold, - start = list(1, 4), end = list(31, 10)) -``` - -The summaries of SU35 forecasts and observations are given below. - -``` -summary(SU35_exp$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 0.00 2.00 5.00 7.12 12.00 26.00 - -summary(SU35_obs$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 0.000 0.000 1.000 2.609 5.000 10.000 - -``` -As shown in the summaries, SEAS5 SU35 forecasts are overestimated by 5 days in terms of mean value. - -Therefore, `CST_BiasCorrection` is used to bias adjust the SU35 forecasts. - -``` -res <- CST_BiasCorrection(obs = SU35_obs, exp = SU35_exp) -SU35_exp_BC <- drop(res$data) -summary(SU35_exp_BC) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# -1.419 0.000 1.613 2.831 4.756 17.768 -``` - -Since there are negative values after bias adjustment, all negative data is converted to zero. - -``` -SU35_exp_BC[SU35_exp_BC < 0] <- 0 -summary(SU35_exp_BC) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 0.000 0.000 1.613 2.943 4.756 17.768 -``` - -Plot the bias-adjusted SU35 forecast in 2016 by running - -``` -SU35_obs_Y2016 <- drop(SU35_obs$data)[4, , ] -SU35_exp_Y2016 <- MeanDims(drop(SU35_exp$data)[, 4, , ], 'member') -SU35_exp_BC_Y2016 <- MeanDims(SU35_exp_BC[, 4, , ], 'member') -cols <- c("#fee5d9", "#fcae91", "#fb6a4a", "#de2d26","#a50f15") - -toptitle <- 'ERA5 SU35 forecast in 2016' -PlotEquiMap(SU35_obs_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'day', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), - cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), - toptitle = toptitle, - colNA = cols[1], bar_label_scale = 1.5, - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) - -toptitle <- 'SU35 forecast in 2016' -PlotEquiMap(SU35_exp_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'day', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), - cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), - toptitle = toptitle, - colNA = cols[1], bar_label_scale = 1.5, - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) - -toptitle <- 'Bias-adjusted SU35 forecast in 2016' -PlotEquiMap(SU35_exp_BC_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'day', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), - cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), - toptitle = toptitle, - colNA = cols[1], bar_label_scale = 1.5, - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) -``` -You can see the figure as below. - - -![](./figures/SU35_ERA5_Y2016-1.png) -![](./figures/SU35_SEAS5_Y2016-1.png) -![](./figures/SU35_SEAS5_BC_Y2016-1.png) - -As seen above, the bias-adjusted SU35 forecasts are much closer to the ERA5 results, although differences remain. - -Beside of the original definition of SU35, here two supplementary functions in the package `CSIndicators` are demonstrated by computing its another definition with the percentile adjustment. - ---- -1. **AbsToProbs -**: to transform ensemble forecast into probabilities by using the Cumulative Distribution Function -2. **QThreshold -**: to transform an absolute threshold into probabilities. ---- - -The above two supplementary functions are required to compute SU35 with the percentile adjustment. The function `AbsToProbs` would be applied to forecast and the `QThreshold` would be used to convert the observations to its percentile based on the given threshold. - -The revised definition of SU35 is to reduce the potential influence induced by the fixed threshold of temperature defined for the index, instead of using the absolute value, the percentile corresponding to 35°C for observation is compared to the percentile corresponding to the predicted daily maximum temperature before being considered as a ‘heat stress’ day. - -As mentioned, the forecast is translated to its percentile by using the function `ABsToProbs` by running - -``` -exp_percentile <- AbsToProbs(tasmax_exp$data) -S5txP <- aperm(drop(exp_percentile), c(2, 1, 3, 4, 5)) -``` - -After that, based on 35 of threshold, the percentile corresponding to each observational value can be calculated as follows. - -``` -obs_percentile <- QThreshold(tasmax_obs$data, threshold = 35) -obs_percentile <- drop(obs_percentile) -``` - -After translating both forecasts and observations into probabilities, the comparison can then be done by running - -``` -SU35_exp_Percentile <- TotalTimeExceedingThreshold(S5txP, threshold = obs_percentile, time_dim = 'ftime') -``` - -Compute the same ensemble-mean SU35 **with percentile adjustment** in 2016 by running - -``` -SU35_exp_per_Y2016 <- MeanDims(SU35_exp_Percentile[, 4, , ], 'member') -``` - -Plot the same map for comparison - -``` -toptitle <- 'SU35 forecast with percentile adjustment in 2016' -PlotEquiMap(SU35_exp_per_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'day', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), - cols = cols[1:4], col_sup = cols[5], brks = seq(0, 8, 2), - toptitle = toptitle, - colNA = cols[1], bar_label_scale = 1.5, - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) - -``` - - -![](./figures/SU35_Percentile_SEAS5_Y2016-1.png) - -As seen in the figure above, applying the percentile adjustment seems to implicitly adjust certain extent of bias which was observed in the non-bias-adjusted SEAS5 forecast. - -The performance of comparison of skills between two definitions requires further analysis such as the application of more skill metrics. - -### 4. AccumulationExceedingThreshold - -The function ´AccumulationExceedingThreshold´ can compute GDD (Growing Degree Days). - -The definition of GDD is the summation of daily differences between daily average temperatures and 10°C between April 1st and October 31st. Here, the tas (daily average temperature) used above (in Section 2. PeriodMean) is loaded again (Please re-use the section of loading tas in Section 2). As per the definition, `threshold` is set to 10 with `diff` set to TRUE so that the function will compute the differences between daily temperature and the threshold given before calculating summation. - -*Note: The data is in degrees Celsiusi at this point* - -``` -GDD_exp <- CST_AccumulationExceedingThreshold(tas_exp, threshold = 10, diff = TRUE) -GDD_obs <- CST_AccumulationExceedingThreshold(tas_obs, threshold = 10, diff = TRUE) -``` - -The summaries of GDD are - -``` -summary(GDD_exp$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 1021 1331 1480 1469 1596 1873 - -summary(GDD_obs$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 1195 1504 1687 1660 1804 2055 -``` - -To compute the correlation coefficient for the period from 2013-2016, run the following lines - -``` -# reorder the dimension -fcst <- Reorder(drop(GDD_exp$data), c(4, 3, 2, 1)) -obs <- Reorder(drop(GDD_obs$data), c(3, 2, 1)) - -EnsCorr <- veriApply('EnsCorr', fcst = fcst, obs = obs, ensdim = 4, tdim = 3) -GDD_Corr <- Reorder(EnsCorr, c(2, 1)) -``` - -To plot the map of correlation coefficient of GDD for the 2013-2016 period. - -``` -cols <- c("#f7fcf5", "#e5f5e0", "#c7e9c0", "#a1d99b", "#74c476") -toptitle <- '2013-2016 correlation coefficient of GDD' -PlotEquiMap(GDD_Corr, lon = tas_obs$lon, lat = tas_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'correlation', - title_scale = .8, axes_label_scale = 1, axes_tick_scale = 1, - margin_scale = c(1, 1, 1, 1), cols = cols, brks = seq(0.5, 1, 0.1), - toptitle = toptitle, bar_label_scale = 1.5, - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) -``` - -The map of correlation coefficient for the 2013-2016 period is shown as below. - -![](./figures/GDD_SEAS5_Corr_Y13-16-1.png) - -The 2013-2016 correlation coefficients of the SEAS5 forecasts of GDD in reference with ERA5 reanalysis over Douro Valley range between 0.6 and 0.8. - -### 5. TotalSpellTimeExceedingThreshold - -One of the critical agricultural indicators related to dry spell is the **Warm Spell Duration Index (WSDI)**, which is defined as the total count of days with at least 6 consecutive days when the daily maximum temperature exceeds its 90th percentile in the seven months into the future. - -The maximum temperature data used in Section 3. Since the daily maximum temperature needs to compare to its 90th percentile, the function `Threshold` in the `CSIndicators` package is required to compute the percentile of observations used for each day. Here the same period (2013-2016) is considered. - -``` -tx_p <- CST_Threshold(tasmax_obs, threshold = 0.9) -``` - -The output will be the 90th percentile of each day of each grid point derived by using all the years in the data.See the dimension and summary as below. - -``` -dim(tx_p$data) -#dataset ftime lat lon -# 1 214 4 4 - -summary(tx_p$data) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 287.0 295.2 299.2 299.4 303.9 309.9 -``` - -With the prepared threshold (90th percentile), the WSDI can be computed by running - -``` -WSDI_exp <- CST_TotalSpellTimeExceedingThreshold(tasmax_exp, threshold = tx_p, spell = 6) -WSDI_obs <- CST_TotalSpellTimeExceedingThreshold(tasmax_obs, threshold = tx_p, spell = 6) -``` - -After checking the summaries, compute the Fair Ranked Probability Skill Score (FRPSS) of WSDI by running the following lines - -``` -# Reorder the data -fcst <- Reorder(drop(WSDI_exp$data), c(4, 3, 2, 1)) -obs <- Reorder(drop(WSDI_obs$data), c(3, 2, 1)) - -# summaries of WSDI -summary(fcst) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 0.00 13.00 28.00 30.65 42.25 82.00 - -summary(obs) -# Min. 1st Qu. Median Mean 3rd Qu. Max. -# 9.00 19.00 22.50 22.91 25.25 33.00 - -# compute FRPSS -f <- veriApply('FairRpss', fcst = fcst, obs = obs, ensdim = 4, tdim = 3, prob = 1:2/3)$skillscore -WSDI_FRPSS <- Reorder(f, c(2,1)) -``` - -Plot the map of WSDI FRPSS for the period from 2013-2016 - -``` -cols <- c("#edf8fb", "#ccece6", "#99d8c9", "#66c2a4") -toptitle <- 'SEAS5 WSDI FRPSS (2013-2016)' - -PlotEquiMap(WSDI_FRPSS, lon = tasmax_obs$lon, lat = tasmax_obs$lat, - intylat = 1, intxlon = 1, width = 6, height = 6, - filled.continents = FALSE, units = 'FRPSS', title_scale = .8, - axes_label_scale = 1, axes_tick_scale = 1, margin_scale = c(1, 1, 1, 1), - cols = cols[1:3], col_inf = 'white', col_sup = cols[4], - brks = seq(0, 0.9, 0.3), toptitle = toptitle, bar_label_scale = 1.5, - bar_extra_margin = c(0, 0, 0, 0), units_scale = 2) -``` - -The FRPSS map for 2013-2016 SEAS WSDI is shown as below. - -![](./figures/WSDI_SEAS5_FRPSS_Y13-16-1.png) - -As seen in the map, the FRPSS in the eastern part of Douro Valley falls in 0.6-0.9, which are good enough to be useful when compared to observational climatology. - - -In addition to the grape/wine sector focused here, the MEDGOLD project also works on the other two sectors: olive/olive oil and durum wheat/pasta. Furthermore, the climate services are also provided at the longer term (up to 30 years) by other project partners. - -Click on [MEDGOLD](https://www.med-gold.eu/climate-services/) for more information. - - -- GitLab From cda6ada8484046d57e20b0999daad6e0df2319c6 Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 19 Oct 2022 15:28:03 +0200 Subject: [PATCH 18/26] Fix link as master --- vignettes/AgriculturalIndicators.Rmd | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vignettes/AgriculturalIndicators.Rmd b/vignettes/AgriculturalIndicators.Rmd index 9487b92..50df881 100644 --- a/vignettes/AgriculturalIndicators.Rmd +++ b/vignettes/AgriculturalIndicators.Rmd @@ -170,7 +170,7 @@ PlotEquiMap(Bias[1,,], lon = prlr_obs$lon, lat = prlr_obs$lat, ``` You will see the following maps of HarvestR bias in 2013. -![](.figures/HarvestR_Bias_2013-1.png) + In 2013, the ensemble-mean SEAS5 seasonal forecast of HarvestR is underestimated by up to 60 mm over Douro Valley region (the central four grid points). @@ -270,7 +270,7 @@ PlotEquiMap(GST_Clim, lon = tas_obs$lon, lat = tas_obs$lat, The ERA5 GST climatology is shown as below. -![](./figures/GST_ERA5_Climatology-1.png) + ERA5 GST ranges from 17-18.5°C over the Douro Valley region for the period from 2013-2016 as shown in the figure. @@ -395,9 +395,9 @@ PlotEquiMap(SU35_exp_BC_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, You can see the figure as below. -![](./figures/SU35_ERA5_Y2016-1.png) -![](./figures/SU35_SEAS5_Y2016-1.png) -![](./figures/SU35_SEAS5_BC_Y2016-1.png) + + + As seen above, the bias-adjusted SU35 forecasts are much closer to the ERA5 results, although differences remain. @@ -454,7 +454,7 @@ PlotEquiMap(SU35_exp_per_Y2016, lon = tasmax_obs$lon, lat = tasmax_obs$lat, ``` -![](./figures/SU35_Percentile_SEAS5_Y2016-1.png) + As seen in the figure above, applying the percentile adjustment seems to implicitly adjust certain extent of bias which was observed in the non-bias-adjusted SEAS5 forecast. @@ -512,7 +512,7 @@ PlotEquiMap(GDD_Corr, lon = tas_obs$lon, lat = tas_obs$lat, The map of correlation coefficient for the 2013-2016 period is shown as below. -![](./figures/GDD_SEAS5_Corr_Y13-16-1.png) + The 2013-2016 correlation coefficients of the SEAS5 forecasts of GDD in reference with ERA5 reanalysis over Douro Valley range between 0.6 and 0.8. @@ -583,7 +583,7 @@ PlotEquiMap(WSDI_FRPSS, lon = tasmax_obs$lon, lat = tasmax_obs$lat, The FRPSS map for 2013-2016 SEAS WSDI is shown as below. -![](./figures/WSDI_SEAS5_FRPSS_Y13-16-1.png) + As seen in the map, the FRPSS in the eastern part of Douro Valley falls in 0.6-0.9, which are good enough to be useful when compared to observational climatology. -- GitLab From 2528112a9adfcc79c92b68cb14e5caac29a7972e Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 19 Oct 2022 15:28:49 +0200 Subject: [PATCH 19/26] Enlarge figure width --- vignettes/EnergyIndicators.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/EnergyIndicators.Rmd b/vignettes/EnergyIndicators.Rmd index f656f56..caf474e 100644 --- a/vignettes/EnergyIndicators.Rmd +++ b/vignettes/EnergyIndicators.Rmd @@ -30,7 +30,7 @@ Although wind turbines cannot extract all of the kinetic energy in the wind, and As an example, we simulate a time series of 1000 wind speed values from a Weibull distribution with scale factor of 6 and a shape factor of 2, which represent a sample of wind speed values obtained at a single location. The Weibull distribution is often assumed to fit observed wind speed values to a probability distribution function. Then, each instantaneous wind speed value is converted to its equivalent WPD. The `mean` and `sd` of the WPD can be employed to summarize the wind resource in that location. Otherwise, we can plot the histograms to see the full distribution of values: -```{r} +```{r, fig.width=7} library(CSIndicators) set.seed(1) oldpar <- par(no.readonly = TRUE) @@ -61,7 +61,7 @@ Notice that power curves are intended to be used with 10-minutal steady wind spe Following on the previous example, we will compute now the CF that would be obtained from our sample of 1000 wind speed values when using a turbine of class IEC I, and compare it to the CF values for a class III: -```{r} +```{r, fig.width=7} WCFI <- WindCapacityFactor(wind, IEC_class = "I") WCFIII <- WindCapacityFactor(wind, IEC_class = "III") par(mfrow=c(1, 3)) -- GitLab From cea4f4a1f5927bac650b2ee5045bd0cae7647ae0 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 19 Oct 2022 17:17:35 +0200 Subject: [PATCH 20/26] Add space in warning texts for all functions --- R/AbsToProbs.R | 2 +- R/AccumulationExceedingThreshold.R | 2 +- R/MergeRefToExp.R | 2 +- R/PeriodAccumulation.R | 2 +- R/QThreshold.R | 2 +- R/SelectPeriodOnData.R | 2 +- R/Threshold.R | 2 +- R/TotalSpellTimeExceedingThreshold.R | 2 +- R/TotalTimeExceedingThreshold.R | 2 +- R/WindCapacityFactor.R | 3 ++- R/WindPowerDensity.R | 3 ++- 11 files changed, 13 insertions(+), 11 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index 89a493b..89c72c9 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -62,7 +62,7 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)[sdate_dim]) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 74a24a9..62845ba 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -65,7 +65,7 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index ad5bb06..068acfe 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -92,7 +92,7 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, dim(data2$Dates$start) <- c(dim(data2$data)[time_dim], dim(data2$data)['sdate']) } else { - warning("Dimensions in 'data' element 'data$Dates$start' are missed and", + warning("Dimensions in 'data' element 'data$Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 0fcf315..5a672e0 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -69,7 +69,7 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/QThreshold.R b/R/QThreshold.R index 2b9702a..4663411 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -84,7 +84,7 @@ CST_QThreshold <- function(data, threshold, start = NULL, end = NULL, dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)[sdate_dim]) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index 5bd9bb6..49575a2 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -48,7 +48,7 @@ CST_SelectPeriodOnData <- function(data, start, end, time_dim = 'ftime', ncores dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/Threshold.R b/R/Threshold.R index 933b3fd..18b8dea 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -68,7 +68,7 @@ CST_Threshold <- function(data, threshold, start = NULL, end = NULL, dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)[sdate_dim]) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 2e56d67..9a5de43 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -69,7 +69,7 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 136fd35..5e800f0 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -73,7 +73,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', dim(data$Dates$start) <- c(dim(data$data)[time_dim], dim(data$data)['sdate']) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed and", + warning("Dimensions in 'data' element 'Dates$start' are missed and ", "all data would be used.") } } diff --git a/R/WindCapacityFactor.R b/R/WindCapacityFactor.R index 3b59da7..659e6d4 100644 --- a/R/WindCapacityFactor.R +++ b/R/WindCapacityFactor.R @@ -64,7 +64,8 @@ CST_WindCapacityFactor <- function(wind, IEC_class = c("I", "I/II", "II", "II/II dim(wind$Dates$start) <- c(dim(wind$data)[time_dim], dim(wind$data)['sdate']) } else { - warning("Dimensions in 'data' element 'Dates$start' are missed/unmatched. All data would be used.") + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } } } diff --git a/R/WindPowerDensity.R b/R/WindPowerDensity.R index 15aacf4..6bbc597 100644 --- a/R/WindPowerDensity.R +++ b/R/WindPowerDensity.R @@ -54,7 +54,8 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, dim(wind$Dates$start) <- c(dim(wind$data)[time_dim], dim(wind$data)['sdate']) } else { - warning("Dimensions in 'wind' element 'Dates$start' are missed/unmatched. All data would be used.") + warning("Dimensions in 'data' element 'Dates$start' are missed and ", + "all data would be used.") } } } -- GitLab From 0758c034c7f657d97c2a6976553fbf99512f2313 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Thu, 20 Oct 2022 14:33:34 +0200 Subject: [PATCH 21/26] Updated NEWS, README documentation, DESCRIPTION added authors and .Rbuildignore --- .Rbuildignore | 2 +- DESCRIPTION | 19 ++++++++++++++++--- NEWS.md | 10 ++++------ README.md | 19 ++++++++++++++----- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index e8159e2..ba637f5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,7 +5,7 @@ ./.nc$ .*^(?!data)\.RData$ .*\.gitlab-ci.yml$ -#^tests$ +^tests$ ./.nfs* ^cran-comments\.md$ ./vignettes/*.md diff --git a/DESCRIPTION b/DESCRIPTION index 6dae74d..d855559 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,28 @@ Package: CSIndicators Title: Climate Services' Indicators Based on Sub-Seasonal to Decadal Predictions -Version: 0.0.1 +Version: 0.0.2 Authors@R: c( - person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-8568-3071")), + 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")), person("Chou", "Chihchung", ,"chihchung.chou@bsc.es", role = "aut"), person("Llorenç", "Lledó", , "llorenc.lledo@bsc.es", role = "aut"), person("González-Reviriego", "Nube", , "nube.gonzalez@bsc.es", role = "ctb"), person("Marcos", "Raül", , "raul.marcos@bsc.es", role = "ctb"), person("Palma", "Lluis", , "lluis.palma@bsc.es", role = "ctb"), + person("An-Chi", "Ho", , "an.ho@bsc.es", role = c("ctb")), person("BSC-CNS", role = "cph")) -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'. This package was developed in the context of H2020 MED-GOLD (776467) and S2S4E (776787) projects. Lledó et al. (2019) . +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'. + This package was developed in the context of H2020 MED-GOLD (776467) and + S2S4E (776787) projects. Lledó et al. (2019) . Depends: R (>= 3.6.0) Imports: diff --git a/NEWS.md b/NEWS.md index 7aefb00..b9b4521 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,4 @@ -### CSIndicators 0.0.2 -**Submission date to CRAN: XX-YY-2021** - -- New features: -- Fixes: - + Vignettes figures +### CSIndicators 0.0.2 (Release date: 2022-06-20) +- 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(). diff --git a/README.md b/README.md index 24069b7..2ed5fde 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ 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. +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 @@ -36,16 +44,17 @@ 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. *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* -*Note: All functions computing indicators allows to subset a time period if required, although this temporal subsetting can also be done with funcitons `SelectPeriodOnData` in a separated step.* +*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.* ### How to contribute 1. Open an issue to ask for help or describe a function to be integrated -2. Agree with maintainers (@ngonzal2, @rmarcos and @nperez) on the requirements +2. Agree with maintainers (@ngonzal2, @rmarcos, @nperez and @erifarov) on the requirements 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 -- GitLab From 327dc10662a9faf1c448e61000d6485195c8db48 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 21 Oct 2022 11:40:07 +0200 Subject: [PATCH 22/26] Add old release to NEWS --- NEWS.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index b9b4521..fa2bb87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,7 @@ -### CSIndicators 0.0.2 (Release date: 2022-06-20) +# 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(). +- 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(). + +# CSIndicators 0.0.1 (Release date: 2021-05-07) +- This package is intended for sub-seasonal, seasonal and decadal climate predictions, but its methods are also applicable to other time-scales. Additionally, the outputs of the functions in this package are compatible with 'CSTools'. This package was developed in the context of H2020 MED-GOLD (776467) and S2S4E (776787) projects. Lledó et al. (2019) . \ No newline at end of file -- GitLab From 2031b5e834c7fefe1213a49b65aa1e95e8624f3b Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 21 Oct 2022 11:47:00 +0200 Subject: [PATCH 23/26] Correct typo from time_dim param word 'function' to 'dimension' --- R/AccumulationExceedingThreshold.R | 4 ++-- R/PeriodAccumulation.R | 4 ++-- R/PeriodMean.R | 4 ++-- R/TotalSpellTimeExceedingThreshold.R | 4 ++-- R/TotalTimeExceedingThreshold.R | 4 ++-- R/WindCapacityFactor.R | 4 ++-- R/WindPowerDensity.R | 4 ++-- man/AccumulationExceedingThreshold.Rd | 2 +- man/CST_AccumulationExceedingThreshold.Rd | 2 +- man/CST_PeriodAccumulation.Rd | 2 +- man/CST_PeriodMean.Rd | 2 +- man/CST_TotalSpellTimeExceedingThreshold.Rd | 2 +- man/CST_TotalTimeExceedingThreshold.Rd | 2 +- man/CST_WindCapacityFactor.Rd | 2 +- man/CST_WindPowerDensity.Rd | 2 +- man/PeriodAccumulation.Rd | 2 +- man/PeriodMean.Rd | 2 +- man/TotalSpellTimeExceedingThreshold.Rd | 2 +- man/TotalTimeExceedingThreshold.Rd | 2 +- man/WindCapacityFactor.Rd | 2 +- man/WindPowerDensity.Rd | 2 +- 21 files changed, 28 insertions(+), 28 deletions(-) diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index 62845ba..cceb07b 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -29,7 +29,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -119,7 +119,7 @@ CST_AccumulationExceedingThreshold <- function(data, threshold, op = '>', #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 5a672e0..ab093be 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -21,7 +21,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -110,7 +110,7 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'time'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/R/PeriodMean.R b/R/PeriodMean.R index 73700fd..55f28cd 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -21,7 +21,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -98,7 +98,7 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 9a5de43..7039f28 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -34,7 +34,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -127,7 +127,7 @@ CST_TotalSpellTimeExceedingThreshold <- function(data, threshold, spell, op = '> #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 5e800f0..6e6e72d 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -37,7 +37,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -134,7 +134,7 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'time'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/R/WindCapacityFactor.R b/R/WindCapacityFactor.R index 659e6d4..ee542eb 100644 --- a/R/WindCapacityFactor.R +++ b/R/WindCapacityFactor.R @@ -30,7 +30,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -120,7 +120,7 @@ CST_WindCapacityFactor <- function(wind, IEC_class = c("I", "I/II", "II", "II/II #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/R/WindPowerDensity.R b/R/WindPowerDensity.R index 6bbc597..bbdd07d 100644 --- a/R/WindPowerDensity.R +++ b/R/WindPowerDensity.R @@ -20,7 +20,7 @@ #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. @@ -100,7 +100,7 @@ CST_WindPowerDensity <- function(wind, ro = 1.225, start = NULL, end = NULL, #' select from the data by providing a list of two elements: the final day of #' the period and the final month of the period. By default it is set to NULL #' and the indicator is computed using all the data provided in \code{data}. -#'@param time_dim A character string indicating the name of the function to +#'@param time_dim A character string indicating the name of the dimension to #' compute the indicator. By default, it is set to 'ftime'. More than one #' dimension name matching the dimensions provided in the object #' \code{data$data} can be specified. diff --git a/man/AccumulationExceedingThreshold.Rd b/man/AccumulationExceedingThreshold.Rd index f7e0982..e646dc6 100644 --- a/man/AccumulationExceedingThreshold.Rd +++ b/man/AccumulationExceedingThreshold.Rd @@ -44,7 +44,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 9785f97..0754c24 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -40,7 +40,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_PeriodAccumulation.Rd b/man/CST_PeriodAccumulation.Rd index 5a2c3ce..afd6080 100644 --- a/man/CST_PeriodAccumulation.Rd +++ b/man/CST_PeriodAccumulation.Rd @@ -28,7 +28,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_PeriodMean.Rd b/man/CST_PeriodMean.Rd index 574e476..c4e3dae 100644 --- a/man/CST_PeriodMean.Rd +++ b/man/CST_PeriodMean.Rd @@ -28,7 +28,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index d395ae6..d19415e 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -40,7 +40,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index 3c5c11f..980d77b 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -38,7 +38,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_WindCapacityFactor.Rd b/man/CST_WindCapacityFactor.Rd index 28f437f..1dd879b 100644 --- a/man/CST_WindCapacityFactor.Rd +++ b/man/CST_WindCapacityFactor.Rd @@ -34,7 +34,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/CST_WindPowerDensity.Rd b/man/CST_WindPowerDensity.Rd index 9e53457..9c3040c 100644 --- a/man/CST_WindPowerDensity.Rd +++ b/man/CST_WindPowerDensity.Rd @@ -32,7 +32,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/PeriodAccumulation.Rd b/man/PeriodAccumulation.Rd index 1f23e66..f6e6d3b 100644 --- a/man/PeriodAccumulation.Rd +++ b/man/PeriodAccumulation.Rd @@ -32,7 +32,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/PeriodMean.Rd b/man/PeriodMean.Rd index 19fb9bf..803a3f2 100644 --- a/man/PeriodMean.Rd +++ b/man/PeriodMean.Rd @@ -32,7 +32,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/TotalSpellTimeExceedingThreshold.Rd b/man/TotalSpellTimeExceedingThreshold.Rd index 2bcebfa..37fd6cc 100644 --- a/man/TotalSpellTimeExceedingThreshold.Rd +++ b/man/TotalSpellTimeExceedingThreshold.Rd @@ -43,7 +43,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 119d392..524f938 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -42,7 +42,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/WindCapacityFactor.Rd b/man/WindCapacityFactor.Rd index 4779ff0..557771e 100644 --- a/man/WindCapacityFactor.Rd +++ b/man/WindCapacityFactor.Rd @@ -40,7 +40,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} diff --git a/man/WindPowerDensity.Rd b/man/WindPowerDensity.Rd index af919a6..8e3c8e3 100644 --- a/man/WindPowerDensity.Rd +++ b/man/WindPowerDensity.Rd @@ -37,7 +37,7 @@ select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in \code{data}.} -\item{time_dim}{A character string indicating the name of the function to +\item{time_dim}{A character string indicating the name of the dimension to compute the indicator. By default, it is set to 'ftime'. More than one dimension name matching the dimensions provided in the object \code{data$data} can be specified.} -- GitLab From 435ce7129996ef0e03d1796b5c07c5afa63e8e0c Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 21 Oct 2022 14:45:29 +0200 Subject: [PATCH 24/26] change if (class == 'Dates') to inherits --- R/MergeRefToExp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 068acfe..311053d 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -111,7 +111,7 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, # TO DO CONCATENATE DATES res <- Apply(list(dates1, dates2), target_dims = time_dim, c, output_dims = time_dim, ncores = ncores)$output1 - if (class(data1$Dates[[1]]) == 'Date') { + if (inherits(data1$Dates[[1]], 'Date')) { data1$Dates <- as.Date(res, origin = '1970-01-01') } else { data1$Dates <- as.POSIXct(res*3600*24, origin = '1970-01-01', tz = 'UTC') -- GitLab From cc720159eacfa2169657fc1c5f24684dacf55588 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 21 Oct 2022 17:14:13 +0200 Subject: [PATCH 25/26] Change data from CSTools in examples and use random. --- R/AbsToProbs.R | 6 ++++-- R/AccumulationExceedingThreshold.R | 5 +++-- R/MergeRefToExp.R | 16 +++++++++------- R/PeriodAccumulation.R | 6 ++++-- R/PeriodMean.R | 11 ++++++++--- R/QThreshold.R | 6 ++++-- R/SelectPeriodOnData.R | 5 +++-- R/Threshold.R | 6 +++--- R/TotalSpellTimeExceedingThreshold.R | 13 ++++++++++--- R/TotalTimeExceedingThreshold.R | 15 ++++++++++++--- man/AbsToProbs.Rd | 2 +- man/CST_AbsToProbs.Rd | 4 +++- man/CST_AccumulationExceedingThreshold.Rd | 5 +++-- man/CST_MergeRefToExp.Rd | 14 ++++++++------ man/CST_PeriodAccumulation.Rd | 4 +++- man/CST_PeriodMean.Rd | 9 +++++++-- man/CST_QThreshold.Rd | 6 ++++-- man/CST_SelectPeriodOnData.Rd | 5 +++-- man/CST_Threshold.Rd | 6 +++--- man/CST_TotalSpellTimeExceedingThreshold.Rd | 13 ++++++++++--- man/CST_TotalTimeExceedingThreshold.Rd | 12 ++++++++++-- man/PeriodAccumulation.Rd | 2 +- man/PeriodMean.Rd | 2 +- man/TotalTimeExceedingThreshold.Rd | 3 ++- 24 files changed, 119 insertions(+), 57 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index 89c72c9..a11506e 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -31,7 +31,9 @@ #'@return An 's2dv_cube' object containing the probabilites in the element \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_prec +#'exp <- NULL +#'exp$data <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'class(exp) <- 's2dv_cube' #'exp_probs <- CST_AbsToProbs(exp) #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) @@ -115,7 +117,7 @@ CST_AbsToProbs <- function(data, start = NULL, end = NULL, #'probabilites in the element \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_prec$data +#'exp <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) #'exp_probs <- AbsToProbs(exp) #'data <- array(rnorm(5 * 2 * 61 * 1), #' c(member = 5, sdate = 2, ftime = 61, lon = 1)) diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index cceb07b..ae08c0d 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -41,8 +41,9 @@ #'@return A 's2dv_cube' object containing the indicator in the element \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_data$exp -#'exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +#'exp <- NULL +#'exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'class(exp) <- 's2dv_cube' #'DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) #' #'@import multiApply diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 068acfe..216dc8e 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -44,15 +44,17 @@ #' seq(as.Date("01-07-1994", "%d-%m-%Y", tz = 'UTC'), #' as.Date("01-12-1994","%d-%m-%Y", tz = 'UTC'), "day")) #'dim(data_dates) <- c(ftime = 154, sdate = 2) +#'data <- NULL +#'data$data <- array(1:(2*154*2), c(ftime = 154, sdate = 2, member= 2)) +#'data$Dates$start <- data_dates +#'class(data) <- 's2dv_cube' #'ref_dates <- seq(as.Date("01-01-1993", "%d-%m-%Y", tz = 'UTC'), #' as.Date("01-12-1994","%d-%m-%Y", tz = 'UTC'), "day") #'dim(ref_dates) <- c(ftime = 350, sdate = 2) -#'ref <- array(1001:1700, c(ftime = 350, sdate = 2)) -#'data <- array(1:(2*154*2), c(ftime = 154, sdate = 2, member= 2)) -#'ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = ref_dates, -#' end = ref_dates)) -#'data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, -#' end = data_dates)) +#'ref <- NULL +#'ref$data <- array(1001:1700, c(ftime = 350, sdate = 2)) +#'ref$Dates$start <- ref_dates +#'class(ref) <- 's2dv_cube' #'new_data <- CST_MergeRefToExp(data1 = ref, data2 = data, #' start1 = list(21, 6), end1 = list(30, 6), #' start2 = list(1, 7), end2 = list(21, 9)) @@ -111,7 +113,7 @@ CST_MergeRefToExp <- function(data1, data2, start1, end1, start2, end2, # TO DO CONCATENATE DATES res <- Apply(list(dates1, dates2), target_dims = time_dim, c, output_dims = time_dim, ncores = ncores)$output1 - if (class(data1$Dates[[1]]) == 'Date') { + if (inherits(data1$Dates[[1]], 'Date')) { data1$Dates <- as.Date(res, origin = '1970-01-01') } else { data1$Dates <- as.POSIXct(res*3600*24, origin = '1970-01-01', tz = 'UTC') diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index ab093be..c64672d 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -34,7 +34,9 @@ #'\code{data}. #' #'@examples -#'exp <- CSTools::lonlat_prec +#'exp <- NULL +#'exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'class(exp) <- 's2dv_cube' #'TP <- CST_PeriodAccumulation(exp) #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) @@ -123,7 +125,7 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, #'indicator in the element \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_prec$data +#'exp <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) #'TP <- PeriodAccumulation(exp, time_dim = 'ftime') #'data <- array(rnorm(5 * 3 * 214 * 2), #' c(memb = 5, sdate = 3, time = 214, lon = 2)) diff --git a/R/PeriodMean.R b/R/PeriodMean.R index 55f28cd..97f99c3 100644 --- a/R/PeriodMean.R +++ b/R/PeriodMean.R @@ -34,8 +34,13 @@ #' \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_data$exp -#'exp$data <- CSTools::lonlat_data$exp$data[1, , 3, , 1, 1] +#'exp <- NULL +#'exp$data <- array(rnorm(45), dim = c(member = 7, ftime = 8)) +#'class(exp) <- 's2dv_cube' +#'exp$Dates$start <- c(seq(as.Date("01-07-1993", "%d-%m-%Y", tz = 'UTC'), +#' as.Date("01-08-1993","%d-%m-%Y", tz = 'UTC'), "day"), +#' seq(as.Date("01-07-1994", "%d-%m-%Y", tz = 'UTC'), +#' as.Date("01-08-1994","%d-%m-%Y", tz = 'UTC'), "day")) #'SA <- CST_PeriodMean(exp) #' #'@import multiApply @@ -111,7 +116,7 @@ CST_PeriodMean <- function(data, start = NULL, end = NULL, #'indicator in the element \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_prec$data +#'exp <- array(rnorm(56), dim = c(member = 7, ftime = 8)) #'SA <- PeriodMean(exp, time_dim = 'ftime') #' #'@import multiApply diff --git a/R/QThreshold.R b/R/QThreshold.R index 4663411..8eb950a 100644 --- a/R/QThreshold.R +++ b/R/QThreshold.R @@ -53,7 +53,9 @@ #' #'@examples #'threshold <- 26 -#'exp <- CSTools::lonlat_prec +#'exp <- NULL +#'exp$data <- array(abs(rnorm(112)*26), dim = c(member = 7, sdate = 8, ftime = 2)) +#'class(exp) <- 's2dv_cube' #'exp_probs <- CST_QThreshold(exp, threshold) #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) @@ -63,7 +65,7 @@ #' 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')) -#'exp_probs <- CST_QThreshold(exp, threshold, start = list(21, 4), end = list(21, 6)) +#'exp_probs <- CST_QThreshold(exp, threshold) #' #'@import multiApply #'@importFrom ClimProjDiags Subset diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index 49575a2..3c162dd 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -21,15 +21,16 @@ #'\code{data$data} during the period requested from \code{start} to \code{end}. #' #'@examples -#'exp <- CSTools::lonlat_prec +#'exp <- NULL #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), +#'exp$Dates$start <- 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')) +#'class(exp) <- 's2dv_cube' #'Period <- CST_SelectPeriodOnData(exp, start = list(21, 6), end = list(21, 9)) #' #'@import multiApply diff --git a/R/Threshold.R b/R/Threshold.R index 18b8dea..0117952 100644 --- a/R/Threshold.R +++ b/R/Threshold.R @@ -38,16 +38,16 @@ #' #'@examples #'threshold <- 0.9 -#'exp <- CSTools::lonlat_prec -#'exp_probs <- CST_Threshold(exp, threshold) +#'exp <- NULL #'exp$data <- array(rnorm(5 * 3 * 214 * 2), #' c(member = 5, sdate = 3, ftime = 214, lon = 2)) -#'exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), +#'exp$Dates$start <- 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')) +#'class(exp) <- 's2dv_cube' #'exp_probs <- CST_Threshold(exp, threshold, start = list(21, 4), end = list(21, 6)) #' #'@import multiApply diff --git a/R/TotalSpellTimeExceedingThreshold.R b/R/TotalSpellTimeExceedingThreshold.R index 7039f28..ac2261a 100644 --- a/R/TotalSpellTimeExceedingThreshold.R +++ b/R/TotalSpellTimeExceedingThreshold.R @@ -45,9 +45,16 @@ #'\code{data}. #' #'@examples -#'exp <- CSTools::lonlat_data$exp -#'exp$data <- array(rnorm(5 * 3 * 20 * 2, mean = 25, sd = 3), -#' c(member = 5, sdate = 3, ftime = 20, lon = 2)) +#'exp <- NULL +#'exp$data <- array(rnorm(5 * 3 * 214 * 2)*23, +#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) +#'exp$Dates$start <- 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')) +#'class(exp) <- 's2dv_cube' #'TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 23, spell = 3) #' #'@import multiApply diff --git a/R/TotalTimeExceedingThreshold.R b/R/TotalTimeExceedingThreshold.R index 6e6e72d..ec25244 100644 --- a/R/TotalTimeExceedingThreshold.R +++ b/R/TotalTimeExceedingThreshold.R @@ -50,8 +50,16 @@ #'\code{data}. #' #'@examples -#'exp <- CSTools::lonlat_data$exp -#'exp$data <- CSTools::lonlat_data$exp$data[1, 1, 3, 3, 1, 1] +#'exp <- NULL +#'exp$data <- array(abs(rnorm(5 * 3 * 214 * 2)*280), +#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) +#'exp$Dates$start <- 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')) +#'class(exp) <- 's2dv_cube' #'DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) #' #'@import multiApply @@ -147,7 +155,8 @@ CST_TotalTimeExceedingThreshold <- function(data, threshold, op = '>', #'indicator in the element \code{data}. #' #'@examples -#'exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +#'exp <- array(abs(rnorm(5 * 3 * 214 * 2)*280), +#' c(member = 5, sdate = 3, ftime = 214, lon = 2)) #'DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') #' #'@import multiApply diff --git a/man/AbsToProbs.Rd b/man/AbsToProbs.Rd index 89b1f83..9b79296 100644 --- a/man/AbsToProbs.Rd +++ b/man/AbsToProbs.Rd @@ -59,7 +59,7 @@ probabilities of each value in the ensemble. If multiple initializations Distribution Function excluding the corresponding initialization. } \examples{ -exp <- CSTools::lonlat_prec$data +exp <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) exp_probs <- AbsToProbs(exp) data <- array(rnorm(5 * 2 * 61 * 1), c(member = 5, sdate = 2, ftime = 61, lon = 1)) diff --git a/man/CST_AbsToProbs.Rd b/man/CST_AbsToProbs.Rd index dcdcef9..fe58b51 100644 --- a/man/CST_AbsToProbs.Rd +++ b/man/CST_AbsToProbs.Rd @@ -54,7 +54,9 @@ probabilities of each value in the ensemble. If multiple initializations Distribution Function excluding the corresponding initialization. } \examples{ -exp <- CSTools::lonlat_prec +exp <- NULL +exp$data <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +class(exp) <- 's2dv_cube' exp_probs <- CST_AbsToProbs(exp) exp$data <- array(rnorm(5 * 3 * 214 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 0754c24..4fb563a 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -68,8 +68,9 @@ function: } } \examples{ -exp <- CSTools::lonlat_data$exp -exp$data <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +exp <- NULL +exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +class(exp) <- 's2dv_cube' DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) } diff --git a/man/CST_MergeRefToExp.Rd b/man/CST_MergeRefToExp.Rd index 102b062..a5b9cc7 100644 --- a/man/CST_MergeRefToExp.Rd +++ b/man/CST_MergeRefToExp.Rd @@ -72,15 +72,17 @@ data_dates <- c(seq(as.Date("01-07-1993", "\%d-\%m-\%Y", tz = 'UTC'), seq(as.Date("01-07-1994", "\%d-\%m-\%Y", tz = 'UTC'), as.Date("01-12-1994","\%d-\%m-\%Y", tz = 'UTC'), "day")) dim(data_dates) <- c(ftime = 154, sdate = 2) +data <- NULL +data$data <- array(1:(2*154*2), c(ftime = 154, sdate = 2, member= 2)) +data$Dates$start <- data_dates +class(data) <- 's2dv_cube' ref_dates <- seq(as.Date("01-01-1993", "\%d-\%m-\%Y", tz = 'UTC'), as.Date("01-12-1994","\%d-\%m-\%Y", tz = 'UTC'), "day") dim(ref_dates) <- c(ftime = 350, sdate = 2) -ref <- array(1001:1700, c(ftime = 350, sdate = 2)) -data <- array(1:(2*154*2), c(ftime = 154, sdate = 2, member= 2)) -ref <- CSTools::s2dv_cube(data = ref, Dates = list(start = ref_dates, - end = ref_dates)) -data <- CSTools::s2dv_cube(data = data, Dates = list(start = data_dates, - end = data_dates)) +ref <- NULL +ref$data <- array(1001:1700, c(ftime = 350, sdate = 2)) +ref$Dates$start <- ref_dates +class(ref) <- 's2dv_cube' new_data <- CST_MergeRefToExp(data1 = ref, data2 = data, start1 = list(21, 6), end1 = list(30, 6), start2 = list(1, 7), end2 = list(21, 9)) diff --git a/man/CST_PeriodAccumulation.Rd b/man/CST_PeriodAccumulation.Rd index afd6080..d1bf476 100644 --- a/man/CST_PeriodAccumulation.Rd +++ b/man/CST_PeriodAccumulation.Rd @@ -55,7 +55,9 @@ by using this function: } } \examples{ -exp <- CSTools::lonlat_prec +exp <- NULL +exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +class(exp) <- 's2dv_cube' TP <- CST_PeriodAccumulation(exp) exp$data <- array(rnorm(5 * 3 * 214 * 2), c(memb = 5, sdate = 3, ftime = 214, lon = 2)) diff --git a/man/CST_PeriodMean.Rd b/man/CST_PeriodMean.Rd index c4e3dae..b9ae538 100644 --- a/man/CST_PeriodMean.Rd +++ b/man/CST_PeriodMean.Rd @@ -55,8 +55,13 @@ this function: } } \examples{ -exp <- CSTools::lonlat_data$exp -exp$data <- CSTools::lonlat_data$exp$data[1, , 3, , 1, 1] +exp <- NULL +exp$data <- array(rnorm(45), dim = c(member = 7, ftime = 8)) +class(exp) <- 's2dv_cube' +exp$Dates$start <- c(seq(as.Date("01-07-1993", "\%d-\%m-\%Y", tz = 'UTC'), + as.Date("01-08-1993","\%d-\%m-\%Y", tz = 'UTC'), "day"), + seq(as.Date("01-07-1994", "\%d-\%m-\%Y", tz = 'UTC'), + as.Date("01-08-1994","\%d-\%m-\%Y", tz = 'UTC'), "day")) SA <- CST_PeriodMean(exp) } diff --git a/man/CST_QThreshold.Rd b/man/CST_QThreshold.Rd index a01c5d2..0edbcba 100644 --- a/man/CST_QThreshold.Rd +++ b/man/CST_QThreshold.Rd @@ -79,7 +79,9 @@ and memb_dim parameters: } \examples{ threshold <- 26 -exp <- CSTools::lonlat_prec +exp <- NULL +exp$data <- array(abs(rnorm(112)*26), dim = c(member = 7, sdate = 8, ftime = 2)) +class(exp) <- 's2dv_cube' exp_probs <- CST_QThreshold(exp, threshold) exp$data <- array(rnorm(5 * 3 * 214 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) @@ -89,6 +91,6 @@ exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", 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')) -exp_probs <- CST_QThreshold(exp, threshold, start = list(21, 4), end = list(21, 6)) +exp_probs <- CST_QThreshold(exp, threshold) } diff --git a/man/CST_SelectPeriodOnData.Rd b/man/CST_SelectPeriodOnData.Rd index 210fcaa..6e04162 100644 --- a/man/CST_SelectPeriodOnData.Rd +++ b/man/CST_SelectPeriodOnData.Rd @@ -34,15 +34,16 @@ A 's2dv_cube' object containing the subset of the object Auxiliary function to subset data for a specific period. } \examples{ -exp <- CSTools::lonlat_prec +exp <- NULL exp$data <- array(rnorm(5 * 3 * 214 * 2), c(memb = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), +exp$Dates$start <- 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')) +class(exp) <- 's2dv_cube' Period <- CST_SelectPeriodOnData(exp, start = list(21, 6), end = list(21, 9)) } diff --git a/man/CST_Threshold.Rd b/man/CST_Threshold.Rd index 906d1b1..5d260e9 100644 --- a/man/CST_Threshold.Rd +++ b/man/CST_Threshold.Rd @@ -65,16 +65,16 @@ given a dataset. } \examples{ threshold <- 0.9 -exp <- CSTools::lonlat_prec -exp_probs <- CST_Threshold(exp, threshold) +exp <- NULL exp$data <- array(rnorm(5 * 3 * 214 * 2), c(member = 5, sdate = 3, ftime = 214, lon = 2)) -exp$Dates[[1]] <- c(seq(as.Date("01-05-2000", format = "\%d-\%m-\%Y"), +exp$Dates$start <- 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')) +class(exp) <- 's2dv_cube' exp_probs <- CST_Threshold(exp, threshold, start = list(21, 4), end = list(21, 6)) } diff --git a/man/CST_TotalSpellTimeExceedingThreshold.Rd b/man/CST_TotalSpellTimeExceedingThreshold.Rd index d19415e..847fed2 100644 --- a/man/CST_TotalSpellTimeExceedingThreshold.Rd +++ b/man/CST_TotalSpellTimeExceedingThreshold.Rd @@ -69,9 +69,16 @@ using function \code{Threshold} or the data can be transform into probabilites by using function \code{AbsToProbs}. See section @examples. } \examples{ -exp <- CSTools::lonlat_data$exp -exp$data <- array(rnorm(5 * 3 * 20 * 2, mean = 25, sd = 3), - c(member = 5, sdate = 3, ftime = 20, lon = 2)) +exp <- NULL +exp$data <- array(rnorm(5 * 3 * 214 * 2)*23, + c(member = 5, sdate = 3, ftime = 214, lon = 2)) +exp$Dates$start <- 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')) +class(exp) <- 's2dv_cube' TTSET <- CST_TotalSpellTimeExceedingThreshold(exp, threshold = 23, spell = 3) } diff --git a/man/CST_TotalTimeExceedingThreshold.Rd b/man/CST_TotalTimeExceedingThreshold.Rd index 980d77b..bbd05e0 100644 --- a/man/CST_TotalTimeExceedingThreshold.Rd +++ b/man/CST_TotalTimeExceedingThreshold.Rd @@ -75,8 +75,16 @@ indices for heat stress can be obtained by using this function: } } \examples{ -exp <- CSTools::lonlat_data$exp -exp$data <- CSTools::lonlat_data$exp$data[1, 1, 3, 3, 1, 1] +exp <- NULL +exp$data <- array(abs(rnorm(5 * 3 * 214 * 2)*280), + c(member = 5, sdate = 3, ftime = 214, lon = 2)) +exp$Dates$start <- 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')) +class(exp) <- 's2dv_cube' DOT <- CST_TotalTimeExceedingThreshold(exp, threshold = 280) } diff --git a/man/PeriodAccumulation.Rd b/man/PeriodAccumulation.Rd index f6e6d3b..c589b9b 100644 --- a/man/PeriodAccumulation.Rd +++ b/man/PeriodAccumulation.Rd @@ -59,7 +59,7 @@ by using this function: } } \examples{ -exp <- CSTools::lonlat_prec$data +exp <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) TP <- PeriodAccumulation(exp, time_dim = 'ftime') data <- array(rnorm(5 * 3 * 214 * 2), c(memb = 5, sdate = 3, time = 214, lon = 2)) diff --git a/man/PeriodMean.Rd b/man/PeriodMean.Rd index 803a3f2..fffb332 100644 --- a/man/PeriodMean.Rd +++ b/man/PeriodMean.Rd @@ -59,7 +59,7 @@ this function: } } \examples{ -exp <- CSTools::lonlat_prec$data +exp <- array(rnorm(56), dim = c(member = 7, ftime = 8)) SA <- PeriodMean(exp, time_dim = 'ftime') } diff --git a/man/TotalTimeExceedingThreshold.Rd b/man/TotalTimeExceedingThreshold.Rd index 524f938..f874b50 100644 --- a/man/TotalTimeExceedingThreshold.Rd +++ b/man/TotalTimeExceedingThreshold.Rd @@ -78,7 +78,8 @@ be obtained by using this function: } } \examples{ -exp <- CSTools::lonlat_data$exp$data[1, 5, 3, 3, 1, 1] +exp <- array(abs(rnorm(5 * 3 * 214 * 2)*280), + c(member = 5, sdate = 3, ftime = 214, lon = 2)) DOT <- TotalTimeExceedingThreshold(exp, threshold = 300, time_dim = 'ftime') } -- GitLab From 4be99a01c72cf49ba2fbdfec1a3257a61c8d58e8 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Fri, 21 Oct 2022 17:41:41 +0200 Subject: [PATCH 26/26] Correct line breaks in examples --- R/AbsToProbs.R | 3 ++- R/AccumulationExceedingThreshold.R | 3 ++- R/PeriodAccumulation.R | 6 ++++-- man/CST_AbsToProbs.Rd | 3 ++- man/CST_AccumulationExceedingThreshold.Rd | 3 ++- man/CST_PeriodAccumulation.Rd | 3 ++- man/PeriodAccumulation.Rd | 3 ++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/R/AbsToProbs.R b/R/AbsToProbs.R index a11506e..708fabd 100644 --- a/R/AbsToProbs.R +++ b/R/AbsToProbs.R @@ -32,7 +32,8 @@ #' #'@examples #'exp <- NULL -#'exp$data <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'exp$data <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, +#' ftime = 9, lat = 2, lon = 2)) #'class(exp) <- 's2dv_cube' #'exp_probs <- CST_AbsToProbs(exp) #'exp$data <- array(rnorm(5 * 3 * 214 * 2), diff --git a/R/AccumulationExceedingThreshold.R b/R/AccumulationExceedingThreshold.R index ae08c0d..f202dca 100644 --- a/R/AccumulationExceedingThreshold.R +++ b/R/AccumulationExceedingThreshold.R @@ -42,7 +42,8 @@ #' #'@examples #'exp <- NULL -#'exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, +#' ftime = 9, lat = 2, lon = 2)) #'class(exp) <- 's2dv_cube' #'DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) #' diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index c64672d..0b3fde5 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -35,7 +35,8 @@ #' #'@examples #'exp <- NULL -#'exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, +#' ftime = 9, lat = 2, lon = 2)) #'class(exp) <- 's2dv_cube' #'TP <- CST_PeriodAccumulation(exp) #'exp$data <- array(rnorm(5 * 3 * 214 * 2), @@ -125,7 +126,8 @@ CST_PeriodAccumulation <- function(data, start = NULL, end = NULL, #'indicator in the element \code{data}. #' #'@examples -#'exp <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +#'exp <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, +#' ftime = 9, lat = 2, lon = 2)) #'TP <- PeriodAccumulation(exp, time_dim = 'ftime') #'data <- array(rnorm(5 * 3 * 214 * 2), #' c(memb = 5, sdate = 3, time = 214, lon = 2)) diff --git a/man/CST_AbsToProbs.Rd b/man/CST_AbsToProbs.Rd index fe58b51..57426ef 100644 --- a/man/CST_AbsToProbs.Rd +++ b/man/CST_AbsToProbs.Rd @@ -55,7 +55,8 @@ Distribution Function excluding the corresponding initialization. } \examples{ exp <- NULL -exp$data <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +exp$data <- array(rnorm(216), dim = c(dataset = 1, member = 2, sdate = 3, + ftime = 9, lat = 2, lon = 2)) class(exp) <- 's2dv_cube' exp_probs <- CST_AbsToProbs(exp) exp$data <- array(rnorm(5 * 3 * 214 * 2), diff --git a/man/CST_AccumulationExceedingThreshold.Rd b/man/CST_AccumulationExceedingThreshold.Rd index 4fb563a..9c0a521 100644 --- a/man/CST_AccumulationExceedingThreshold.Rd +++ b/man/CST_AccumulationExceedingThreshold.Rd @@ -69,7 +69,8 @@ function: } \examples{ exp <- NULL -exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, + ftime = 9, lat = 2, lon = 2)) class(exp) <- 's2dv_cube' DOT <- CST_AccumulationExceedingThreshold(exp, threshold = 280) diff --git a/man/CST_PeriodAccumulation.Rd b/man/CST_PeriodAccumulation.Rd index d1bf476..abc79b6 100644 --- a/man/CST_PeriodAccumulation.Rd +++ b/man/CST_PeriodAccumulation.Rd @@ -56,7 +56,8 @@ by using this function: } \examples{ exp <- NULL -exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +exp$data <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, + ftime = 9, lat = 2, lon = 2)) class(exp) <- 's2dv_cube' TP <- CST_PeriodAccumulation(exp) exp$data <- array(rnorm(5 * 3 * 214 * 2), diff --git a/man/PeriodAccumulation.Rd b/man/PeriodAccumulation.Rd index c589b9b..9903321 100644 --- a/man/PeriodAccumulation.Rd +++ b/man/PeriodAccumulation.Rd @@ -59,7 +59,8 @@ by using this function: } } \examples{ -exp <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, ftime = 9, lat = 2, lon = 2)) +exp <- array(rnorm(216)*200, dim = c(dataset = 1, member = 2, sdate = 3, + ftime = 9, lat = 2, lon = 2)) TP <- PeriodAccumulation(exp, time_dim = 'ftime') data <- array(rnorm(5 * 3 * 214 * 2), c(memb = 5, sdate = 3, time = 214, lon = 2)) -- GitLab