diff --git a/R/classifyQA.R b/R/classifyQA.R index 266efd0..1478bfb 100644 --- a/R/classifyQA.R +++ b/R/classifyQA.R @@ -5,7 +5,7 @@ #' @param img RasterLayer or SpatRaster. Landsat 8 OLI QA band. #' @param type Character. Classes which should be returned. One or more of c("background", "cloud", "cirrus","snow", "water"). #' @param confLayers Logical. Return one layer per class classified by confidence levels, i.e. cloud:low, cloud:med, cloud:high. -#' @param ... further arguments passed to \link[raster]{writeRaster} +#' @param ... further arguments passed to \link[terra]{writeRaster} #' @inheritParams encodeQA #' #' @seealso \link{encodeQA} \link{decodeQA} diff --git a/R/coregisterImages.R b/R/coregisterImages.R index 4ef97ac..14559ca 100644 --- a/R/coregisterImages.R +++ b/R/coregisterImages.R @@ -12,7 +12,7 @@ #' @param nBins Integer. Number of bins to calculate joint histogram. #' @param reportStats Logical. If \code{FALSE} it will return only the shifted images. Otherwise it will return the shifted image in a list containing stats such as mutual information per shift and joint histograms. #' @param verbose Logical. Print status messages. Overrides global RStoolbox.verbose option. -#' @param ... further arguments passed to \code{\link[raster]{writeRaster}}. +#' @param ... further arguments passed to \code{\link[terra]{writeRaster}}. #' @param slave DEPRECATED! Argument was renamed. Please use \code{img} from now on. #' @param master DEPRECATED! Argument was renamed. Please use \code{ref} from now on. #' @details diff --git a/R/ggR.R b/R/ggR.R index 3fb64d5..f7999a3 100644 --- a/R/ggR.R +++ b/R/ggR.R @@ -29,7 +29,7 @@ #' When \code{img} contains factor values and \code{annotation=TRUE}, the raster values will automatically be converted #' to numeric in order to proceed with the brightness calculation. #' -#' The raster package provides a class lookup-table for categorical rasters (e.g. what you get if you run superClass in classification mode). If your raster has a lookup-table ggR will automatically treat it as categorical (see \link[raster]{factor}). +#' The raster package provides a class lookup-table for categorical rasters (e.g. what you get if you run superClass in classification mode). If your raster has a lookup-table ggR will automatically treat it as categorical (see \link[terra]{factor}). #' However, the factor status of Raster objects is easily lost and the values are interpreted as numeric. In such cases you should make use of the \code{forceCat = TRUE} argument, which makes sure #' that ggplot2 uses a discrete scale, not a continuous one. #' diff --git a/R/ggRGB.R b/R/ggRGB.R index 293ece3..0351575 100644 --- a/R/ggRGB.R +++ b/R/ggRGB.R @@ -2,7 +2,7 @@ #' #' Calculates RGB color composite raster for plotting with ggplot2. Optional values for clipping and and stretching can be used to enhance the imagery. #' -#' Functionality is based on \code{\link[raster]{plotRGB}} from the raster package. +#' Functionality is based on \code{\link[terra]{plotRGB}} from the raster package. #' #' @param img RasterStack or RasterBrick #' @param r Integer or character. Red layer in x. Can be set to \code{NULL}, in which case the red channel will be set to zero. diff --git a/R/histMatch.R b/R/histMatch.R index 34aad88..278d365 100644 --- a/R/histMatch.R +++ b/R/histMatch.R @@ -11,7 +11,7 @@ #' @param intersectOnly Logical. If \code{TRUE} sampling will only take place in the overlap extent of the two rasters. Otherwise the full rasters will be used for sampling. #' @param paired Logical. If \code{TRUE} the corresponding pixels will be used in the overlap. #' @param returnFunctions Logical. If \code{TRUE} the matching functions will be returned instead of applying them to \code{x}. -#' @param ... Further arguments to be passed to \link[raster]{writeRaster}. +#' @param ... Further arguments to be passed to \link[terra]{writeRaster}. #' @param forceInteger Logical. Force integer output. #' @note \code{x} and \code{ref} must have the same number of layers. #' @return A SpatRaster of \code{x} adjusted to the histogram of \code{ref}. If \code{returnFunctions = TRUE} a list of functions (one for each layer) will be returned instead. diff --git a/R/mesma.R b/R/mesma.R index bc12682..a9e6f1d 100644 --- a/R/mesma.R +++ b/R/mesma.R @@ -11,7 +11,7 @@ #' @param iterate Integer. Set maximum iteration per pixel. Processing time could increase the more iterations are made possible. Default is 400. #' @param tolerance Numeric. Tolerance limit representing a nearly zero minimal number. Default is 1e-8. #' @param verbose Logical. Prints progress messages during execution. -#' @param ... further arguments passed to \link[raster]{writeRaster}. +#' @param ... further arguments passed to \link[terra]{writeRaster}. #' #' @return SpatRaster. The object will contain one band per endmember, with each value representing the estimated presence probability of the endmember per pixel (0 to 1), and an RMSE band. #' diff --git a/R/rasterCVA.R b/R/rasterCVA.R index 06c59ca..59870d4 100644 --- a/R/rasterCVA.R +++ b/R/rasterCVA.R @@ -21,13 +21,14 @@ #' Returns a SpatRaster with two layers: change vector angle and change vector magnitude #' @export #' @examples +#' \donttest{ #' library(terra) #' pca <- rasterPCA(lsat)$map #' #' ## Do change vector analysis #' cva <- rasterCVA(pca[[1:2]], pca[[3:4]]) #' cva -#' plot(cva) +#' } rasterCVA <- function(x, y, tmf = NULL, nct = NULL, ...) { x <- .toTerra(x) y <- .toTerra(y) diff --git a/R/rasterPCA.R b/R/rasterPCA.R index d0d1f87..c087a55 100644 --- a/R/rasterPCA.R +++ b/R/rasterPCA.R @@ -20,10 +20,11 @@ #' @param spca Logical. If \code{TRUE}, perform standardized PCA. Corresponds to centered and scaled input image. This is usually beneficial for equal weighting of all layers. (\code{FALSE} by default) #' @param maskCheck Logical. Masks all pixels which have at least one NA (default TRUE is reccomended but introduces a slow-down, see Details when it is wise to disable maskCheck). #' Takes effect only if nSamples is NULL. -#' @param ... further arguments to be passed to \link[raster]{writeRaster}, e.g. filename. +#' @param ... further arguments to be passed to \link[terra]{writeRaster}, e.g. filename. #' @return Returns a named list containing the PCA model object ($model) and a SpatRaster with the principal component layers ($object). #' @export #' @examples +#' \donttest{ #' library(ggplot2) #' library(reshape2) #' ggRGB(rlogo, 1,2,3) @@ -42,6 +43,7 @@ #' plots <- lapply(1:3, function(x) ggR(rpc$map, x, geom_raster = TRUE)) #' grid.arrange(plots[[1]],plots[[2]], plots[[3]], ncol=2) #' } +#' } rasterPCA <- function(img, nSamples = NULL, nComp = nlyr(img), spca = FALSE, maskCheck = TRUE, ...){ img <- .toTerra(img) @@ -54,7 +56,7 @@ rasterPCA <- function(img, nSamples = NULL, nComp = nlyr(img), spca = FALSE, ma ellip[["norm"]] <- NULL } - if(nComp > terra::nlyr(img)) nComp <- terra::nlyr(img) + if(nComp > nlyr(img)) nComp <- nlyr(img) if(!is.null(nSamples)){ trainData <- terra::spatSample(img, size = nSamples, na.rm = TRUE) @@ -70,7 +72,7 @@ rasterPCA <- function(img, nSamples = NULL, nComp = nlyr(img), spca = FALSE, ma covMat <- terra::layerCor(img, "cov", na.rm = TRUE) model <- stats::princomp(covmat = covMat$covariance, cor = spca) model$center <- covMat$mean - model$n.obs <- t(global(img, "sum", na.rm = TRUE)) + model$n.obs <- ncell(any(!is.na(img))) if(spca) { ## Calculate scale as population sd like in in princomp @@ -79,7 +81,8 @@ rasterPCA <- function(img, nSamples = NULL, nComp = nlyr(img), spca = FALSE, ma } } ## Predict - out <- .paraRasterFun(img, predict, args = list(model = model, index = 1:nComp), wrArgs = ellip) + out <- .paraRasterFun(img, terra::predict, args = list(model = model, na.rm = TRUE, index = 1:nComp), wrArgs = ellip) + names(out) <- paste0("PC", 1:nComp) structure(list(call = match.call(), model = model, map = out), class = c("rasterPCA", "RStoolbox")) diff --git a/R/readMeta.R b/R/readMeta.R index a9179ce..baf9145 100644 --- a/R/readMeta.R +++ b/R/readMeta.R @@ -268,7 +268,7 @@ readMeta <- function(file, raw = FALSE){ #' @param na Numeric vector. No-data value per band #' @param vsat Numeric vector. Saturation value per band #' @param scal Numeric vector. Scale factor per band. e.g. if data was scaled to 1000*reflectance for integer conversion. -#' @param dtyp Character vector. Data type per band. See \code{\link[raster]{dataType}} for options. +#' @param dtyp Character vector. Data type per band. See \code{\link[terra]{dataType}} for options. #' @param radRes Numeric vector. Radiometric resolution per band. #' @param spatRes Numeric vector. Spatial resolution per band. #' @param calrad data.frame. Calibration coefficients for dn->radiance conversion. Must have columns 'gain' and 'offset'. Rows named according to \code{bands}. diff --git a/R/topCor.R b/R/topCor.R index 98a97d5..4e575d0 100644 --- a/R/topCor.R +++ b/R/topCor.R @@ -3,7 +3,7 @@ #' account and correct for changes in illumination due to terrain elevation. #' #' @param img SpatRaster. Imagery to correct -#' @param dem SpatRaster. Either a digital elevation model as a RasterLayer or a RasterStack/Brick with pre-calculated slope and aspect (see \link[raster]{terrain}) in which case the layers must be named 'slope' and 'aspect'. +#' @param dem SpatRaster. Either a digital elevation model as a RasterLayer or a RasterStack/Brick with pre-calculated slope and aspect (see \link[terra]{terrain}) in which case the layers must be named 'slope' and 'aspect'. #' Must have the same dimensions as \code{img}. #' @param metaData Character, ImageMetaData. Either a path to a Landsat meta-data file (MTL) or an ImageMetaData object (see \link{readMeta}) #' @param solarAngles Numeric vector containing sun azimuth and sun zenith (in radians and in that order). Not needed if metaData is provided @@ -11,7 +11,7 @@ #' @param stratImg RasterLayer or SpatRaster to define strata, e.g. NDVI. Or the string 'slope' in which case stratification will be on \code{nStrat} slope classes. Only relevant if \code{method = 'minnaert'}. #' @param nStrat Integer. Number of bins or quantiles to stratify by. If a bin has less than 50 samples it will be merged with the next bin. Only relevant if \code{method = 'minnaert'}. #' @param illu SpatRaster. Optional pre-calculated ilumination map. Run topCor with method="illu" to calculate an ilumination map -#' @param ... arguments passed to \code{\link[raster]{writeRaster}} +#' @param ... arguments passed to \code{\link[terra]{writeRaster}} #' @details #' For detailed discussion of the various approaches please see Riano et al. (2003). #' diff --git a/R/unsuperClass.R b/R/unsuperClass.R index bb21e14..75a0fd6 100644 --- a/R/unsuperClass.R +++ b/R/unsuperClass.R @@ -16,7 +16,7 @@ #' Clustering is done using \code{\link[stats]{kmeans}}. This can be done for all pixels of the image (\code{clusterMap=FALSE}), however this can be slow and is #' not memory safe. Therefore if you have large raster data (> memory), as is typically the case with remote sensing imagery it is advisable to choose clusterMap=TRUE (the default). #' This means that a kmeans cluster model is calculated based on a random subset of pixels (\code{nSamples}). Then the distance of *all* pixels to the cluster centers -#' is calculated in a stepwise fashion using \code{\link[raster]{predict}}. Class assignment is based on minimum euclidean distance to the cluster centers. +#' is calculated in a stepwise fashion using \code{\link[terra]{predict}}. Class assignment is based on minimum euclidean distance to the cluster centers. #' #' The solution of the kmeans algorithm often depends on the initial configuration of class centers which is chosen randomly. #' Therefore, kmeans is usually run with multiple random starting configurations in order to find a convergent solution from different starting configurations. @@ -122,7 +122,7 @@ unsuperClass <- function(img, nSamples = 10000, nClasses = 5, nStarts = 25, nIte #' @param object unsuperClass object #' @param img Raster object. Layernames must correspond to layernames used to train the superClass model, i.e. layernames in the original raster image. #' @param output Character. Either 'classes' (kmeans class; default) or 'distances' (euclidean distance to each cluster center). -#' @param ... further arguments to be passed to \link[raster]{writeRaster}, e.g. filename +#' @param ... further arguments to be passed to \link[terra]{writeRaster}, e.g. filename #' @export #' @return #' Returns a raster with the K-means distances base on your object passed in the arguments. diff --git a/man/ImageMetaData.Rd b/man/ImageMetaData.Rd index 3cea2be..88e9611 100644 --- a/man/ImageMetaData.Rd +++ b/man/ImageMetaData.Rd @@ -80,7 +80,7 @@ ImageMetaData( \item{scal}{Numeric vector. Scale factor per band. e.g. if data was scaled to 1000*reflectance for integer conversion.} -\item{dtyp}{Character vector. Data type per band. See \code{\link[raster]{dataType}} for options.} +\item{dtyp}{Character vector. Data type per band. See \code{\link[terra]{dataType}} for options.} \item{calrad}{data.frame. Calibration coefficients for dn->radiance conversion. Must have columns 'gain' and 'offset'. Rows named according to \code{bands}.} diff --git a/man/classifyQA.Rd b/man/classifyQA.Rd index e8adb00..382d2e6 100644 --- a/man/classifyQA.Rd +++ b/man/classifyQA.Rd @@ -24,7 +24,7 @@ classifyQA( \item{legacy}{Encoding systematic Options: \code{c("collection1", "pre_collection")}. Default is "collection1" for the Landsat Collection 1 8-bit quality designations. Use "pre_collection" for imagery downloaded before the Collection 1 quality designations were introduced} -\item{...}{further arguments passed to \link[raster]{writeRaster}} +\item{...}{further arguments passed to \link[terra]{writeRaster}} } \value{ Returns a SpatRaster with maximal five classes: diff --git a/man/coregisterImages.Rd b/man/coregisterImages.Rd index e3e33e2..c26c2ba 100644 --- a/man/coregisterImages.Rd +++ b/man/coregisterImages.Rd @@ -40,7 +40,7 @@ If shift is a matrix it must have two columns (x shift and y shift), then only t \item{slave}{DEPRECATED! Argument was renamed. Please use \code{img} from now on.} -\item{...}{further arguments passed to \code{\link[raster]{writeRaster}}.} +\item{...}{further arguments passed to \code{\link[terra]{writeRaster}}.} } \value{ \code{reportStats=FALSE} returns a SpatRaster (x-y shifted image). diff --git a/man/ggR.Rd b/man/ggR.Rd index 8729cf1..9508846 100644 --- a/man/ggR.Rd +++ b/man/ggR.Rd @@ -66,7 +66,7 @@ Plot single layer imagery in grey-scale. Can be used with a SpatRaster. When \code{img} contains factor values and \code{annotation=TRUE}, the raster values will automatically be converted to numeric in order to proceed with the brightness calculation. -The raster package provides a class lookup-table for categorical rasters (e.g. what you get if you run superClass in classification mode). If your raster has a lookup-table ggR will automatically treat it as categorical (see \link[raster]{factor}). +The raster package provides a class lookup-table for categorical rasters (e.g. what you get if you run superClass in classification mode). If your raster has a lookup-table ggR will automatically treat it as categorical (see \link[terra]{factor}). However, the factor status of Raster objects is easily lost and the values are interpreted as numeric. In such cases you should make use of the \code{forceCat = TRUE} argument, which makes sure that ggplot2 uses a discrete scale, not a continuous one. diff --git a/man/ggRGB.Rd b/man/ggRGB.Rd index fa6d451..ebb4734 100644 --- a/man/ggRGB.Rd +++ b/man/ggRGB.Rd @@ -77,7 +77,7 @@ Note that you can't use scale_fill* in addition to the latter, because it alread Calculates RGB color composite raster for plotting with ggplot2. Optional values for clipping and and stretching can be used to enhance the imagery. } \details{ -Functionality is based on \code{\link[raster]{plotRGB}} from the raster package. +Functionality is based on \code{\link[terra]{plotRGB}} from the raster package. } \examples{ diff --git a/man/histMatch.Rd b/man/histMatch.Rd index b46aedd..ad32558 100644 --- a/man/histMatch.Rd +++ b/man/histMatch.Rd @@ -36,7 +36,7 @@ histMatch( \item{returnFunctions}{Logical. If \code{TRUE} the matching functions will be returned instead of applying them to \code{x}.} -\item{...}{Further arguments to be passed to \link[raster]{writeRaster}.} +\item{...}{Further arguments to be passed to \link[terra]{writeRaster}.} } \value{ A SpatRaster of \code{x} adjusted to the histogram of \code{ref}. If \code{returnFunctions = TRUE} a list of functions (one for each layer) will be returned instead. diff --git a/man/mesma.Rd b/man/mesma.Rd index 4ff69fb..1db9b40 100644 --- a/man/mesma.Rd +++ b/man/mesma.Rd @@ -20,7 +20,7 @@ mesma(img, em, method = "NNLS", iterate = 400, tolerance = 1e-08, ..., verbose) \item{tolerance}{Numeric. Tolerance limit representing a nearly zero minimal number. Default is 1e-8.} -\item{...}{further arguments passed to \link[raster]{writeRaster}.} +\item{...}{further arguments passed to \link[terra]{writeRaster}.} \item{verbose}{Logical. Prints progress messages during execution.} } diff --git a/man/predict.unsuperClass.Rd b/man/predict.unsuperClass.Rd index 95023a8..ffb0816 100644 --- a/man/predict.unsuperClass.Rd +++ b/man/predict.unsuperClass.Rd @@ -13,7 +13,7 @@ \item{output}{Character. Either 'classes' (kmeans class; default) or 'distances' (euclidean distance to each cluster center).} -\item{...}{further arguments to be passed to \link[raster]{writeRaster}, e.g. filename} +\item{...}{further arguments to be passed to \link[terra]{writeRaster}, e.g. filename} } \value{ Returns a raster with the K-means distances base on your object passed in the arguments. diff --git a/man/rasterCVA.Rd b/man/rasterCVA.Rd index 7ef16da..5145a67 100644 --- a/man/rasterCVA.Rd +++ b/man/rasterCVA.Rd @@ -33,11 +33,12 @@ For example for a given pixel in image A and B for the red and nir band the chan Angles are returned *in degree* beginning with 0 degrees pointing 'north', i.e. the y-axis, i.e. the second band. } \examples{ +\donttest{ library(terra) pca <- rasterPCA(lsat)$map ## Do change vector analysis cva <- rasterCVA(pca[[1:2]], pca[[3:4]]) cva -plot(cva) +} } diff --git a/man/rasterPCA.Rd b/man/rasterPCA.Rd index 6e94307..c7ec20a 100644 --- a/man/rasterPCA.Rd +++ b/man/rasterPCA.Rd @@ -25,7 +25,7 @@ rasterPCA( \item{maskCheck}{Logical. Masks all pixels which have at least one NA (default TRUE is reccomended but introduces a slow-down, see Details when it is wise to disable maskCheck). Takes effect only if nSamples is NULL.} -\item{...}{further arguments to be passed to \link[raster]{writeRaster}, e.g. filename.} +\item{...}{further arguments to be passed to \link[terra]{writeRaster}, e.g. filename.} } \value{ Returns a named list containing the PCA model object ($model) and a SpatRaster with the principal component layers ($object). @@ -47,6 +47,7 @@ Standardised PCA (SPCA) can be useful if imagery or bands of different dynamic r has the same effect as using normalised bands of unit variance. } \examples{ +\donttest{ library(ggplot2) library(reshape2) ggRGB(rlogo, 1,2,3) @@ -66,3 +67,4 @@ if(require(gridExtra)){ grid.arrange(plots[[1]],plots[[2]], plots[[3]], ncol=2) } } +} diff --git a/man/topCor.Rd b/man/topCor.Rd index d9a19b1..62ca99f 100644 --- a/man/topCor.Rd +++ b/man/topCor.Rd @@ -19,7 +19,7 @@ topCor( \arguments{ \item{img}{SpatRaster. Imagery to correct} -\item{dem}{SpatRaster. Either a digital elevation model as a RasterLayer or a RasterStack/Brick with pre-calculated slope and aspect (see \link[raster]{terrain}) in which case the layers must be named 'slope' and 'aspect'. +\item{dem}{SpatRaster. Either a digital elevation model as a RasterLayer or a RasterStack/Brick with pre-calculated slope and aspect (see \link[terra]{terrain}) in which case the layers must be named 'slope' and 'aspect'. Must have the same dimensions as \code{img}.} \item{metaData}{Character, ImageMetaData. Either a path to a Landsat meta-data file (MTL) or an ImageMetaData object (see \link{readMeta})} @@ -34,7 +34,7 @@ Must have the same dimensions as \code{img}.} \item{illu}{SpatRaster. Optional pre-calculated ilumination map. Run topCor with method="illu" to calculate an ilumination map} -\item{...}{arguments passed to \code{\link[raster]{writeRaster}}} +\item{...}{arguments passed to \code{\link[terra]{writeRaster}}} } \value{ SpatRaster diff --git a/man/unsuperClass.Rd b/man/unsuperClass.Rd index 0c401ff..de36069 100644 --- a/man/unsuperClass.Rd +++ b/man/unsuperClass.Rd @@ -50,7 +50,7 @@ Unsupervised clustering of SpatRaster data using kmeans clustering Clustering is done using \code{\link[stats]{kmeans}}. This can be done for all pixels of the image (\code{clusterMap=FALSE}), however this can be slow and is not memory safe. Therefore if you have large raster data (> memory), as is typically the case with remote sensing imagery it is advisable to choose clusterMap=TRUE (the default). This means that a kmeans cluster model is calculated based on a random subset of pixels (\code{nSamples}). Then the distance of *all* pixels to the cluster centers -is calculated in a stepwise fashion using \code{\link[raster]{predict}}. Class assignment is based on minimum euclidean distance to the cluster centers. +is calculated in a stepwise fashion using \code{\link[terra]{predict}}. Class assignment is based on minimum euclidean distance to the cluster centers. The solution of the kmeans algorithm often depends on the initial configuration of class centers which is chosen randomly. Therefore, kmeans is usually run with multiple random starting configurations in order to find a convergent solution from different starting configurations. diff --git a/tests/testthat/test-panSharpen.R b/tests/testthat/test-panSharpen.R index 904c79d..cdb6414 100755 --- a/tests/testthat/test-panSharpen.R +++ b/tests/testthat/test-panSharpen.R @@ -3,9 +3,6 @@ context("panSharpen") library(terra) test_that("panSharpen methods", { - skip_on_cran() - skip_on_covr() - skip_on_ci() suppressWarnings({ agg <- aggregate(lsat, 10) pan <- sum(lsat[[1:3]]) diff --git a/tests/testthat/test-rsOpts.R b/tests/testthat/test-rsOpts.R index 68c35ea..c7bf261 100644 --- a/tests/testthat/test-rsOpts.R +++ b/tests/testthat/test-rsOpts.R @@ -1,11 +1,11 @@ context("rsOpts & .vMessage") test_that("setting global options",{ - expect_false(options("RStoolbox.verbose")[[1]]) - expect_silent(.vMessage("MIC CHECK 12")) - expect_silent(rsOpts(verbose = TRUE)) - expect_true(options("RStoolbox.verbose")[[1]]) - expect_message(.vMessage("MIC CHECK 12"), "MIC CHECK 12") - expect_silent(rsOpts(verbose = FALSE)) - }) + expect_false(options("RStoolbox.verbose")[[1]]) + expect_silent(.vMessage("MIC CHECK 12")) + expect_silent(rsOpts(verbose = TRUE)) + expect_true(options("RStoolbox.verbose")[[1]]) + expect_message(.vMessage("MIC CHECK 12"), "MIC CHECK 12") + expect_silent(rsOpts(verbose = FALSE)) +})