diff --git a/DESCRIPTION b/DESCRIPTION index 3ecc5df..52e7657 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,5 +41,5 @@ Suggests: LinkingTo: Rcpp, RcppArmadillo License: GPL (>=3) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 LazyData: true diff --git a/R/RStoolbox.R b/R/RStoolbox.R index d79ed63..9ac197a 100644 --- a/R/RStoolbox.R +++ b/R/RStoolbox.R @@ -62,7 +62,7 @@ #' @importFrom grDevices hsv #' @useDynLib RStoolbox #' @importFrom Rcpp sourceCpp -#' @docType package +#' @docType _PACKAGE #' @name RStoolbox NULL @@ -100,5 +100,17 @@ NULL #' @keywords datasets #' @name lsat #' @examples -#' ggRGB(lsat, stretch = "lin") +#' ggRGB(lsat, stretch = "sqrt") +NULL + +#' Sentinel 2 MSI L2A Scene +#' +#' Contains all 13 bands in already converted spectral reflectances +#' +#' @usage sen2 +#' @docType data +#' @keywords datasets +#' @name sen2 +#' @examples +#' ggRGB(sen2, r=4, g=3, b=2, stretch = "lin") NULL diff --git a/R/classifyQA.R b/R/classifyQA.R index 1478bfb..ade05e0 100644 --- a/R/classifyQA.R +++ b/R/classifyQA.R @@ -2,7 +2,7 @@ #' #' extracts five classes from QA band: background, cloud, cirrus, snow and water. #' -#' @param img RasterLayer or SpatRaster. Landsat 8 OLI QA band. +#' @param img 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[terra]{writeRaster} diff --git a/R/cloudMask.R b/R/cloudMask.R index 0ee5bf0..0a729ba 100644 --- a/R/cloudMask.R +++ b/R/cloudMask.R @@ -4,7 +4,7 @@ #' and thermal band for semi-automated creation of a cloud mask. Since it relies on thermal information it doesn't work well for sensors without #' thermal bands. #' -#' @param x RasterBrick or RasterStack or SpatRaster with reflectance and brightness temperature OR the mask of a previous run of \code{cloudMask} with \code{returnDiffLayer=TRUE}. +#' @param x SpatRaster with reflectance and brightness temperature OR the mask of a previous run of \code{cloudMask} with \code{returnDiffLayer=TRUE}. #' @param threshold Numeric. cloud detection threshold. If not provided it will be guessed. Everything *below* this threshold will be considered a cloud pixel (unless it is removed by filtering afterwards). #' @param blue Character or integer. Bandname or number for the blue band #' @param tir Character or integer. Bandname or number for the thermal band diff --git a/R/coregisterImages.R b/R/coregisterImages.R index 14559ca..e133a11 100644 --- a/R/coregisterImages.R +++ b/R/coregisterImages.R @@ -3,8 +3,8 @@ #' Shifts an image to match a reference image. Matching is based on maximum #' mutual information. #' -#' @param img SpatRaster or SpatRaster. Image to shift to match reference image. \code{img} and \code{ref} must have equal numbers of bands. -#' @param ref SpatRaster or SpatRaster. Reference image. \code{img} and \code{ref} must have equal numbers of bands. +#' @param img SpatRaster. Image to shift to match reference image. \code{img} and \code{ref} must have equal numbers of bands. +#' @param ref SpatRaster. Reference image. \code{img} and \code{ref} must have equal numbers of bands. #' @param shift Numeric or matrix. If numeric, then shift is the maximal absolute radius (in pixels of \code{img} resolution) which \code{img} is shifted (\code{seq(-shift, shift, by=shiftInc)}). #' If shift is a matrix it must have two columns (x shift and y shift), then only these shift values will be tested. #' @param shiftInc Numeric. Shift increment (in pixels, but not restricted to integer). Ignored if \code{shift} is a matrix. diff --git a/R/estimateHaze.R b/R/estimateHaze.R index e7f4c5c..b673c39 100644 --- a/R/estimateHaze.R +++ b/R/estimateHaze.R @@ -2,7 +2,7 @@ #' #' estimates the digital number (DN) pixel value of *dark* objects for the visible wavelength range. #' -#' @param x RasterLayer or SpatRaster or a previous result from \code{estimateHaze} with \code{returnTables = TRUE} from which to estimate haze +#' @param x SpatRaster or a previous result from \code{estimateHaze} with \code{returnTables = TRUE} from which to estimate haze #' @param hazeBands Integer or Character. Band number or bandname from which to estimate atmospheric haze (optional if x contains only one layer) #' @param darkProp Numeric. Proportion of pixels estimated to be dark. #' @param maxSlope Logical. Use \code{darkProp} only as an upper boundary and search for the DN of maximum slope in the histogram below this value. diff --git a/R/fCover.R b/R/fCover.R index 269f9c0..faedd48 100755 --- a/R/fCover.R +++ b/R/fCover.R @@ -3,8 +3,8 @@ #' fCover takes a classified high resolution image, e.g. vegetation and non-vegetation based on Landsat and calculates cover fractions for #' pixels of a coarser resolution, e.g. MODIS. #' -#' @param classImage high resolution RasterLayer or SpatRaster containing a landcover classification, e.g. as obtained by \link{superClass}. -#' @param predImage coarse resolution RasterLayer or SpatRaster for which fractional cover will be estimated. +#' @param classImage high resolution SpatRaster containing a landcover classification, e.g. as obtained by \link{superClass}. +#' @param predImage coarse resolution SpatRaster for which fractional cover will be estimated. #' @param nSamples Integer. Number of pixels to sample from predImage to train the regression model #' @param classes Integer. Classes for which fractional cover should be estimated (one or more). #' @param model Character. Which model to fit for image regression. See \link[caret]{train} for options. Defaults to randomForest ('rf') diff --git a/R/getValidation.R b/R/getValidation.R index 0144a10..40ad874 100755 --- a/R/getValidation.R +++ b/R/getValidation.R @@ -11,7 +11,7 @@ #' @examples #' library(pls) #' ## Fit classifier (splitting training into 70\% training data, 30\% validation data) -#' train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +#' train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) #' SC <- superClass(rlogo, trainData = train, responseCol = "class", #' model="pls", trainPartition = 0.7) #' ## Independent testset-validation diff --git a/R/ggR.R b/R/ggR.R index 75d3688..cb58d11 100644 --- a/R/ggR.R +++ b/R/ggR.R @@ -2,7 +2,7 @@ #' #' Plot single layer imagery in grey-scale. Can be used with a SpatRaster. #' -#' @param img raster +#' @param img SpatRaster #' @param layer Character or numeric. Layername or number. Can be more than one layer, in which case each layer is plotted in a subplot. #' @param maxpixels Integer. Maximal number of pixels to sample. #' @param ext Extent object to crop the image diff --git a/R/ggRGB.R b/R/ggRGB.R index 0578e68..91c47bf 100644 --- a/R/ggRGB.R +++ b/R/ggRGB.R @@ -4,7 +4,7 @@ #' #' Functionality is based on \code{\link[terra]{plotRGB}} from the raster package. #' -#' @param img RasterStack or RasterBrick +#' @param img SpatRaster #' @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. #' @param g Integer or character. Green layer in x. Can be set to \code{NULL}, in which case the green channel will be set to zero. #' @param b Integer or character. Blue layer in x. Can be set to \code{NULL}, in which case the blue channel will be set to zero. diff --git a/R/histMatch.R b/R/histMatch.R index 278d365..16a120d 100644 --- a/R/histMatch.R +++ b/R/histMatch.R @@ -3,8 +3,8 @@ #' Performs image to image contrast adjustments based on histogram matching using empirical cumulative #' distribution functions from both images. #' -#' @param x RasterLayer or SpatRaster. Source raster which is to be modified. -#' @param ref RasterLayer or SpatRaster. Reference raster, to which x will be matched. +#' @param x SpatRaster. Source raster which is to be modified. +#' @param ref SpatRaster. Reference raster, to which x will be matched. #' @param xmask RasterLayer or SpatRaster. Mask layer for \code{x} to exclude pixels which might distort the histogram, i.e. are not present in \code{ref}. Any NA pixel in \code{xmask} will be ignored (\code{maskvalue = NA}). #' @param refmask RasterLayer or SpatRaster. Mask layer for \code{ref}. Any NA pixel in \code{refmask} will be ignored (\code{maskvalue = NA}). #' @param nSamples Integer. Number of random samples from each image to build the histograms. diff --git a/R/internalFunctions.R b/R/internalFunctions.R index da7a505..611eb77 100644 --- a/R/internalFunctions.R +++ b/R/internalFunctions.R @@ -57,7 +57,7 @@ } #' Run raster functions -#' @param SpatRaster Object +#' @param raster SpatRaster #' @param rasterFun function. E.g. predict, calc, overlay #' @param args list. arguments to be passed to rasterFun. #' @param wrArgs arguments to be passed to rasterFun, typically to writeRaster diff --git a/R/mesma.R b/R/mesma.R index a9e6f1d..f1dbc39 100644 --- a/R/mesma.R +++ b/R/mesma.R @@ -2,7 +2,7 @@ #' #' \code{mesma} performs a multiple endmember spectral mixture analysis on a multiband raster image. #' -#' @param img RasterLayer or RasterBrick or SpatRaster. Remote sensing imagery (usually hyperspectral). +#' @param img SpatRaster. Remote sensing imagery (usually hyperspectral). #' @param em Matrix or data.frame with spectral endmembers. Rows represent a single endmember of a class, columns represent the spectral bands (i.e. columns correspond to number of bands in \code{img}). Number of rows needs to be > 1. #' @param method Character. Select an unmixing method. Currently, only "NNLS" is implemented. Default is "NNLS". #' \itemize{ diff --git a/R/oneHotEncode.R b/R/oneHotEncode.R index 3e73df4..3b5270b 100644 --- a/R/oneHotEncode.R +++ b/R/oneHotEncode.R @@ -2,7 +2,7 @@ #' #' Splits a categorical raster layer (or a vector) into a multilayer raster (or matrix). #' -#' @param img RasterLayer or SpatRaster or integer/numeric vector containing multiple classes +#' @param img SpatRaster or integer/numeric vector containing multiple classes #' @param classes integer: vector of classes which should be extracted #' @param background integer: background value (default = 0) #' @param foreground integer: foreground value (default = 1) diff --git a/R/panSharpen.R b/R/panSharpen.R index 6b35397..51ccdda 100644 --- a/R/panSharpen.R +++ b/R/panSharpen.R @@ -3,8 +3,8 @@ #' provides different methods for pan sharpening a coarse resolution (typically multispectral) image with #' a higher reolution panchromatic image. Values of the pan-chromatic and multispectral images must be of the same scale, (e.g. from 0:1, or all DNs from 0:255) #' -#' @param img RasterLayer or SpatRaster. Coarse resolution multispectral image -#' @param pan RasterLayer or SpatRaster. High resolution image, typically panchromatic. +#' @param img SpatRaster. Coarse resolution multispectral image +#' @param pan SpatRaster. High resolution image, typically panchromatic. #' @param method Character. Choose method from c("pca", "ihs", "brovey"). #' @param r Character or Integer. Red band in \code{img}. Only relevant if \code{method!='pca'} #' @param g Character or Integer. Green band in \code{img}. Only relevant if \code{method!='pca'} diff --git a/R/pifMatch.R b/R/pifMatch.R index 1dadfc1..4f55e2f 100755 --- a/R/pifMatch.R +++ b/R/pifMatch.R @@ -2,8 +2,8 @@ #' #' Match one scene to another based on linear regression of pseudo-invariant features (PIF). #' -#' @param img RasterStack or RasterBrick or SpatRaster. Image to be adjusted. -#' @param ref RasterStack or RasterBrick or SpatRaster. Reference image. +#' @param img SpatRaster. Image to be adjusted. +#' @param ref SpatRaster. Reference image. #' @param method Method to calculate pixel similarity. Options: euclidean distance ('ed'), spectral angle ('sam') or pearson correlation coefficient ('cor'). #' @param quantile Numeric. Threshold quantile used to identify PIFs #' @param returnPifMap Logical. Return a binary raster map ot pixels which were identified as pesudo-invariant features. diff --git a/R/rasterCVA.R b/R/rasterCVA.R index 5093fe0..92c29cb 100644 --- a/R/rasterCVA.R +++ b/R/rasterCVA.R @@ -3,8 +3,8 @@ #' Calculates angle and magnitude of change vectors. #' Dimensionality is limited to two bands per image. #' -#' @param x RasterBrick or RasterStack or SpatRaster with two layers. This will be the reference/origin for the change calculations. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin. -#' @param y RasterBrick or RasterStack or SpatRaster with two layers. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin. +#' @param x SpatRaster with two layers. This will be the reference/origin for the change calculations. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin. +#' @param y SpatRaster with two layers. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin. #' @param tmf Numeric. Threshold median factor (optional). Used to calculate a threshold magnitude for which pixels are considered stable, i.e. no change. Calculated as \code{tmf * mean(magnitude[magnitude > 0])}. #' @param nct Numeric. No-change threshold (optional). Alternative to \code{tmf}. Sets an absolute threshold. Change magnitudes below \code{nct} are considered stable and set to NA. #' @param ... further arguments passed to writeRaster diff --git a/R/rasterEntropy.R b/R/rasterEntropy.R index bc38d25..5635aeb 100644 --- a/R/rasterEntropy.R +++ b/R/rasterEntropy.R @@ -5,7 +5,7 @@ #' #' Entropy is calculated as -sum(p log(p)); p being the class frequency per pixel. #' -#' @param img RasterStack or RasterBrick or SpatRaster +#' @param img SpatRaster #' @param ... additional arguments passed to writeRaster #' @return #' SpatRaster "entropy" diff --git a/R/rasterPCA.R b/R/rasterPCA.R index 37c7e19..8102015 100644 --- a/R/rasterPCA.R +++ b/R/rasterPCA.R @@ -1,6 +1,6 @@ #' Principal Component Analysis for Rasters #' -#' Calculates R-mode PCA for RasterBricks or RasterStacks and returns a RasterBrick with multiple layers of PCA scores. +#' Calculates R-mode PCA for SpatRasters and returns a SpatRaster with multiple layers of PCA scores. #' #' Internally rasterPCA relies on the use of \link[stats]{princomp} (R-mode PCA). If nSamples is given the PCA will be calculated #' based on a random sample of pixels and then predicted for the full raster. If nSamples is NULL then the covariance matrix will be calculated @@ -14,7 +14,7 @@ #' Standardised PCA (SPCA) can be useful if imagery or bands of different dynamic ranges are combined. SPC uses the correlation matrix instead of the covariance matrix, which #' has the same effect as using normalised bands of unit variance. #' -#' @param img RasterLayer or SpatRaster. +#' @param img SpatRaster. #' @param nSamples Integer or NULL. Number of pixels to sample for PCA fitting. If NULL, all pixels will be used. #' @param nComp Integer. Number of PCA components to return. #' @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) diff --git a/R/rescaleImage.R b/R/rescaleImage.R index 8dc4ca7..c71f35f 100644 --- a/R/rescaleImage.R +++ b/R/rescaleImage.R @@ -8,7 +8,7 @@ #' By providing `xmin = -1` and `xmax = 1` the values can be rescaled to any other range, #' e.g. 1 to 100 while comparability to other rescaled NDVI scenes is retained. #' -#' @param x patRaster or numeric vector. Image to normalise. +#' @param x SpatRaster or numeric vector. Image to normalise. #' @param y SpatRaster or numeric vector. Reference image. Optional. Used to extract min and max values if ymin or ymax are missing. #' @param xmin Numeric. Min value of x. Either a single value or one value per layer in x. If xmin is not provided it will be extracted from x. #' @param xmax Numeric. Max value of x. Either a single value or one value per layer in x. If xmax is not provided it will be extracted from x. diff --git a/R/sam.R b/R/sam.R index c646afe..4f180b4 100644 --- a/R/sam.R +++ b/R/sam.R @@ -2,7 +2,7 @@ #' #' Calculates the angle in spectral space between pixels and a set of reference spectra (endmembers) for image classification based on spectral similarity. #' -#' @param img RasterBrick or RasterStack or SpatRaster. Remote sensing imagery. +#' @param img SpatRaster. Remote sensing imagery. #' @param em Matrix or data.frame with endmembers. Each row should contain the endmember spectrum of a class, i.e. columns correspond to bands in \code{img}. It is reccomended to set the rownames to class names. #' @param angles Logical. If \code{TRUE} a RasterBrick containing each one layer per endmember will be returned containing the spectral angles. #' @param ... further arguments to be passed to \code{\link[terra]{writeRaster}} diff --git a/R/spectralIndices.R b/R/spectralIndices.R index f20cef4..5af8970 100644 --- a/R/spectralIndices.R +++ b/R/spectralIndices.R @@ -2,7 +2,7 @@ #' #' Calculate a suite of multispectral indices such as NDVI, SAVI etc. in an efficient way. #' -#' @param img SpatRaster, Typically remote sensing imagery, which is to be classified. +#' @param img SpatRaster. Typically remote sensing imagery, which is to be classified. #' @param blue Character or integer. Blue band. #' @param green Character or integer. Green band. #' @param red Character or integer. Red band. diff --git a/R/superClass.R b/R/superClass.R index 025c6b2..5b1151d 100644 --- a/R/superClass.R +++ b/R/superClass.R @@ -70,7 +70,7 @@ #' library(randomForest) #' library(e1071) #' library(terra) -#' train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +#' train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) #' #' ## Plot training data #' olpar <- par(no.readonly = TRUE) # back-up par @@ -498,7 +498,7 @@ superClass <- function(img, trainData, valData = NULL, responseCol = NULL, #' @export #' @examples #' ## Load training data -#' train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +#' train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) #' #' ## Fit classifier #' SC <- superClass(rlogo, trainData = train, responseCol = "class", @@ -527,7 +527,6 @@ 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 - print(img) .paraRasterFun(img, rasterFun=terra::predict, args = list(model=model, type = predType, index = probInd, na.rm = TRUE), wrArgs = wrArgs) } diff --git a/R/tasseledCap.R b/R/tasseledCap.R index d0c241a..43588d0 100644 --- a/R/tasseledCap.R +++ b/R/tasseledCap.R @@ -3,7 +3,7 @@ #' Calculates brightness, greenness and wetness from multispectral imagery. #' Currently implemented Landsat 4 TM, Landsat 5 TM, Landsat 7ETM+, Landsat 8 OLI, MODIS, QuickBird, Spot5 and RapidEye. #' -#' @param img RasterBrick or RasterStack or SpatRaster. Input image. Band order must correspond to sensor specifications (see Details and Examples) +#' @param img SpatRaster. Input image. Band order must correspond to sensor specifications (see Details and Examples) #' @param sat Character. Sensor; one of: c("Landsat4TM", "Landsat5TM", "Landsat7ETM", "Landsat8OLI", "MODIS", "QuickBird", "Spot5", "RapidEye"). Case is irrelevant. #' @param ... Further arguments passed to writeRaster. #' @export diff --git a/R/validateMap.R b/R/validateMap.R index 55a4e3e..8d9181e 100644 --- a/R/validateMap.R +++ b/R/validateMap.R @@ -3,7 +3,7 @@ #' #' validate a map from a classification or regression model. This can be useful to update the accuracy assessment after filtering, e.g. for a minimum mapping unit. #' -#' @param map RasterLayer or SpatRaster. The classified map. +#' @param map SpatRaster. The classified map. #' @param valData sf object with validation data (POLYGONs or POINTs). #' @param nSamplesV Integer. Number of pixels to sample for validation (only applies to polygons). #' @param responseCol Character. Column containing the validation data in attribute table of \code{valData}. @@ -17,7 +17,7 @@ #' library(terra) #' #' ## Training data -#' poly <- readRDS(system.file("external/trainingPolygons.rds", package="RStoolbox")) +#' poly <- readRDS(system.file("external/trainingPolygons_lsat.rds", package="RStoolbox")) #' #' ## Split training data in training and validation set (50%-50%) #' splitIn <- createDataPartition(poly$class, p = .5)[[1]] diff --git a/R/zzz.R b/R/zzz.R index bccf384..41bdbd3 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -12,10 +12,16 @@ lsat_rs <- terra::readRDS(system.file("external", "lsat.rds", package = pkgname)) assign("lsat", lsat_rs, envir=as.environment("package:RStoolbox")) + srtml_rs <- terra::readRDS(system.file("external", "srtm_lsat.rds", package = pkgname)) + assign("srtm", srtml_rs, envir=as.environment("package:RStoolbox")) + rlogo_rs <- terra::readRDS(system.file("external", "rlogo.rds", package = pkgname)) assign("rlogo", rlogo_rs, envir=as.environment("package:RStoolbox")) - srtm_rs <- terra::readRDS(system.file("external", "srtm.rds", package = pkgname)) - assign("srtm", srtm_rs, envir=as.environment("package:RStoolbox")) + sen2_rs <- terra::readRDS(system.file("external", "sen2.rds", package = pkgname)) + assign("sen2", sen2_rs, envir=as.environment("package:RStoolbox")) + + srtms_rs <- terra::readRDS(system.file("external", "srtm_sen2.rds", package = pkgname)) + assign("srtm_sen2", srtms_rs, envir=as.environment("package:RStoolbox")) } diff --git a/inst/external/sen2.rds b/inst/external/sen2.rds new file mode 100644 index 0000000..cc44bf0 Binary files /dev/null and b/inst/external/sen2.rds differ diff --git a/inst/external/srtm.rds b/inst/external/srtm_lsat.rds similarity index 100% rename from inst/external/srtm.rds rename to inst/external/srtm_lsat.rds diff --git a/inst/external/srtm_sen2.rds b/inst/external/srtm_sen2.rds new file mode 100644 index 0000000..740ab77 Binary files /dev/null and b/inst/external/srtm_sen2.rds differ diff --git a/inst/external/trainingPoints.rds b/inst/external/trainingPoints_lsat.rds similarity index 100% rename from inst/external/trainingPoints.rds rename to inst/external/trainingPoints_lsat.rds diff --git a/inst/external/trainingPoints_sen2.rds b/inst/external/trainingPoints_sen2.rds new file mode 100644 index 0000000..673e647 Binary files /dev/null and b/inst/external/trainingPoints_sen2.rds differ diff --git a/inst/external/trainingPolygons.rds b/inst/external/trainingPolygons_lsat.rds similarity index 100% rename from inst/external/trainingPolygons.rds rename to inst/external/trainingPolygons_lsat.rds diff --git a/inst/external/trainingPolygons_sen2.rds b/inst/external/trainingPolygons_sen2.rds new file mode 100644 index 0000000..2a70969 Binary files /dev/null and b/inst/external/trainingPolygons_sen2.rds differ diff --git a/man/RStoolbox.Rd b/man/RStoolbox.Rd index d050715..e855708 100755 --- a/man/RStoolbox.Rd +++ b/man/RStoolbox.Rd @@ -1,6 +1,6 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/RStoolbox.R -\docType{package} +\docType{_PACKAGE} \name{RStoolbox} \alias{RStoolbox} \title{RStoolbox: A Collection of Remote Sensing Tools} diff --git a/man/classifyQA.Rd b/man/classifyQA.Rd index 382d2e6..17e915a 100644 --- a/man/classifyQA.Rd +++ b/man/classifyQA.Rd @@ -14,7 +14,7 @@ classifyQA( ) } \arguments{ -\item{img}{RasterLayer or SpatRaster. Landsat 8 OLI QA band.} +\item{img}{SpatRaster. Landsat 8 OLI QA band.} \item{type}{Character. Classes which should be returned. One or more of c("background", "cloud", "cirrus","snow", "water").} diff --git a/man/cloudMask.Rd b/man/cloudMask.Rd index 0bcf1a9..05f3301 100755 --- a/man/cloudMask.Rd +++ b/man/cloudMask.Rd @@ -15,7 +15,7 @@ cloudMask( ) } \arguments{ -\item{x}{RasterBrick or RasterStack or SpatRaster with reflectance and brightness temperature OR the mask of a previous run of \code{cloudMask} with \code{returnDiffLayer=TRUE}.} +\item{x}{SpatRaster with reflectance and brightness temperature OR the mask of a previous run of \code{cloudMask} with \code{returnDiffLayer=TRUE}.} \item{threshold}{Numeric. cloud detection threshold. If not provided it will be guessed. Everything *below* this threshold will be considered a cloud pixel (unless it is removed by filtering afterwards).} diff --git a/man/coregisterImages.Rd b/man/coregisterImages.Rd index c26c2ba..6fd4008 100644 --- a/man/coregisterImages.Rd +++ b/man/coregisterImages.Rd @@ -19,9 +19,9 @@ coregisterImages( ) } \arguments{ -\item{img}{SpatRaster or SpatRaster. Image to shift to match reference image. \code{img} and \code{ref} must have equal numbers of bands.} +\item{img}{SpatRaster. Image to shift to match reference image. \code{img} and \code{ref} must have equal numbers of bands.} -\item{ref}{SpatRaster or SpatRaster. Reference image. \code{img} and \code{ref} must have equal numbers of bands.} +\item{ref}{SpatRaster. Reference image. \code{img} and \code{ref} must have equal numbers of bands.} \item{shift}{Numeric or matrix. If numeric, then shift is the maximal absolute radius (in pixels of \code{img} resolution) which \code{img} is shifted (\code{seq(-shift, shift, by=shiftInc)}). If shift is a matrix it must have two columns (x shift and y shift), then only these shift values will be tested.} diff --git a/man/estimateHaze.Rd b/man/estimateHaze.Rd index eccc8cd..f56b39a 100644 --- a/man/estimateHaze.Rd +++ b/man/estimateHaze.Rd @@ -14,7 +14,7 @@ estimateHaze( ) } \arguments{ -\item{x}{RasterLayer or SpatRaster or a previous result from \code{estimateHaze} with \code{returnTables = TRUE} from which to estimate haze} +\item{x}{SpatRaster or a previous result from \code{estimateHaze} with \code{returnTables = TRUE} from which to estimate haze} \item{hazeBands}{Integer or Character. Band number or bandname from which to estimate atmospheric haze (optional if x contains only one layer)} diff --git a/man/fCover.Rd b/man/fCover.Rd index 102caf3..aea6068 100755 --- a/man/fCover.Rd +++ b/man/fCover.Rd @@ -22,9 +22,9 @@ fCover( ) } \arguments{ -\item{classImage}{high resolution RasterLayer or SpatRaster containing a landcover classification, e.g. as obtained by \link{superClass}.} +\item{classImage}{high resolution SpatRaster containing a landcover classification, e.g. as obtained by \link{superClass}.} -\item{predImage}{coarse resolution RasterLayer or SpatRaster for which fractional cover will be estimated.} +\item{predImage}{coarse resolution SpatRaster for which fractional cover will be estimated.} \item{nSamples}{Integer. Number of pixels to sample from predImage to train the regression model} diff --git a/man/getValidation.Rd b/man/getValidation.Rd index ddf807f..fd0d676 100755 --- a/man/getValidation.Rd +++ b/man/getValidation.Rd @@ -25,7 +25,7 @@ Extract validation results from superClass objects \examples{ library(pls) ## Fit classifier (splitting training into 70\\% training data, 30\\% validation data) -train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) SC <- superClass(rlogo, trainData = train, responseCol = "class", model="pls", trainPartition = 0.7) ## Independent testset-validation diff --git a/man/ggR.Rd b/man/ggR.Rd index c49521f..5359fcc 100644 --- a/man/ggR.Rd +++ b/man/ggR.Rd @@ -22,7 +22,7 @@ ggR( ) } \arguments{ -\item{img}{raster} +\item{img}{SpatRaster} \item{layer}{Character or numeric. Layername or number. Can be more than one layer, in which case each layer is plotted in a subplot.} diff --git a/man/ggRGB.Rd b/man/ggRGB.Rd index ebb4734..b8c9e08 100644 --- a/man/ggRGB.Rd +++ b/man/ggRGB.Rd @@ -25,7 +25,7 @@ ggRGB( ) } \arguments{ -\item{img}{RasterStack or RasterBrick} +\item{img}{SpatRaster} \item{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/man/histMatch.Rd b/man/histMatch.Rd index ad32558..c30de9d 100644 --- a/man/histMatch.Rd +++ b/man/histMatch.Rd @@ -18,9 +18,9 @@ histMatch( ) } \arguments{ -\item{x}{RasterLayer or SpatRaster. Source raster which is to be modified.} +\item{x}{SpatRaster. Source raster which is to be modified.} -\item{ref}{RasterLayer or SpatRaster. Reference raster, to which x will be matched.} +\item{ref}{SpatRaster. Reference raster, to which x will be matched.} \item{xmask}{RasterLayer or SpatRaster. Mask layer for \code{x} to exclude pixels which might distort the histogram, i.e. are not present in \code{ref}. Any NA pixel in \code{xmask} will be ignored (\code{maskvalue = NA}).} diff --git a/man/lsat.Rd b/man/lsat.Rd index 1375beb..d1fae63 100644 --- a/man/lsat.Rd +++ b/man/lsat.Rd @@ -12,6 +12,6 @@ Subset of Landsat 5 TM Scene: LT52240631988227CUB02 Contains all seven bands in DN format. } \examples{ -ggRGB(lsat, stretch = "lin") +ggRGB(lsat, stretch = "sqrt") } \keyword{datasets} diff --git a/man/mesma.Rd b/man/mesma.Rd index 1db9b40..f7d4b83 100644 --- a/man/mesma.Rd +++ b/man/mesma.Rd @@ -7,7 +7,7 @@ mesma(img, em, method = "NNLS", iterate = 400, tolerance = 1e-08, ..., verbose) } \arguments{ -\item{img}{RasterLayer or RasterBrick or SpatRaster. Remote sensing imagery (usually hyperspectral).} +\item{img}{SpatRaster. Remote sensing imagery (usually hyperspectral).} \item{em}{Matrix or data.frame with spectral endmembers. Rows represent a single endmember of a class, columns represent the spectral bands (i.e. columns correspond to number of bands in \code{img}). Number of rows needs to be > 1.} diff --git a/man/oneHotEncode.Rd b/man/oneHotEncode.Rd index 454152a..cdf8a81 100644 --- a/man/oneHotEncode.Rd +++ b/man/oneHotEncode.Rd @@ -7,7 +7,7 @@ oneHotEncode(img, classes, background = 0, foreground = 1, na.rm = FALSE, ...) } \arguments{ -\item{img}{RasterLayer or SpatRaster or integer/numeric vector containing multiple classes} +\item{img}{SpatRaster or integer/numeric vector containing multiple classes} \item{classes}{integer: vector of classes which should be extracted} diff --git a/man/panSharpen.Rd b/man/panSharpen.Rd index 0c45486..d186f8d 100644 --- a/man/panSharpen.Rd +++ b/man/panSharpen.Rd @@ -7,9 +7,9 @@ panSharpen(img, pan, r, g, b, pc = 1, method = "brovey", norm = TRUE) } \arguments{ -\item{img}{RasterLayer or SpatRaster. Coarse resolution multispectral image} +\item{img}{SpatRaster. Coarse resolution multispectral image} -\item{pan}{RasterLayer or SpatRaster. High resolution image, typically panchromatic.} +\item{pan}{SpatRaster. High resolution image, typically panchromatic.} \item{r}{Character or Integer. Red band in \code{img}. Only relevant if \code{method!='pca'}} diff --git a/man/pifMatch.Rd b/man/pifMatch.Rd index f0a30b6..c567241 100644 --- a/man/pifMatch.Rd +++ b/man/pifMatch.Rd @@ -15,9 +15,9 @@ pifMatch( ) } \arguments{ -\item{img}{RasterStack or RasterBrick or SpatRaster. Image to be adjusted.} +\item{img}{SpatRaster. Image to be adjusted.} -\item{ref}{RasterStack or RasterBrick or SpatRaster. Reference image.} +\item{ref}{SpatRaster. Reference image.} \item{method}{Method to calculate pixel similarity. Options: euclidean distance ('ed'), spectral angle ('sam') or pearson correlation coefficient ('cor').} diff --git a/man/rasterCVA.Rd b/man/rasterCVA.Rd index d732039..54b7a97 100644 --- a/man/rasterCVA.Rd +++ b/man/rasterCVA.Rd @@ -7,9 +7,9 @@ rasterCVA(x, y, tmf = NULL, nct = NULL, ...) } \arguments{ -\item{x}{RasterBrick or RasterStack or SpatRaster with two layers. This will be the reference/origin for the change calculations. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin.} +\item{x}{SpatRaster with two layers. This will be the reference/origin for the change calculations. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin.} -\item{y}{RasterBrick or RasterStack or SpatRaster with two layers. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin.} +\item{y}{SpatRaster with two layers. Both rasters (y and y) need to correspond to each other, i.e. same resolution, extent and origin.} \item{tmf}{Numeric. Threshold median factor (optional). Used to calculate a threshold magnitude for which pixels are considered stable, i.e. no change. Calculated as \code{tmf * mean(magnitude[magnitude > 0])}.} diff --git a/man/rasterEntropy.Rd b/man/rasterEntropy.Rd index 99c78f2..26be715 100644 --- a/man/rasterEntropy.Rd +++ b/man/rasterEntropy.Rd @@ -7,7 +7,7 @@ rasterEntropy(img, ...) } \arguments{ -\item{img}{RasterStack or RasterBrick or SpatRaster} +\item{img}{SpatRaster} \item{...}{additional arguments passed to writeRaster} } diff --git a/man/rasterPCA.Rd b/man/rasterPCA.Rd index 047db48..ed3d99a 100644 --- a/man/rasterPCA.Rd +++ b/man/rasterPCA.Rd @@ -14,7 +14,7 @@ rasterPCA( ) } \arguments{ -\item{img}{RasterLayer or SpatRaster.} +\item{img}{SpatRaster.} \item{nSamples}{Integer or NULL. Number of pixels to sample for PCA fitting. If NULL, all pixels will be used.} @@ -31,7 +31,7 @@ Takes effect only if nSamples is NULL.} Returns a named list containing the PCA model object ($model) and a SpatRaster with the principal component layers ($object). } \description{ -Calculates R-mode PCA for RasterBricks or RasterStacks and returns a RasterBrick with multiple layers of PCA scores. +Calculates R-mode PCA for SpatRasters and returns a SpatRaster with multiple layers of PCA scores. } \details{ Internally rasterPCA relies on the use of \link[stats]{princomp} (R-mode PCA). If nSamples is given the PCA will be calculated diff --git a/man/rescaleImage.Rd b/man/rescaleImage.Rd index ed70a1b..66717f8 100644 --- a/man/rescaleImage.Rd +++ b/man/rescaleImage.Rd @@ -7,7 +7,7 @@ rescaleImage(x, y, xmin, xmax, ymin, ymax, forceMinMax = FALSE, ...) } \arguments{ -\item{x}{patRaster or numeric vector. Image to normalise.} +\item{x}{SpatRaster or numeric vector. Image to normalise.} \item{y}{SpatRaster or numeric vector. Reference image. Optional. Used to extract min and max values if ymin or ymax are missing.} diff --git a/man/sam.Rd b/man/sam.Rd index 87e114c..e80ea13 100644 --- a/man/sam.Rd +++ b/man/sam.Rd @@ -7,7 +7,7 @@ sam(img, em, angles = FALSE, ...) } \arguments{ -\item{img}{RasterBrick or RasterStack or SpatRaster. Remote sensing imagery.} +\item{img}{SpatRaster. Remote sensing imagery.} \item{em}{Matrix or data.frame with endmembers. Each row should contain the endmember spectrum of a class, i.e. columns correspond to bands in \code{img}. It is reccomended to set the rownames to class names.} diff --git a/man/spectralIndices.Rd b/man/spectralIndices.Rd index 8a1ce61..33cec27 100755 --- a/man/spectralIndices.Rd +++ b/man/spectralIndices.Rd @@ -28,7 +28,7 @@ spectralIndices( ) } \arguments{ -\item{img}{SpatRaster, Typically remote sensing imagery, which is to be classified.} +\item{img}{SpatRaster. Typically remote sensing imagery, which is to be classified.} \item{blue}{Character or integer. Blue band.} diff --git a/man/superClass.Rd b/man/superClass.Rd index bcb6201..c906079 100755 --- a/man/superClass.Rd +++ b/man/superClass.Rd @@ -117,7 +117,7 @@ library(caret) library(randomForest) library(e1071) library(terra) -train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) ## Plot training data olpar <- par(no.readonly = TRUE) # back-up par diff --git a/man/tasseledCap.Rd b/man/tasseledCap.Rd index f27ff74..1997671 100644 --- a/man/tasseledCap.Rd +++ b/man/tasseledCap.Rd @@ -7,7 +7,7 @@ tasseledCap(img, sat, ...) } \arguments{ -\item{img}{RasterBrick or RasterStack or SpatRaster. Input image. Band order must correspond to sensor specifications (see Details and Examples)} +\item{img}{SpatRaster. Input image. Band order must correspond to sensor specifications (see Details and Examples)} \item{sat}{Character. Sensor; one of: c("Landsat4TM", "Landsat5TM", "Landsat7ETM", "Landsat8OLI", "MODIS", "QuickBird", "Spot5", "RapidEye"). Case is irrelevant.} diff --git a/man/validateMap.Rd b/man/validateMap.Rd index e14c7b0..5d1a527 100644 --- a/man/validateMap.Rd +++ b/man/validateMap.Rd @@ -14,7 +14,7 @@ validateMap( ) } \arguments{ -\item{map}{RasterLayer or SpatRaster. The classified map.} +\item{map}{SpatRaster. The classified map.} \item{valData}{sf object with validation data (POLYGONs or POINTs).} @@ -37,7 +37,7 @@ library(caret) library(terra) ## Training data -poly <- readRDS(system.file("external/trainingPolygons.rds", package="RStoolbox")) +poly <- readRDS(system.file("external/trainingPolygons_lsat.rds", package="RStoolbox")) ## Split training data in training and validation set (50\%-50\%) splitIn <- createDataPartition(poly$class, p = .5)[[1]] diff --git a/prep-release/makeRelease.sh b/prep-release/makeRelease.sh index dc8ab4c..d1eae84 100755 --- a/prep-release/makeRelease.sh +++ b/prep-release/makeRelease.sh @@ -32,7 +32,7 @@ Rscript -e "library(devtools); library(methods); document(); install()" ## Re-build example data -tmstr=$(git log -1 --format=%ct data/ inst/external/trainingPoints.rds inst/external/landsat/) +tmstr=$(git log -1 --format=%ct data/ inst/external/trainingPoints_lsat.rds inst/external/landsat/) texmpl=$(git log example-data -1 --format=%ct) if [ $(( tmstr > texmpl )) -eq 0 ] then @@ -45,7 +45,7 @@ then ## Back to master git checkout master - git checkout example-data data/rlogo.rda data/srtm.rda data/lsat.rda inst/external/landsat inst/external/trainingPolygons.rds + git checkout example-data data/rlogo.rda data/srtm.rda data/lsat.rda inst/external/landsat inst/external/trainingPolygons_lsat.rds Rscript -e "library(devtools); library(methods); document()" git commit -a -m "Automatic commit: Pull example data from branch example-data" else diff --git a/tests/testthat/test-getValidation.R b/tests/testthat/test-getValidation.R index 74be44e..163d8de 100755 --- a/tests/testthat/test-getValidation.R +++ b/tests/testthat/test-getValidation.R @@ -1,7 +1,7 @@ context("getValidation") suppressPackageStartupMessages(library("randomForest")) -train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) train$num <- rnorm(nrow(train)) class <- superClass(rlogo, trainData = train, responseCol = "class", tuneLength = 1, trainPartition = 0.7, predict = FALSE) reg <- superClass(rlogo, trainData = train, responseCol = "num", tuneLength = 1, trainPartition = 0.7, predict = FALSE, mode = "regression") diff --git a/tests/testthat/test-ggplot.R b/tests/testthat/test-ggplot.R index 8737fa1..8716fc6 100644 --- a/tests/testthat/test-ggplot.R +++ b/tests/testthat/test-ggplot.R @@ -4,7 +4,7 @@ library(terra) test_that("ggR returns proper ggplot2 classes or data.frames", { suppressWarnings({ tests <- expand.grid(forceCat = c(TRUE, FALSE), anno = c(TRUE, FALSE), ggLayer = c(TRUE, FALSE), ggObj = c(TRUE,FALSE)) - builds <- lapply(1:nrow(tests), function(i) ggR(rlogo, forceCat = tests$forceCat[i], ggObj = tests$ggObj[i], geom_raster = !tests$anno[i], ggLayer = tests$ggLayer[i])) + builds <- lapply(seq_len(nrow(tests)), function(i) ggR(rlogo, forceCat = tests$forceCat[i], ggObj = tests$ggObj[i], geom_raster = !tests$anno[i], ggLayer = tests$ggLayer[i])) tinfo <- paste0("forceCat=", tests[,1], ", anno=", tests[,2], ", ggLayer=", tests[,3], ", ggObj=", tests[,4]) ## Annotation vs geom_raster @@ -13,7 +13,7 @@ test_that("ggR returns proper ggplot2 classes or data.frames", { ## ggLayers if(!inherits(builds[[which(with(tests, ggObj & ggLayer))[1]]], "ggproto")){ ## Current ggplot2 release version - for(s in which(with(tests, ggObj & ggLayer))) expect_is(builds[[s]], c("proto"), info = tinfo[s]) + for(s in which(with(tests, ggObj & ggLayer))) expect_is(builds[[s]], "proto", info = tinfo[s]) for(s in which(with(tests, ggObj & ggLayer & anno))) expect_equal(builds[[s]]$geom$objname, "raster_ann", info = tinfo[s]) for(s in which(with(tests, ggObj & ggLayer & !anno))) expect_equal(builds[[s]]$geom$objname, "raster", info = tinfo[s]) } else { @@ -60,7 +60,7 @@ test_that("ggR works with single valued rasters", { test_that("ggRGB returns proper ggplot2 classes or data.frames", { tests <- expand.grid(anno = c(TRUE, FALSE), ggLayer = c(TRUE, FALSE), ggObj = c(TRUE,FALSE), stretch=c("sqrt", "hist", "log", "lin")) - builds <- lapply(1:nrow(tests), function(i) ggRGB(rlogo, ggObj = tests$ggObj[i], geom_raster = !tests$anno[i], ggLayer = tests$ggLayer[i], stretch = tests$stretch[i] )) + builds <- lapply(seq_len(nrow(tests)), function(i) ggRGB(rlogo, ggObj = tests$ggObj[i], geom_raster = !tests$anno[i], ggLayer = tests$ggLayer[i], stretch = tests$stretch[i] )) tinfo <- paste0("anno=", tests$anno, ", ggLayer=", tests$ggLayer, ", ggObj=", tests$ggObj) ## Stand-alone @@ -69,7 +69,7 @@ test_that("ggRGB returns proper ggplot2 classes or data.frames", { ## ggLayers if(!inherits(builds[[which(with(tests, ggObj & ggLayer))[1]]], "ggproto")){ ## Current ggplot2 release version - for(s in which(with(tests, ggObj & ggLayer))) expect_is(builds[[s]], c("proto"), info = tinfo[s]) + for(s in which(with(tests, ggObj & ggLayer))) expect_is(builds[[s]], "proto", info = tinfo[s]) for(s in which(with(tests, ggObj & ggLayer & anno))) expect_equal(builds[[s]]$geom$objname, "raster_ann", info = tinfo[s]) for(s in which(with(tests, ggObj & ggLayer & !anno))) expect_equal(builds[[s]]$geom$objname, "raster", info = tinfo[s]) } else { diff --git a/tests/testthat/test-internalFunctions.R b/tests/testthat/test-internalFunctions.R index 2b0e90b..59d1273 100644 --- a/tests/testthat/test-internalFunctions.R +++ b/tests/testthat/test-internalFunctions.R @@ -2,7 +2,7 @@ context("internal functions") terra <- rast(ncol = 5, nrow=5, vals = 1) -sf <- readRDS(system.file("external/trainingPolygons.rds", package="RStoolbox")) +sf <- readRDS(system.file("external/trainingPolygons_lsat.rds", package="RStoolbox")) test_that("Loaded as sf", { expect_is(sf, c("sf", "data.frame")) diff --git a/tests/testthat/test-saveReadRSTBX.R b/tests/testthat/test-saveReadRSTBX.R index 5e7d399..82b4668 100644 --- a/tests/testthat/test-saveReadRSTBX.R +++ b/tests/testthat/test-saveReadRSTBX.R @@ -2,7 +2,7 @@ context("save and read RSTBX objects") library(terra) ## Create RSTBX object -train <- readRDS(system.file("external/trainingPoints.rds", package="RStoolbox")) +train <- readRDS(system.file("external/trainingPoints_lsat.rds", package="RStoolbox")) sc <- superClass(rlogo, train, tuneLength = 1, resp="class") ## Save and re-import diff --git a/tests/testthat/test-superClass.R b/tests/testthat/test-superClass.R index e6a490c..092031e 100644 --- a/tests/testthat/test-superClass.R +++ b/tests/testthat/test-superClass.R @@ -9,7 +9,7 @@ lsat_t <- lsat lsat_t <- lsat_t[[1:4]] ## Set-up test data set.seed(1) -poly <- readRDS(system.file("external/trainingPolygons.rds", package="RStoolbox")) +poly <- readRDS(system.file("external/trainingPolygons_lsat.rds", package="RStoolbox")) poly$res <- as.numeric(poly$class) poly <- st_as_sf(poly) pts <- st_join(st_as_sf(st_sample(poly, 100, type = "regular")), poly) diff --git a/tests/testthat/test-validateMap.R b/tests/testthat/test-validateMap.R index 306f71f..1418494 100644 --- a/tests/testthat/test-validateMap.R +++ b/tests/testthat/test-validateMap.R @@ -4,7 +4,7 @@ lsat_t <- lsat_t[[1:4]] ## Set-up test data set.seed(1) -poly <- readRDS(system.file("external/trainingPolygons.rds", package="RStoolbox")) +poly <- readRDS(system.file("external/trainingPolygons_lsat.rds", package="RStoolbox")) poly$classNum <- as.numeric(poly$class) sc <- superClass(lsat_t, trainData = poly, nSamples = 50, responseCol = "class", model = "mlc", trainPartition = 0.7, predict = TRUE)