Skip to content

Commit

Permalink
Merge pull request #107 from bleutner/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KonstiDE authored Feb 16, 2024
2 parents 0406c45 + 1ca770c commit 67fe89e
Show file tree
Hide file tree
Showing 64 changed files with 98 additions and 81 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ Suggests:
LinkingTo: Rcpp,
RcppArmadillo
License: GPL (>=3)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
LazyData: true
16 changes: 14 additions & 2 deletions R/RStoolbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#' @importFrom grDevices hsv
#' @useDynLib RStoolbox
#' @importFrom Rcpp sourceCpp
#' @docType package
#' @docType _PACKAGE
#' @name RStoolbox
NULL

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion R/classifyQA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion R/cloudMask.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/coregisterImages.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion R/estimateHaze.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions R/fCover.R
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion R/getValidation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/ggR.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/ggRGB.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions R/histMatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion R/internalFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/mesma.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion R/oneHotEncode.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions R/panSharpen.R
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
4 changes: 2 additions & 2 deletions R/pifMatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions R/rasterCVA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/rasterEntropy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions R/rasterPCA.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/rescaleImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion R/sam.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion R/spectralIndices.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions R/superClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)

}
Expand Down
2 changes: 1 addition & 1 deletion R/tasseledCap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/validateMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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]]
Expand Down
10 changes: 8 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

}
Binary file added inst/external/sen2.rds
Binary file not shown.
File renamed without changes.
Binary file added inst/external/srtm_sen2.rds
Binary file not shown.
File renamed without changes.
Binary file added inst/external/trainingPoints_sen2.rds
Binary file not shown.
File renamed without changes.
Binary file added inst/external/trainingPolygons_sen2.rds
Binary file not shown.
2 changes: 1 addition & 1 deletion man/RStoolbox.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/cloudMask.Rd

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

Loading

0 comments on commit 67fe89e

Please sign in to comment.