The `grainchanger`

package provides functionality for data aggregation to a grid via moving-window or direct methods.

The moving-window data aggregation method smooths the surface using a specified function within a moving window of a specified size and shape prior to aggregation.

The moving window approach allows users to capture some information about landscape structure at the scale at which the process acts in the landscape.

The below example shows the moving-window data aggregation in action. It aggregates a categorical raster to a grid using Shannon evenness as the function calculated within a square moving window of 5 units. This value is included as a column on the grid `sf`

object.

The direct method simply aggregates to the grid using the specified function, essentially acting as a wrapper for the `raster`

aggregate function.

The below example shows the direct data aggregation in action. It aggregates a continuous raster to a grid using the range as the function calculated for each cell of the larger grid. This value is included as a column on the grid `sf`

object. `var_range`

is an inbuilt function in the `grainchanger`

package.

There are a number of inbuilt functions in the grainchanger package, with their useage outlined below. While it is possible to use user-defined functions within both `winmove_agg`

and `nomove_agg`

, we welcome suggestions for additional functions. Please add as an issue - doing it this way means we can maximise the speed of the function.

Function.Name | Description | Additional.arguments |
---|---|---|

wm_prop | Calculate the proportion of a given class within the moving window | lc_class (numeric) |

wm_classes | Calculate the number of classes within the moving window | |

wm_shei | Calculate the Shannon evenness within the moving window | lc_class (numeric) |

wm_mean | Calculate the mean value within the moving window | |

nm_shei | Calculate the Shannon evenness within the larger cell | lc_class (numeric) |

nm_prop | Calculate the proportion of a given class within the larger cell | lc_class (numeric) |

var_range | Calculate the range of values (can be used with or without a moving window |

The `create_torus`

function takes as input a square or rectangular landscape and pads it by a specified radius, creating the effect of a torus. We developed this function in order to avoid edge effects when testing methods on simulated landscapes (such as those from NLMR).