| lsp_transform {motif} | R Documentation | 
Transforms lsp objects
Description
It allows for transforming spatial signatures (outputs of
the lsp_signature() function) using user-provided functions.
See examples for more details.
Usage
lsp_transform(x, fun, ...)
Arguments
| x | Object of class  | 
| fun | A user-provided function. | 
| ... | Additional arguments for  | 
Value
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
Examples
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]]
[Package motif version 0.6.4 Index]