# s2dverification

s2dverification (seasonal to decadal verification) is an R framework that aids in the analysis of forecasts from the data retrieval stage, through computation of statistics and skill scores against observations, to visualisation of data and results. While some of its components are only targeted to verification of seasonal to decadal climate forecasts, it provides with tools that can be useful for verification of forecasts in any field.

Find out more in the overview below, on the wiki page at <https://earth.bsc.es/gitlab/es/s2dverification/wikis/home> or on the CRAN website at <https://cran.r-project.org/web/packages/s2dverification/index.html>. You can also sign up to the s2dverification mailing list by sending a message with the subject 'subscribe' to s2dverification-request@bsc.es if you want to keep abreast of internal discussons or latest development releases.

## Installation

s2dverification has a system dependency, the CDO libraries, for interpolation of grid data and retrieval of metadata. Make sure you have these libraries installed in the system or download and install from <https://code.zmaw.de/projects/cdo>.

You can then install the released version of s2dverification from CRAN:
```R
install.packages("s2dverification")
```

Or the development version from the GitLab repository:
```R
# install.packages("devtools")
devtools::install_git("https://earth.bsc.es/gitlab/es/s2dverification.git")
```

## Overview

The following diagram depicts the modules of s2dverification and how they interact:

![s2dverification module diagram](vignettes/s2dv_modules.png)

The [Data retrieval](https://earth.bsc.es/gitlab/es/s2dverification/wikis/data_retrieval.md) module allows you to gather and homogenize NetCDF data files stored in a local or remote file system. A previous step is required, however, to set up some configuration parameters so that the module can locate the source files and recognize their format.

Once the data has been loaded into an R object, [Basic statistics](https://earth.bsc.es/gitlab/es/s2dverification/wikis/basic_statistics.md) can be computed, such as climatologies, trends, bias correction, smoothing, ...

Either after computing basic statistics or directly from the original data, the functions in the [Verification](https://earth.bsc.es/gitlab/es/s2dverification/wikis/verification.md) module allow you to compute deterministic and probabilistic scores and skill scores, such as root mean square error, time or spatial correlation or brier score.

[Visualisation](https://earth.bsc.es/gitlab/es/s2dverification/wikis/visualisation.md) functions are also provided to plot the results obtained from any of the modules above. 

Next you can see an example of usage of s2dverification spanning its four modules.

### Data retrieval

```{R}
library(s2dverification, lib.loc = '~/s2dverification/s2dverification.Rcheck')
expA <- list(name = 'experimentA',
             path = file.path('~/example/experiments/$EXP_NAME$/monthly_mean', 
                              '$VAR_NAME$/$VAR_NAME$_$START_DATE$.nc'))
expB <- list(name = 'experimentB',
             path = file.path('~/example/experiments/$EXP_NAME$/monthly_mean',
                              '$VAR_NAME$/$VAR_NAME$_$START_DATE$.nc'))
obsX <- list(name = 'observationX',
             path = file.path('~/example/observations/$OBS_NAME$/monthly_mean',
                              '$VAR_NAME$/$VAR_NAME$_$YEAR$$MONTH$.nc'))
data <- Load('tas', list(expA, expB), list(obsX),
             sdates = c('19851101', '19911101', '19971101'),
             lonmin = 100, lonmax = 250, latmin = -10, latmax = 60,
             leadtimemin = 2, leadtimemax = 7,
             output = 'lonlat', grid = 't106grid', 
             method = 'distance-weighted')
```

### Basic statistics
```R
```

### Verification
```R
```

### Visualisation
```R
```
