# Plot for the manuscript
library(CSTools)
library(zeallot)
glosea5 <- '/esnas/exp/glosea5/specs-seasonal_i1p1/$STORE_FREQ$_mean/$VAR_NAME$-allmemb/$VAR_NAME$_$START_DATE$.nc'
c(exp, obs) %<-% CST_Load(var = 'tas', exp = list(list(name = 'glosea5', path = glosea5),
                                                                           list(name = 'ecmwf/system4_m1'),
                                                                           list(name = 'meteofrance/system5_m1')),
                                                obs = "erainterim", sdates = '19921101',
                                                leadtimemin = 2, leadtimemax = 2,
                                                lonmin = -20, lonmax = 70, latmin = 25, latmax = 75, 
                                                storefreq = "monthly", sampleperiod = 1,  nmember = 15, 
                                                output = "areave")
dim(exp$data) <- c(dataset = 3, members = 15)
terciles <- t(round(apply(exp$data - 273.15, 1, quantile, c(0.33, 0.66)), 1))
extremes <- t(round(apply(exp$data - 273.15, 1, quantile, c(0.10, 0.99)), 1))
PlotForecastPDF(exp$data - 273.15, tercile.limits = terciles,
                             obs = as.vector(obs$data) - 273.15,
                             extreme.limits = extremes,
                             fcst.name = c('Glosea5', 'ECMWF', 'MeteoFrance'),
                             var.name = 'Air Temperature at surface (ºC)',
                             title = 'December 1992 forecast initialized on November 1992')

# ---------------------------------------------------


library(CSTools)
library(zeallot)
ini <- 1992
fin <- 2012
start <- as.Date(paste(ini, 11, "01", sep = ""), "%Y%m%d")
end <- as.Date(paste(fin, 11, "01", sep = ""), "%Y%m%d")
dateseq <- format(seq(start, end, by = "year"), "%Y%m%d")
glosea5 <- '/esnas/exp/glosea5/specs-seasonal_i1p1/$STORE_FREQ$_mean/$VAR_NAME$-allmemb/$VAR_NAME$_$START_DATE$.nc'

c(exp, obs) %<-% 
   CST_Load(var = 'tas', exp = list(list(name = 'glosea5', path = glosea5), 
                                  list(name = 'ecmwf/system4_m1'),
                                  list(name = 'meteofrance/system5_m1')),
                  obs = "erainterim", sdates = dateseq[1],
                  leadtimemin = 2, leadtimemax = 2,
                  lonmin = -20, lonmax = 70, latmin = 25, latmax = 75, 
                  storefreq = "monthly", sampleperiod = 1,  nmember = 15, 
                  output = "areave")
dim(exp$data)
dim(obs$data)
dim(exp$data) <- c(dataset = 3, members = 15)
quantile(exp$data[1,] - 273.15, 0.33)
quantile(exp$data[1,] - 273.15, 0.66)
terciles <- c(2.1, 2.0 , 4.3, 2.4, 2.6, 4.7)
dim(terciles) <- c(3, 2) 
quantile(exp$data[1,] - 273.15, 0.10)
quantile(exp$data[1,] - 273.15, 0.99)
extremes <- c(1.4, 1.8, 4.1, 3.6, 3.4, 5.0)
dim(extremes) <- c(3, 2)
PlotForecastPDF(exp$data - 273.15, tercile.limits = terciles,
                obs = as.vector(obs$data) - 273.15,
                extreme.limits = extremes, 
                fcst.name = c('Glosea5', 'ECMWF', 'MeteoFrance'),
                var.name = 'Air Temperature at surface (ºC)',
                title = 'December 1992 forecast initialized on November 1992')


