A fast, parallel implementation of convolutions for grid-type data (matrices, rasters and other grid based objects).
pfocal(
data,
kernel,
edge_value = 0,
transform_function = "MULTIPLY",
reduce_function = "SUM",
mean_divider = "ONE",
variance = FALSE,
na.rm = NA,
mp = TRUE,
debug_use_r_implementation = FALSE,
...
)[matrix-type] Grid to compute onto.
[matrix] Computation kernel (neighborhood).
[numeric] Numeric value, NA or NaN.The value to
give at the edge of the kernel matrix when the moving window overflows
the data grid.
[character] The function to apply to the
cell values covered by the kernel. For possible values, see
pfocal_info_transform(). Default to "MULTIPLY".
[character] The function to apply to the kernel
values after the function passed in transform_function has been applied
(the function that summarize the data). For possible values, see
pfocal_info_reduce(). Default to "SUM".
[character] Optional, allows to specify how the
final value at each cell is divided by a value that can be function of
the intermediate data resulting of applying transform_function. For
possible values, see pfocal_info_mean_divisor(). Default to "ONE" (for
no division).
[logical] Whether to return the "variance" of the
intermediate values at each point (for more details please see
pfocal_info_variance()). Default to FALSE (just returns the value
at each point).
[NA OR logical] The behavior to adopt for dealing with
missing values, default to NA (faster option). For possible values see
pfocal_info_nan_policy().
[logical] Whether to use the open_mp implementation,
default to TRUE.
[logical] Used for debugging purposes
whether to use the slow R implementation instead of the fast C++ code.
Default to FALSE.
None used at the moment .
The updated, convoluted grid.
Note that the memory allocation for the output is of size
sizeof(double) * ncol * nrow and for the intermediate
values, sizeof(double) * (ncol + kernel_ncol) * (nrow + kernel_nrow/2).
# NOT RUN {
data <- matrix(nrow = 10, ncol = 10, data = runif(10 * 10))
kernel <- matrix(1 / 9, nrow = 3, ncol = 3)
pfocal(data = data, kernel = kernel)
# }
Run the code above in your browser using DataLab