Data aggregation via moving window or direct methods. Aggregate a fine-resolution raster to a grid. The moving window method smooths the surface using a specified function within a moving window of a specified size and shape prior to aggregation. The direct method simply aggregates to the grid using the specified function.
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 direct method simply aggregates to the grid using the specified
function, essentially acting as a wrapper for the raster
aggregate
function.
You can install the development version from GitHub with:
# install.packages("devtools")devtools::install_github("laurajanegraham/grainchanger")
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.
library(grainchanger)library(ggplot2)library(landscapetools)# categorical landscapeshow_landscape(cat_ls)#> Loading required package: raster#> Loading required package: sp
# moving-window aggregation using Shannon evennessg_sf$mwda <- winmove_agg(g = g_sf,dat = cat_ls,d = 5,type = "rectangle",fun = "shei",lc_class = 0:3)ggplot(g_sf) + geom_sf(aes(fill = mwda))
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.
# continuous landscapeshow_landscape(cont_ls)
# direct aggregation using rangeg_sf$range <- nomove_agg(g = g_sf,dat = cat_ls,fun = "var_range")ggplot(g_sf) + geom_sf(aes(fill = range))
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).
torus <- create_torus(cat_ls, 5)show_landscape(torus)
grainchanger
in R doing
citation(package = 'grainchanger')
NEWS.md
file to track changes to the package.