I am working with @ptrascas and other people to use SUNSET, and when doing our developments, we miss having the CST version (i.e. functions working on s2dv_cube) for some of the s2dv functions.

For instance, when trying to use the saving module of SUNSET we need to ensure the 'var' dimension exists and it is of length one at least. InsertDim works fine for the array but it does not add the new dimension to `$dims`

element to the s2dv_cube.

I think other functions could also be enhanced for SUNSET.

Could you consider creating a CST version for some of the s2dv functions?

Núria

**vagudets**
(621ed770)
*
at
29 Jul 14:07
*

This development is ready to be merged.

It includes a new function to calculate the spread to error ratio along with its statistical significance.

This is related to this merge request in SUNSET: sunset!141

Thanks,

Nadia

**vagudets**
(a7efa26d)
*
at
29 Jul 14:07
*

Merge branch 'dev-spread_error_ratio' into 'master'

*
... and
1 more commit
*

Hi @vagudets,

I have finished formatting the unit test and, unless some other adjustments are needed, I think it is ready to merge:)

Thanks,

Ariadna

**abatalla**
(621ed770)
*
at
25 Jul 15:39
*

Format fix test-SprErr.R

**abatalla**
(1fa20d4e)
*
at
25 Jul 13:24
*

Remove expect_equal(SprErr(exp4, obs4, dat_dim = 'dataset')$ratio[1...

**abatalla**
(5496826f)
*
at
25 Jul 13:23
*

Clean comments and format of test-SprErr.R

```
# Sample data for points with 4 options:
## point 1: numeric data
## point 2: hcst numeric, obs NA
## point 3: hcst NA obs NA
## point 4: hcst NA obs numeric
hcst <- array(c(rnorm(8*2*2*20), rep(NA, 96*20/3)),
c(syear = 8, ftime = 2, member = 20, points = 4))
obs <- array(c(rep(c(0,0,1),8*2), rep(NA, 96), rep(c(0,0,1),8*2)),
c(bin = 3, syear = 8, ftime = 2, points = 4))
hcst <- GetProbs(hcst, prob_threshold = c(1/3, 2/3), time_dim = 'syear')
test <- RPSS(hcst, obs, time_dim = 'syear', memb_dim = NULL,
cat_dim = 'bin', Fair = fair, nmemb = nmemb,
nmemb_ref = sdate_dim - 1,
cross.val = FALSE,
na.rm = FALSE)
```

I think the problem comes from good_values at line 537:

```
# Use good values only
good_values <- !is.na(rps_exp[, i, j])
if (f_NAs <= sum(good_values) / length(good_values)) {
obs_data <- obs[good_values, , j]
```

Including an alternative to this condition seems to partially work in line 568:

```
else {
probs_clim_cumsum <- array(NA, c(1, 2))
}
```

```
test <- RPSS(hcst, obs, time_dim = 'syear', memb_dim = NULL,
cat_dim = 'bin', Fair = fair, nmemb = nmemb,
nmemb_ref = sdate_dim - 1,
cross.val = FALSE,
na.rm = FALSE)
> dim(test$rpss)
ftime points
2 4
> test$rpss[,1]
[1] -0.1782544 -0.1715976
> test$rpss[,2]
[1] NA NA
> test$rpss[,3]
[1] NA NA
> test$rpss[,4]
[1] NA NA
test <- RPSS(hcst, obs, time_dim = 'syear', memb_dim = NULL,
cat_dim = 'bin', Fair = fair, nmemb = nmemb,
nmemb_ref = sdate_dim - 1,
cross.val = FALSE,
na.rm = TRUE)
Error in colSums((probs_exp_cumsum - probs_obs_cumsum)^2) :
'x' must be an array of at least two dimensions
```

I would expect the result to be the same fo na.rm = TRUE, but in this case, RPS() fails when computing the RPS for the hcst. It could make sense.

Núria

Hi,

I am getting errors for 'tos' variable when using probabilities. It is related to NAs and both, an.rm = TRUE/FALSE, return errors:

```
> rpss <- RPSS(exp = ano_hcst_probs_ev, obs = ano_obs_probs_ev,
time_dim = 'syear', memb_dim = NULL,
cat_dim = 'probs', Fair = fair, nmemb = nmemb,
nmemb_ref = sdate_dim - 1,
cross.val = FALSE,
na.rm = FALSE,
ncores = recipe$Analysis$ncores)
Error in do.ply(i) :
task 1 failed - "object 'probs_clim_cumsum' not found"
> rpss <- RPSS(exp = ano_hcst_probs_ev, obs = ano_obs_probs_ev,
time_dim = 'syear', memb_dim = NULL,
cat_dim = 'probs', Fair = fair, nmemb = nmemb,
nmemb_ref = sdate_dim - 1,
cross.val = FALSE,
na.rm = TRUE,
ncores = recipe$Analysis$ncores)
Error in do.ply(i) :
task 1 failed - "'x' must be an array of at least two dimensions"
```

I need this to work, so, I keep investigating.

Núria

**vagudets**
(42e258ac)
*
at
24 Jul 15:56
*

Merge branch 'dev-NAO_fcst' into 'master'

*
... and
16 more commits
*

I have added the possibility of `NAO()`

to accept a `exp_cor`

object and then return the NAO forecast in the branch https://earth.bsc.es/gitlab/es/s2dv/-/tree/dev-NAO_fcst?ref_type=heads

If this object is not NULL, the past NAO (using `exp`

or `obs`

depending on the `obsproj`

parameter) is calculated without cross-validation and then projected on the forecast anomalies using `.ProjectField`

function.

Maybe @vtorralba could confirm if she agrees with this procedure.

I think the code already works, and I plan to integrate it into SUNSET to evaluate the results.

Cheers,

Núria

Issue #119

The current version of RPS and RPSS accept probabilities. For the fair version of these metrics, the calculation requires the number of members from which these probabilities were calculated. A new parameter is required because the data inputs don't have a member dimension. I named it

`nmemb`

and it is only required when Fair is TRUE.

I am not using the reference forecast parameter, but in that case, the number of members may differ from those in the experiment. Therefore, in the RPSS case, a new

`nmemb_ref`

parameter is needed.

When the climatology is the reference forecast,

`nmemb_ref`

should be equal to the number of years used to compute the climatology.

FYI @nperez

**vagudets**
(c93fc8ce)
*
at
24 Jul 15:42
*

Merge branch 'master' into 'dev-NAO_fcst'

*
... and
22 more commits
*

**abatalla**
(c22c2b1e)
*
at
15 Jul 16:39
*

removed source() lines in test-SprErr.R

**abatalla**
(1a79b299)
*
at
15 Jul 16:15
*

Unit test for SprErr.R

Hi @vagudets,

Right! Well seen, documentation now says default value of `na.rm`

is `FALSE`

.

And okay, I will leave all NAs in the `SprErr(exp4_2, obs4_2, dat_dim = 'dataset')$ratio`

check.

Regarding the `SprErr(exp4, obs4, dat_dim = 'dataset')$ratio`

values, should I just skip this check then?

```
expect_equal(
SprErr(exp4, obs4, dat_dim = 'dataset')$ratio[1],
SprErr(exp2, obs2)$ratio
)
```

Thank you,

Ariadna

My bad! Actually, this (the duplicated values) also happens for RPSS, so I guess it's related to the data and not a bug:

```
RPSS(exp4, obs4, dat_dim = 'dataset')$rpss
, , 1
[,1] [,2]
[1,] -0.7763158 -0.7763158
[2,] -0.5394737 -1.0131579
[3,] -1.4868421 -0.3026316
, , 2
[,1] [,2]
[1,] -0.7763158 -0.7763158
[2,] -0.5394737 -1.0131579
[3,] -1.4868421 -0.3026316
```

Victòria

**abatalla**
(f8fffa24)
*
at
12 Jul 15:49
*

Bugfix: default value of na.rm is FALSE