From 2e14fcf64a474a14bc0c01517b15a2357e34a65b Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Mon, 20 Feb 2017 11:47:54 +0100 Subject: [PATCH 1/4] Small warning fix. --- R/Utils.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/Utils.R b/R/Utils.R index 806ad92d..210cdfaf 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -341,12 +341,14 @@ if (!is.null(work_piece[['progress_amount']])) { cat("\n") } - cat(paste0("! Warning: the dataset with index ", tail(work_piece[['indices']], 1), - " in '", work_piece[['dataset_type']], "' is originally on ", - "a grid coarser than the common grid and it has been ", - "extrapolated. Check the results carefully. It is ", - "recommended to specify as common grid the coarsest grid ", - "among all requested datasets via the parameter 'grid'.\n")) + if (!explore_dims) { + cat(paste0("! Warning: the dataset with index ", tail(work_piece[['indices']], 1), + " in '", work_piece[['dataset_type']], "' is originally on ", + "a grid coarser than the common grid and it has been ", + "extrapolated. Check the results carefully. It is ", + "recommended to specify as common grid the coarsest grid ", + "among all requested datasets via the parameter 'grid'.\n")) + } } # Now calculate if the user requests for a lonlat subset or for the # entire field -- GitLab From 17b5e3590e78da8888c6856567343407a3801bd3 Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Tue, 21 Feb 2017 15:51:13 +0100 Subject: [PATCH 2/4] Small fix in ArrayToNetCDF documentation. --- man/ArrayToNetCDF.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/ArrayToNetCDF.Rd b/man/ArrayToNetCDF.Rd index b857eaf2..fcfb7700 100644 --- a/man/ArrayToNetCDF.Rd +++ b/man/ArrayToNetCDF.Rd @@ -13,8 +13,8 @@ ArrayToNetCDF(arrays = list(temperature = array(1:9, c(3, 3))), \item{Via the dimension names of each provided array:}{The dimension names of each of the provided arrays will be interpreted as names for the dimensions of the NetCDF files. Read further for special dimension names that will trigger special behaviours, such as 'time' and 'var'.\cr E.g:\cr \code{ -temperature <- array(rnorm(10 * 50 * 100), dim = c(10, 50, 100)) -names(dim(temperature)) <- c('time', 'latitude', 'longitude') +temperature <- array(rnorm(100 * 50 * 10), dim = c(100, 50, 10)) +names(dim(temperature)) <- c('longitude', 'latitude', 'time') ArrayToNetCDF(list(temperature = temperature), file_path = 'example.nc') } } -- GitLab From 64b1ea728d4d350d7a9192e3f102cb094e29a2ae Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Mon, 27 Feb 2017 17:04:11 +0100 Subject: [PATCH 3/4] ArrayToNetCDF now accepts customized attributes. --- R/ArrayToNetCDF.R | 8 ++++++++ man/CDORemap.Rd | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/ArrayToNetCDF.R b/R/ArrayToNetCDF.R index 2b573f63..0d8a87b8 100644 --- a/R/ArrayToNetCDF.R +++ b/R/ArrayToNetCDF.R @@ -297,6 +297,14 @@ ArrayToNetCDF <- function(arrays, file_path) { } ncatt_put(ncdf_object, defined_vars[[var_counter]]$name, 'coordinates', var_info[['coordinates']]) } + attrs_to_skip <- which(names(var_info) %in% c('addOffset', 'scaleFact', 'coordinates')) + attrs_to_add <- names(var_info) + if (length(attrs_to_skip) > 0) { + attrs_to_add <- attrs_to_add[-attrs_to_skip] + } + for (attribute_name in attrs_to_add) { + ncatt_put(ncdf_object, defined_vars[[var_counter]]$name, attribute_name, var_info[[attribute_name]]) + } var_counter <- var_counter + 1 } } diff --git a/man/CDORemap.Rd b/man/CDORemap.Rd index 7960d7bb..fa539dc6 100644 --- a/man/CDORemap.Rd +++ b/man/CDORemap.Rd @@ -14,7 +14,7 @@ CDORemap(data_array = NULL, lons, lats, grid, method, \item{data_array}{Multidimensional numeric array to be interpolated. If provided, it must have at least a longitude and a latitude dimensions, identified by the array dimension names. The names for these dimensions must be one of the recognized by s2dverification (can be checked with \code{s2dverification:::.KnownLonNames()} and \code{s2dverification:::.KnownLatNames()}).} \item{lons}{Numeric vector or array of longitudes of the centers of the grid cells. Its size must match the size of the longitude/latitude dimensions of the input array.} \item{lats}{Numeric vector or array of latitudes of the centers of the grid cells. Its size must match the size of the longitude/latitude dimensions of the input array.} - \item{grid}{Character string specifying either a name of a grid (recognized by CDO; e.g.: 'r256x128', 't106grid') or a path to another NetCDF file which to read the grid from (a single grid must be defined in such file).} + \item{grid}{Character string specifying either a name of a target grid (recognized by CDO; e.g.: 'r256x128', 't106grid') or a path to another NetCDF file which to read the target grid from (a single grid must be defined in such file).} \item{method}{Character string specifying an interpolation method (recognized by CDO; e.g.: 'con', 'bil', 'bic', 'dis'). The following long names are also supported: 'conservative', 'bilinear', 'bicubic' and 'distance-weighted'.} \item{avoid_writes}{The step of permutation is needed when the input array has more than 3 dimensions and none of the longitude or latitude dimensions in the right-most position (CDO would not accept it without permuting previously). This step, executed by default when needed, can be avoided for the price of writing more intermediate files (whis usually is unconvenient) by setting the parameter \code{avoid_writes = TRUE}.} \item{crop}{Whether to crop the data after interpolation with 'cdo sellonlatbox' (TRUE) or to extend interpolated data to the whole world as CDO does by default (FALSE). If \code{crop = TRUE} then the longitude and latitude borders which to crop at are taken as the limits of the cells at the borders ('lons' and 'lats' are perceived as cell centers), i.e. the resulting array will contain data that covers the same area as the input array. This is equivalent to specifying \code{crop = 'preserve'}, i.e. preserving area. If \code{crop = 'tight'} then the borders which to crop at are taken as the minimum and maximum cell centers in 'lons' and 'lats', i.e. the area covered by the resulting array may be smaller if interpolating from a coarse grid to a fine grid. The parameter 'crop' also accepts a numeric vector of custom borders which to crop at: c(western border, eastern border, southern border, northern border). } -- GitLab From a3b3990aa4d72eedac396a15fcdb75aa020d062d Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Wed, 1 Mar 2017 19:03:17 +0100 Subject: [PATCH 4/4] Bugfix in CDORemap. --- R/CDORemap.R | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/R/CDORemap.R b/R/CDORemap.R index 24809c3f..7d6ff391 100644 --- a/R/CDORemap.R +++ b/R/CDORemap.R @@ -79,19 +79,39 @@ CDORemap <- function(data_array = NULL, lons, lats, grid, method, } } else { if (!(lon_dim %in% names(dim(lons)))) { - stop("Parameter 'lon' must have the same longitude dimension name as the 'data_array'.") + if (!return_array) { + if (any(names(dim(lons)) %in% known_lon_names)) { + lon_dim <- names(dim(lons))[which(names(dim(lons)) %in% known_lon_names)] + names(dim(data_array))[2] <- lon_dim + } else { + stop("Parameter 'lon' must have a longitude dimension.") + } + } else { + stop("Parameter 'lon' must have the same longitude dimension name as the 'data_array'.") + } } if (length(dim(lons)) > 1 && !(lat_dim %in% names(dim(lons)))) { stop("Parameter 'lon' must have the same latitude dimension name as the 'data_array'.") } } if (is.null(names(dim(lats)))) { - if (length(dim(lats)) > 1) { + if (length(dim(lats)) == 1) { + names(dim(lats)) <- lat_dim + } else { stop("Parameter 'lats' must be provided with dimension names.") } } else { if (!(lat_dim %in% names(dim(lats)))) { - stop("Parameter 'lat' must have the same latitude dimension name as the 'data_array'.") + if (!return_array) { + if (any(names(dim(lats)) %in% known_lat_names)) { + lat_dim <- names(dim(lats))[which(names(dim(lats)) %in% known_lat_names)] + names(dim(data_array))[1] <- lat_dim + } else { + stop("Parameter 'lat' must have a latitude dimension.") + } + } else { + stop("Parameter 'lat' must have the same latitude dimension name as the 'data_array'.") + } } if (length(dim(lats)) > 1 && !(lon_dim %in% names(dim(lats)))) { stop("Parameter 'lat' must have the same longitude dimension name as the 'data_array'.") -- GitLab