Returning the attributes of the variable with retrieve=F in a StartR load
Right now, we don't have the attributes of the variables (such as the units for instance) when using retrieve=F in a startR call.
Would it be possible to add it at some point? It's useful for me when I want then to save the data in a netcdf file with the correct metadata for instance.
Part of a script that can be used (part of this one: /esarchive/scratch/Earth/acarreri/scripts/bkup_scripts_HR_forecast/scripts_R/1-1.Load_and_save_seasonal_forecast_timeseries_rawvalues_ocean_seaice_variables.R
):
library(startR)
expid <- 'a3vg'
model <- 'EC-Earth3-HR'
compo <- 'Omon'
grid <- 'gn'
vari <- 'tosmean'
reg <- 'Nino3'
startdates <- as.character(c(seq(1990,1992)))
init_month <- 5
length_forecast <- 4
membs_num <- c(seq(1,2))
forecast_month <- c(seq(init_month,(init_month+length_forecast-1)))
membs <- paste0('r', membs_num, 'i1p1f1', sep="")
path <- paste0('/esarchive/exp/ecearth/', expid, '/diags/DCPP/EC-Earth-Consortium/', model, '/dcppA-hindcast/$memb$/', compo, '/$var$/', grid, '/v*/$var$_', compo, '_', model, '_dcppA-hindcast_s$sdate$-$memb$_', grid, '_$chunk$.nc')
data_exp_retrieved <- startR::Start(dat = path,
var = vari,
memb = membs,
region = reg,
region_var = 'region',
sdate = startdates,
time = c(1:length(forecast_month)),
chunk = 'all',
chunk_depends = 'sdate',
time_across = 'chunk',
merge_across_dims = TRUE,
return_vars = list(time=c('sdate','chunk'), region=NULL),
retrieve = T)
print(attr(data_exp_retrieved,"Variables")$common[[vari]]$units)
return the correct units with retrieve=T but returns NULL with retrieve=F.
Many thanks