ecmwf s2s
I am trying to compare the code that I have to the parameters available in an atomic recipe to define the temporal settings.
- sdate: is a character indicating a date "YYYYMMDD"
- fcst_year: is a character indicating the year "YYYY"
- hcst_start: for ECMWF, by default, 20 years previous to fcst_year
- hcst_end: for ECMWF, by default, 1 year previous to fcst_year
- ftime_min
- ftime_max
- week_day: # Not sure if we can use it for ECMWF
- sday_window
- sweek_window
# To take it from config:
path_hcst <- "/esarchive/exp/ecmwf/s2s-monthly_ensforhc/daily/tas/"
path_fcst <- "/esarchive/exp/ecmwf/s2s-monthly_ensfor/daily/tas/"
sdate <- recipe$Analysis$Time$sdate
sweek <- recipe$Analysis$Time$sweek_window
sday <- recipe$Analysis$Time$sday_window
hcst.start <- recipe$Analysis$Time$hcst_start
hcst.end <- recipe$Analysis$Time$hcst_end
var <- recipe$Analysis$Variable$name
# Convert sdate to date
sdate <- as.Date(as.character(sdate), format = "%Y%m%d")
# Use sweek_window to define all initialisations
## first a window of days to cover a period
timeframe <- (sweek + (sday - 1)/2)/2 * 4 # 4 is the number of days from Thursday to Monday
inidates <- seq(sdate - timeframe, sdate + timeframe, 1)
# Subset Mondays and Thursdays
inidates <- inidates[which(wday(inidates) %in% c(2,5))] # Sunday is one for lubridate
## sweek is a vector of Thursdays and Mondays of length sweek + extra dates for sday
# create sday sample
inidates <- do.call("c", lapply(1:sweek, function(x) {inidates[x:(x+(sday+1)/2)]}))
# format for path strings
inidates <- format(inidates, "%Y%m%d")
# add dimensions for Start()
dim(inidates) <- c(sday = sday, sweek = sweek)
# generalize for all years in hindcast period
years <- hcst.start:hcst.end
inidates <- do.call("c", lapply(years, function(x) {
paste0(x, format(as.Date(inidates, "%Y%m%d"), "%m%d"))}))
file_dates <- do.call("c", lapply(inidates, function(x) {
paste0("2024", format(as.Date(x, "%Y%m%d"), "%m%d"),
"/", var, "_", x, ".nc")}))
# This can be removed
# To check if they are correct with file.exists()
files <- do.call("c", lapply(inidates, function(x) {
paste0(path_hcst, "2024", format(as.Date(x, "%Y%m%d"), "%m%d"),
"/", var, "_", x, ".nc")}))
dim(files) <- c(sday = sday, sweek = sweek, syear = length(years))
files.fcst <- paste0(path_fcst, "/", var, "_", format(sdate, "%Y%m%d"),".nc")
To debugg it, I am using the following code:
recipe <- list(Analysis = list(Variables = list(name = 'tas'),
Time = list(
sdate = 20241024,
fcst_year = "2024",
hcst_start= '2004',
hcst_end= '2023',
ftime_min= 1,
ftime_max= 4,
week_day= "Thursday",
sday_window= 3,
sweek_window= 9)))
Edited by Nuria Pérez-Zanón