diff --git a/DESCRIPTION b/DESCRIPTION
index 65d63334880856f748c05608743345a92b297ff1..114cdcb1bb2e6034c47d4709cea9badcea2492ba 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,9 +1,10 @@
Package: startR
Title: Automatically Retrieve Multidimensional Distributed Data Sets
-Version: 0.1.4
+Version: 1.0.0
Authors@R: c(
person("BSC-CNS", role = c("aut", "cph")),
person("Nicolau", "Manubens", , "nicolau.manubens@bsc.es", role = c("aut")),
+ person("An Chi", "Ho", , "aho@bsc.es", role = c("ctb")),
person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("ctb", "cre"), comment = c(ORCID = "0000-0001-8568-3071")),
person("Javier", "Vegas", , "javier.vegas@bsc.es", role = c("ctb")),
person("Pierre-Antoine", "Bretonniere", , "pierre-antoine.bretonniere@bsc.es", role = c("ctb")),
diff --git a/NEWS.md b/NEWS.md
index ab5acb1aa9c180da0ac92b83869a4b8c75db6d24..1352407ed748c3bd6d8843bb90b809cedda7023c 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,9 @@
-# startR next release (Release date: )
+# startR v1.0.0 (Release date: 2020-03-23)
+- Bugfixes of lat and lon assigned by 'values' in Start(). In v0.1.4 it is incorrect when assigned from big to small values.
+- Compatiblity break: Develop longitude and latitude reorder convention.
+The reordering functions (i.e., Sort() and CircularSort()) are well-functioning now.
+
+# startR v0.1.4 (Release date: 2020-02-10)
- Bugfixes of transform in Start(). Change the default value of param 'extra_cells' to 2. (issue37)
- Bugfixes of chunk function in Utils.R (issue23)
- Bugfixes of paramter 'split_multiselected_dims' in ByChunk.R
diff --git a/R/SelectorChecker.R b/R/SelectorChecker.R
index 141cae2178fb7c25f18d1171f470f4bf3cdc15ad..14bae7edc40ef2bb921567a0b932517a13594d78 100644
--- a/R/SelectorChecker.R
+++ b/R/SelectorChecker.R
@@ -52,7 +52,7 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE,
}
} else if (is.numeric(selectors[[i]])) {
if (is.numeric(var)) {
- val <- selectors[[i]]
+
tol <- 0
if (!is.null(tolerance)) {
if (!any(class(tolerance) %in% "numeric")) {
@@ -60,28 +60,52 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE,
}
tol <- tolerance
}
+
+ val <- selectors[[i]]
+
if (i == 1) {
if (crescent_selectors) {
val <- val - tol
- selectors[[i]] <- which(var >= val)[1]
+ if (var[1] < var[2]) {
+ selectors[[i]] <- which(var >= val)[1]
+ } else if (var[1] > var[2]) {
+ selectors[[i]] <- rev(which(var >= val))[1]
+ }
+
} else {
val <- val + tol
- selectors[[i]] <- rev(which(var <= val))[1]
+ if (var[1] < var[2]) {
+ selectors[[i]] <- rev(which(var <= val))[1]
+ } else if (var[1] > var[2]) {
+ selectors[[i]] <- which(var <= val)[1]
+ }
}
}
- else {
+ else if (i == 2) {
if (crescent_selectors) {
val <- val + tol
- selectors[[i]] <- rev(which(var <= val))[1]
+ if (var[1] < var[2]) {
+ selectors[[i]] <- rev(which(var <= val))[1]
+ } else if (var[1] > var[2]) {
+ selectors[[i]] <- which(var <= val)[1]
+ }
+
} else {
val <- val - tol
- selectors[[i]] <- which(var >= val)[1]
+ if (var[1] < var[2]) {
+ selectors[[i]] <- which(var >= val)[1]
+ } else if (var[1] > var[2]) {
+ selectors[[i]] <- rev(which(var >= val))[1]
+ }
}
}
+
+
} else {
stop("Numeric selectors provided but possible values in 'var' are not numeric.")
}
} else if (any(c("POSIXct", "POSIXlt", "POSIXt", "Date") %in% class(selectors[[i]]))) {
+ # TODO: Here, change to as above (numeric part).
if (any(c("POSIXct", "POSIXlt", "POSIXt", "Date") %in% class(var))) {
val <- selectors[[i]]
tol <- 0
@@ -114,6 +138,7 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE,
}
}
}
+
# The checker is returning a list of two indices.
##selectors[[1]]:selectors[[2]]
selectors
diff --git a/R/Start.R b/R/Start.R
index eec20acd0b4e9cd583964d27fa6a3be99633931f..0076e9aa1236daa438573a94ccde57b93cab4fa5 100644
--- a/R/Start.R
+++ b/R/Start.R
@@ -1408,21 +1408,32 @@ debug <- TRUE
picked_vars_to_transform <- names(picked_vars[[i]])[picked_vars_to_transform]
new_vars_to_transform <- picked_vars[[i]][picked_vars_to_transform]
which_are_ordered <- which(!sapply(picked_vars_ordered[[i]][picked_vars_to_transform], is.null))
+
+##NOTE: The following 'if' replaces the original with reordering vector
if (length(which_are_ordered) > 0) {
- new_vars_to_transform[which_are_ordered] <- picked_vars_ordered[[i]][which_are_ordered]
+ tmp <- which(!is.na(match(names(picked_vars_ordered[[i]]), names(which_are_ordered))))
+ new_vars_to_transform[which_are_ordered] <- picked_vars_ordered[[i]][tmp]
+
}
vars_to_transform <- c(vars_to_transform, new_vars_to_transform)
}
+
+##NOTE: Above is non-common vars, here is common vars (ie, return_vars = NULL).
picked_common_vars_to_transform <- which(names(picked_common_vars) %in% transform_vars)
if (length(picked_common_vars_to_transform) > 0) {
picked_common_vars_to_transform <- names(picked_common_vars)[picked_common_vars_to_transform]
- new_vars_to_transform <- picked_common_vars[[i]][picked_common_vars_to_transform]
- which_are_ordered <- which(!sapply(picked_common_vars_ordered[[i]][picked_common_vars_to_transform], is.null))
+
+ new_vars_to_transform <- picked_common_vars[picked_common_vars_to_transform]
+ which_are_ordered <- which(!sapply(picked_common_vars_ordered[picked_common_vars_to_transform], is.null))
+
if (length(which_are_ordered) > 0) {
- new_vars_to_transform[which_are_ordered] <- picked_common_vars_ordered[[i]][which_are_ordered]
+
+ tmp <- which(!is.na(match(names(picked_common_vars_ordered), names(which_are_ordered))))
+ new_vars_to_transform[which_are_ordered] <- picked_common_vars_ordered[tmp]
}
vars_to_transform <- c(vars_to_transform, new_vars_to_transform)
}
+
# Transform the variables
transformed_data <- do.call(transform, c(list(data_array = NULL,
variables = vars_to_transform,
@@ -1955,34 +1966,128 @@ print("-> THE INNER DIMENSION DOES NOT GO ACROSS ANY FILE DIMENSION OR IT DOES B
if (!is.null(var_ordered) && !selectors_are_indices) {
if (!is.null(dim_reorder_params[[inner_dim]])) {
if (is.list(sub_array_of_selectors)) {
- sub_array_reordered <- dim_reorder_params[[inner_dim]](unlist(sub_array_of_selectors))
- sub_array_unorder <- sort(sub_array_reordered$ix, index.return = TRUE)$ix
- sub_array_of_selectors <- as.list(sub_array_reordered$x[sub_array_unorder])
- is_circular_dim <- attr(dim_reorder_params[[inner_dim]], 'circular')
- if (!is.null(is_circular_dim)) {
- if (is_circular_dim) {
- goes_across_prime_meridian <- abs(sub_array_of_selectors[[1]]) > abs(sub_array_of_selectors[[2]])
- ## TODO: if (bounds[1] > bounds[2]) goes_across_prime_meridian <- !goes_across_prime_meridian
+
+## NOTE: The check of 'goes_across_prime_meridian' is moved forward to here.
+ is_circular_dim <- attr(dim_reorder_params[[inner_dim]], "circular")
+ if (!is.null(is_circular_dim)) {
+ if (is_circular_dim) {
+
+# NOTE: Use CircularSort() to put the values in the assigned range, and get the order.
+# For example, [-10, 20] in CircularSort(0, 360) is [350, 20]. The $ix list is [2, 1].
+# 'goes_across_prime_meridian' means the selector range across the border. For example,
+# CircularSort(-180, 180) with selector [170, 190] -> goes_across_prime_meridian = TRUE.
+ tmp <- dim_reorder_params[[inner_dim]](unlist(sub_array_of_selectors))$ix
+ goes_across_prime_meridian <- tmp[1] > tmp[2]
+ }
}
- }
+
+ # HERE change to the same code as below (under 'else'). Not sure why originally
+ #it uses additional lines, which make reorder not work.
+ sub_array_of_selectors <- as.list(dim_reorder_params[[inner_dim]](unlist(sub_array_of_selectors))$x)
+ #sub_array_reordered <- dim_reorder_params[[inner_dim]](unlist(sub_array_of_selectors))
+ #sub_array_unorder <- sort(sub_array_reordered$ix, index.return = TRUE)$ix
+ #sub_array_of_selectors <- as.list(sub_array_reordered$x[sub_array_unorder])
+
+# Add warning if the boundary is out of range
+ if (sub_array_of_selectors[1] < range(var_ordered)[1] | sub_array_of_selectors[1] > range(var_ordered)[2]) {
+ .warning(paste0("The lower boundary of selector of ",
+ inner_dim,
+ " is out of range [",
+ min(var_ordered), ", ", max(var_ordered), "]. ",
+ "Check if the desired range is all included."))
+ }
+ if (sub_array_of_selectors[2] < range(var_ordered)[1] | sub_array_of_selectors[2] > range(var_ordered)[2]) {
+ .warning(paste0("The upper boundary of selector of ",
+ inner_dim,
+ " is out of range [",
+ min(var_ordered), ", ", max(var_ordered), "]. ",
+ "Check if the desired range is all included."))
+ }
+
+
} else {
sub_array_of_selectors <- dim_reorder_params[[inner_dim]](sub_array_of_selectors)$x
}
}
+
+# NOTE: The ideal solution for selecting indices in goes_across_prime_meridian case
+# is modified SelectorCheckor.R. But now SelectorCheckor doesn't know the info of
+#goes_across_prime_meridian, so I do the adjustion after calling SelectorCheckor().
sub_array_of_indices <- selector_checker(sub_array_of_selectors, var_ordered,
tolerance = if (aiat) {
NULL
} else {
tolerance_params[[inner_dim]]
})
+
+ if (goes_across_prime_meridian & sub_array_of_indices[[1]] < sub_array_of_indices[[2]]) {
+ if (!(sub_array_of_selectors[[1]] %in% var_ordered)){
+ sub_array_of_indices[[1]] <- sub_array_of_indices[[1]] - 1
+ }
+
+ if (!(sub_array_of_selectors[[2]] %in% var_ordered)){
+ sub_array_of_indices[[2]] <- sub_array_of_indices[[2]] + 1
+ }
+ }
+
+#NOTE: the possible case?
+ if (goes_across_prime_meridian & sub_array_of_indices[[1]] > sub_array_of_indices[[2]]) {
+ .stop("The case is goes_across_prime_meridian but no adjustion for the indices!")
+ }
+
+ if (any(is.na(sub_array_of_indices))) {
+
+ stop(paste0("The selectors of ", inner_dim,
+ " are out of range [", min(var_ordered),
+ ", ", max(var_ordered), "]."))
+ }
+
} else {
+
+# Add warning if the boundary is out of range
+ if (is.list(sub_array_of_selectors)) {
+ if (sub_array_of_selectors[1] <
+ min(sub_array_of_values) | sub_array_of_selectors[1] >
+ max(sub_array_of_values)) {
+ .warning(paste0("The lower boundary of selector of ",
+ inner_dim, " is out of range [",
+ min(sub_array_of_values), ", ",
+ max(sub_array_of_values), "]. ",
+ "Check if the desired range is all included."))
+ }
+ if (sub_array_of_selectors[2] <
+ min(sub_array_of_values) | sub_array_of_selectors[2] >
+ max(sub_array_of_values)) {
+ .warning(paste0("The upper boundary of selector of ",
+ inner_dim, " is out of range [",
+ min(sub_array_of_values), ", ",
+ max(sub_array_of_values), "]. ",
+ "Check if the desired range is all included."))
+ }
+ }
+
sub_array_of_indices <- selector_checker(sub_array_of_selectors, sub_array_of_values,
tolerance = if (aiat) {
NULL
} else {
tolerance_params[[inner_dim]]
})
+
+ if (any(is.na(sub_array_of_indices))) {
+
+ stop(paste0("The selectors of ", inner_dim,
+ " are out of range [", min(sub_array_of_values),
+ ", ", max(sub_array_of_values), "]."))
+ }
+
}
+ ## This 'if' runs in both Start() and Compute(). In Start(), it doesn't have any effect (no chunk).
+ ## In Compute(), it creates the indices for each chunk. For example, if 'sub_array_of_indices'
+ ## is c(5:10) and chunked into 2, 'sub_array_of_indices' becomes c(5:7) for chunk = 1, c(8:10)
+ ## for chunk = 2. If 'sub_array_of_indices' is list(55, 62) and chunked into 2, it becomes
+ ## list(55, 58) for chunk = 1 and list(59, 62) for chunk = 2.
+ ## TODO: The list can be turned into vector here? So afterward no need to judge if it is list
+ ## or vector.
if (!is.list(sub_array_of_indices)) {
sub_array_of_indices <- sub_array_of_indices[chunk_indices(length(sub_array_of_indices),
chunks[[inner_dim]]["chunk"],
@@ -1992,13 +2097,13 @@ print("-> THE INNER DIMENSION DOES NOT GO ACROSS ANY FILE DIMENSION OR IT DOES B
tmp <- chunk_indices(length(sub_array_of_indices[[1]]:sub_array_of_indices[[2]]),
chunks[[inner_dim]]["chunk"], chunks[[inner_dim]]["n_chunks"],
inner_dim)
- start_pt <- sub_array_of_indices[[1]]
- sub_array_of_indices[[1]] <- start_pt + tmp[1] - 1
- sub_array_of_indices[[2]] <- start_pt + tmp[length(tmp)] - 1
+ vect <- sub_array_of_indices[[1]]:sub_array_of_indices[[2]]
+ sub_array_of_indices[[1]] <- vect[tmp[1]]
+ sub_array_of_indices[[2]] <- vect[tmp[length(tmp)]]
}
- # The sub_array_of_indices now contains numeric indices of the values to be taken.
+ # The sub_array_of_indices now contains numeric indices of the values to be taken by each chunk.
-#Check if all the files have the selectors assigned (e.g., region = 'Grnland') _20191015
+# Check if all the files have the selectors assigned (e.g., region = 'Grnland') _20191015
if (is.character(sub_array_of_selectors)) {
array_of_var_files_check <- vector('list', length(selector_indices))
for (k in 1:length(selector_indices)) {
@@ -2031,8 +2136,16 @@ if (inner_dim %in% dims_to_check) {
print("-> SELECTORS REQUESTED BEFORE TRANSFORM.")
}
}
+
+###NOTE: Here, the transform, is different from the below part of non-transform.
+# search 'if (goes_across_prime_meridian' to find the lines below.
if (goes_across_prime_meridian) {
- sub_array_of_fri <- 1:n
+# NOTE: before changing, the return is already correct. sub_array_of_fri is defined
+# again afterward. Not sure if here is redundant.
+ sub_array_of_fri <- c(1:min(unlist(sub_array_of_indices)),
+ max(unlist(sub_array_of_indices)):n)
+
+
#gap_width <- sub_array_of_indices[[1]] - sub_array_of_indices[[2]] - 1
#sub_array_of_fri <- c((1:(sub_array_of_indices[[2]] + min(gap_width, beta))),
# (sub_array_of_indices[[1]] - min(gap_width, beta)):n)
@@ -2042,24 +2155,46 @@ print("-> SELECTORS REQUESTED BEFORE TRANSFORM.")
}
first_index <- min(unlist(sub_array_of_indices))
last_index <- max(unlist(sub_array_of_indices))
- if (first_index - beta <= 0 | last_index + beta > n) {
- sub_array_of_fri <- 1:n
- .warning(paste0("Adding the parameter transform_extra_cells = ",
- transform_extra_cells, " to the transformed index excesses ",
- "the border. Use the whole index instead."))
- } else {
- sub_array_of_fri <- (first_index - beta):(last_index + beta)
- }
- #start_padding <- min(beta, first_index - 1)
- #end_padding <- min(beta, n - last_index)
- #sub_array_of_fri <- (first_index - start_padding):(last_index + end_padding)
+
+ start_padding <- min(beta, first_index - 1)
+ end_padding <- min(beta, n - last_index)
+ sub_array_of_fri <- (first_index - start_padding):(last_index + end_padding)
+ if (start_padding != beta | end_padding != beta) {
+ .warning(paste0("Adding parameter transform_extra_cells = ",
+ transform_extra_cells, " to the transformed index excesses ",
+ "the border. The border index is used for transformation."))
+ }
+
}
subset_vars_to_transform <- vars_to_transform
if (!is.null(var_ordered)) {
+
+##NOTE: if var_ordered is common_vars, it doesn't have attributes and it is a vector.
+## Turn it into array and add dimension name.
+ if (!is.array(var_ordered)) {
+ var_ordered <- as.array(var_ordered)
+ names(dim(var_ordered)) <- inner_dim
+ }
+
subset_vars_to_transform[[var_with_selectors_name]] <- Subset(var_ordered, inner_dim, sub_array_of_fri)
} else {
+##NOTE: It should be redundant because without reordering the var should remain array
+## But just stay same with above...
+ if (!is.array(sub_array_of_values)) {
+ sub_array_of_values <- as.array(sub_array_of_values)
+ names(dim(sub_array_of_values)) <- inner_dim
+ }
+
subset_vars_to_transform[[var_with_selectors_name]] <- Subset(sub_array_of_values, inner_dim, sub_array_of_fri)
}
+## NOTE: Remove 'crop' from transform_params if no reorder. It causes error.
+## But 'crop' has effect on reorder cases... need further investigation
+ if (is.null(dim_reorder_params[[inner_dim]])) {
+ if ('crop' %in% names(transform_params)) {
+ transform_params <- transform_params[-which(names(transform_params) == 'crop')]
+ }
+ }
+
transformed_subset_var <- do.call(transform, c(list(data_array = NULL,
variables = subset_vars_to_transform,
file_selectors = selectors_of_first_files_with_data[[i]]),
@@ -2078,9 +2213,24 @@ print("-> SELECTORS REQUESTED BEFORE TRANSFORM.")
} else {
NULL
})
+
+# Check if selectors fall out of the range of the transform grid
+# It may happen when original lon is [-180, 180] while want to regrid to
+# [0, 360], and lon selector = [-20, -10].
+ if (any(is.na(sub_array_of_sri))) {
+ stop(paste0("The selectors of ",
+ inner_dim, " are out of range of transform grid '",
+ transform_params$grid, "'. Use parameter '",
+ inner_dim, "_reorder' or change ", inner_dim,
+ " selectors."))
+ }
+
if (goes_across_prime_meridian) {
- sub_array_of_sri <- c(1:sub_array_of_sri[[2]], sub_array_of_sri[[1]]:length(transformed_subset_var))
- #sub_array_of_sri <- c(sub_array_of_sri[[1]]:length(transformed_subset_var), 1:sub_array_of_sri[[2]])
+ # Because sub_array_of_sri order is exchanged due to
+ # previous development, here [[1]] and [[2]] should exchange
+ sub_array_of_sri <- c(1:sub_array_of_sri[[1]],
+ sub_array_of_sri[[2]]:length(transformed_subset_var))
+
} else if (is.list(sub_array_of_sri)) {
sub_array_of_sri <- sub_array_of_sri[[1]]:sub_array_of_sri[[2]]
}
@@ -2135,8 +2285,9 @@ print(str(tvi))
list(value = sub_array_of_sri)))
} else {
if (goes_across_prime_meridian) {
- #sub_array_of_fri <- 1:n
- sub_array_of_fri <- c(1:sub_array_of_indices[[2]], sub_array_of_indices[[1]]:n)
+ sub_array_of_fri <- c(1:min(unlist(sub_array_of_indices)),
+ max(unlist(sub_array_of_indices)):n)
+
} else if (is.list(sub_array_of_indices)) {
sub_array_of_fri <- sub_array_of_indices[[1]]:sub_array_of_indices[[2]]
} else {
@@ -3124,3 +3275,4 @@ print(str(store_indices))
}
is.null(sub_array)
}
+
diff --git a/inst/doc/faq.md b/inst/doc/faq.md
index b6df41cedefa5cd487bb6dd5d5767bf0a74c3c28..08c5d984c600fd298d669061e0f159e3d8b8e133 100644
--- a/inst/doc/faq.md
+++ b/inst/doc/faq.md
@@ -10,12 +10,19 @@ This document intends to be the first reference for any doubts that you may have
4. [Use package function in Compute()](#4-use-package-function-in-compute)
5. [Do interpolation in Start() (using parameter 'transform')](#5-do-interpolation-in-start-using-parameter-transform)
6. [Get data attributes without retrieving data to workstation](#6-get-data-attributes-without-retrieving-data-to-workstation)
+ 7. [Avoid or specify a node from cluster in Compute()](#7-avoid-or-specify-a-node-from-cluster-in-compute)
+ 8. [Define a path with multiple dependencies](#8-define-a-path-with-multiple-dependencies)
+ 9. [Use CDORemap() in function](#9-use-cdoremap-in-function)
+ 10. [The number of members depends on the start date](#10-the-number-of-members-depends-on-the-start-date)
+ 11. [Select the longitude/latitude region](#11-select-the-longitudelatitude-region)
+ 12. [What will happen if reorder function is not used](#12-what-will-happen-if-reorder-function-is-not-used)
2. **Something goes wrong...**
1. [No space left on device](#1-no-space-left-on-device)
2. [ecFlow UI remains blue and does not update status](#2-ecflow-ui-remains-blue-and-does-not-update-status)
- 3. [Compute() successfully but then killed on R session](#3-compute-successfully-but-then-killed-on-r-session)
+ 3. [Compute() successfully but then killed on R session](#3-compute-successfully-but-then-killed-on-r-session)
+ 4. [My jobs work well in workstation and fatnodes but not on Power9 (or vice versa)](#4-my-jobs-work-well-in-workstation-and-fatnodes-but-not-on-power9-or-vice-versa)
## 1. How to
@@ -295,6 +302,145 @@ And if you want to retrieve the data to the workstation afterward, you can use `
Find examples at [usecase.md](/inst/doc/usecase.md), ex1_1 and ex1_3.
+### 7. Avoid or specify a node from cluster in Compute()
+
+When submitting a job to Fatnodes using Compute(), the parameter 'extra_queue_params' could be used to restricthe job to be run in a expecific node as follows:
+
+```
+ extra_queue_params = list('#SBATCH -w moore'),
+```
+
+or exclude a specific node from job by:
+
+```
+ extra_queue_params = list('#SBATCH -x moore'),
+```
+
+Look at the position of `extra_queue_params` parameter in a full call of Compute:
+
+```
+ res <- Compute(wf1,
+ chunks = list(ensemble = 20,
+ sdate = 2),
+ threads_load = 2,
+ threads_compute = 4,
+ cluster = list(queue_host = queue_host,
+ queue_type = 'slurm',
+ extra_queue_params = list('#SBATCH -x moore'),
+ cores_per_job = 2,
+ temp_dir = temp_dir,
+ r_module = 'R/3.5.0-foss-2018b',
+ polling_period = 10,
+ job_wallclock = '01:00:00',
+ max_jobs = 40,
+ bidirectional = FALSE),
+ ecflow_suite_dir = ecflow_suite_dir,
+ wait = TRUE)
+```
+
+### 8. Define a path with multiple dependencies
+
+The structure of the BSC Earth data repository 'esarchive' allows us to create a path pattern to the data by using different variables (between dollar symbol), such as `$var$`, for the variable name, or `$sdates$`, for the start date of the simulation. Here is an example for loading monthly simulations of system4_m1 data:
+
+`path <- '/esarchive/exp/ecmwf/system4_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc'`
+
+The function Start() will require two parameters 'var' and 'sdate' to load the desired data.
+
+In some cases, the creation of the path could be a little bit more complicated. Some researchers create their own EC-Earth experiments which are identified by an experiment ID (`$expid$`) and with different model version (`$version`), even for different members (`$member$`):
+
+| expid | member | version |
+|-------|----------|---------|
+| a1st | r7i1p1f1 |v20190302|
+| a1sx |r10i1p1f1 |v20190308|
+
+In this case, the variable member and version have different value depending on the expid (the member r10i1p1f1 does not exist for expid a1st). The path will include this varibles:
+
+`path <- '/esarchive/exp/ecearth/$expid$/diags/CMIP/EC-Earth-Consortium/EC-Earth3/historical/$member$/Omon/$var$/gn/$version$/$var$_Omon_EC-Earth3_historical_$member$_gn_$year$.nc'`
+
+However, the following parameters are mandatory to make Start() aware of that they are not independent variables:
+
+```
+ member_depends = 'expid',
+ version_depends = 'expid',
+```
+
+The final Start() call will look like:
+
+```
+yrh1 = 1960
+yrh2 = 2014
+years <- paste0(c(yrh1 : yrh2), '01-', c(yrh1 : yrh2), '12')
+data <- Start(dat = repos,
+ var = 'tosmean',
+ expid = c('a1st','a1sx'),
+ member = 'all',
+ version = 'all',
+ member_depends = 'expid',
+ version_depends = 'expid',
+ year = years,
+ time = 'all',
+ region = indices(1 : 4),
+ return_vars = list(time = NULL, region = NULL),
+ retrieve = TRUE)
+```
+
+### 9. Use CDORemap() in function
+
+If you want to interpolate data by s2dverification::CDORemap in function, you need to tell the
+machine which CDO module to use. Therefore, `CDO_module = 'CDO/1.9.5-foss-2018b'` should be
+added in Compute() cluster list. See the example in usecase [ex2_3_cdo.R](inst/doc/usecase/ex2_3_cdo.R).
+
+### 10. The number of members depends on the start date
+
+In seasonal forecast, some start dates, such as November 1st, are more widely used than others. For those start dates extensively used, the number of members available is greater than for other start dates. This is the case of the seasonal forecast system ECMWF SEAS5 (system5_m1):
+ - for the start date November 1st, 1999, there are 51 members available, while
+ - for the start date September 1st, 1999, there are 25 members available.
+
+When trying to load both start dates at once using Start(), the order in which the start dates is specified will impact on the dimensions of the dataset if all members are loaded with `member = 'all'`:
+ - `sdates = c('19991101', '19990901')`, the member dimension will be of length 51, showing missing values for the members 26 to 51 in the second start date;
+ - `sdates = c('19990901', '19991101')`, the member dimension will be of length 25, any member will be missing.
+
+The code to reproduce this behaviour could be found in the Use Cases section, [example 1.4](/inst/doc/usecase/ex1_4_variable_nmember.R).
+
+### 11. Select the longitude/latitude region
+
+There are three ways to specify the dimension selectors: special keywords('all', 'first', 'last'), indices, or values (find more details in [pratical guide](inst/doc/practical_guide.md)).
+The parameter 'xxx_reorder' is only effective when using **values**.
+
+There are two reorder functions in startR package, **Sort()** for latitude and **CircularSort()** for longitude.
+Sort() is a wrapper function of base function sort(), rearranging the values from low to high (decreasing = TRUE, default) or
+from high to low (decreasing = FALSE). For example, if you want to sort latitude from 90 to -90, use `latitude_reorder = Sort(decreasing = TRUE)`.
+By this means, the result will always from big to small value no matter how the original order is.
+
+On the other hand, the concept of CircularSort() is different. It is used for a circular region, putting the out-of-region values back to the region.
+It requires two input numbers defining the borders of the whole region, which are usually [0, 360] or [-180, 180]. For example,
+`longitude_reorder = CircularSort(0, 360)` means that the left border is 0 and the right border is 360, so 360 will be put back to 0, 361 will be put back to 1,
+and -1 will become 359. After circulating values, CircularSort() also sorts the values from small to big. It may cause the discontinous sub-region,
+but the problem can be solved by assigning the borders correctly.
+
+The following chart helps you to decide how to use CircularSort() to get the desired region.
+The first row represents the longitude border of the requested region, e.g., `values(list(lon.min, lon.max))`.
+Note that this chart only provides the idea. The real numbers may slightly differ depending on the original/transform values.
+
+
+
+Find the usecases here [ex1_5_latlon_reorder.R](inst/doc/usecase/ex1_5_latlon_reorder.R)
+
+### 12. What will happen if reorder function is not used
+
+The reorder functions (i.e., Sort() and CircularSort()) are always recommended to adopt in Start() so you can ensure the result is in line
+with your expectation (find more details at [how-to-11](#11-select-the-longitudelatitude-region) above). If the functions are not used, the situation will be more complicated and easier to
+get unexpected results.
+
+Without reorder functions, the longitude and latitude selectors must be within the respective range in the original file, and the result order
+will be the same order as how you request. If transformation is performed simultaneously, you need to consider the latitude/longitude range of
+the transform grid too. The requested region values cannot fall out of both the original and the transformed region.
+
+The following chart shows some examples.
+
+
+
+
## Something goes wrong...
### 1. No space left on device
@@ -332,3 +478,26 @@ When Compute() on HPCs, the machines are able to process data which are much lar
Further explanation: though the complete output (i.e., merging all the chunks into one returned array) cannot be sent back to workstation, but the chunking results (.Rds file) are completed and saved in the directory '/STARTR_CHUNKING_'. If you still want to use the chunking results, you can find them there.
+
+### 4. My jobs work well in workstation and fatnodes but not on Power9 (or vice versa)
+
+There are several possible reasons for this situation. Here we list some of them, and please let us know if you find any other reason not listed here yet.
+- **R module or package version difference.** Sometimes, the versions among these
+machines are not consistency, and it might cause the problem. Try to load
+different module to see if it fixes the problem.
+- **The package is not known by the machine you use.** If the package you use
+in the function does not include in the R module, you have to assign the
+parameter `lib_dir` in the cluster list in Compute() (see more details in
+[practical_guide.md](https://earth.bsc.es/gitlab/es/startR/blob/master/inst/doc/practical_guide.md#compute-on-cte-power-9).)
+- **The function is specified the package name ahead.** The package name needs
+to be added in front of function connected with '::' (e.g., `s2dv::Clim`) or with
+ ':::' if the function is internal (e.g., `CSTools:::.cal`).
+- **Source or load the file not in the machine you use.** If you use self-defined
+function or load data in the function, you need to put those files in the machine
+you run the computation on, so the machine can find it (e.g., when submitting jobs
+to power9, you should put the files in Power9 instead of local workstation.)
+- **Connection problem.** Test the successful script you used to use (if you do not
+have one, go to [usecase.md](https://earth.bsc.es/gitlab/es/startR/tree/develop-FAQcluster/inst/doc/usecase) to find one!).
+If it fails, it means that your connection to machine or the ecFlow setting has
+some problem.
+
diff --git a/inst/doc/figures/lon-2.PNG b/inst/doc/figures/lon-2.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..570151241b7b54a7fba28166cd7e75b64f0a6017
Binary files /dev/null and b/inst/doc/figures/lon-2.PNG differ
diff --git a/inst/doc/figures/lon-3.PNG b/inst/doc/figures/lon-3.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..da29a4c4f6f49f9f34dc03aa6e1d9f81dafc03b4
Binary files /dev/null and b/inst/doc/figures/lon-3.PNG differ
diff --git a/inst/doc/practical_guide.md b/inst/doc/practical_guide.md
index 0ae2806ddee86e09ba2525fa18dea0e0cb30fdd7..d476652420df126e1893af3191ea63de2137bab8 100644
--- a/inst/doc/practical_guide.md
+++ b/inst/doc/practical_guide.md
@@ -87,7 +87,6 @@ res <- Compute(wf,
cluster = list(queue_host = 'p9login1.bsc.es',
queue_type = 'slurm',
temp_dir = '/gpfs/scratch/bsc32/bsc32473/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.5/',
r_module = 'R/3.5.0-foss-2018b',
job_wallclock = '00:10:00',
cores_per_job = 4,
@@ -570,7 +569,6 @@ res <- Compute(wf,
cluster = list(queue_host = 'p9login1.bsc.es',
queue_type = 'slurm',
temp_dir = '/gpfs/scratch/bsc32/bsc32473/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.5/',
r_module = 'R/3.5.0-foss-2018b',
cores_per_job = 4,
job_wallclock = '00:10:00',
@@ -703,7 +701,6 @@ res <- Compute(wf,
cluster = list(queue_host = 'p9login1.bsc.es',
queue_type = 'slurm',
temp_dir = '/gpfs/scratch/bsc32/bsc32473/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.5/',
r_module = 'R/3.5.0-foss-2018b',
cores_per_job = 4,
job_wallclock = '00:10:00',
@@ -951,7 +948,6 @@ res <- Compute(wf,
queue_type = 'slurm',
data_dir = '/gpfs/projects/bsc32/share/startR_data_repos/',
temp_dir = '/gpfs/scratch/pr1efe00/pr1efe03/startR_tests/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.4/',
r_module = 'R/3.4.0',
cores_per_job = 2,
job_wallclock = '00:10:00',
@@ -1027,7 +1023,6 @@ r <- Compute(wf,
cluster = list(queue_host = 'p9login1.bsc.es',
queue_type = 'slurm',
temp_dir = '/gpfs/scratch/bsc32/bsc32473/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.5/',
r_module = 'R/3.5.0-foss-2018b',
cores_per_job = 4,
job_wallclock = '00:10:00',
@@ -1056,7 +1051,6 @@ cluster = list(queue_host = 'mn2.bsc.es',
queue_type = 'slurm',
data_dir = '/gpfs/projects/bsc32/share/startR_data_repos/',
temp_dir = '/gpfs/scratch/pr1efe00/pr1efe03/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.4/',
r_module = 'R/3.4.0',
cores_per_job = 2,
job_wallclock = '00:10:00',
@@ -1075,7 +1069,6 @@ cluster = list(queue_host = 'nord1.bsc.es',
queue_type = 'lsf',
data_dir = '/gpfs/projects/bsc32/share/startR_data_repos/',
temp_dir = '/gpfs/scratch/bsc32/bsc32473/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.3/',
init_commands = list('module load intel/16.0.1'),
r_module = 'R/3.3.0',
cores_per_job = 2,
@@ -1095,7 +1088,6 @@ cluster = list(queue_host = 'mt1.bsc.es',
queue_type = 'slurm',
data_dir = '/gpfs/projects/bsc32/share/startR_data_repos/',
temp_dir = '/gpfs/scratch/bsc32/bsc32473/startR_hpc/',
- lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.3/',
r_module = 'R/3.3.3',
cores_per_job = 2,
job_wallclock = '00:10:00',
diff --git a/inst/doc/usecase.md b/inst/doc/usecase.md
index 880020d990e607a97631d80007bd84c3f91a6f79..1dac948604c43c034a50d36cbc88aadf1aeda3b5 100644
--- a/inst/doc/usecase.md
+++ b/inst/doc/usecase.md
@@ -4,11 +4,29 @@ In this document, you can link to the example scripts for various demands. For t
1. **Retrieve data (use `Start()` only)**
1. [Interpolation in Start()](inst/doc/usecase/ex1_1_tranform.R)
- Do the interpolation within Start(), and compare with Load() result. When the Start() parameter `transform_extra_cells = 2`, the two results will be the same.
- 2. [Use s2dverification map plotting functions for exp and obs data](inst/doc/usecase/ex1_2_plotmap.R)
- Use `s2dverification::PlotEquiMap, PlotStereoMap, PlotLayout` to visualize load-in data, and use the experimental data attributes to load in associated observational data. It also shows how to use parameters `xxx_reorder`, `xxx_across`, `merge_across_dims`, `split_multiselected_dims`.
- 3. [Use experimental data attribute to load in oberservational data](inst/doc/usecase/ex1_3_attr_loadin.R)
+ Do the interpolation within Start(), and compare with Load() result. When the Start() parameter `transform_extra_cells = 2`, the two results will be the same.
+
+ 2. [Load experimental and observational data with same dimension structure](inst/doc/usecase/ex1_2_exp_obs_attr.R)
+ This script tells you how to load experimental and observational data in a
+ consistent way, facilating the following comparison. In this case, experimental
+ data is one file per year, each file contains 12 months (time = 12). However,
+ observational data is one file per month, each file contains only one time step.
+ You can learn how to select all the required year and month for observation, and
+ tweak the dimension to make it consistent with experiment.
+ The highlight paramters used in this usecase are: **'*_across'**,
+ **'merge_across_dims'**, and **'split_multiselected_dims'**.
+
+ 3. [Use experimental data attribute to load in oberservational data](inst/doc/usecase/ex1_3_attr_loadin.R)
Load the experimental data first (with `retrieve = FALSE`), then retreive its dates and time attributes to use in the observational data load-in. It also shows how to use parameters `xxx_tolerance`, `xxx_across`, `merge_across_dims`, `split_multiselected_dims`.
+
+ 4. [Checking impact of start date order in the number of members](inst/doc/usecase/ex1_4_variable_nmember.R)
+ Mixing start dates of different months can lead to load different number of members, check the code provided and the [FAQ 10](/inst/doc/faq.md).
+
+ 5. [Use reorder functions to get desired lat/lon region](inst/doc/usecase/ex1_5_latlon_reorder.R)
+ This script shows you how to use reorder function (`Sort()`, `CircularSort()`) to
+get the desired longitude and latitude region. See [FAQ How-to-#11] (/inst/doc/faq.md#11-read-latitude-and-longitude-with-the-usage-of-parameter-xxx_reorder)
+for more explanation.
+
2. **Execute computation (use `Compute()`)**
1. [Function working on time dimension](inst/doc/usecase/ex2_1_timedim.R)
diff --git a/inst/doc/usecase/ex1_2_exp_obs_attr.R b/inst/doc/usecase/ex1_2_exp_obs_attr.R
new file mode 100644
index 0000000000000000000000000000000000000000..de1926e426d74ed719950c8ea785a1f2c458c47b
--- /dev/null
+++ b/inst/doc/usecase/ex1_2_exp_obs_attr.R
@@ -0,0 +1,117 @@
+#---------------------------------------------------------------------
+# This script tells you how to load experimental and observational data in a
+# consistent way, facilating the following comparison.
+
+# First, we load the experimental data. Because the latitude order of observation
+# is opposite with experiment, and the sdate/time dimension is also different, we
+# use the attributes (sdate and latitude) of experimental data to define the
+# selectors for observation.
+
+# You can see how to use parameter '*_across', 'merge_across_dims', and
+# 'split_multiselected_dims' to create the consistent dimension as experiment.
+
+#---------------------------------------------------------------------
+library(startR)
+
+# exp
+repos_exp <- paste0('/esarchive/exp/ecearth/a1tr/cmorfiles/CMIP/EC-Earth-Consortium/',
+ 'EC-Earth3/historical/r24i1p1f1/Amon/$var$/gr/v20190312/',
+ '$var$_Amon_EC-Earth3_historical_r24i1p1f1_gr_$sdate$01-$sdate$12.nc')
+
+exp <- Start(dat = repos_exp,
+ var = 'tas',
+ sdate = as.character(c(2005:2008)),
+ time = indices(1:3),
+ lat = 'all',
+ lon = 'all',
+ synonims = list(lat = c('lat', 'latitude'),
+ lon = c('lon', 'longitude')),
+ return_vars = list(lon = NULL,
+ lat = NULL,
+ time = 'sdate'),
+ retrieve = FALSE)
+
+# Retrieve attributes for the following observation.
+# Because latitude order in experiment is [-90, 90] but in observation is [90, -90],
+# latitude values need to be retrieved and used below.
+lats <- attr(exp, 'Variables')$common$lat
+# The 'time' attribute is dependent on 'sdate'. You can see the dimension below.
+dates <- attr(exp, 'Variables')$common$time
+# dim(dates)
+#sdate ftime
+# 4 3
+
+#-------------------------------------------
+
+# obs
+# 1. For lat, use experiment attribute. For lon, it is not necessary because they have
+# same values.
+# 2. For dimension 'date', it is a vector involving the first 3 months (ftime) of the four years (sdate).
+# 3. Dimension 'time' is assigned by the matrix, so we can seperate 'sdate' and 'time'
+# using 'split_multiselected_dims' later.
+# 4. Because the 'time' is actually across all the files, so we need to specify
+# 'time_across'. Then, use 'merge_across_dims' to make dimension 'date' disappears.
+# At this moment, the dimension is 'time = 12'.
+# 5. However, we want to seperate year and month (which are 'sdate' and 'ftime' in
+# experimental data). So we use 'split_multiselected_dims' to split the two dimensions
+# of dimension 'time'.
+
+repos_obs <- '/esarchive/recon/ecmwf/erainterim/monthly_mean/$var$_f6h/$var$_$date$.nc'
+
+obs <- Start(dat = repos_obs,
+ var = 'tas',
+ date = unique(format(dates, '%Y%m')),
+ time = values(dates), #dim: [sdate = 4, time = 3]
+ lat = values(lats),
+ lon = 'all',
+ time_across = 'date',
+ merge_across_dims = TRUE,
+ split_multiselected_dims = TRUE,
+ synonims = list(lat = c('lat', 'latitude'),
+ lon = c('lon', 'longitude')),
+ return_vars = list(lon = NULL,
+ lat = NULL,
+ time = 'date'),
+ retrieve = FALSE)
+
+#==========================
+# Check attributes
+#==========================
+
+##-----dimension-----
+print(attr(exp, 'Dimensions'))
+# dat var sdate time lat lon
+# 1 1 4 3 256 512
+
+print(attr(obs, 'Dimensions'))
+# dat var sdate time lat lon
+# 1 1 4 3 256 512
+
+##-----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"
+
+print(attr(obs, 'Variables')$common$time)
+# [1] "2005-01-31 18:00:00 CET" "2006-01-31 18:00:00 CET"
+# [3] "2007-01-31 18:00:00 CET" "2008-01-31 18:00:00 CET"
+# [5] "2005-02-28 18:00:00 CET" "2006-02-28 18:00:00 CET"
+# [7] "2007-02-28 18:00:00 CET" "2008-02-29 18:00:00 CET"
+# [9] "2005-03-31 19:00:00 CEST" "2006-03-31 19:00:00 CEST"
+#[11] "2007-03-31 19:00:00 CEST" "2008-03-31 19:00:00 CEST"
+
+##-----lat-----
+print(attr(exp, 'Variables')$common$lat[1:3])
+#[1] -89.46282 -88.76695 -88.06697
+print(attr(exp, 'Variables')$common$lat[256])
+#[1] 89.46282
+
+print(attr(obs, 'Variables')$common$lat[1:3])
+#[1] -89.46282 -88.76695 -88.06697
+print(attr(obs, 'Variables')$common$lat[256])
+#[1] 89.46282
+
diff --git a/inst/doc/usecase/ex1_2_plotmap.R b/inst/doc/usecase/ex1_2_plotmap.R
deleted file mode 100644
index f6230b4ccc16f19e0d3e17f0a4afd5121fcb7356..0000000000000000000000000000000000000000
--- a/inst/doc/usecase/ex1_2_plotmap.R
+++ /dev/null
@@ -1,130 +0,0 @@
-#---------------------------------------------------------------------
-# 1. Check the data with s2dverification map plotting functions
-# 2. Read associated data of another data set matching the dates of the first one
-# 3. How to use paramters `xxx_reorder`, `xxx_across`, `merge_across_dims`, `split_multiselected_dims`
-#---------------------------------------------------------------------
-library(startR)
-library(s2dverification)
-
-path <- '/esarchive/exp/ecearth/a0lg/monthly_mean/$var$_*/'
-repos <- paste0(path, '$var$_*_S$sdate$_$member$_$chunk$.nc')
-header <- Start(dat = repos,
- var = 'tas',
- member = indices(1:5),
- sdate = indices(1:21 * 2),
- chunk = 'all',
- ftime = indices(1:3),
- lat = 'all',
- lon = 'all',
- lat_reorder = Sort(),
- lon_reorder = CircularSort(0, 360),
- chunk_depends = 'sdate',
- ftime_across = 'chunk',
- merge_across_dims = TRUE,
- split_multiselected_dims = TRUE,
- synonims = list(ftime = 'time',
- lat = c('lat', 'latitude'),
- lon = c('lon', 'longitude')),
- return_vars = list(lon = NULL,
- lat = NULL,
- time = 'sdate')
- )
-
-# ------ Check exp data ------
- attr(header, 'Dimensions')
-# dat var member sdate ftime lat lon
-# 1 1 5 21 3 256 512
-# ----------------------------
-
-lon <- attr(header, 'Variables')$common$lon
-lat <- attr(header, 'Variables')$common$lat
-
-data <- eval(header) #retrieve data
-
-
-# check 5 members
-PlotLayout(PlotEquiMap,
- c('lon', 'lat'),
- Subset(data, c('dat', 'var', 'sdate', 'ftime'), list(1, 1, 1, 1)),
- lon,
- lat,
- fill = FALSE
- )
-
-# check 3 ftimes
-PlotLayout(PlotEquiMap,
- c('lon', 'lat'),
- Subset(data, c('dat', 'var', 'sdate', 'member'), list(1, 1, 1, 1)),
- lon,
- lat,
- fill = FALSE
- )
-
-# check 21 sdates
-PlotLayout(PlotStereoMap,
- c('lon', 'lat'),
- Subset(data, c('dat', 'var', 'ftime', 'member'), list(1, 1, 1, 1)),
- lon,
- lat,
- fill = FALSE
- )
-
-
-#-----------------------------
-# Associated obs data
-#-----------------------------
-dates <- attr(header, 'Variables')$common$time #use date attributes in exp data
-#> dim(dates)
-#sdate ftime
-# 21 3
-
-path <- '/esarchive/recon/ecmwf/erainterim/monthly_mean/$var$_*/'
-repos <- paste0(path, '$var$_$date$.nc')
-data_obs <- Start(dat = repos,
- var = 'tas',
- date = unique(format(dates, '%Y%m')),
- ftime = values(dates),
- lat = 'all',
- lon = 'all',
- lat_reorder = Sort(),
- lon_reorder = CircularSort(0, 360),
- # ftime continues along date
- ftime_across = 'date',
- # merge ftime and date into one dim
- merge_across_dims = TRUE,
- # separate ftime dimension, which is [sdate = 21, ftime = 3]
- split_multiselected_dims = TRUE,
- synonims = list(ftime = 'time',
- lat = c('lat', 'latitude'),
- lon = c('lon', 'longitude')),
- return_vars = list(lon = NULL,
- lat = NULL,
- ftime = 'date')
- )
-# ------ Check obs data ------
- attr(data_obs, 'Dimensions')
-# dat var sdate ftime lat lon
-# 1 1 21 3 256 512
-# ----------------------------
-
-# retrieve obs data into workstation
-data_obs <- eval(data_obs)
-
-# check 3 ftimes
-PlotLayout(PlotEquiMap,
- c('lon', 'lat'),
- Subset(data_obs, c('dat', 'var', 'sdate'), list(1, 1, 1)),
- attr(data_obs, 'Variables')$common$lon,
- attr(data_obs, 'Variables')$common$lat,
- fill = FALSE
- )
-
-# check 2 sdates
-PlotLayout(PlotEquiMap,
- c('lon', 'lat'),
- Subset(data_obs, c('dat', 'var', 'sdate', 'ftime'), list(1, 1, 1:2, 1)),
- attr(data_obs, 'Variables')$common$lon,
- attr(data_obs, 'Variables')$common$lat,
- fill = FALSE
- )
-
diff --git a/inst/doc/usecase/ex1_4_variable_nmember.R b/inst/doc/usecase/ex1_4_variable_nmember.R
new file mode 100644
index 0000000000000000000000000000000000000000..495c6f8278685482cd865378c59ed40faca3e38f
--- /dev/null
+++ b/inst/doc/usecase/ex1_4_variable_nmember.R
@@ -0,0 +1,52 @@
+# This code shows that the number of members could depend on the start date
+# and the order of start dates requested
+# See FAQ 10 [The members depends on the start date](/inst/doc/faq.md)
+
+library(startR)
+
+path_list <- list(list(name = 'system5',
+ path = '/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc'))
+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(),
+ 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
+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(),
+ 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
+
+# Any missing value:
+apply(data_Sep_Nov, 4, function(x){sum(is.na(x))})
+
+
+
diff --git a/inst/doc/usecase/ex1_5_latlon_reorder.R b/inst/doc/usecase/ex1_5_latlon_reorder.R
new file mode 100644
index 0000000000000000000000000000000000000000..c54314f5f7a2da70c2d7f1672eb7cc1c3578ae6d
--- /dev/null
+++ b/inst/doc/usecase/ex1_5_latlon_reorder.R
@@ -0,0 +1,170 @@
+#---------------------------------------------------------------------
+# This script shows you how to use reorder function (Sort, CircularSort)
+# to get the desired longitude and latitude region.
+
+# Note that the information of the lon/lat system in the original file is
+# provided in order to illustrate a clearer picture, but it doesn't affect
+# the results as long as the reorder functions are used.
+
+# Also, whether transformation is used or not, the range results remain the same.
+
+# See faq.md How-to-#11 for more explanation.
+
+#---------------------------------------------------------------------
+
+library(startR)
+
+#----------------------------
+# CASE 1:
+# Original file: lon [0:360]; lat [90:-90]
+# Desired region: lon [-10, 10] in [-180, 180] system; lat [-20, 20] from south to north
+# transformation: No
+#----------------------------
+# tips:
+# 1. Use 'latitude_reorder = Sort()' to sort latitude from south to north.
+# The default of the hidden parameter 'decreasing' is TRUE.
+# 2. Use 'longitude_reorder = CircularSort(-180, 180). It helps put the longitude values
+# in [-180:180] system, so you can get the continuous region across 0 degree.
+# 3. With reorder functions, the original file range does not affect the results.
+#----------------------------
+
+path_exp <- paste0('/esarchive/exp/ecmwf/system5_m1/daily_mean/',
+ '$var$_f6h/$var$_$sdate$.nc')
+var <- 'psl'
+sdate <- '19821201'
+
+lons.min <- -10
+lons.max <- 10
+lats.min <- -20
+lats.max <- 20
+
+
+res <- Start(dat = path_exp,
+ var = var,
+ ensemble = 'first',
+ sdate = sdate,
+ time = indices(1),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# Check the longitude and latitude
+as.vector(attr(res, 'Variables')$dat1$latitude)
+# [1] -19.8126401 ...... [142] 19.8126401
+as.vector(attr(res, 'Variables')$dat1$longitude)
+# [1] -10.0000000 ...... [73] 10.0000000
+
+
+
+#----------------------------
+# CASE 2:
+# Original file: lon [0:360]; lat [90:-90]
+# Desired region: lon [-10, 10] in [-180, 180] system; lat [20, -20] from north to south
+# transformation: Yes, to 'r360x181'
+#----------------------------
+# tips:
+# 1. Use 'latitude_reorder = Sort(decreasing = TRUE)' to sort latitude from north to south.
+# 2. Use 'longitude_reorder = CircularSort(-180, 180). It helps put the longitude values
+# in [-180:180] system, so you can get the continuous region across 0 degree.
+# 3. With the usage of reorder functions, transformation does not affect the results.
+# 4. With reorder functions, the original file range does not affect the results.
+#----------------------------
+
+path_exp <- paste0('/esarchive/exp/ecmwf/system5_m1/daily_mean/',
+ '$var$_f6h/$var$_$sdate$.nc')
+var <- 'psl'
+sdate <- '19821201'
+
+lons.min <- -10
+lons.max <- 10
+lats.min <- 20
+lats.max <- -20
+
+res <- Start(dat = path_exp,
+ var = var,
+ ensemble = 'first',
+ sdate = sdate,
+ time = indices(1),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = TRUE),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min, lons.max,
+ lats.min, lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ synonims = list(latitude=c('lat', 'latitude'),
+ longitude=c('lon', 'longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# Check the longitude and latitude
+as.vector(attr(res, 'Variables')$dat1$latitude)
+# [1] 20 ...... [41] -20
+as.vector(attr(res, 'Variables')$dat1$longitude)
+# [1] -10 ...... [21] 10
+
+
+
+#----------------------------
+# CASE 3:
+# Original file: lon [-180:180]; lat [90:-90]
+# Desired region: lon [300, 320] in [0, 360] system; lat [-10, -20] from north to south
+# transformation: Yes, to 'r360x181'
+#----------------------------
+# tips:
+# 1. Use 'latitude_reorder = Sort(decreasing = TRUE)' to sort latitude from north to south.
+# 2. Use 'longitude_reorder = CircularSort(0, 360). It helps put the longitude values
+# in [-180:180] system, so you can get the continuous region across 0 degree.
+# 3. With the usage of reorder functions, transformation does not affect the results.
+# 4. With reorder functions, the original file range does not affect the results.
+#----------------------------
+
+path_exp <- paste0('/esarchive/recon/ecmwf/era5/original_files/',
+ 'reorder/daily_mean/$var$/$var$_$sdate$.nc')
+var <- 'tas'
+sdate <- '199212'
+
+lons.min <- 300
+lons.max <- 320
+lats.min <- -10
+lats.max <- -20
+
+res <- Start(dat = path_exp,
+ var = var,
+ sdate = sdate,
+ time = indices(1),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = TRUE),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min, lons.max,
+ lats.min, lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ synonims = list(latitude=c('lat', 'latitude'),
+ longitude=c('lon', 'longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# Check the longitude and latitude
+as.vector(attr(res, 'Variables')$dat1$latitude)
+# [1] -10 ...... [11] -20
+as.vector(attr(res, 'Variables')$dat1$longitude)
+# [1] 300 ...... [21] 320
+
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 0000000000000000000000000000000000000000..d424073d93d066a0a8c2bf330e87c67a34fbf0c8
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,5 @@
+library(testthat)
+library(startR)
+
+test_check("startR")
+
diff --git a/tests/testthat/test-Start-reorder-lat.R b/tests/testthat/test-Start-reorder-lat.R
new file mode 100644
index 0000000000000000000000000000000000000000..f53a9ec12cfcc1ed39df7791330fd95fca79c2b8
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lat.R
@@ -0,0 +1,872 @@
+context("Start() lat Reorder test")
+
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10]
+#3 resolution 1-1 2-<1 3->1
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region
+
+##############################################
+path_exp <- '/esarchive/exp/ecmwf/system5_m1/daily_mean/$var$_f6h/$var$_$sdate$.nc'
+
+## Origin longitude in file: [0:360]
+
+##############################################
+test_that("1-1-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.25761, 19.81264),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(40, 45),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 19
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+
+})
+
+##############################################
+test_that("1-2-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 20
+lats.max <- 10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.25761, 19.81264),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+})
+
+##############################################
+test_that("1-3-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -10
+lats.max <- -20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-19.81264, -10.25761),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-4-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -20
+lats.max <- -10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-19.81264, -10.25761),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("2-1-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(9.976578, 20.093670),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(40, 45),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 19
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+
+})
+
+##############################################
+test_that("2-2-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 20
+lats.max <- 10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(9.976578, 20.093670),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("2-3-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -10
+lats.max <- -20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-20.093670, -9.976578),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("2-4-2-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -20
+lats.max <- -10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-20.093670, -9.976578),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-2-3-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = NULL,
+ longitude = NULL,
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$common$latitude)),
+ c(10.25761, 19.81264),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ attr(res, 'Variables')$dat1$latitude,
+ NULL
+ )
+ expect_equal(
+ (attr(res, 'Variables')$common$latitude)[1] < (attr(res, 'Variables')$common$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$common$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("2-1-2-3-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = NULL,
+ longitude = NULL,
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$common$latitude)),
+ c(9.976578, 20.093670),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ attr(res, 'Variables')$dat1$latitude,
+ NULL
+ )
+ expect_equal(
+ (attr(res, 'Variables')$common$latitude)[1] < (attr(res, 'Variables')$common$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$common$latitude),
+ 'array'
+ )
+})
+##############################################
+##############################################
+test_that("1-1-2-2-2-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.25761, 19.81264),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(40, 45),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 19
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+
+})
+##############################################
+test_that("1-2-2-2-2-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 20
+lats.max <- 10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.25761, 19.81264),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-2-2-2-3-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.25761, 19.81264),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 35
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("2-1-2-2-2-3-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(9.976578, 20.093670),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+
+##############################################
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10]
+#3 resolution 1-1 2-<1 3->1
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region
+
+
+##############################################
+test_that("1-1-2-2-1-1-2-3", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-1-2-2-3-1-2-3", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-2-2-3-2-2-3", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-2-2-3-1-2-1", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = T),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-3. Selector type: indices(list)", {
+
+})
+##############################################
+test_that("1-4. Selector type: indices(vector)", {
+
+})
+##############################################
+test_that("1-4. Selector type: indices(vector)", {
+
+})
+
diff --git a/tests/testthat/test-Start-reorder-latCoarse.R b/tests/testthat/test-Start-reorder-latCoarse.R
new file mode 100644
index 0000000000000000000000000000000000000000..bc6f480a8af702e354584345e34cc9ff3acc771e
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-latCoarse.R
@@ -0,0 +1,874 @@
+context("Start() lat Reorder test")
+
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10]
+#3 resolution 1-1 2-<1 3->1 4-> mixed
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region
+
+
+## mixed resolution indicates lower than 1 degree resolution for longitude and higer for latitude.
+##############################################
+#path_exp <- '/esarchive/exp/ecmwf/system5_m1/daily_mean/$var$_f6h/$var$_$sdate$.nc'
+path_exp <- '/esarchive/exp/ncar/cesm-dple/monthly_mean/$var$/$var$_$sdate$.nc'
+## Origin longitude in file: [0:358.75] step 1.25 degrees #288 values
+## latitude: -90 o 90 {-90, -89.05759 ...} #192 values
+##############################################
+test_that("1-1-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path = path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.83770, 19.31937),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(40, 45),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 5
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+
+})
+
+##############################################
+test_that("1-2-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 20
+lats.max <- 10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.83770, 19.31937),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+})
+
+##############################################
+test_that("1-3-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -10
+lats.max <- -20
+
+res <- Start(dat = list(list(path = path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-19.31937, -10.83770),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-4-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -20
+lats.max <- -10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-19.31937, -10.83770),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("2-1-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(9.895288, 20.261780),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(40, 45),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 5
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+
+})
+
+##############################################
+test_that("2-2-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 20
+lats.max <- 10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(9.895288, 20.261780),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("2-3-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -10
+lats.max <- -20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-20.261780, -9.895288),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("2-4-4-2-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- -20
+lats.max <- -10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(-20.261780, -9.895288),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-4-3-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = NULL,
+ longitude = NULL,
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$common$latitude)),
+ c(10.83770, 19.31937),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ attr(res, 'Variables')$dat1$latitude,
+ NULL
+ )
+ expect_equal(
+ (attr(res, 'Variables')$common$latitude)[1] < (attr(res, 'Variables')$common$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$common$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("2-1-4-3-1-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = NULL,
+ longitude = NULL,
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$common$latitude)),
+ c(9.895288, 20.261780),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ attr(res, 'Variables')$dat1$latitude,
+ NULL
+ )
+ expect_equal(
+ (attr(res, 'Variables')$common$latitude)[1] < (attr(res, 'Variables')$common$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$common$latitude),
+ 'array'
+ )
+})
+##############################################
+##############################################
+test_that("1-1-4-2-2-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.83770, 19.31937),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(40, 45),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 5
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+
+})
+##############################################
+test_that("1-2-4-2-2-1-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 20
+lats.max <- 10
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.83770, 19.31937),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-4-2-2-3-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10.83770, 19.31937),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 10
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("2-1-4-2-2-3-1-x", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(9.895288, 20.261780),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+
+##############################################
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10]
+#3 resolution 1-1 2-<1 3->1 4 -> mixed4 -> mixed4 -> mixed4 -> mixed
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region
+
+
+##############################################
+test_that("1-1-4-2-1-1-2-3", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-1-4-2-3-1-2-3", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-4-2-3-2-2-3", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-4-2-3-1-2-1", {
+lons.min <- 40
+lons.max <- 45
+lats.min <- 10
+lats.max <- 20
+
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = T),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = T),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+# lat
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$latitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$latitude)[1] < (attr(res, 'Variables')$dat1$latitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$latitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$latitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-3. Selector type: indices(list)", {
+
+})
+##############################################
+test_that("1-4. Selector type: indices(vector)", {
+
+})
+##############################################
+test_that("1-4. Selector type: indices(vector)", {
+
+})
+
diff --git a/tests/testthat/test-Start-reorder-lon-transform_-180to180.R b/tests/testthat/test-Start-reorder-lon-transform_-180to180.R
new file mode 100644
index 0000000000000000000000000000000000000000..1b8a96b44f3ae49c4b32a3d53f4975e9e271cc62
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lon-transform_-180to180.R
@@ -0,0 +1,919 @@
+context("Start() lon Reorder transform -180to180 test")
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10] 5-[-10, 10] 6-[10, -10] 7-[300, 350] 8-[170, 190]
+#3 resolution 1-1 2-<1 3->1
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-'r360x181'
+#8 transform_crop 1-T 2-F 3-region 4-x
+
+##############################################
+# 3-2
+## Origin longitude in file: [-179.71875:180]
+path_exp <- '/esarchive/recon/ecmwf/era5/original_files/reorder/daily_mean/$var$/$var$_$sdate$.nc'
+variable <- 'tas'
+sdate <- '199212'
+
+##############################################
+test_that("1-1-2-2-1-1-2-4", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-2-2-2-1-1-2-4", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+
+##############################################
+test_that("1-5-2-2-1-1-2-4", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+
+##############################################
+test_that("1-6-2-2-1-1-2-4", {
+lons.min <- 10
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-1-1-2-4", {
+lons.min <- 170
+lons.max <- 190
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(170, 180),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-2-2-3", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-2-2-2-2-2-2-3", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-2-2-3", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[341:342],
+ c(340, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-2-2-3", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-5-2-2-2-2-2-3", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-6-2-2-2-2-2-3", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(20, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 331
+ )
+})
+##############################################
+test_that("1-7-2-2-2-2-2-3", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-2-2-2-3", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-3-2-3", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-2-2-2-2-3-2-3", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[191:192],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-3-2-3", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[161:162],
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-3-2-3", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+
+##############################################
+test_that("1-5-2-2-2-3-2-3", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-6-2-2-2-3-2-3", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 331
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[171:172],
+ c(-10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-7-2-2-2-3-2-3", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-30, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-2-3-2-3", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
diff --git a/tests/testthat/test-Start-reorder-lon-transform_0to360.R b/tests/testthat/test-Start-reorder-lon-transform_0to360.R
new file mode 100644
index 0000000000000000000000000000000000000000..5ef55769fd4ce52f0b1a06a450547910be785664
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lon-transform_0to360.R
@@ -0,0 +1,999 @@
+context("Start() lon Reorder transform 0to360 test")
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10] 5-[-10, 10] 6-[10, -10] 7-[300, 350] 8-[350, 370]
+#3 resolution 1-1 2-<1 3->1
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-'r360x181'
+#8 transform_crop 1-T 2-F 3-region 4-x
+
+##############################################
+# 3-2
+## Origin longitude in file: [0:360]
+path_exp <- '/esarchive/exp/ecmwf/system5_m1/daily_mean/$var$_f6h/$var$_$sdate$.nc'
+variable <- 'psl'
+sdate <- '19821201'
+
+##############################################
+test_that("1-1-2-2-1-1-2-4", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-2-2-2-1-1-2-4", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-5-2-2-1-1-2-4", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+
+##############################################
+test_that("1-6-2-2-1-1-2-4", {
+lons.min <- 10
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-7-2-2-1-1-2-4", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-1-1-2-4", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(350, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 10
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-2-2-3", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-2-2-2-2-2-2-3", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-2-2-3", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[341:342],
+ c(340, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-2-2-3", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-5-2-2-2-2-2-3", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-6-2-2-2-2-2-3", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(20, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 331
+ )
+})
+##############################################
+test_that("1-7-2-2-2-2-2-3", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-2-2-2-3", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-3-2-3", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-2-2-2-2-3-2-3", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[191:192],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-3-2-3", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[161:162],
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-3-2-3", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+
+##############################################
+test_that("1-5-2-2-2-3-2-3", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-6-2-2-2-3-2-3", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 331
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[171:172],
+ c(-10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-7-2-2-2-3-2-3", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-30, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-2-3-2-3", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
diff --git a/tests/testthat/test-Start-reorder-lon-transform_0to360Coarse.R b/tests/testthat/test-Start-reorder-lon-transform_0to360Coarse.R
new file mode 100644
index 0000000000000000000000000000000000000000..262673bd1cf7f11961d37c584b143b960dfbcb2e
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lon-transform_0to360Coarse.R
@@ -0,0 +1,1003 @@
+context("Start() lon Reorder transform 0to360 test")
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10] 5-[-10, 10] 6-[10, -10] 7-[300, 350] 8-[350, 370]
+#3 resolution 1-1 2-<1 3->1 4 -> mixed
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-'r360x181'
+#8 transform_crop 1-T 2-F 3-region 4-x
+
+##############################################
+# 3-2
+## Origin longitude in file: [0:360]
+path_exp <- '/esarchive/exp/ncar/cesm-dple/monthly_mean/$var$/$var$_$sdate$.nc'
+
+## Origin longitude in file: [0:358.75] step 1.25 degrees #288 values
+## latitude: -90 o 90 {-90, -89.05759 ...} #192 values
+
+variable <- 'psl'
+sdate <- '20001101'
+
+##############################################
+test_that("1-1-2-2-1-1-2-4", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-2-2-2-1-1-2-4", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-5-2-2-1-1-2-4", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+
+##############################################
+test_that("1-6-2-2-1-1-2-4", {
+lons.min <- 10
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-7-2-2-1-1-2-4", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-1-1-2-4", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con'),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(350, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 10
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-2-2-3", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-2-2-2-2-2-2-3", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-2-2-3", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[341:342],
+ c(340, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-2-2-3", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+##############################################
+test_that("1-5-2-2-2-2-2-3", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-6-2-2-2-2-2-3", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(20, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 331
+ )
+})
+##############################################
+test_that("1-7-2-2-2-2-2-3", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-2-2-2-3", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[11:12],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-3-2-3", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-2-2-2-2-3-2-3", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[191:192],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-3-2-3", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 351
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[161:162],
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-3-2-3", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 11
+ )
+})
+
+##############################################
+test_that("1-5-2-2-2-3-2-3", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-6-2-2-2-3-2-3", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 331
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[171:172],
+ c(-10, 20),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-7-2-2-2-3-2-3", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-30, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
+##############################################
+test_that("1-8-2-2-2-3-2-3", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ member = indices(1),
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ transform = CDORemapper,
+ transform_params = list(grid ='r360x181',
+ method = 'con',
+ crop = c(lons.min,lons.max,
+ lats.min,lats.max)),
+ transform_vars = c('longitude', 'latitude'),
+ transform_extra_cells = 2,
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 21
+ )
+})
diff --git a/tests/testthat/test-Start-reorder-lon0to360Coarse.R b/tests/testthat/test-Start-reorder-lon0to360Coarse.R
new file mode 100644
index 0000000000000000000000000000000000000000..461042a83acf74b77bab87d9d3e3519f224fd32e
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lon0to360Coarse.R
@@ -0,0 +1,622 @@
+context("Start() lon Reorder non-transform 0to360 test")
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10] 5-[-10, 10] 6-[10, -10] 7-[300, 350] 8-[350, 370]
+#3 resolution 1-1 2-<1 3->1 4-> mixed
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region 4-x
+
+##############################################
+# 3-2
+path_exp <- '/esarchive/exp/ncar/cesm-dple/monthly_mean/$var$/$var$_$sdate$.nc'
+
+## Origin longitude in file: [0:358.75] step 1.25 degrees #288 values
+## latitude: -90 o 90 {-90, -89.05759 ...} #192 values
+##############################################
+test_that("1-1-4-2-1-1-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 9
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-2-4-2-1-1-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+##############################################
+test_that("1-5-4-2-1-1-1-x", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+
+})
+
+##############################################
+test_that("1-6-4-2-1-1-1-x", {
+lons.min <- 10
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+
+##############################################
+test_that("1-7-4-2-1-1-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-8-4-2-1-1-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(350, 358.75),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-4-2-2-2-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 9
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-4-2-2-3-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 9
+ )
+})
+##############################################
+test_that("1-2-4-2-2-2-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(281)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[9:10],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-2-4-2-2-3-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(281)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[153:154],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-3-4-2-2-2-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(281)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[273:274],
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 358.75),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-4-2-2-3-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(281)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[129:130],
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-4-2-2-2-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-4-4-2-2-3-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-5-4-2-2-2-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-5-4-2-2-3-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-30, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-6-4-2-2-2-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(17),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[9:10],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-6-4-2-2-3-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '20001101',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(17),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+})
diff --git a/tests/testthat/test-Start-reorder-lon_-180to180.R b/tests/testthat/test-Start-reorder-lon_-180to180.R
new file mode 100644
index 0000000000000000000000000000000000000000..38cd6b8efbe7c3ec9442e637ed4597ffab6ed390
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lon_-180to180.R
@@ -0,0 +1,774 @@
+context("Start() lon Reorder non-transform -180to180 test")
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10] 5-[-10, 10] 6-[10, -10] 7-[300, 350] 8-[170, 190]
+#3 resolution 1-1 2-<1 3->1
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region 4-x
+
+##############################################
+# 3-2
+
+## Origin longitude in file: [-179.71875:180]
+path_exp <- '/esarchive/recon/ecmwf/era5/original_files/reorder/daily_mean/$var$/$var$_$sdate$.nc'
+variable <- 'tas'
+sdate <- '199212'
+
+##############################################
+test_that("1-1-2-2-1-1-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10.12500, 19.96875),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 36
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-2-2-2-1-1-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10.12500, 19.96875),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+
+##############################################
+test_that("1-3-2-2-1-1-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-19.96875, -10.12500),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+
+##############################################
+test_that("1-4-2-2-1-1-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-19.96875, -10.12500),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-5-2-2-1-1-1-x", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-9.84375,9.84375),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+
+})
+
+##############################################
+test_that("1-6-2-2-1-1-1-x", {
+lons.min <- 10
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c( -9.84375, 9.84375),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+
+##############################################
+test_that("1-8-2-2-1-1-1-x", {
+lons.min <- 170
+lons.max <- 190
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(170.1562, 180),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-2-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10.12500, 19.96875),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 36
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-2-2-2-3-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10.12500, 19.96875),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 36
+ )
+})
+##############################################
+test_that("1-2-2-2-2-2-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ 1244
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[36:37],
+ c(9.84375, 20.25000),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-2-2-2-2-3-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ 1244
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[676:677],
+ c(9.84375, 20.25000),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-3-2-2-2-2-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ 1244
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[1209:1210],
+ c(339.7500, 350.1562),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359.7222),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-3-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ 1244
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[569:570],
+ c(-20.25000, -9.84375),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-2-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(340.0312, 349.8750),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-4-2-2-2-3-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-19.96875, -10.12500),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-5-2-2-2-2-1-x", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359.7188),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 71
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[36:37],
+ c(9.84375, 350.15625),
+ tolerance = 0.0001
+ )
+})
+
+##############################################
+test_that("1-5-2-2-2-3-1-x", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-9.84375, 9.84375),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-6-2-2-2-2-1-x", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(20.2500, 349.8750),
+ tolerance = 0.001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 1173
+ )
+})
+
+##############################################
+test_that("1-6-2-2-2-3-1-x", {
+lons.min <- 20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-180, 179.7188),
+ tolerance = 0.001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 1173
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[605:606],
+ c(-10.12500, 20.25000),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-7-2-2-2-2-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330.1875, 349.8750),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 71
+ )
+
+})
+##############################################
+test_that("1-7-2-2-2-3-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-29.8125, -10.1250),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 71
+ )
+
+})
+
+##############################################
+test_that("1-8-2-2-2-2-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ 71,
+ tolerance = 0.0001
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[36:37],
+ c(9.84375, 350.15625),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-8-2-2-2-3-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = variable,
+ sdate = sdate,
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ 71,
+ tolerance = 0.0001
+ )
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-9.84375, 9.84375),
+ tolerance = 0.0001
+ )
+})
diff --git a/tests/testthat/test-Start-reorder-lon_0to360.R b/tests/testthat/test-Start-reorder-lon_0to360.R
new file mode 100644
index 0000000000000000000000000000000000000000..67d0e908612336b09ddff32add7f6a4a0d381230
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-lon_0to360.R
@@ -0,0 +1,622 @@
+context("Start() lon Reorder non-transform 0to360 test")
+#1 selector type 1-values(list) 2-values(vector) 3-indices 4-'all' 5-mix
+#2 selector range 1-[10, 20] 2-[20, 10] 3-[-10, -20] 4-[-20, -10] 5-[-10, 10] 6-[10, -10] 7-[300, 350] 8-[350, 370]
+#3 resolution 1-1 2-<1 3->1
+#4 returns_var 1-NULL 2-'dat'
+#5 lat_reorder/Sort() 1-No 2-Yes,decreasing = F 3-Yes,decreasing = T
+#6 lon_reorder/CircularSort() 1-No 2-Yes,(0, 360) 3-Yes,(-180, 180)
+#7 transform 1-NO 2-YES
+#8 transform_crop 1-T 2-F 3-region 4-x
+
+##############################################
+# 3-2
+path_exp <- '/esarchive/exp/ecmwf/system5_m1/daily_mean/$var$_f6h/$var$_$sdate$.nc'
+
+## Origin longitude in file: [0:359.722222222222]
+
+##############################################
+test_that("1-1-2-2-1-1-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+
+# lon
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 37
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+
+##############################################
+test_that("1-2-2-2-1-1-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+##############################################
+test_that("1-5-2-2-1-1-1-x", {
+lons.min <- -10
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+
+})
+
+##############################################
+test_that("1-6-2-2-1-1-1-x", {
+lons.min <- 10
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ FALSE
+ )
+})
+
+##############################################
+test_that("1-7-2-2-1-1-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-8-2-2-1-1-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(3:4),
+ latitude = values(c(lats.min:lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(350, 359.7222222),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+##############################################
+##############################################
+test_that("1-1-2-2-2-2-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 37
+ )
+ expect_equal(
+ class(attr(res, 'Variables')$dat1$longitude),
+ 'array'
+ )
+})
+##############################################
+test_that("1-1-2-2-2-3-1-x", {
+lons.min <- 10
+lons.max <- 20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+ expect_equal(
+ length(attr(res, 'Variables')$dat1$longitude),
+ 37
+ )
+})
+##############################################
+test_that("1-2-2-2-2-2-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(1261)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[37:38],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-2-2-2-2-3-1-x", {
+lons.min <- 20
+lons.max <- 10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(1261)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[685:686],
+ c(10, 20),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-3-2-2-2-2-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(1261)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[1225:1226],
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(0, 359.7222),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-3-2-2-2-3-1-x", {
+lons.min <- -10
+lons.max <- -20
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(1261)
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[577:578],
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-4-2-2-2-2-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(340, 350),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+##############################################
+test_that("1-4-2-2-2-3-1-x", {
+lons.min <- -20
+lons.max <- -10
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-20, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-5-2-2-2-2-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(330, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-5-2-2-2-3-1-x", {
+lons.min <- 330
+lons.max <- 350
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-30, -10),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ (attr(res, 'Variables')$dat1$longitude)[1] < (attr(res, 'Variables')$dat1$longitude)[2],
+ TRUE
+ )
+})
+
+##############################################
+test_that("1-6-2-2-2-2-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(0, 360),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(73),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ as.vector((attr(res, 'Variables')$dat1$longitude))[37:38],
+ c(10, 350),
+ tolerance = 0.0001
+ )
+})
+##############################################
+test_that("1-6-2-2-2-3-1-x", {
+lons.min <- 350
+lons.max <- 370
+lats.min <- 10
+lats.max <- 20
+res <- Start(dat = list(list(path=path_exp)),
+ var = 'psl',
+ member = 'all',
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(),
+ longitude_reorder = CircularSort(-180, 180),
+ longitude = values(list(lons.min, lons.max)),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = F)
+ expect_equal(
+ length((attr(res, 'Variables')$dat1$longitude)),
+ c(73),
+ tolerance = 0.0001
+ )
+ expect_equal(
+ range((attr(res, 'Variables')$dat1$longitude)),
+ c(-10, 10),
+ tolerance = 0.0001
+ )
+})
diff --git a/tests/testthat/test-Start-reorder-retrieve.R b/tests/testthat/test-Start-reorder-retrieve.R
new file mode 100644
index 0000000000000000000000000000000000000000..47412f59279905449384e00b96836fad422e7950
--- /dev/null
+++ b/tests/testthat/test-Start-reorder-retrieve.R
@@ -0,0 +1,157 @@
+context("Start() lon Reorder non-transform retrieve test")
+
+
+##############################################
+test_that("original range 0to360", {
+
+## Origin longitude in file: [0:359.722222222222]
+path_exp <- '/esarchive/exp/ecmwf/system5_m1/daily_mean/$var$_f6h/$var$_$sdate$.nc'
+
+lons.min <- -2
+lons.max <- 2
+lats.min <- 10
+lats.max <- 12
+
+
+res <- Start(dat = path_exp,
+ var = 'psl',
+ member = indices(1),
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = T)
+
+
+res1 <- Start(dat = path_exp,
+ var = 'psl',
+ member = indices(1),
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = TRUE),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = T)
+
+
+res2 <- Start(dat = path_exp,
+ var = 'psl',
+ member = indices(1),
+ sdate = '19821201',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = TRUE),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude'),
+ member=c('ensemble','realization')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = T)
+
+ expect_equal(
+ res1[1,1,1,1,1,1:7,],
+ res[1,1,1,1,1,7:1,]
+ )
+ expect_equal(
+ res1[1,1,1,1,1,1,8:15],
+ res2[1,1,1,1,1,1,1:8]
+ )
+ expect_equal(
+ res1[1,1,1,1,1,1,1:7],
+ res2[1,1,1,1,1,1,9:15]
+ )
+
+})
+
+
+##############################################
+test_that("original range -180to180", {
+
+## Origin longitude in file: [0:359.722222222222]
+path_exp <- '/esarchive/recon/ecmwf/era5/original_files/reorder/daily_mean/$var$/$var$_$sdate$.nc'
+variable <- 'tas'
+sdate <- '199212'
+
+lons.min <- -2
+lons.max <- 2
+lats.min <- 10
+lats.max <- 12
+
+
+res <- Start(dat = path_exp,
+ var = variable,
+ sdate = '199212',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = T)
+
+res1 <- Start(dat = path_exp,
+ var = variable,
+ sdate = '199212',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = TRUE),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(-180, 180),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = T)
+
+
+res2 <- Start(dat = path_exp,
+ var = variable,
+ sdate = '199212',
+ time = indices(4),
+ latitude = values(list(lats.min, lats.max)),
+ latitude_reorder = Sort(decreasing = TRUE),
+ longitude = values(list(lons.min, lons.max)),
+ longitude_reorder = CircularSort(0, 360),
+ synonims = list(latitude=c('lat','latitude'),
+ longitude=c('lon','longitude')),
+ return_vars = list(latitude = 'dat',
+ longitude = 'dat',
+ time = NULL),
+ retrieve = T)
+
+ expect_equal(
+ res1[1,1,1,1,1:7,],
+ res[1,1,1,1,7:1,]
+ )
+ expect_equal(
+ res1[1,1,1,1,1,8:15],
+ res2[1,1,1,1,1,1:8]
+ )
+ expect_equal(
+ res1[1,1,1,1,1,1:7],
+ res2[1,1,1,1,1,9:15]
+ )
+
+})
+