From ee58fa412eda9bfb4d6afc63cef442cdc35e8c4b Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 11 Dec 2020 08:56:00 +0100 Subject: [PATCH 1/3] Correct exp time attribute to UTC --- inst/doc/usecase/ex1_2_exp_obs_attr.R | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/inst/doc/usecase/ex1_2_exp_obs_attr.R b/inst/doc/usecase/ex1_2_exp_obs_attr.R index acff7c9..2e4b5da 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" -- GitLab From 77ea7adfcc48370a572e4c0f71136653a46f6d6f Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 11 Dec 2020 08:56:20 +0100 Subject: [PATCH 2/3] Add time attribute check --- inst/doc/usecase/ex1_3_attr_loadin.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inst/doc/usecase/ex1_3_attr_loadin.R b/inst/doc/usecase/ex1_3_attr_loadin.R index a918e16..d514c30 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'. -- GitLab From 4428c6552d8f4cb2e426ad8de8676ee81ff2ee84 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 11 Dec 2020 09:00:40 +0100 Subject: [PATCH 3/3] Include 'hours' to PCICt time transfer --- R/NcDataReader.R | 2 ++ tests/testthat/test-Start-calendar.R | 32 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/R/NcDataReader.R b/R/NcDataReader.R index 74df355..222d11d 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/tests/testthat/test-Start-calendar.R b/tests/testthat/test-Start-calendar.R index 2653920..19ac0df 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 +) +}) -- GitLab