diff --git a/R/RStoolbox.R b/R/RStoolbox-package.R similarity index 98% rename from R/RStoolbox.R rename to R/RStoolbox-package.R index 4c9e4e3..1af3d58 100644 --- a/R/RStoolbox.R +++ b/R/RStoolbox-package.R @@ -46,6 +46,9 @@ #' \item \code{\link{ggRGB}}: efficient plotting of remote sensing imagery in RGB with ggplot2 #' } #' +#' @keywords earth-observation, remote-sensing, spatial-data-analysis +#' "RStoolbox" +#' #' @import sf terra #' @importFrom exactextractr exact_extract #' @importFrom lifecycle is_present deprecate_warn deprecated @@ -62,7 +65,6 @@ #' @importFrom grDevices hsv #' @useDynLib RStoolbox #' @importFrom Rcpp sourceCpp -#' @docType package #' @name RStoolbox NULL diff --git a/R/superClass.R b/R/superClass.R index 5b1151d..701975d 100644 --- a/R/superClass.R +++ b/R/superClass.R @@ -318,7 +318,7 @@ superClass <- function(img, trainData, valData = NULL, responseCol = NULL, wrArgs$filename <- filename ## remove filename from args if is.null(filename) --> standard writeRaster handling applies spatPred <- .paraRasterFun(img, rasterFun=terra::predict, args = list(model=caretModel, type = predType, index = probInd, na.rm = T), wrArgs = wrArgs) if(predType != "prob") - names(spatPred) <- responseCol + names(spatPred) <- paste0(responseCol, "_supervised") } else { spatPred <- "No map was produced (predict = FALSE)." @@ -528,7 +528,7 @@ predict.superClass <- function(object, img, predType = "raw", filename = NULL, d wrArgs <- c(list(...), list(filename = filename, datatype = datatype)) wrArgs$filename <- filename ## remove filename from args if is.null(filename) --> standard writeRaster handling applies .paraRasterFun(img, rasterFun=terra::predict, args = list(model=model, type = predType, index = probInd, na.rm = TRUE), wrArgs = wrArgs) - + } #' @method print superClass diff --git a/R/unsuperClass.R b/R/unsuperClass.R index 75a0fd6..b0bf867 100644 --- a/R/unsuperClass.R +++ b/R/unsuperClass.R @@ -103,11 +103,12 @@ unsuperClass <- function(img, nSamples = 10000, nClasses = 5, nStarts = 25, nIte } else { out <- app(img, fun = function(x, kmeans= model){ predKmeansCpp(x, centers=kmeans$centers, returnDistances)}, ...) - names(out) <- if(returnDistances) paste0("dist_c", 1:nClasses) else "class" + names(out) <- if(returnDistances) paste0("dist_c", 1:nClasses) else "class_unsupervised" } model$cluster <- NULL structure(list(call = match.call(), model = model, map = out), class = c("unsuperClass", "RStoolbox")) + } diff --git a/inst/external/sen2.rds b/inst/external/sen2.rds index cc44bf0..d8dea67 100644 Binary files a/inst/external/sen2.rds and b/inst/external/sen2.rds differ diff --git a/inst/external/srtm_sen2.rds b/inst/external/srtm_sen2.rds index 740ab77..b37d0ca 100644 Binary files a/inst/external/srtm_sen2.rds and b/inst/external/srtm_sen2.rds differ diff --git a/inst/external/trainingPoints_sen2.rds b/inst/external/trainingPoints_sen2.rds index 673e647..5b5120d 100644 Binary files a/inst/external/trainingPoints_sen2.rds and b/inst/external/trainingPoints_sen2.rds differ diff --git a/inst/external/trainingPolygons_sen2.rds b/inst/external/trainingPolygons_sen2.rds index 2a70969..0310543 100644 Binary files a/inst/external/trainingPolygons_sen2.rds and b/inst/external/trainingPolygons_sen2.rds differ diff --git a/man/RStoolbox.Rd b/man/RStoolbox.Rd index ce9ca62..ff8cb6b 100755 --- a/man/RStoolbox.Rd +++ b/man/RStoolbox.Rd @@ -1,8 +1,6 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RStoolbox.R -\docType{package} +% Please edit documentation in R/RStoolbox-package.R \name{RStoolbox} -\alias{RStoolbox-package} \alias{RStoolbox} \title{RStoolbox: A Collection of Remote Sensing Tools} \description{ @@ -60,28 +58,7 @@ The RStoolbox package provides a set of functions which simplify performing stan } } -\seealso{ -Useful links: -\itemize{ - \item \url{https://bleutner.github.io/RStoolbox/} - \item \url{https://github.com/bleutner/RStoolbox} - \item Report bugs at \url{https://github.com/bleutner/RStoolbox/issues} -} - -} -\author{ -\strong{Maintainer}: Konstantin Mueller \email{konstantinfinn.mueller@gmx.de} (\href{https://orcid.org/0000-0001-6540-3124}{ORCID}) - -Authors: -\itemize{ - \item Benjamin Leutner \email{rstoolboxpackage@gmail.com} (\href{https://orcid.org/0000-0002-6893-2002}{ORCID}) - \item Ned Horning \email{horning@amnh.org} - \item Jakob Schwalb-Willmann \email{movevis@schwalb-willmann.de} (\href{https://orcid.org/0000-0003-2665-1509}{ORCID}) -} - -Other contributors: -\itemize{ - \item Robert J. Hijmans \email{r.hijmans@gmail.com} (\href{https://orcid.org/0000-0001-5872-2872}{ORCID}) [contributor] -} - -} +\keyword{"RStoolbox"} +\keyword{earth-observation,} +\keyword{remote-sensing,} +\keyword{spatial-data-analysis} diff --git a/man/lsat.Rd b/man/lsat.Rd index d1fae63..f47324d 100644 --- a/man/lsat.Rd +++ b/man/lsat.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RStoolbox.R +% Please edit documentation in R/RStoolbox-package.R \docType{data} \name{lsat} \alias{lsat} diff --git a/man/rlogo.Rd b/man/rlogo.Rd index bd19195..ddcb792 100644 --- a/man/rlogo.Rd +++ b/man/rlogo.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RStoolbox.R +% Please edit documentation in R/RStoolbox-package.R \docType{data} \name{rlogo} \alias{rlogo} diff --git a/man/sen2.Rd b/man/sen2.Rd index 8f9dc66..9178a0d 100644 --- a/man/sen2.Rd +++ b/man/sen2.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RStoolbox.R +% Please edit documentation in R/RStoolbox-package.R \docType{data} \name{sen2} \alias{sen2} diff --git a/man/srtm.Rd b/man/srtm.Rd index 5395561..0fa9e7f 100644 --- a/man/srtm.Rd +++ b/man/srtm.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RStoolbox.R +% Please edit documentation in R/RStoolbox-package.R \docType{data} \name{srtm} \alias{srtm} diff --git a/man/srtm_sen2.Rd b/man/srtm_sen2.Rd index 87e8172..9f1d2f4 100644 --- a/man/srtm_sen2.Rd +++ b/man/srtm_sen2.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RStoolbox.R +% Please edit documentation in R/RStoolbox-package.R \docType{data} \name{srtm_sen2} \alias{srtm_sen2} diff --git a/tests/testthat/test-superClass.R b/tests/testthat/test-superClass.R index 092031e..5a9ad09 100644 --- a/tests/testthat/test-superClass.R +++ b/tests/testthat/test-superClass.R @@ -144,13 +144,12 @@ test_that("terra inputs",{ }) # if (identical(Sys.getenv("NOT_CRAN"), "true") ) { - ## Tiny raster bug caused superClass to fail when predictions were written to .grd file -# test_that("NA in raster remains NA",{ -# expect_is(sc <- superClass(lsNA, trainData = pts, responseCol = "class", model = "rf", -# filename = rasterTmpFile(), trainPartition = 0.7, predict = TRUE), "superClass") -# expect_equal(sum(is.na(sc$map[1:100,])), 100*ncol(lsNA)) -# expect_false(anyNA(sc$map[101:nrow(lsNA),])) -# }) + test_that("NA in raster remains NA",{ + expect_is(sc <- superClass(lsNA, trainData = pts, responseCol = "class", model = "rf", + filename = .terraTmpFile(), trainPartition = 0.7, predict = TRUE), "superClass") + expect_equal(sum(is.na(sc$map[1:100,])), 100*ncol(lsNA)) + expect_false(anyNA(sc$map[101:nrow(lsNA),])) + }) ## Checks after clipping test_that("fails if no validation points remain after clipping",{ @@ -163,5 +162,4 @@ if (identical(Sys.getenv("NOT_CRAN"), "true") ) { test_that("projection mismatch errors", expect_error(superClass(lsat_t, trainData = poly, responseCol = "class"), "must have the same projection") ) -# }