Generate simulated patches
generate_patches.RdGenerate simulated patches
Arguments
- simulated_field_sf
A simulated field as an sf object as generated by the function
generate_field- config_sp
A list that contains the parameters for filtering the field to patches. The list should contain the following parameters:
patch_threshold: a numeric representing the threshold below which the field is masked away to leave only the patches
Details
Generate simulated patches from a simulated field. In this context a patch is defined as an isolated area of a field. This could represent a stand of a specific species of tree, or a coral reef as just two examples. The patches are generated by filtering the field to only include areas that are above a certain threshold.
Examples
library(sf)
library(gstat)
library(ggplot2)
config_sp <- list(
seed = 1,
crs = 4326,
model = "Exp",
psill = 1,
range = 15,
nugget = 0,
patch_threshold = 1.75
)
spatial_domain <- st_geometry(
st_multipoint(
x = rbind(
c(0, -10),
c(3, -10),
c(10, -20),
c(1, -21),
c(2, -16),
c(0, -10)
)
)
) |>
st_set_crs(config_sp$crs) |>
st_cast("POLYGON")
set.seed(config_sp$seed)
spatial_grid <- spatial_domain |>
st_set_crs(NA) |>
st_sample(size = 10000, type = "regular") |>
st_set_crs(config_sp$crs)
simulated_field <- generate_field(spatial_grid, config_sp)
#> [using unconditional Gaussian simulation]
simulated_patches <- generate_patches(simulated_field, config_sp)
#> Spherical geometry (s2) switched off
#> Spherical geometry (s2) switched on
simulated_patches |> ggplot() + geom_sf(fill="lightblue")