Skip to content

Commit 92b50da

Browse files
committed
🔀 Merge remote-tracking branch 'origin/feature/plot_potential_site' into develop
2 parents e94931b + 9fc80f5 commit 92b50da

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

‎R/cli.R‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ plot_usage_area_by_individual <- function(options) {
3131
grDevices::dev.off()
3232
}
3333

34+
plot_potential_site <- function(options) {
35+
config_content <- read_config(options[["config-path"]])
36+
trips_data <- readr::read_csv(options[["data-path"]], show_col_types = FALSE)
37+
percentage_distribution <- options[["percentage-distribution"]]
38+
n_iterations <- options[["n-iterations"]]
39+
40+
wrapper <- xxTrack2KBA_Wrapper$new(trips_data, config_content, percentage_distribution)
41+
representative_assess <- wrapper$get_representative_assess(percentage_distribution, n_iterations)
42+
site <- wrapper$get_potential_site(representative_assess, percentage_distribution, population_size = options[["population-size"]])
43+
sf::sf_use_s2(FALSE)
44+
track2KBA::mapSite(site)
45+
ggplot2::ggsave(filename = options[["output-path"]], device = "png")
46+
}
3447

3548
#' Plot Representative Assessment
3649
#'

‎R/representative_assess.R‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ xxTrack2KBA_Wrapper <- R6::R6Class(
5050
polyOut = FALSE
5151
)
5252
return(Site)
53+
},
54+
get_potential_site = function(repr, percentage_distribution, population_size) {
55+
Site <- track2KBA::findSite(
56+
KDE = self$KDE$KDE.Surface,
57+
represent = repr$out,
58+
levelUD = percentage_distribution,
59+
popSize = population_size,
60+
polyOut = TRUE
61+
)
62+
return(Site)
5363
}
5464
)
5565
)
@@ -105,6 +115,16 @@ Track2KBA_Wrapper <- R6::R6Class(
105115
polyOut = FALSE
106116
)
107117
return(Site)
118+
},
119+
get_potential_site = function(repr, percentage_distribution, population_size) {
120+
Site <- track2KBA::findSite(
121+
KDE = self$KDE$KDE.Surface,
122+
represent = repr$out,
123+
levelUD = percentage_distribution,
124+
popSize = population_size,
125+
polyOut = TRUE
126+
)
127+
return(Site)
108128
}
109129
)
110130
)

‎tests/testthat/test_cli.R‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ describe("process fisheries data", {
1919
})
2020

2121
trips_path <- "/workdir/tests/data/trips_5_ids.csv"
22+
describe("plot potential site", {
23+
output_path <- "/workdir/tests/potential_site.png"
24+
options <- list("data-path" = trips_path, "config-path" = config_path, "output-path" = output_path, "percentage-distribution" = 50, "n-iterations" = 10, "population-size" = 10)
25+
it("write figure", {
26+
testtools::if_exist_remove(output_path)
27+
plot_potential_site(options)
28+
expect_true(testtools::exist_output_file(output_path))
29+
testtools::if_exist_remove(output_path)
30+
})
31+
})
32+
2233
describe("plot ussage area by a proportion of the total birds", {
2334
output_path <- "/workdir/tests/usage_area.png"
2435
options <- list("data-path" = trips_path, "config-path" = config_path, "output-path" = output_path, "percentage-distribution" = 50, "n-iterations" = 10)

0 commit comments

Comments
 (0)