sim_surface: Populate a raster with simulated values

View source: R/spatial_tools.R

sim_surfaceR Documentation

Populate a raster with simulated values

Description

This function is designed to populate a raster with simulated values. To implement the function, a (blank) raster should be supplied. A user-defined function, or list of functions, is evaluated across this raster, or across sub-regions of this raster, to generate a new raster with simulated values.

Usage

sim_surface(
  blank,
  n = 1L,
  sim_values,
  mask = NULL,
  mask_inside = FALSE,
  plot = 1:2L
)

Arguments

blank

A raster.

n

An integer that defines the number of (approximately equal area) pieces into which to split blank.

sim_values

A function or, if n > 1L, a list of functions, that, for a given number of cells, simulate new values for those cells.

mask, mask_inside

Arguments required to implement a spatial mask via mask_io.

plot

An integer that defines whether or not to plot a histogram of simulated values (1L), a heat map of the simulated raster (2L) or both (1:2L).

Value

The function returns a raster, with the same properties as blank, with values generated from the sim_values function(s).

Author(s)

Edward Lavender

Examples

#### Example (1): Simulate values across the whole raster
sim_surface(dat_gebco,
  sim_values = function(n) stats::runif(n = n, 0, 1)
)
sim_surface(dat_gebco,
  sim_values = function(n) stats::rnorm(n = n, 0, 1)
)

#### Example (2): Simulate values differently across different areas
# .. by defining the number of areas into which to split the raster
# .. and a list of function(s)
sim_surface(dat_gebco,
  n = 2, sim_values = list(
    function(n) stats::runif(n = n, 0, 1),
    function(n) stats::runif(n = n, 10, 11)
  )
)

#### Example (3): Include a spatial mask
sim_surface(dat_gebco,
  n = 2, sim_values = list(
    function(n) stats::runif(n = n, 9, 10),
    function(n) stats::runif(n = n, 10, 11)
  ),
  mask = dat_coast, mask_inside = TRUE
)


edwardlavender/flapper documentation built on Jan. 22, 2025, 2:44 p.m.