#' Calculate Weights
#'
#' @param x RasterStack with realizations
#' @param y RasterStack with shares
#' @param size size of a motifel
#'
#' @return a list of data.frames
#' @export
#'
#' @examples
#' \dontrun{
#' library(raster)
#' real_raster = create_realization(perc_raster)
#' plot(real_raster)
#' b = calculate_weight(real_raster, perc_raster, size = 10)
#'
#' real_rasters = create_realizations(perc_raster, n = 5)
#' plot(real_rasters)
#' d = calculate_weights(real_rasters, perc_raster, size = 10)
#' }
calculate_weights = function(x, y, size){
out = if (requireNamespace("pbapply", quietly = TRUE)){
# raster::stack(
pbapply::pblapply(raster::as.list(x), calculate_weight, y = y, size = size)
# )
} else {
# raster::stack(
lapply(raster::as.list(x), calculate_weight, y = y, size = size)
# )
}
return(out)
}
calculate_weight = function(x, y, size){
# x = cats; y = s; size = 2
x_areas = motifel_areas(x = raster::as.matrix(x), size = size)
y_prep = lapply(raster::as.list(y), raster::as.matrix)
y_sums = do.call(cbind, lapply(y_prep, motifel_sums, size = size))
motifel_adjustment(x_areas, y_sums)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.