load 24h observations from hourly files corresponding with specific hindcast times
Hi @aho ,
I am loading forecasts of instantantaneous daily wind speed values and I would like to load their corresponding observed value (from ERA5 hourly files). The forecasts are daily files with up to 47 days forecasts.
I have been trying to do this by obtaining the specific dates from the hindcast and using it to read the observations. However the observations are in monthly files with hourly values. It is not obviuos how to reorganise the obs to match the hindcast dates (also one has to take only the midnight value and discard the other hourly values).
Let me know if you have any idea if this can be done with Start! thanks!
Although the best option to handle this may be to create similar 24h files for ERA5 from the 1hourly files so they have the same format.
library(startR)
library(s2dv)
var_name='sfcWind'
hcst<-Start(dat = '/esarchive/exp/ecmwf/s2s-monthly_ensforhc/daily/$var$_f24h/$sdate$/$var$_$syear$.nc',
var = var_name,
sdate = '20161222',
syear = 'all',
time_day ='all',
latitude=indices(1),#'all',
longitude=indices(1),#'all',
ensemble = 'all',
syear_depends = 'sdate',
synonims = list(time_day='time'),
return_vars = list(latitude = 'dat',
longitude = 'dat',
time = c('sdate','syear')
),
retrieve = T)
dates <- attr(hcst, 'Variables')$common$time
#> dim(dates)
#sdate syear time_day
# 1 20 47
# get YYYYMM format (ERA5 is stored as 1 month files with all the hourly values 720 or 740)
file_date <- sapply(dates, format, '%Y%m')
dim(file_date) <- dim(dates)
obs <- Start(dat = '/esarchive/recon/ecmwf/era5/1hourly/$var$/$var$_$file_date$.nc',
var = var_name,
file_date= file_date, # dim('sdate','time')
latitude = indices(1),
longitude =indices(1),
time_hours = 'all', # seq(1,744,24)
#transform = CDORemapper,
#transform_params = list(
# grid = paste0('/esarchive/exp/ncep/cfs-v2/',
# 'weekly_mean/s2s/tas_f24h/tas_19990104.nc'),#
# method = 'con',
# crop = c(lons.min,lons.max,lats.min,lats.max)
# ),
# transform_vars = c('latitude', 'longitude'),
synonims = list(latitude=c('lat','latitude'),
longitude=c('lon','longitude'),
time_hours='time'),
return_vars = list(latitude = 'dat',
longitude = 'dat',#
time = c('file_date')),
split_multiselected_dims = TRUE,
retrieve=T)