Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstiDE committed Jan 16, 2024
1 parent 523c6f2 commit 75e21d9
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion R/classifyQA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion R/coregisterImages.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/ggR.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/ggRGB.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion R/histMatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion R/mesma.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down
3 changes: 2 additions & 1 deletion R/rasterCVA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions R/rasterPCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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"))

Expand Down
2 changes: 1 addition & 1 deletion R/readMeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
4 changes: 2 additions & 2 deletions R/topCor.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#' 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
#' @param method Character. One of c("cos", "avgcos", "minnaert", "C", "stat", "illu"). Choosing 'illu' will return only the local illumination map.
#' @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).
#'
Expand Down
4 changes: 2 additions & 2 deletions R/unsuperClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion man/ImageMetaData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/classifyQA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/coregisterImages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ggR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ggRGB.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/histMatch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mesma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/predict.unsuperClass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/rasterCVA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/rasterPCA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/topCor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/unsuperClass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions tests/testthat/test-panSharpen.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down
Loading

0 comments on commit 75e21d9

Please sign in to comment.