From 39d3ab1eea82d792c8b5715eae33360c2613033d Mon Sep 17 00:00:00 2001 From: Beaudette Date: Thu, 2 May 2024 11:49:33 -0700 Subject: [PATCH] safely handle all-NA results, skipping RAT and notify user --- R/ISSR800.R | 13 +++++++++++-- R/WCS-utils.R | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/R/ISSR800.R b/R/ISSR800.R index b7148c11..26b18fe1 100644 --- a/R/ISSR800.R +++ b/R/ISSR800.R @@ -49,7 +49,7 @@ ISSR800.wcs <- function(aoi, var, res = 800, quiet = FALSE) { stop("package 'terra' is required", call. = FALSE) } - # sanity check: aoi specification + # sanity check: AOI specification if (!inherits(aoi, c('list', 'Spatial', 'sf', 'sfc', 'bbox', 'RasterLayer', 'SpatRaster', 'SpatVector'))) { stop('invalid `aoi` specification', call. = FALSE) } @@ -176,8 +176,17 @@ ISSR800.wcs <- function(aoi, var, res = 800, quiet = FALSE) { # set layer name in object names(r) <- var.spec$desc + # test for all NA + # if TRUE, we cannot process RATs + .allNA <- terra::global(r, fun = "isNA")$isNA == terra::ncell(r) + + # message when all cells are NA + if(.allNA) { + message('all cells are NA') + } + # optional processing of RAT - if (!is.null(var.spec$rat)) { + if (!is.null(var.spec$rat) && !.allNA) { # get rat rat <- try(suppressWarnings(read.csv(var.spec$rat, stringsAsFactors = FALSE)), silent = TRUE) diff --git a/R/WCS-utils.R b/R/WCS-utils.R index 579dacef..c4d0a07d 100644 --- a/R/WCS-utils.R +++ b/R/WCS-utils.R @@ -659,6 +659,7 @@ WCS_details <- function(wcs = c('mukey', 'ISSR800', 'soilColor')) { ) +## TODO: dynamically get vintage from ... where? .mukey.spec <- list( 'gnatsgo' = list(