Function Explanation

swf.clumper.regular simulates iteratively changes in SWF habitat within a spatial matrix. It takes a matrix where swfCat category represents habitat and agriCat represents non-habitat. Then it applies a clumping algorithm to rearrange habitat cells to form larger, more connected patches. Pixels can only change in the direction agriCat –> swfCat. Other categories do not move.

The basic logic of the function is:

  • Dissects the matrix in smaller kernels (can be also the whole image)
  • Extract SWF edges with the Canny algotithm (sigma user defined)
  • Finds spatial indexes of AgriCat cells
  • Finds indexes of SWF cells that fall on edges (attractors)
  • Finds indexes of SWF cells that do not fall on edges (movable cells)
  • Picks edge SWF from a low, medium or high SWF density area (user defined) which is then used as an “attractor”
  • Picks Q (number is user defined) agri cell that are the closest neighbours to the attractor favouring diagonal neighbour to avoid straight lines
  • Picks the Q (number is user defined) non-edge SWF farthest from the attractor which are the SWF that move.
  • Saves the rearrenged matrix which is used for the next iteration

Function options

  • Hmatrix A matrix representing the initial habitat state.
  • swfCat Integer representing habitat category in the matrix.
  • agriCat Integer representing non-habitat category in the matrix.
  • foreCat Integer representing fores (habitat) category in the matrix.
  • Q Integer representing the number of cells to be moved in each kernel per iteration.
  • iterations Number of iterations for the aggregation process.
  • kernelCl Vertical size of the kernel for processing.
  • kernelRw Horizontal size of the kernel for processing.
  • NNeighbors Threshold of neighbours in a kernel below which habitat pixels are moved in a kernel.
  • maxDistance Searching radius for habitat pixel aggregation.
  • Density Strategy for selecting the cell as a gravity center. “H” to choose area with high habitat cover, “L” from low, “M” for median density.
  • queensCase If TRUE, all 8 directions are considered for neighbors; if FALSE, only orthogonal neighbors are considered.
  • np Number of cores for parallel processing.
  • deBug If TRUE, debugging information is provided.

Import raster