Skip to content

Commit

Permalink
safely handle all-NA results, skipping RAT and notify user
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed May 2, 2024
1 parent 00598ac commit 39d3ab1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/ISSR800.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions R/WCS-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ WCS_details <- function(wcs = c('mukey', 'ISSR800', 'soilColor')) {
)


## TODO: dynamically get vintage from ... where?
.mukey.spec <- list(

'gnatsgo' = list(
Expand Down

0 comments on commit 39d3ab1

Please sign in to comment.