pfocal: Fast, parallel implementation of grid data convolution

View source: R/pfocal.R

pfocalR Documentation

Fast, parallel implementation of grid data convolution

Description

A fast, parallel implementation of convolutions for grid-type data (matrices, rasters and other grid based objects).

Usage

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

Arguments

data

[matrix-type] Grid to compute onto.

kernel

[matrix] Computation kernel (neighborhood).

edge_value

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

transform_function

[character] The function to apply to the cell values covered by the kernel. For possible values, see pfocal_info_transform(). Default to "MULTIPLY".

reduce_function

[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".

mean_divider

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

variance

[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.rm

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

mp

[logical] Whether to use the open_mp implementation, default to TRUE.

debug_use_r_implementation

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

Details

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

Value

The updated, convoluted grid.

Examples


data <- matrix(nrow = 10, ncol = 10, data = runif(10 * 10))
kernel <- matrix(1 / 9, nrow = 3, ncol = 3)
pfocal(data = data, kernel = kernel)


LandSciTech/pfocal documentation built on Aug. 27, 2022, 8:55 a.m.