ex1_4_variable_nmember.R 3.4 KB
Newer Older
nperez's avatar
nperez committed
# This code shows that the number of members could depend on the start date
aho's avatar
aho committed
# and the order of start dates requested.
# See FAQ 10 [The members depends on the start date](https://earth.bsc.es/gitlab/es/startR/-/blob/master/inst/doc/faq.md#10-the-number-of-members-depends-on-the-start-date)
nperez's avatar
nperez committed

library(startR)

path_list <- list(list(name = 'system5',   
aho's avatar
aho committed
                       path = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc'))
nperez's avatar
nperez committed
sdates_exp <- c('19991101', '19990901')
data_Nov_Sep <- Start(dat = path_list,
                      var = 'psl',
                      member = 'all',
                      sdate = sdates_exp,
                      time = indices(1),
                      latitude = values(list(0, 20)),
                      latitude_reorder=Sort(),
nperez's avatar
nperez committed
                      longitude = values(list(0, 5)),
                      synonims = list(latitude = c('lat', 'latitude'),
                                      longitude = c('lon', 'longitude'),
                                      member = c('ensemble', 'realization')),
                      retrieve = TRUE)
# 51 members 
dim(data_Nov_Sep)
#      dat       var    member     sdate      time  latitude longitude 
#        1         1        51         2         1        71        19 
nperez's avatar
nperez committed
apply(data_Nov_Sep, 4, function(x){sum(is.na(x))})
# 26 missing values for the second start date

sdates_exp <- c('19990901', '19991101')
data_Sep_Nov <- Start(dat = path_list,
                      var = 'psl',
                      member = 'all',
                      sdate = sdates_exp,
                      time = indices(1),
                      latitude = values(list(0, 20)),
                      latitude_reorder=Sort(),
nperez's avatar
nperez committed
                      longitude = values(list(0, 5)),
                      synonims = list(latitude = c('lat', 'latitude'),
                                      longitude = c('lon', 'longitude'),
                                       member = c('ensemble', 'realization')),
                      retrieve = TRUE)

# 25 members available
dim(data_Sep_Nov)
#      dat       var    member     sdate      time  latitude longitude 
#        1         1        25         2         1        71        19 
nperez's avatar
nperez committed

# Any missing value:
apply(data_Sep_Nov, 4, function(x){sum(is.na(x))})


aho's avatar
aho committed
# Use 'largest_dims_length = TRUE' to explore the largest dimension length among all the files.

sdates_exp <- c('19990901', '19991101')
data_Sep_Nov2 <- Start(dat = path_list,
                       var = 'psl',
                       member = 'all',
                       sdate = sdates_exp,
                       time = indices(1),
                       latitude = values(list(0, 20)),
                       latitude_reorder=Sort(),
                       longitude = values(list(0, 5)),
                       synonims = list(latitude = c('lat', 'latitude'),
                                       longitude = c('lon', 'longitude'),
                                        member = c('ensemble', 'realization')),
                       largest_dims_length = T,
                       retrieve = TRUE)

dim(data_Sep_Nov2)
#      dat       var    member     sdate      time  latitude longitude 
#        1         1        51         2         1        71        19 
identical(as.vector(data_Sep_Nov2[1, 1, , 2, 1, , ]), as.vector(data_Nov_Sep[1, 1, , 1, 1, , ]))
#[1] TRUE
identical(as.vector(data_Sep_Nov2[1, 1, , 1, 1, , ]), as.vector(data_Nov_Sep[1, 1, , 2, 1, , ]))
#[1] TRUE
nperez's avatar
nperez committed