Title: | Local Pattern Analysis |
---|---|
Description: | Describes spatial patterns of categorical raster data for any defined regular and irregular areas. Patterns are described quantitatively using built-in signatures based on co-occurrence matrices but also allows for any user-defined functions. It enables spatial analysis such as search, change detection, and clustering to be performed on spatial patterns (Nowosad (2021) <doi:10.1007/s10980-020-01135-0>). |
Authors: | Jakub Nowosad [aut, cre] |
Maintainer: | Jakub Nowosad <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.6.4 |
Built: | 2025-02-19 05:15:49 UTC |
Source: | https://github.com/nowosad/motif |
Determine unique classes (internal function)
determine_classes(x, window)
determine_classes(x, window)
x |
|
window |
|
A list with vector of numbers (unique classes)
Adds clusters' ids to a lsp object.
The output can be of stars
, sf
, or terra
class.
See examples.
lsp_add_clusters(x, clust, output = "sf", window = NULL)
lsp_add_clusters(x, clust, output = "sf", window = NULL)
x |
Object of class |
clust |
Vector containing an id value for each row in |
output |
The class of the output. Either |
window |
Specifies areas for analysis. It can be either: |
Object of class stars
, sf
, or terra
(depending on the output
argument) with an additional column "clust"
representing clusters' id values.
library(stars) library(sf) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) landform_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") landform_dist = lsp_to_dist(landform_cove, dist_fun = "jensen-shannon") landform_hclust = hclust(landform_dist, method = "ward.D2") #plot(landform_hclust) clusters = cutree(landform_hclust, k = 4) landform_grid_sf = lsp_add_clusters(landform_cove, clusters) #plot(landform_grid_sf["clust"]) #landform_grid_sfq = lsp_add_quality(landform_grid_sf, # landform_dist) #plot(landform_grid_sfq["quality"]) ## larger data example # library(stars) # library(sf) # landform = read_stars(system.file("raster/landform.tif", package = "motif"), # proxy = FALSE) # landform_cove = lsp_signature(landform, # type = "cove", # window = 200, # normalization = "pdf") # # landform_dist = lsp_to_dist(landform_cove, # dist_fun = "jensen-shannon") # # landform_hclust = hclust(landform_dist, method = "ward.D2") # plot(landform_hclust) # # clusters = cutree(landform_hclust, k = 6) # # landform_grid_sf = lsp_add_clusters(landform_cove, clusters) # plot(landform_grid_sf["clust"]) # # landform_grid_sfq = lsp_add_quality(landform_grid_sf, # landform_dist) # plot(landform_grid_sfq["quality"])
library(stars) library(sf) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) landform_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") landform_dist = lsp_to_dist(landform_cove, dist_fun = "jensen-shannon") landform_hclust = hclust(landform_dist, method = "ward.D2") #plot(landform_hclust) clusters = cutree(landform_hclust, k = 4) landform_grid_sf = lsp_add_clusters(landform_cove, clusters) #plot(landform_grid_sf["clust"]) #landform_grid_sfq = lsp_add_quality(landform_grid_sf, # landform_dist) #plot(landform_grid_sfq["quality"]) ## larger data example # library(stars) # library(sf) # landform = read_stars(system.file("raster/landform.tif", package = "motif"), # proxy = FALSE) # landform_cove = lsp_signature(landform, # type = "cove", # window = 200, # normalization = "pdf") # # landform_dist = lsp_to_dist(landform_cove, # dist_fun = "jensen-shannon") # # landform_hclust = hclust(landform_dist, method = "ward.D2") # plot(landform_hclust) # # clusters = cutree(landform_hclust, k = 6) # # landform_grid_sf = lsp_add_clusters(landform_cove, clusters) # plot(landform_grid_sf["clust"]) # # landform_grid_sfq = lsp_add_quality(landform_grid_sf, # landform_dist) # plot(landform_grid_sfq["quality"])
Adds spatial data of each region in an lsp or sf object.
The output is an lsp or sf object with an additional column "region"
.
See examples.
lsp_add_examples(x, y, window = NULL) ## S3 method for class 'lsp' lsp_add_examples(x, y, window = NULL) ## S3 method for class 'sf' lsp_add_examples(x, y, window = NULL)
lsp_add_examples(x, y, window = NULL) ## S3 method for class 'lsp' lsp_add_examples(x, y, window = NULL) ## S3 method for class 'sf' lsp_add_examples(x, y, window = NULL)
x |
Object of class |
y |
Object of class |
window |
Specifies areas for analysis. It can be either: |
The input object with a new column "region"
.
The "region"
column is a list with a raster extracted for each row.
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 100) selected_coma = subset(landcover_coma, id %in% c(5, 10, 15, 35)) selected_coma selected_coma = lsp_add_examples(x = selected_coma, y = landcover) selected_coma plot(selected_coma$region[[1]]) plot(selected_coma$region[[4]]) # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 100) selected_coma = subset(landcover_coma, id %in% c(5, 80, 1971, 2048)) selected_coma selected_coma = lsp_add_examples(x = selected_coma, y = landcover) selected_coma plot(selected_coma$region[[1]]) plot(selected_coma$region[[4]])
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 100) selected_coma = subset(landcover_coma, id %in% c(5, 10, 15, 35)) selected_coma selected_coma = lsp_add_examples(x = selected_coma, y = landcover) selected_coma plot(selected_coma$region[[1]]) plot(selected_coma$region[[4]]) # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 100) selected_coma = subset(landcover_coma, id %in% c(5, 80, 1971, 2048)) selected_coma selected_coma = lsp_add_examples(x = selected_coma, y = landcover) selected_coma plot(selected_coma$region[[1]]) plot(selected_coma$region[[4]])
Calculates three metrics to evaluate quality of spatial patterns' clustering or segmentation.
When the type is "cluster"
, then metrics of inhomogeneity, distinction, and quality are calculated.
When the type is "segmentation"
, then metrics of inhomogeneity, isolation, and quality are calculated.
For more information, see Details below.
lsp_add_quality(x, x_dist, type = "cluster", regions = FALSE)
lsp_add_quality(x, x_dist, type = "cluster", regions = FALSE)
x |
Object of class |
x_dist |
Object of class |
type |
Either |
regions |
Not implemented yet |
For type "cluster"
, this function calculates three quality metrics to evaluate spatial patterns' clustering:
(1) inhomogeneity - it measures a degree of mutual dissimilarity
between all objects in a cluster. This value is between 0 and 1,
where small value indicates that all objects in the cluster
represent consistent patterns so the cluster is pattern-homogeneous.
(2) distinction - it is an average distance between the focus cluster
and all of the other clusters.
This value is between 0 and 1, where large value indicates that the cluster
stands out from the other clusters.
(3) quality - overall quality of a cluster. It is calculated as
1 - (inhomogeneity / distinction). This value is also between 0 and 1,
where increased values indicate increased quality.
For type "segmentation"
, this function calculates three quality metrics to evaluate spatial patterns' segmentation:
(1) inhomogeneity - it measures a degree of mutual dissimilarity
between all objects in a cluster. This value is between 0 and 1,
where small value indicates that all objects in the cluster
represent consistent patterns so the cluster is pattern-homogeneous.
(2) isolation - it is an average distance between the focus cluster
and all of its neighbors. This value is between 0 and 1,
where large value indicates that the cluster
stands out from its surroundings.
(3) quality - overall quality of a cluster. It is calculated as
1 - (inhomogeneity / distinction). This value is also between 0 and 1,
where increased values indicate increased quality.
Object of class sf
with three additional columns representing quality metrics.
Jakub Nowosad & Tomasz F. Stepinski (2021) Pattern-based identification and mapping of landscape types using multi-thematic data, International Journal of Geographical Information Science, DOI: 10.1080/13658816.2021.1893324
lsp_add_clusters
# see examples of `lsp_add_clusters()`
# see examples of `lsp_add_clusters()`
Creates or adds a sf object based on the input object or a set of parameters.
It accepts either an object of class stars
or lsp
.
In the first case, the output is created based on
a set of parameters (window_size
and window_shift
or window
).
In the second case, the output converts the lsp
object into
a sf
object.
lsp_add_sf(x = NULL, window = NULL, metadata = TRUE) ## Default S3 method: lsp_add_sf(x = NULL, window = NULL, metadata = TRUE) ## S3 method for class 'lsp' lsp_add_sf(x = NULL, window = NULL, metadata = TRUE)
lsp_add_sf(x = NULL, window = NULL, metadata = TRUE) ## Default S3 method: lsp_add_sf(x = NULL, window = NULL, metadata = TRUE) ## S3 method for class 'lsp' lsp_add_sf(x = NULL, window = NULL, metadata = TRUE)
x |
Object of class |
window |
Specifies areas for analysis. It can be either: |
metadata |
Logical. Only when |
An sf
object converted from the input object or a provided set of parameters
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_sf(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_sf(lc_cove) plot(lc_cove_lsp["id"]) plot(lc_cove_lsp["na_prop"]) # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_sf(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_sf(lc_cove) plot(lc_cove_lsp["id"]) plot(lc_cove_lsp["na_prop"])
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_sf(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_sf(lc_cove) plot(lc_cove_lsp["id"]) plot(lc_cove_lsp["na_prop"]) # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_sf(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_sf(lc_cove) plot(lc_cove_lsp["id"]) plot(lc_cove_lsp["na_prop"])
Creates or adds a stars object based on the input object or a set of parameters.
It accepts either an object of class stars
or lsp
.
In the first case, the output is created based on
the window
parameter.
In the second case, the output converts the lsp
object into
a stars
object.
lsp_add_stars(x = NULL, window = NULL, metadata = TRUE) ## Default S3 method: lsp_add_stars(x = NULL, window = NULL, metadata = TRUE) ## S3 method for class 'lsp' lsp_add_stars(x = NULL, window = NULL, metadata = TRUE)
lsp_add_stars(x = NULL, window = NULL, metadata = TRUE) ## Default S3 method: lsp_add_stars(x = NULL, window = NULL, metadata = TRUE) ## S3 method for class 'lsp' lsp_add_stars(x = NULL, window = NULL, metadata = TRUE)
x |
Object of class |
window |
Specifies areas for analysis. It can be either: |
metadata |
Logical. Only when |
A stars
object converted from the input object or a provided set of parameters
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_stars(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_stars(lc_cove) plot(lc_cove_lsp) plot(lc_cove_lsp["na_prop"]) # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_stars(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_stars(lc_cove) plot(lc_cove_lsp) plot(lc_cove_lsp["na_prop"])
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_stars(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_stars(lc_cove) plot(lc_cove_lsp) plot(lc_cove_lsp["na_prop"]) # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) plot(landform) landform_lsp = lsp_add_stars(landform, window = 100) plot(landform_lsp) lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") lc_cove_lsp = lsp_add_stars(lc_cove) plot(lc_cove_lsp) plot(lc_cove_lsp["na_prop"])
Creates or adds a terra object based on the input object or a set of parameters.
It accepts either an object of class stars
or lsp
.
In the first case, the output is created based on
the window
parameter.
In the second case, the output converts the lsp
object into
a terra
object.
lsp_add_terra(x = NULL, window = NULL, metadata = TRUE)
lsp_add_terra(x = NULL, window = NULL, metadata = TRUE)
x |
Object of class |
window |
Specifies areas for analysis. It can be either: |
metadata |
Logical. Only when |
A terra
object converted from the input object or a provided set of parameters
library(stars) library(terra) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) #plot(landform) landform_lsp = lsp_add_terra(landform, window = 100) #plot(landform_lsp) #lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") #lc_cove_lsp = lsp_add_terra(lc_cove) #plot(lc_cove_lsp) #plot(lc_cove_lsp["na_prop"])
library(stars) library(terra) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) #plot(landform) landform_lsp = lsp_add_terra(landform, window = 100) #plot(landform_lsp) #lc_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") #lc_cove_lsp = lsp_add_terra(lc_cove) #plot(lc_cove_lsp) #plot(lc_cove_lsp["na_prop"])
Compares two spatial datasets containing categorical raster data.
It accepts a categorical raster dataset with one or more attributes, and compares it to the second dataset with the same attributes and dimensions.
The both dataset are either compared to as whole areas, areas divided into regular windows, or areas divided into irregular windows.
This function allows for several types of comparisons using different representations of spatial patterns, including "coma" (co-occurrence matrix), "cove" (co-occurrence vector), "cocoma" (co-located co-occurrence matrix), "cocove" (co-located co-occurrence vector), "wecoma" (weighted co-occurrence matrix), "wecove" (weighted co-occurrence vector), "incoma" (integrated co-occurrence matrix), "incove" (integrated co-occurrence vector). These representations are created for both datasets, and next a distance between them is calculated using a selected measure from the philentropy::distance
function.
Additional parameters, such as neighbourhood or normalization types, are also available.
lsp_compare( x, y, type, dist_fun, window = NULL, output = "stars", neighbourhood = 4, threshold = 0.5, ordered = FALSE, repeated = FALSE, normalization = "pdf", wecoma_fun = "mean", wecoma_na_action = "replace", ... )
lsp_compare( x, y, type, dist_fun, window = NULL, output = "stars", neighbourhood = 4, threshold = 0.5, ordered = FALSE, repeated = FALSE, normalization = "pdf", wecoma_fun = "mean", wecoma_na_action = "replace", ... )
x |
Object of class |
y |
Object of class |
type |
Type of the calculated signature. It can be |
dist_fun |
Distance measure used. This function uses the |
window |
Specifies areas for analysis. It can be either: |
output |
The class of the output. Either |
neighbourhood |
The number of directions in which cell adjacencies are considered as neighbours: 4 (rook's case) or 8 (queen's case). The default is 4. |
threshold |
The share of NA cells to allow metrics calculation. |
ordered |
For |
repeated |
For |
normalization |
For |
wecoma_fun |
For |
wecoma_na_action |
For |
... |
Additional arguments for the |
Object of class stars
(or sf
or terra's SpatRaster
, depending on the output
argument).
It has four attributes:
(1) id
- an id of each window.
For irregular windows, it is the values provided in the window
argument,
(2) na_prop_x
- share (0-1) of NA
cells for each window in the x
object,
(3) na_prop_y
- share (0-1) of NA
cells for each window in the y
object,
(4) dist
- calculated distance between signatures for each window
library(stars) lc15 = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) lc01 = read_stars(system.file("raster/landcover2001s.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregionss.gpkg", package = "motif")) ecoregions = st_transform(ecoregions, st_crs(lc15)) c1 = lsp_compare(lc01, lc15, type = "cove", dist_fun = "jensen-shannon", window = ecoregions["id"]) plot(c1["dist"]) # larger data example library(stars) lc15 = read_stars(system.file("raster/landcover2015.tif", package = "motif")) lc01 = read_stars(system.file("raster/landcover2001.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregions.gpkg", package = "motif")) ecoregions = st_transform(ecoregions, st_crs(lc15)) c1 = lsp_compare(lc01, lc15, type = "cove", dist_fun = "jensen-shannon", window = ecoregions["id"]) plot(c1["dist"])
library(stars) lc15 = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) lc01 = read_stars(system.file("raster/landcover2001s.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregionss.gpkg", package = "motif")) ecoregions = st_transform(ecoregions, st_crs(lc15)) c1 = lsp_compare(lc01, lc15, type = "cove", dist_fun = "jensen-shannon", window = ecoregions["id"]) plot(c1["dist"]) # larger data example library(stars) lc15 = read_stars(system.file("raster/landcover2015.tif", package = "motif")) lc01 = read_stars(system.file("raster/landcover2001.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregions.gpkg", package = "motif")) ecoregions = st_transform(ecoregions, st_crs(lc15)) c1 = lsp_compare(lc01, lc15, type = "cove", dist_fun = "jensen-shannon", window = ecoregions["id"]) plot(c1["dist"])
Extracts a local landscape from categorical raster data based on its id and provided window
argument.
lsp_extract(x, window, id)
lsp_extract(x, window, id)
x |
Object of class |
window |
Specifies areas for analysis. It can be either: |
id |
Id of the local landscape - it is possible to find in the output of |
A stars
or terra
object cropped to the extent of a selected local landscape
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregionss.gpkg", package = "motif")) extract1 = lsp_extract(x = landform, window = 100, id = 25) plot(extract1) ecoregions = st_transform(ecoregions, st_crs(landform)) extract2 = lsp_extract(x = landform, window = ecoregions["id"], id = 11) plot(extract2) # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregions.gpkg", package = "motif")) extract1 = lsp_extract(x = landform, window = 100, id = 1895) plot(extract1) ecoregions = st_transform(ecoregions, st_crs(landform)) extract2 = lsp_extract(x = landform, window = ecoregions["id"], id = 7) plot(extract2)
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregionss.gpkg", package = "motif")) extract1 = lsp_extract(x = landform, window = 100, id = 25) plot(extract1) ecoregions = st_transform(ecoregions, st_crs(landform)) extract2 = lsp_extract(x = landform, window = ecoregions["id"], id = 11) plot(extract2) # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) ecoregions = read_sf(system.file("vector/ecoregions.gpkg", package = "motif")) extract1 = lsp_extract(x = landform, window = 100, id = 1895) plot(extract1) ecoregions = st_transform(ecoregions, st_crs(landform)) extract2 = lsp_extract(x = landform, window = ecoregions["id"], id = 7) plot(extract2)
Creates a raster mosaic by rearranging spatial data for example regions. See examples.
lsp_mosaic(x, output = "stars")
lsp_mosaic(x, output = "stars")
x |
Usually the output of the |
output |
The class of the output. Either |
A stars
or terra
object
# larger data example library(stars) library(sf) landform = read_stars(system.file("raster/landform.tif", package = "motif")) landform_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") landform_dist = lsp_to_dist(landform_cove, dist_fun = "jensen-shannon") landform_hclust = hclust(landform_dist, method = "ward.D2") plot(landform_hclust) clusters = cutree(landform_hclust, k = 6) landform_grid_sf = lsp_add_clusters(landform_cove, clusters) plot(landform_grid_sf["clust"]) landform_grid_sf_sel = landform_grid_sf %>% dplyr::filter(na_prop == 0) %>% dplyr::group_by(clust) %>% dplyr::slice_sample(n = 16, replace = TRUE) landform_grid_sf_sel = lsp_add_examples(x = landform_grid_sf_sel, y = landform) landform_grid_sf_sel landform_clust_m = lsp_mosaic(landform_grid_sf_sel) plot(landform_clust_m)
# larger data example library(stars) library(sf) landform = read_stars(system.file("raster/landform.tif", package = "motif")) landform_cove = lsp_signature(landform, type = "cove", window = 200, normalization = "pdf") landform_dist = lsp_to_dist(landform_cove, dist_fun = "jensen-shannon") landform_hclust = hclust(landform_dist, method = "ward.D2") plot(landform_hclust) clusters = cutree(landform_hclust, k = 6) landform_grid_sf = lsp_add_clusters(landform_cove, clusters) plot(landform_grid_sf["clust"]) landform_grid_sf_sel = landform_grid_sf %>% dplyr::filter(na_prop == 0) %>% dplyr::group_by(clust) %>% dplyr::slice_sample(n = 16, replace = TRUE) landform_grid_sf_sel = lsp_add_examples(x = landform_grid_sf_sel, y = landform) landform_grid_sf_sel landform_clust_m = lsp_mosaic(landform_grid_sf_sel) plot(landform_clust_m)
Converts a list-column with signatures into many numeric columns
lsp_restructure(x)
lsp_restructure(x)
x |
|
Object of class lsp
.
It has several columns: (1) id
- an id of each window.
For irregular windows, it is the values provided in the window
argument,
(2) na_prop
- share (0-1) of NA
cells for each window,
(3) one or more columns representing values of the signature
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 100) landcover_cover = lsp_restructure(landcover_cove) landcover_cover lsp_add_sf(landcover_cover)
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 100) landcover_cover = lsp_restructure(landcover_cove) landcover_cover lsp_add_sf(landcover_cover)
Searches for areas with similar spatial patterns in categorical data.
It accepts a categorical raster dataset with one or more attributes, and compares it to the second (usually larger) dataset with the same attributes.
The first dataset is either compared to a whole area, areas divided into regular windows, or areas divided into irregular windows from the second dataset.
This function allows for several types of comparisons using different representations of spatial patterns, including "coma" (co-occurrence matrix), "cove" (co-occurrence vector), "cocoma" (co-located co-occurrence matrix), "cocove" (co-located co-occurrence vector), "wecoma" (weighted co-occurrence matrix), "wecove" (weighted co-occurrence vector), "incoma" (integrated co-occurrence matrix), "incove" (integrated co-occurrence vector). These representations are created for both datasets, and next a distance between them is calculated using a selected measure from the philentropy::distance
function.
Additional parameters, such as neighbourhood or normalization types, are also available.
lsp_search( x, y, type, dist_fun, window = NULL, output = "stars", neighbourhood = 4, threshold = 0.5, ordered = FALSE, repeated = FALSE, normalization = "pdf", wecoma_fun = "mean", wecoma_na_action = "replace", classes = NULL, ... )
lsp_search( x, y, type, dist_fun, window = NULL, output = "stars", neighbourhood = 4, threshold = 0.5, ordered = FALSE, repeated = FALSE, normalization = "pdf", wecoma_fun = "mean", wecoma_na_action = "replace", classes = NULL, ... )
x |
Object of class |
y |
Object of class |
type |
Type of the calculated signature. It can be |
dist_fun |
Distance measure used. This function uses the |
window |
Specifies areas for analysis. It can be either: |
output |
The class of the output. Either |
neighbourhood |
The number of directions in which cell adjacencies are considered as neighbours: 4 (rook's case) or 8 (queen's case). The default is 4. |
threshold |
The share of NA cells to allow metrics calculation. |
ordered |
For |
repeated |
For |
normalization |
For |
wecoma_fun |
For |
wecoma_na_action |
For |
classes |
Which classes (categories) should be analyzed? This parameter expects a list of the same length as the number of attributes in |
... |
Additional arguments for the |
Object of class stars
(or sf
or terra's SpatRaster
, depending on the output
argument).
It has three attributes:
(1) id
- an id of each window.
For irregular windows, it is the values provided in the window
argument,
(2) na_prop
- share (0-1) of NA
cells for each window in the y
object,
(3) dist
- calculated distance between the x
object and each window in the y
object
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) plot(landcover) ext = st_bbox(c(xmin = -249797.344531127, xmax = -211162.693944285, ymin = -597280.143035389, ymax = -558645.492448547), crs = st_crs(landcover)) landcover_ext = landcover[ext] plot(landcover_ext) ecoregions = read_sf(system.file("vector/ecoregionss.gpkg", package = "motif")) plot(ecoregions["id"]) s1 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.9, window = 100) plot(s1["dist"]) ecoregions = st_transform(ecoregions, st_crs(landcover)) s2 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.5, window = ecoregions["id"]) plot(s2["dist"]) # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) plot(landcover) ext = st_bbox(c(xmin = -249797.344531127, xmax = -211162.693944285, ymin = -597280.143035389, ymax = -558645.492448547), crs = st_crs(landcover)) landcover_ext = landcover[ext] plot(landcover_ext) ecoregions = read_sf(system.file("vector/ecoregions.gpkg", package = "motif")) plot(ecoregions["id"]) s1 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.9, window = 1000) plot(s1["dist"]) ecoregions = st_transform(ecoregions, st_crs(landcover)) s2 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.5, window = ecoregions["id"]) plot(s2["dist"])
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) plot(landcover) ext = st_bbox(c(xmin = -249797.344531127, xmax = -211162.693944285, ymin = -597280.143035389, ymax = -558645.492448547), crs = st_crs(landcover)) landcover_ext = landcover[ext] plot(landcover_ext) ecoregions = read_sf(system.file("vector/ecoregionss.gpkg", package = "motif")) plot(ecoregions["id"]) s1 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.9, window = 100) plot(s1["dist"]) ecoregions = st_transform(ecoregions, st_crs(landcover)) s2 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.5, window = ecoregions["id"]) plot(s2["dist"]) # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) plot(landcover) ext = st_bbox(c(xmin = -249797.344531127, xmax = -211162.693944285, ymin = -597280.143035389, ymax = -558645.492448547), crs = st_crs(landcover)) landcover_ext = landcover[ext] plot(landcover_ext) ecoregions = read_sf(system.file("vector/ecoregions.gpkg", package = "motif")) plot(ecoregions["id"]) s1 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.9, window = 1000) plot(s1["dist"]) ecoregions = st_transform(ecoregions, st_crs(landcover)) s2 = lsp_search(landcover_ext, landcover, type = "cove", dist_fun = "jensen-shannon", threshold = 0.5, window = ecoregions["id"]) plot(s2["dist"])
Calculates selected spatial signatures based on categorical raster data. It also allows for calculations for any defined regular and irregular areas. It has several built-in signatures but also allows for any user-defined functions.
lsp_signature( x, type, window = NULL, neighbourhood = 4, threshold = 0.9, ordered = FALSE, repeated = FALSE, normalization = "pdf", wecoma_fun = "mean", wecoma_na_action = "replace", classes = NULL )
lsp_signature( x, type, window = NULL, neighbourhood = 4, threshold = 0.9, ordered = FALSE, repeated = FALSE, normalization = "pdf", wecoma_fun = "mean", wecoma_na_action = "replace", classes = NULL )
x |
Object of class |
type |
Type of the calculated signature. It can be |
window |
Specifies areas for analysis. It can be either: |
neighbourhood |
The number of directions in which cell adjacencies are considered as neighbours: 4 (rook's case) or 8 (queen's case). The default is 4. |
threshold |
The share of NA cells (0-1) to allow metrics calculation. |
ordered |
For |
repeated |
For |
normalization |
For |
wecoma_fun |
For |
wecoma_na_action |
For |
classes |
Which classes (categories) should be analyzed? This parameter expects a list of the same length as the number of attributes in |
Object of class lsp
.
It has three columns: (1) id
- an id of each window.
For irregular windows, it is the values provided in the window
argument,
(2) na_prop
- share (0-1) of NA
cells for each window,
(3) signature
- a list-column containing calculated signatures
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 2000) landcover_coma landcover_comp = lsp_signature(landcover, type = "composition", threshold = 0.9) landcover_comp # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 2000) landcover_coma landcover_comp = lsp_signature(landcover, type = "composition", threshold = 0.9) landcover_comp
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 2000) landcover_coma landcover_comp = lsp_signature(landcover, type = "composition", threshold = 0.9) landcover_comp # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) landcover_coma = lsp_signature(landcover, type = "coma", threshold = 0.9, window = 2000) landcover_coma landcover_comp = lsp_signature(landcover, type = "composition", threshold = 0.9) landcover_comp
Calculates a distance matrix based on an object of class lsp
.
lsp_to_dist(x, dist_fun, unit = "log2", p = NULL)
lsp_to_dist(x, dist_fun, unit = "log2", p = NULL)
x |
An object of class |
dist_fun |
A distance/dissimilarity method used.
All possible values can be found using
the |
unit |
A character string specifying the logarithm unit
that should be used to compute distances that depend on log computations:
|
p |
Power of the Minkowski distance.
Used only when the |
An object of class '"dist"“
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 400) landcover_cove dist_cov = lsp_to_dist(landcover_cove, dist_fun = "jensen-shannon") dist_cov # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 2000) landcover_cove dist_cov = lsp_to_dist(landcover_cove, dist_fun = "jensen-shannon") dist_cov
library(stars) landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif")) landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 400) landcover_cove dist_cov = lsp_to_dist(landcover_cove, dist_fun = "jensen-shannon") dist_cov # larger data example library(stars) landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif")) landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 2000) landcover_cove dist_cov = lsp_to_dist(landcover_cove, dist_fun = "jensen-shannon") dist_cov
It allows for transforming spatial signatures (outputs of
the lsp_signature()
function) using user-provided functions.
See examples for more details.
lsp_transform(x, fun, ...)
lsp_transform(x, fun, ...)
x |
Object of class |
fun |
A user-provided function. |
... |
Additional arguments for |
Object of class lsp
.
It has three columns: (1) id
- an id of each window.
For irregular windows, it is the values provided in the window
argument,
(2) na_prop
- share (0-1) of NA
cells for each window,
(3) signature
- a list-column containing with calculated signatures
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) result_coma500 = lsp_signature(landform, type = "coma", threshold = 0.5, window = 500) #see how the first signature looks result_coma500$signature[[1]] my_function = function(mat){ mat_c = colSums(mat) freqs = mat_c / sum(mat) # entropy -sum(freqs * log2(freqs), na.rm = TRUE) } result_coma500_2 = lsp_transform(result_coma500, my_function) #see how the first signature looks after transformation result_coma500_2$signature[[1]] # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) result_coma500 = lsp_signature(landform, type = "coma", threshold = 0.5, window = 500) #see how the first signature looks result_coma500$signature[[1]] my_function = function(mat){ mat_c = colSums(mat) freqs = mat_c / sum(mat) # entropy -sum(freqs * log2(freqs), na.rm = TRUE) } result_coma500_2 = lsp_transform(result_coma500, my_function) #see how the first signature looks after transformation result_coma500_2$signature[[1]]
library(stars) landform = read_stars(system.file("raster/landforms.tif", package = "motif")) result_coma500 = lsp_signature(landform, type = "coma", threshold = 0.5, window = 500) #see how the first signature looks result_coma500$signature[[1]] my_function = function(mat){ mat_c = colSums(mat) freqs = mat_c / sum(mat) # entropy -sum(freqs * log2(freqs), na.rm = TRUE) } result_coma500_2 = lsp_transform(result_coma500, my_function) #see how the first signature looks after transformation result_coma500_2$signature[[1]] # larger data example library(stars) landform = read_stars(system.file("raster/landform.tif", package = "motif")) result_coma500 = lsp_signature(landform, type = "coma", threshold = 0.5, window = 500) #see how the first signature looks result_coma500$signature[[1]] my_function = function(mat){ mat_c = colSums(mat) freqs = mat_c / sum(mat) # entropy -sum(freqs * log2(freqs), na.rm = TRUE) } result_coma500_2 = lsp_transform(result_coma500, my_function) #see how the first signature looks after transformation result_coma500_2$signature[[1]]
Prepares window* arguments (internal function)
prepare_window(x, window)
prepare_window(x, window)
x |
Object of class |
window |
Specifies areas for analysis. It can be either: |
A list with window
, window_size
, and window_shift