From 7a8687bfeb4bab04b128b957c74b7d8a5ab56c94 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 17 Jun 2022 09:43:50 +0200 Subject: [PATCH 1/2] Fix typo --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index df06e6b..704763c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,9 +8,9 @@ - PlotEquiMap(): Add useRaster = TRUE in image() if possible (i.e., latitude and longitude are regularly spaced.) - PlotEquiMap(): New parameters xlonshft ylatshft xlabels ylabels for self-defined axis - PlotEquiMap(): Flexible map longitude range -- New function: WeightCells, DiffCorr, ResidualCorr, RPSS, RPSSS +- New function: WeightCells, DiffCorr, ResidualCorr, RPS, RPSS - Clim() and MeanDims() efficiency improvement -- CDORemap(): Add time metadata to avoid cdo warning like Warning (find_time_vars): Time variable >time< not found! +- CDORemap(): Add time metadata to avoid cdo warning like "Warning (find_time_vars): Time variable >time< not found!" # s2dv 1.1.0 (Release date: 2021-12-14) - New functions: RatioPredictableComponents, SignalNoiseRatio -- GitLab From 4ae74c6e272303fc29b6b1dc9d2bb833f31ad76b Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 22 Jun 2022 11:58:23 +0200 Subject: [PATCH 2/2] Stop printing cdo command messages. Improve 'crop' documentation --- NEWS.md | 3 ++- R/CDORemap.R | 48 +++++++++++++++++++++++++++++---------------- man/CDORemap.Rd | 41 ++++++++++++++++++++++++++------------ man/s2dv-package.Rd | 1 + 4 files changed, 63 insertions(+), 30 deletions(-) diff --git a/NEWS.md b/NEWS.md index 704763c..558b667 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,7 +10,8 @@ - PlotEquiMap(): Flexible map longitude range - New function: WeightCells, DiffCorr, ResidualCorr, RPS, RPSS - Clim() and MeanDims() efficiency improvement -- CDORemap(): Add time metadata to avoid cdo warning like "Warning (find_time_vars): Time variable >time< not found!" +- CDORemap(): Add arbitrary time metadata to avoid cdo warning like "Warning (find_time_vars): Time variable >time< not found!" +- CDORemap(): Stop printing messages from cdo command. # s2dv 1.1.0 (Release date: 2021-12-14) - New functions: RatioPredictableComponents, SignalNoiseRatio diff --git a/R/CDORemap.R b/R/CDORemap.R index 6a9a7e5..ce3ed35 100644 --- a/R/CDORemap.R +++ b/R/CDORemap.R @@ -42,18 +42,35 @@ #' for the price of writing more intermediate files (whis usually is #' unconvenient) by setting the parameter \code{avoid_writes = TRUE}. #'@param 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). +#' 'cdo sellonlatbox' (TRUE) or to extend interpolated data to the whole +#' world as CDO does by default (FALSE). The default value is TRUE.\cr +#' \itemize{ +#' \item{ +#' If \code{crop = TRUE}, the longitude and latitude borders to be cropped +#' at are taken as the limits of the cells at the borders (not the values +#' of 'lons' and 'lats', which 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. Notice that the longitude range of returning array will +#' follow the original data 'lons' instead of the target grid 'grid'. +#' } +#' \item{ +#' If \code{crop = FALSE}, the returning array is not cropped, i.e., a +#' global domain, and the longitude range will be the same as the target +#' grid 'grid'. +#' } +#' \item{ +#' If \code{crop = 'tight'}, the borders to be cropped 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. +#' } +#' \item{ +#' The parameter 'crop' also accepts a numeric vector of customized borders +#' to be cropped at:\cr +#' c(western border, eastern border, southern border, northern border). +#' } +#' } #'@param force_remap Whether to force remapping, even if the input data array #' is already on the target grid. #'@param write_dir Path to the directory where to create the intermediate @@ -414,7 +431,6 @@ CDORemap <- function(data_array = NULL, lons, lats, grid, method, } if (is.logical(crop)) { if (crop) { - warning("Parameter 'crop' = 'TRUE'. The output grid range will follow the input lons and lats.") if (length(lons) == 1 || length(lats) == 1) { stop("CDORemap cannot remap if crop = TRUE and values for only one ", "longitude or one latitude are provided. Either a) provide ", @@ -525,8 +541,6 @@ CDORemap <- function(data_array = NULL, lons, lats, grid, method, } ###--- } - } else if (crop == FALSE) { - warning("Parameter 'crop' = 'FALSE'. The output grid range will follow parameter 'grid'.") } } else if (is.numeric(crop)) { if (length(crop) != 4) { @@ -794,11 +808,11 @@ CDORemap <- function(data_array = NULL, lons, lats, grid, method, ',', format(lat_extremes[2], scientific = FALSE), ' -') } err <- try({ - system(paste0("cdo -s ", sellonlatbox, "remap", method, ",", grid, " ", tmp_file, " ", tmp_file2)) + system(paste0("cdo -s ", sellonlatbox, "remap", method, ",", grid, " ", tmp_file, " ", tmp_file2), ignore.stdout = T, ignore.stderr = T) }) file.remove(tmp_file) if (is(err, 'try-error') || err > 0) { - stop("CDO remap failed.") + stop("CDO remap failed. Possible problem: parameter 'grid'.") } ncdf_remapped <- nc_open(tmp_file2) if (!lons_lats_taken) { diff --git a/man/CDORemap.Rd b/man/CDORemap.Rd index b49f944..61f6101 100644 --- a/man/CDORemap.Rd +++ b/man/CDORemap.Rd @@ -49,18 +49,35 @@ 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).} +'cdo sellonlatbox' (TRUE) or to extend interpolated data to the whole +world as CDO does by default (FALSE). The default value is TRUE.\cr +\itemize{ + \item{ + If \code{crop = TRUE}, the longitude and latitude borders to be cropped + at are taken as the limits of the cells at the borders (not the values + of 'lons' and 'lats', which 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. Notice that the longitude range of returning array will + follow the original data 'lons' instead of the target grid 'grid'. + } + \item{ + If \code{crop = FALSE}, the returning array is not cropped, i.e., a + global domain, and the longitude range will be the same as the target + grid 'grid'. + } + \item{ + If \code{crop = 'tight'}, the borders to be cropped 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. + } + \item{ + The parameter 'crop' also accepts a numeric vector of customized borders + to be cropped at:\cr + c(western border, eastern border, southern border, northern border). + } +}} \item{force_remap}{Whether to force remapping, even if the input data array is already on the target grid.} diff --git a/man/s2dv-package.Rd b/man/s2dv-package.Rd index 871a8b6..3c98a95 100644 --- a/man/s2dv-package.Rd +++ b/man/s2dv-package.Rd @@ -31,6 +31,7 @@ Authors: Other contributors: \itemize{ \item Roberto Bilbao \email{roberto.bilbao@bsc.es} [contributor] + \item Josep Cos \email{josep.cos@bsc.es} [contributor] \item Carlos Delgado \email{carlos.delgado@bsc.es} [contributor] \item Llorenç Lledó \email{llorenc.lledo@bsc.es} [contributor] \item Andrea Manrique \email{andrea.manrique@bsc.es} [contributor] -- GitLab