Define the state of the environment
sim_state_env.Rd
This function updates the state environment of a given simulation object by either using a provided SpatRaster, a predefined function (`gradient` or `uniform`), or a user-defined function. The updated simulation object with the new state environment and metadata is returned.
Arguments
- simulation_object
An object representing the simulation. The object should contain a `background` slot and a `state_env` slot.
- fun
a user-defined function.
- filename
A character string specifying the filename to save the resultant SpatRaster. If `NULL`, the SpatRaster is not saved to a file.
- spatraster
A `SpatRaster` object to be used directly as the state environment. If provided, it overrides the `fun` parameter.
- ...
Additional arguments to be passed to the function specified in `fun`.
Value
An updated simulation object with the newly added state of the environment in the correct slot
Details
- If a `spatraster` is provided, the function checks that its dimensions match those of the simulation object's background. - If `fun` is provided as a user-defined function, it will be applied to the simulation object. - If `filename` is provided, the resultant SpatRaster is saved, and the filename is returned.
Examples
if (FALSE) { # \dontrun{
sim_obj <- sim_state_env(sim_obj, fun = state_env_uniform, value = 0.5)
sim_obj <- sim_state_env(sim_obj, fun = state_env_gradient, from = 0, to = 1)
sim_obj <- sim_state_env(sim_obj, spatraster = my_spatraster)
sim_obj <- sim_state_env(sim_obj, fun = my_custom_function)
sim_obj <- sim_state_env(sim_obj, fun = state_env_uniform, filename = "output.tif")
} # }