diff --git a/R/NcDataReader.R b/R/NcDataReader.R index 74df355aba72891d602a99d57fe99fa89b01e93f..222d11dcfae494bbd622ccd6094ad01001ae5f49 100644 --- a/R/NcDataReader.R +++ b/R/NcDataReader.R @@ -205,6 +205,8 @@ NcDataReader <- function(file_path = NULL, file_object = NULL, } else if (units %in% c('minute', 'minutes')) { # units <- 'mins' result <- result * 60 # min to sec + } else if (units %in% c('hour', 'hours')) { + result <- result * 60 * 60 # hour to sec } else if (units %in% c('day', 'days')) { # units <- 'days' result <- result * 24 * 60 * 60 # day to sec diff --git a/inst/doc/usecase/ex1_2_exp_obs_attr.R b/inst/doc/usecase/ex1_2_exp_obs_attr.R index acff7c9167d19b7bee40e96913859c0982c310b3..2e4b5da965ba642081bf0e362c7b873004f9d9e7 100644 --- a/inst/doc/usecase/ex1_2_exp_obs_attr.R +++ b/inst/doc/usecase/ex1_2_exp_obs_attr.R @@ -89,13 +89,12 @@ print(attr(obs, 'Dimensions')) ##-----time----- print(attr(exp, 'Variables')$common$time) -# [1] "2005-01-16 13:14:44 CET" "2006-01-16 13:14:44 CET" -# [3] "2007-01-16 13:14:44 CET" "2008-01-16 13:14:44 CET" -# [5] "2005-02-15 01:14:44 CET" "2006-02-15 01:14:44 CET" -# [7] "2007-02-15 01:14:44 CET" "2008-02-15 13:14:44 CET" -# [9] "2005-03-16 13:14:44 CET" "2006-03-16 13:14:44 CET" -#[11] "2007-03-16 13:14:44 CET" "2008-03-16 13:14:44 CET" - +# [1] "2005-01-16 12:00:00 UTC" "2006-01-16 12:00:00 UTC" +# [3] "2007-01-16 12:00:00 UTC" "2008-01-16 12:00:00 UTC" +# [5] "2005-02-15 00:00:00 UTC" "2006-02-15 00:00:00 UTC" +# [7] "2007-02-15 00:00:00 UTC" "2008-02-15 12:00:00 UTC" +# [9] "2005-03-16 12:00:00 UTC" "2006-03-16 12:00:00 UTC" +#[11] "2007-03-16 12:00:00 UTC" "2008-03-16 12:00:00 UTC" print(attr(obs, 'Variables')$common$time) # [1] "2005-01-31 18:00:00 UTC" "2006-01-31 18:00:00 UTC" # [3] "2007-01-31 18:00:00 UTC" "2008-01-31 18:00:00 UTC" diff --git a/inst/doc/usecase/ex1_3_attr_loadin.R b/inst/doc/usecase/ex1_3_attr_loadin.R index a918e167c6f23092d8d27690613061e98e7affd5..d514c3061745a7aa926c31e094727806b3219238 100644 --- a/inst/doc/usecase/ex1_3_attr_loadin.R +++ b/inst/doc/usecase/ex1_3_attr_loadin.R @@ -104,6 +104,30 @@ erai[1, 1, 2, 31, 1, 1] # 1st March also, since June only has 30 days # The experimental and observational data are comparable with same structure. +#---------Check time attributes-------- +dim(attr(erai, 'Variables')$common$time) +#file_date time +# 8 31 +attr(erai, 'Variables')$common$time[1, ] +# [1] "1994-05-01 UTC" "1994-05-02 UTC" "1994-05-03 UTC" "1994-05-04 UTC" +# [5] "1994-05-05 UTC" "1994-05-06 UTC" "1994-05-07 UTC" "1994-05-08 UTC" +# [9] "1994-05-09 UTC" "1994-05-10 UTC" "1994-05-11 UTC" "1994-05-12 UTC" +#[13] "1994-05-13 UTC" "1994-05-14 UTC" "1994-05-15 UTC" "1994-05-16 UTC" +#[17] "1994-05-17 UTC" "1994-05-18 UTC" "1994-05-19 UTC" "1994-05-20 UTC" +#[21] "1994-05-21 UTC" "1994-05-22 UTC" "1994-05-23 UTC" "1994-05-24 UTC" +#[25] "1994-05-25 UTC" "1994-05-26 UTC" "1994-05-27 UTC" "1994-05-28 UTC" +#[29] "1994-05-29 UTC" "1994-05-30 UTC" "1994-05-31 UTC" +attr(erai, 'Variables')$common$time[2, ] +# [1] "1994-06-01 UTC" "1994-06-02 UTC" "1994-06-03 UTC" "1994-06-04 UTC" +# [5] "1994-06-05 UTC" "1994-06-06 UTC" "1994-06-07 UTC" "1994-06-08 UTC" +# [9] "1994-06-09 UTC" "1994-06-10 UTC" "1994-06-11 UTC" "1994-06-12 UTC" +#[13] "1994-06-13 UTC" "1994-06-14 UTC" "1994-06-15 UTC" "1994-06-16 UTC" +#[17] "1994-06-17 UTC" "1994-06-18 UTC" "1994-06-19 UTC" "1994-06-20 UTC" +#[21] "1994-06-21 UTC" "1994-06-22 UTC" "1994-06-23 UTC" "1994-06-24 UTC" +#[25] "1994-06-25 UTC" "1994-06-26 UTC" "1994-06-27 UTC" "1994-06-28 UTC" +#[29] "1994-06-29 UTC" "1994-06-30 UTC" NA + + # //////////////////"BONUS"////////////////////// # Here is something more to show the usage of parameter 'merge_across_dims_narm'. diff --git a/tests/testthat/test-Start-calendar.R b/tests/testthat/test-Start-calendar.R index 2653920d01882996fafc152bccb1b489748f23b5..19ac0dff59f48fe7c679c403c0440347315d6229 100644 --- a/tests/testthat/test-Start-calendar.R +++ b/tests/testthat/test-Start-calendar.R @@ -146,3 +146,35 @@ expect_equal( ) }) + +test_that("4. gregorian/standard, 6hrly", { + repos_obs <- paste0('/esarchive/recon/ecmwf/erainterim/6hourly/', + '$var$/$var$_199405.nc') + date <- paste0('1994-05-', sprintf('%02d', 1:31), ' 00:00:00') + date <- as.POSIXct(date, tz = 'UTC') +# attr(date, 'tzone') <- 'UTC' + data <- Start(dat = repos_obs, + var = 'tas', + time = date, + latitude = indices(1), + longitude = indices(1), + return_vars = list(latitude = NULL, + longitude = NULL, + time = NULL), + retrieve = TRUE) + +expect_equal( + as.vector(attr(data, 'Variables')$common$time[1:31]), + as.vector(date) +) +expect_equal( + as.vector(data)[1:5], + c(255.0120, 256.8095, 254.3654, 254.6059, 257.0551), + tolerance = 0.0001 +) +expect_equal( + as.vector(data)[length(data)], + c(268.2216), + tolerance = 0.0001 +) +})