gaussWindow: Generate a Gaussian window for smoothing rasters.

Description Usage Arguments Details Value See Also Examples

Description

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).

Usage

1
gaussWindow(n, sigma = n/5)

Arguments

n

The dimension of the window, i.e. the window has dimension n * n. n must be an odd number (in order to have the focal cell in the center) so if an even number is specified n + 1 is used instead, without a warning.

sigma

The dispersion of the Gaussian.

Details

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.

Value

A square matrix of dimension n (or n + 1, see above) giving the weights for moving window smoothing.

See Also

focal, biasGrid

Examples

 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)

SEEG-Oxford/seegSDM documentation built on May 9, 2019, 11:08 a.m.