library(CSTools)
library(s2dv)

# Toy data:
exp <- rnorm(144*73*23*63)
obs <- rnorm(144*73*23*1)

# Provide named dimensions:
dim(exp) <- c(lon = 144, lat = 73, ftime = 23, member = 63, sdate = 1, dataset = 1)
dim(obs) <- c(lon = 144, lat = 73, ftime = 23, member = 1, sdate = 1, dataset = 1 )
exp <- Reorder(exp, c('dataset', 'member', 'sdate', 'ftime', 'lat', 'lon'))
obs <- Reorder(obs, c('dataset', 'member', 'sdate', 'ftime', 'lat', 'lon'))

# Convert to class s2dv_cube
exp <- s2dv_cube(exp, lon = 1:144, lat = 1:73,
                 Variable = list(varName = "stormtd", level = "10m"))
obs <- s2dv_cube(obs, lon = 1:144, lat = 1:73,
                 Variable = list(varName = "stormtd", level = "10m"))

# Compute Anomalies:

ano <- CST_Anomaly(exp, obs, memb = F, dim_anom = 4)
dim(ano$exp$data)
dim(ano$obs$data)
summary(ano$exp$data)
summary(ano$obs$data)
#-------------------------------------------------------------------------


# Toy data:
exp <- 1:(144*73*23*63)
obs <- 1:(144*73*23*1)

# Provide named dimensions:
dim(exp) <- c(lon = 144, lat = 73, data = 23, member = 63)
dim(obs) <- c(lon = 144, lat = 73, data = 23, member = 1)
exp <- Reorder(exp, c('member', 'data', 'lat', 'lon')

# Convert to class s2dv_cube
exp <- s2dv_cube(exp, lon = 1:144, lat = 1:73,
                 Variable = list(varName = "stormtd", level = "10m"))
obs <- s2dv_cube(obs, lon = 1:144, lat = 1:73,
                 Variable = list(varName = "stormtd", level = "10m"))

# Compute Anomalies:

ano <- CST_Anomaly(exp, obs, memb = T)

# --------------------------------------------------------------
# Toy data:
exp <- 1:(144 * 73 * 4 * 3 * 63)
obs <- 1:(144 * 73 * 4 * 3 * 1)

# Provide named dimensions:
dim(exp) <- c(dataset = 1, lon = 144, lat = 73, sdate = 3, ftime = 4, member = 63)
dim(obs) <- c(dataset = 1, lon = 144, lat = 73, sdate = 3, ftime = 4, member = 1)
exp <- Reorder(exp, c('dataset', 'member', 'sdate', 'ftime','lat', 'lon'))
obs <- Reorder(obs, c('dataset', 'member', 'sdate', 'ftime','lat', 'lon'))

# Convert to class s2dv_cube
exp <- s2dv_cube(exp, lon = 1:144, lat = 1:73,
                 Variable = list(varName = "stormtd", level = "10m"))
obs <- s2dv_cube(obs, lon = 1:144, lat = 1:73,
                 Variable = list(varName = "stormtd", level = "10m"))

# Compute Anomalies:

ano <- CST_Anomaly(exp, obs, memb = T)

 

