diff --git a/R/cli.R b/R/cli.R index f30ea2f..c5065a8 100644 --- a/R/cli.R +++ b/R/cli.R @@ -31,6 +31,18 @@ plot_usage_area_by_individual <- function(options) { grDevices::dev.off() } +plot_potential_site <- function(options) { + config_content <- read_config(options[["config-path"]]) + gps_data <- readr::read_csv(options[["data-path"]], show_col_types = FALSE) + percentage_distribution <- options[["percentage-distribution"]] + n_iterations <- options[["n-iterations"]] + + wrapper <- Track2KBA_Wrapper$new(gps_data, config_content, percentage_distribution) + representative_assess <- wrapper$get_representative_assess(percentage_distribution, n_iterations) + site <- wrapper$get_potential_site(representative_assess, percentage_distribution, population_size = options[["population-size"]]) + track2KBA::mapSite(site) + ggplot2::ggsave(filename = options[["output-path"]], device = "png") +} #' Plot Representative Assessment #' diff --git a/R/representative_assess.R b/R/representative_assess.R index dd828ab..4f73d29 100644 --- a/R/representative_assess.R +++ b/R/representative_assess.R @@ -50,6 +50,16 @@ Track2KBA_Wrapper <- R6::R6Class( polyOut = FALSE ) return(Site) + }, + get_potential_site = function(repr, percentage_distribution, population_size) { + Site <- track2KBA::findSite( + KDE = self$KDE$KDE.Surface, + represent = repr$out, + levelUD = percentage_distribution, + popSize = population_size, + polyOut = TRUE + ) + return(Site) } ) ) diff --git a/tests/testthat/test_cli.R b/tests/testthat/test_cli.R index 6ae4a02..de73f5d 100644 --- a/tests/testthat/test_cli.R +++ b/tests/testthat/test_cli.R @@ -18,6 +18,17 @@ describe("process fisheries data", { }) }) +describe("plot potential site", { + output_path <- "/workdir/tests/potential_site.png" + gps_path <- "/workdir/tests/data/raw_gps_albatros_5_ids.csv" + options <- list("data-path" = gps_path, "config-path" = config_path, "output-path" = output_path, "percentage-distribution" = 50, "n-iterations" = 10, "population-size" = 10) + it("write figure", { + testtools::if_exist_remove(output_path) + plot_potential_site(options) + expect_true(testtools::exist_output_file(output_path)) + testtools::if_exist_remove(output_path) + }) +}) describe("plot ussage area by a proportion of the total birds", { output_path <- "/workdir/tests/usage_area.png" gps_path <- "/workdir/tests/data/raw_gps_albatros_5_ids.csv"