library(CSTools)
# CST_BiasCorrection
mod1 <- 1 : (1 * 3 * 4 * 5 * 6 * 7)
dim(mod1) <- c(dataset = 1, member = 3, sdate = 4, ftime = 5, lat = 6, lon = 7)
obs1 <- 1 : (1 * 1 * 4 * 5 * 6 * 7)
dim(obs1) <- c(dataset = 1, member = 1, sdate = 4, ftime = 5, lat = 6, lon = 7)
lon <- seq(0, 30, 5)
lat <- seq(0, 25, 5)
exp <- list(data = mod1, lat = lat, lon = lon)
obs <- list(data = obs1, lat = lat, lon = lon)
attr(exp, 'class') <- 's2dv_cube'
attr(obs, 'class') <- 's2dv_cube'
a <- CST_BiasCorrection(exp = exp, obs = obs)
str(a)
PlotEquiMap(a$data[1,1,1,1,,], lon = a$lon, lat = a$lat, filled.continents = F)

# CST_Calibration
mod1 <- 1 : (1 * 3 * 4 * 5 * 6 * 7)
dim(mod1) <- c(dataset = 1, member = 3, sdate = 4, ftime = 5, lat = 6, lon = 7)
obs1 <- 1 : (1 * 1 * 4 * 5 * 6 * 7)
dim(obs1) <- c(dataset = 1, member = 1, sdate = 4, ftime = 5, lat = 6, lon = 7)
lon <- seq(0, 30, 5)
lat <- seq(0, 25, 5)
exp <- list(data = mod1, lat = lat, lon = lon)
obs <- list(data = obs1, lat = lat, lon = lon)
attr(exp, 'class') <- 's2dv_cube'
attr(obs, 'class') <- 's2dv_cube'
b <- CST_Calibration(exp = exp, obs = obs, cal.method = "bias")
str(b)
PlotEquiMap(b$data[1,1,1,1,,], lon = a$lon, lat = a$lat, filled.continents = F)

dim(a$data)
dim(b$data)

plot(1:5, a$data[1,1,1,,1,1], ylim = c(-5,50))
lines(1:5, obs$data[1,1,1,,1,1], lwd = 2)
lines(1:5, exp$data[1,1,1,,1,1], col = 'blue')
lines(1:5, b$data[1,1,1,,1,1], type = 'p', pch = 16, col = 'red')

a <- CST_BiasCorrection(exp = lonlat_data$exp, obs = lonlat_data$obs)
b <- CST_Calibration(exp = lonlat_data$exp, obs = lonlat_data$obs, cal.method = 'bias')

plot(1:3, a$data[1,1,1,,1,1], ylim = c(275,282))
lines(1:3, lonlat_data$obs$data[1,1,1,,1,1], lwd = 2)
lines(1:3, lonlat_data$exp$data[1,1,1,,1,1], col = 'blue')
lines(1:3, b$data[1,1,1,,1,1], type = 'p', pch = 16, col = 'red')
