-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plotting function for simualtionobject class, new and improve roxygen…
… comments for functions, including basic included functions. Move extract() call inside sim_effort() rather than the supplied custom function. Vignette under development.
- Loading branch information
1 parent
030c97d
commit 3182e52
Showing
27 changed files
with
798 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
#' Defines effort using a custom function | ||
#' Defines effort using a built-in function, a custom function, or sf POINTS | ||
#' | ||
#' @param simulation_object a SimulationObject | ||
#' @param fun a function that takes the simulation object and returns a simulation object with data in effort slot | ||
#' @param ... other parameters for the user supplied function fun | ||
#' @return A SimulationObject with a state_target_realised | ||
#' This function applies a user-supplied function to a SimulationObject to define effort. | ||
#' | ||
#' @param simulation_object A SimulationObject containing simulation data. | ||
#' @param fun A function that takes the simulation_object and additional parameters, and returns a modified simulation_object with effort data. | ||
#' @param sf Optional; if provided, skips applying 'fun' and directly uses this Spatial*DataFrame (sf) for effort calculation. | ||
#' @param ... Additional parameters passed to the user-supplied function 'fun'. | ||
#' @return A SimulationObject with updated effort information. | ||
#' @examples | ||
#' \dontrun{ | ||
#' sim_effort(simulation_object, fun, ...) | ||
#' } | ||
sim_effort <- function(simulation_object, fun, ...) { | ||
#' @export | ||
sim_effort <- function(simulation_object, fun, sf=NULL, ...) { | ||
simulation_object_original <- simulation_object | ||
simulation_object <- read_sim_obj_rasters(simulation_object) | ||
|
||
if(is.character(fun)){ | ||
if(!(fun %in% c("uniform"))){ | ||
stop("Provided function must be 'uniform'") | ||
if (is.null(sf)){ | ||
if(is.character(fun)){ | ||
if(!(fun %in% c("basic"))){ | ||
stop("Provided function must be 'basic'") | ||
} | ||
fun <- get(paste0("effort_",fun)) | ||
} | ||
fun <- get(paste0("effort_",fun)) | ||
# apply the function | ||
effort_sf <- fun(simulation_object, ...) | ||
} else { | ||
effort_sf <- sf | ||
} | ||
|
||
# apply the function | ||
effort <- fun(simulation_object, ...) | ||
#get values from env, suitability, realised | ||
extracted_values <- terra::extract(simulation_object@state_env,effort_sf) | ||
effort_sf[,names(extracted_values)] <- extracted_values | ||
extracted_values <- terra::extract(simulation_object@state_target_suitability,effort_sf) | ||
effort_sf[,paste0("suit_",names(extracted_values))] <- extracted_values | ||
extracted_values <- terra::extract(simulation_object@state_target_realised,effort_sf) | ||
effort_sf[,paste0("real_",names(extracted_values))] <- extracted_values | ||
|
||
# validity checks | ||
fun_args <- as.list(match.call()) | ||
simulation_object_original@metadata[["effort"]] <- fun_args[3:length(fun_args)] | ||
|
||
simulation_object_original@effort <- effort | ||
simulation_object_original@effort <- effort_sf | ||
simulation_object_original@hash <- hash_sim_obj(simulation_object_original) | ||
simulation_object_original | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.