Newer
Older
author: "Earth Sciences department, Barcelona Supercomputing Center (BSC)"
output: rmarkdown::html_vignette
vignette: >
---
<!--
```{r, echo = FALSE}
knitr::opts_chunk$set(eval = FALSE)
```
-->
## 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.R -** Spring Total Precipitation (SprR) and Harvest Total Precipitation (HarvestR)
2. **PeriodMean.R -** Growing Season Temperature (GST) and Spring Mean Temperature Maximum (SPRTX)
3. **TotalTimeExceedingThreshold.R -** Number of Heat Stress Days - 35°C (SU35), 36°C (SU36), 40°C (SU40) and Spring Heat Stress Days - 32°C (Spr32)
4. **AccumulationExceedingThreshold.R -** Growing Degree Days (GDD)
5. **TotalSpellTimeExceedingThreshold.R -** 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/web/packages/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.R -** to select the data in the requested period
2. **SelectPeriodOnDates.R -** to select the time dimension in the requested period
3. **Threshold.R -** 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.
`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(s2dv)
library(s2dverification)
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/web/packages/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`.
var <- 'prlr'; lonmax <- 353; lonmin <- 352.25; latmax <- 41.75; latmin <- 41
cdoMethod <- 'bicubic'; leadtimemin <- 1; leadtimemax <- 214
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')
prlr_dv <- CST_Load(var = var, exp = list(S5path_prlr), obs = list(path_ERA5prlr_CDS), sdates = sdates, lonmax = lonmax, lonmin = lonmin, latmax = latmax, latmin = latmin, storefreq = 'daily', leadtimemin = leadtimemin, leadtimemax = leadtimemax, nmember = 3, output = "lonlat", grid = "r1440x721", method = cdoMethod)
The output contains elements `prlr_dv$exp$data` and `prlr_dv$obs$data` with dimensions:
```{r}
dim(prlr_dv$exp$data)
dataset member sdate ftime lat lon
1 3 4 214 4 4
dim(prlr_dv$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_dv$exp, start = list(21, 4), end = list(21, 6))
SprR_obs <- CST_PeriodAccumulation(prlr_dv$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)
The forecast SprR for the 1st member from 2013-2016 of the 1st grid point in mm are:
#[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_dv$exp, start = list(21, 8), end = list(21, 10))
HarvestR_obs <- CST_PeriodAccumulation(prlr_dv$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
```{r}
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
```{r}
lon <- prlr_dv$obs$lon; lat <- prlr_dv$obs$lat
pname_root <- "/esarchive/scratch/cchou/MEDGOLD/"
# Load Douro Valley boundary
load(file = paste0(pname_root, "demo/input/DV_boundary.RData"))
douro$x <- douro$x - 360
cols <- c('#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac')
brks <- seq(-60, 60, by = 20)
toptitle <- 'Ensemble-mean bias of HarvestR in 2013'
PlotEquiMap(Bias[1,,], lon = lon, lat = 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 = brks, toptitle = toptitle, colNA = 'white', 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.
<img src="vignettes/figures/HarvestR_Bias_2013-1.png" width="30%"/>
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).
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
```{r}
var <- 'tas'; lonmax <- 353; lonmin <- 352.25; latmax <- 41.75; latmin <- 41
cdoMethod <- 'bicubic'; leadtimemin <- 1; leadtimemax <- 214
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')
sdates <- paste0(2013:2016, '04', '01')
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
tas_dv <- CST_Load(var = var, exp = list(S5path), obs = list(ERA5path), sdates = sdates, lonmax = lonmax, lonmin = lonmin, latmax = latmax, latmin = latmin, storefreq = 'daily', leadtimemin = leadtimemin, leadtimemax = leadtimemax, nmember = 3, output = "lonlat", grid = "r1440x721", method = cdoMethod)
```
The output contains observations `tas_dv$obs$data` and forecast `tas_dv$exp$data`, and their dimensions and summaries are like
```{r}
dim(tas_dv$obs$data)
dataset member sdate ftime lat lon
1 1 4 214 4 4
dim(tas_dv$exp$data)
dataset member sdate ftime lat lon
1 3 4 214 4 4
summary(tas_dv$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_dv$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
```{r}
tas_dv$exp$data <- tas_dv$exp$data - 273.15
tas_dv$obs$data <- tas_dv$obs$data - 273.15
GST_exp <- CST_PeriodMean(tas_dv$exp, start = list(1, 4), end = list(31, 10))
GST_obs <- CST_PeriodMean(tas_dv$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:
```{r}
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
```{r}
# compute ERA5 GST climatology
GST_Clim <- MeanDims(drop(GST_obs$data), 'sdate')
# plot the map of climatology
cols <- c('#ffffd4','#fee391','#fec44f','#fe9929','#ec7014','#cc4c02','#8c2d04')
brks <- seq(16, 18.5, by = 0.5)
toptitle <- '2013-2016 mean ERA5 GST'
PlotEquiMap(GST_Clim, lon = lon, lat = 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 = brks, toptitle = toptitle, colNA = 'white', bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2)
<img src="vignettes/figures/GST_ERA5_Climatology-1.png" width="30%"/>
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.R
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
```{r}
var <- 'tasmax'; lonmax <- 353; lonmin <- 352.25; latmax <- 41.75; latmin <- 41
cdoMethod <- 'bicubic'; leadtimemin <- 1; leadtimemax <- 214
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')
sdates <- paste0(2013:2016, '04', '01')
tasmax_dv <- CST_Load(var = var, exp = list(S5path), obs = list(ERA5path), sdates = sdates, lonmax = lonmax, lonmin = lonmin, latmax = latmax, latmin = latmin, storefreq = 'daily', leadtimemin = leadtimemin, leadtimemax = leadtimemax, nmember = 3, output = "lonlat", grid = "r1440x721", method = cdoMethod, nprocs = 1)
```
Change the unit of temperature to from °C to K for the comparison with the threshold defined (for example 35°C here). And the longitude and latitude are prepared for plotting the figure.
```{r}
tasmax_dv$exp$data <- tasmax_dv$exp$data - 273.15
tasmax_dv$obs$data <- tasmax_dv$obs$data - 273.15
SU35_exp <- CST_TotalTimeExceedingThreshold(tasmax_dv$exp, threshold = threshold, start = list(1, 4), end = list(31, 10))
SU35_obs <- CST_TotalTimeExceedingThreshold(tasmax_dv$obs, threshold = threshold, start = list(1, 4), end = list(31, 10))
```
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
The summaries of SU35 forecasts and observations are given below.
```{r}
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.
```{r}
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.
```{r}
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
```{r}
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")
brks <- seq(0, 8, by = 2)
toptitle <- 'ERA5 SU35 forecast in 2016'
PlotEquiMap(SU35_obs_Y2016, lon = lon, lat = 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 = brks, toptitle = toptitle, colNA = cols[1], bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2)
PlotEquiMap(SU35_exp_Y2016, lon = lon, lat = 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 = brks, toptitle = toptitle, colNA = cols[1], bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2)
PlotEquiMap(SU35_exp_BC_Y2016, lon = lon, lat = 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 = brks, toptitle = toptitle, colNA = cols[1], bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2)
<img src="vignettes/figures/SU35_ERA5_Y2016-1.png" width="30%"/>
<img src="vignettes/figures/SU35_SEAS5_Y2016-1.png" width="30%"/>
<img src="vignettes/figures/SU35_SEAS5_BC_Y2016-1.png" width="30%"/>
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.
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
---
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
```{r}
exp_percentile <- AbsToProbs(tasmax_dv$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.
```{r}
obs_percentile <- QThreshold(tasmax_dv$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
```{r}
SU35_exp_Percentile <- TotalTimeExceedingThreshold(S5txP, threshold = obs_percentile, time_dim = 'ftime')
```
Compute the same ensemble-mean SU35 **with percentile adjustment** in 2016 by running
```{r}
SU35_exp_per_Y2016 <- MeanDims(SU35_exp_Percentile[, 4, , ], 'member')
```
Plot the same map for comparison
```{r}
toptitle <- 'SU35 forecast with percentile adjustment in 2016'
PlotEquiMap(SU35_exp_per_Y2016, lon = lon, lat = 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 = brks, toptitle = toptitle, colNA = cols[1], bar_label_scale = 1.5, bar_extra_margin = c(0, 0, 0, 0), units_scale = 2)
<img src="vignettes/figures/SU35_Percentile_SEAS5_Y2016-1.png" width="30%"/>
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.R
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.R) is loaded again (Please re-use the section of loading tas in Section 2).
Change the unit, if necessary, from °C to K and prepare the longitude and latitude by running
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
```{r}
tas_dv$exp$data <- tas_dv$exp$data - 273.15
tas_dv$obs$data <- tas_dv$obs$data - 273.15
lon <- tas_dv$obs$lon; lat <- tas_dv$obs$lat
```
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.
```{r}
GDD_exp <- CST_AccumulationExceedingThreshold(tas_dv$exp, threshold = 10, diff = TRUE)
GDD_obs <- CST_AccumulationExceedingThreshold(tas_dv$obs, threshold = 10, diff = TRUE)
```
The summaries of GDD are
```{r}
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
```{r}
# reorder the dimension
fcst <- Reorder(GDD_exp$data, c(4, 3, 2, 1))
obs <- Reorder(GDD_obs$data, c(3, 2, 1))
c <- veriApply('EnsCorr', fcst = fcst, obs = obs, ensdim = 4, tdim = 3)
GDD_Corr <- Reorder(c, c(2, 1))
```
To plot the map of correlation coefficient of GDD for the 2013-2016 period.
```{r}
cols <- c("#f7fcf5", "#e5f5e0", "#c7e9c0", "#a1d99b", "#74c476")
brks <- seq(0.5, 1, by = 0.1)
toptitle <- '2013-2016 correlation coefficient of GDD'
PlotEquiMap(GDD_Corr, lon = lon, lat = 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 = brks, 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.
<img src="vignettes/figures/GDD_SEAS5_Corr_Y13-16-1.png" width="30%"/>
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.R
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. TotalTimeExceedingThreshold.R is loaded here again (If necessary re-use the codes above).
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.
```{r}
tx_p <- CST_Threshold(tasmax_dv$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.
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
See the dimension and summary as below.
```{r}
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
```{r}
WSDI_exp <- CST_TotalSpellTimeExceedingThreshold(tasmax_dv$exp, threshold = tx_p, spell = 6)
WSDI_obs <- CST_TotalSpellTimeExceedingThreshold(tasmax_dv$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
```{r}
# 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
```{r}
cols <- c("#edf8fb", "#ccece6", "#99d8c9", "#66c2a4")
brks <- seq(0, 0.9, by = 0.3)
toptitle <- 'SEAS5 WSDI FRPSS (2013-2016)'
PlotEquiMap(WSDI_FRPSS, lon = lon, lat = 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 = brks, 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.
<img src="vignettes/figures/WSDI_SEAS5_FRPSS_Y13-16-1.png" width="30%"/>
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.