Description Usage Arguments Details Value See Also Examples
Create a window (essentially just a matrix) of dimensionn
with Gaussian weights (using dispersion parameter sigma
) for use in moving window smoothing (e.g. focal
from the raster
package or biasGrid
from this package).
1 | gaussWindow(n, sigma = n/5)
|
n |
The dimension of the window, i.e. the window has dimension |
sigma |
The dispersion of the Gaussian. |
The density of the Gaussian is calculated as:
exp(-(r ^ 2) / (2 * sigma ^ 2))
where r is the euclidean distance (in number of cells) from the focal (center) cell.
A square matrix of dimension n
(or n + 1
, see above) giving the weights for moving window smoothing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # create a raster
r <- raster(nrows = 10, ncols = 10,
xmn = 0, xmx = 10,
ymn = 0, ymx = 10)
r <- setValues(r, round(runif(ncell(r)) * 10))
# set up the Gaussian window, using the default value of sigma
window <- gaussWindow(n = 5)
window
# run the moving window smoother, padding and ignoring NAs
r2 <- focal(r, window, pad = TRUE, na.rm= TRUE)
# plot the before and after
par(mfrow = c(1, 2))
plot(r)
plot(r2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.