View source: R/gaussiansmooth.R
gaussiansmooth | R Documentation |
This function returns a grid of the same dimension as the input in which each
cell has a gaussian weighted mean of cells around it in the input grid. To
speed up processing with large bandwidths (SD) it may upscale the data prior to
applying a Gaussian kernel. The amount of upscaling is determined by the
kernel.dim
argument which sets the target dimension (in cells) of the
kernel at the courser resolution. The function can use a weights table to run
directly on a landcover grid substituting the cover values with weights as
defined in the weights table and with the no.match
and na.value
arguments. Edge correction is used; NA
cells and cells outside of the
region are not included in the calculation.
gaussiansmooth(x, sd, max.r, kernel.dim, ...)
## S3 method for class 'grid'
gaussiansmooth(x, sd, max.r=3*sd, kernel.dim=21, max.p.na=1,
sample.points, weights, no.match=0, use.old = FALSE,
na.value = NA, ...)
x |
|
sd |
The standard deviation of the kernel used to do the smoothing (in map units). |
max.r |
The maximum radius that weights are calculated for (in map units).
It defaults to three times |
kernel.dim |
The dimension of the kernel in the upscaled grid. It must be an odd number.
This controls the amount of upscaling, which is adjusted such that a
|
max.p.na |
If the proportion of |
sample.points |
(optional) a dataframe or matrix with columns "x" and "y" containing the map unit coordinates of points. If specified the function will return both the samples and a grid (in a list). |
weights |
(optional) a dataframe or matrix with columns "value" and "weight". If
|
no.match |
If weights are supplied this determines the value to use when cells in |
na.value |
If weights are supplied this determines the value to use when cells in |
use.old |
if |
... |
arguments to be passed to other methods. |
If sample.points
are not provided then the function will return a grid.
If sample.points
are provided the grid method will return a two item
list: sample
containing a vector of sampled values, and grid
.
It is left up to the user to make sure that the weights
table is
complete. Any values that occur in the grid but are not in the "value" column
of weights
will be replaced with no.match
prior to smoothing
unless they are NA
in which case they will be replaced with na.value
.
Ethan Plunkett
kernelsmooth
, makegaussiankernel
,
upscale
, and downscale
are all called by this function.
kernelsmooth
does the same thing but allows for user specified
kernels.
calckernel
allows calculating a kernel weighted average for a
single cell.
kernsource
is similar but works by summing kernels centered on
each cell, it may be faster if the non-zero values in the grid are sparse and
the SD is small.
swap
is used internally to substitute values when weights are used.
# Matrix method
m <- matrix(1:60, 6, 10)
k <- matrix(1, 3, 3)
k[2,2] <- 3
k <- k/sum(k)
m2 <- kernelsmooth(m, k)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.