knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 7, dev = "png" )
The fundamental element of the pattern-based spatial analysis is a numerical description of spatial patterns (so-called signature).
This vignette shows how to derive spatial signatures using the lsp_signature()
function on example datasets.
Let's start by attaching necessary packages:
library(motif) library(stars) library(sf)
For this vignette, we use several spatial objects.
The first one is a "raster/landcover2015.tif"
file.
landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif"))
This file contains a land cover data for New Guinea, with seven possible categories: (1) agriculture, (2) forest, (3) grassland, (5) settlement, (6) shrubland, (7) sparse vegetation, and (9) water.
landcover = droplevels(landcover) plot(landcover, key.pos = 4, key.width = lcm(5), main = NULL)
The second one is a "raster/landform.tif"
file.
landform = read_stars(system.file("raster/landform.tif", package = "motif"))
It has fourteen landform categories (plus surface water) for the same area.
landform = droplevels(landform) plot(landform, key.pos = 4, key.width = lcm(8), main = NULL)
The third example object is random_ndvi
.
set.seed(222) random_ndvi = landcover random_ndvi$ndvi = runif(length(random_ndvi[[1]]), min = 1, max = 10) random_ndvi$ndvi[is.na(random_ndvi$landcover2015.tif)] = NA random_ndvi$landcover2015.tif = NULL
It is an artificial dataset representing numerical weights for each cell for the same area as the datasets above.
plot(random_ndvi)
"coma"
) representation - one layerThe first type of signature is a co-occurrence matrix ("coma"
).
It requires just one layer (one attribute in a stars
object).
coma_output = lsp_signature(landcover, type = "coma", window = 100) coma_output
The output is an object of class lsp
with three columns:
id
- an id of each window (area)na_prop
- share (0-1) of NA
cells for each windowsignature
- a list-column containing with calculated signaturesWe can see a signature for selected local landscape extracting it from the signature
column:
coma_output$signature[[1]]
Co-occurrence vector ("cove"
) is rearrangement of a co-occurrence matrix into one-dimensional object:
cove_output = lsp_signature(landcover, type = "cove", window = 100) cove_output
This representation can be used to compare different local landscapes.
Learn more about these representations at https://nowosad.github.io/comat/articles/coma.html.
wecoma
) representation - two layersThe next type of signature is a weighted co-occurrence matrix ("wecoma"
).
It requires two layers - a stars
object with two attributes.
The first one is a categorical raster data, while the second one is a continuous raster data containing weights.
wecoma_output = lsp_signature(c(landcover, random_ndvi), type = "wecoma", window = 100) wecoma_output
Weighted co-occurrence vector ("wecove"
) is rearrangement of a weighted co-occurrence matrix into one-dimensional object:
wecove_output = lsp_signature(c(landcover, random_ndvi), type = "wecove", window = 100) wecove_output
Learn more about these representations at https://nowosad.github.io/comat/articles/wecoma.html.
incoma
) representation - two or more layersThe next type of signature is an integrated co-occurrence matrix (incoma
).
It requires two or more layers - a stars
object with two or more attributes.
All layers must be categorical raster data.
incoma_output = lsp_signature(c(landcover, landform), type = "incoma", window = 100)
Integrated co-occurrence vector ("incove"
) is rearrangement of an integrated co-occurrence matrix into one-dimensional object:
incove_output = lsp_signature(c(landcover, landform), type = "incove", window = 100)
Learn more about these representations at https://nowosad.github.io/comat/articles/incoma.html
"composition"
) - one layerA composition signature describes proportions of categories in a local landscape.
It requires one layer (a stars
object with one attribute).
composition_output = lsp_signature(landcover, type = "composition", window = 100) composition_output
By default, it is normalized to sum to 1:
composition_output$signature[[1]]
To get an actual number of cells of each category, the normalization
should be set to "none"
:
composition_output2 = lsp_signature(landcover, type = "composition", window = 100, normalization = "none") composition_output2$signature[[1]]
The motif package also allows calculating signature based on a user-defined function.
This function should accept only one argument, which is a list containing one or more matrices.
For example my_fun()
below counts how many non-NA cells exist in each local landscape.
my_fun = function(x){ sum(!is.na(c(x[[1]]))) }
Importantly, we need to set normalization = "none"
to prevent the normalization of the output.
my_fun_output = lsp_signature(landcover, type = my_fun, window = 100, normalization = "none") my_fun_output
We can see that in the first local landscape we have r my_fun_output$signature[[1]]
non-NA cells.
my_fun_output$signature[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.