From a6929305e8d8da9c135d3a927b2f1f7e40149699 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 9 Jun 2023 16:16:39 +0200 Subject: [PATCH] Add warning for automatic detected grid type --- R/Load.R | 4 ++++ R/Utils.R | 4 ++++ man/Load.Rd | 4 ++++ tests/testthat/test-Load.R | 40 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/R/Load.R b/R/Load.R index cca99bf..47da2b3 100644 --- a/R/Load.R +++ b/R/Load.R @@ -395,6 +395,10 @@ #' If not specified and the selected output type is 'lon', 'lat' or 'lonlat', #' this parameter takes as default value the grid of the first experimental #' dataset, which is read automatically from the source files.\cr +#' Note that the auto-detected grid type is not guarenteed to be correct, and +#' it won't be correct if the netCDF file doesn't contain global domain. +#' Please check the warning carefully to ensure the detected grid type is +#' expected, or assign this parameter even regridding is not needed. #' The grid must be supported by 'cdo' tools. Now only supported: rNXxNY #' or tTRgrid.\cr #' Both rNXxNY and tRESgrid yield rectangular regular grids. rNXxNY yields diff --git a/R/Utils.R b/R/Utils.R index cb6eb34..adcded6 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -291,6 +291,10 @@ } else { grid_name <- paste0('t', .nlat2t(grid_lats), 'grid') } + if (is.null(work_piece[['grid']])) { + .warning(paste0("Detect the grid type to be '", grid_name, "'. ", + "If it is not expected, assign parameter 'grid' to avoid wrong result.")) + } } # If a common grid is requested, we will also calculate its size which we will use # later on. diff --git a/man/Load.Rd b/man/Load.Rd index 10c03f9..f91c315 100644 --- a/man/Load.Rd +++ b/man/Load.Rd @@ -273,6 +273,10 @@ interpolating to the specified grid.\cr If not specified and the selected output type is 'lon', 'lat' or 'lonlat', this parameter takes as default value the grid of the first experimental dataset, which is read automatically from the source files.\cr +Note that the auto-detected grid type is not guarenteed to be correct, and +it won't be correct if the netCDF file doesn't contain global domain. +Please check the warning carefully to ensure the detected grid type is +expected, or assign this parameter even regridding is not needed. The grid must be supported by 'cdo' tools. Now only supported: rNXxNY or tTRgrid.\cr Both rNXxNY and tRESgrid yield rectangular regular grids. rNXxNY yields diff --git a/tests/testthat/test-Load.R b/tests/testthat/test-Load.R index c87beac..5e2e723 100644 --- a/tests/testthat/test-Load.R +++ b/tests/testthat/test-Load.R @@ -176,5 +176,45 @@ c(rep(NA, 4), 101250, rep(NA, 5), 100940, NA), tolerance = 0.0001 ) +}) + +test_that("1-4.", { + +exp <- list(list( + name = "system5_m1", + path = file.path("/esarchive/exp/ecmwf/system5_m1/monthly_mean/$VAR_NAME$_f6h/$VAR_NAME$_$START_DATE$.nc") + )) + +suppressWarnings( +res <- Load( + var = "tas", + exp = exp, + obs = NULL, + sdates = c('19930201'), + output = "lonlat", + leadtimemin = 1, + leadtimemax = 1, + nmember = 2, + latmin = -90, #10, + latmax = 90, #12, + lonmin = 0, + lonmax = 359.9, + grid = 'r1296x640', #'t426grid', + dimnames = list(lon='longitude', lat='latitude', member='ensemble'), + nprocs = 1) +) +expect_equal( +dim(res$mod), +c(dataset = 1, member = 2, sdate = 1, ftime = 1, lat = 640, lon = 1296) +) +expect_equal( +as.vector(res$mod[1, 1, 1, 1, 100, 1:4]), +c(277.38, 277.38, 277.37, 277.37), +tolerance = 0.0001 +) +expect_equal( +any(is.na(res$mod)), +FALSE +) }) -- GitLab