Skip to content

Commit

Permalink
separate distance calculation and filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
wlangera committed Aug 7, 2024
1 parent 80dccd2 commit cd5d915
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 3 additions & 5 deletions source/targets/data_preparation/R/data_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ select_within_time_periods <- function(counts_df) {
return(out_df)
}

# Select data within circle radius
select_within_circle_radius <- function(counts_df, radius = 300) {
# Calculate distance of observation to center point
calculate_obs_dist <- function(counts_df) {
require("dplyr")
require("rlang")
require("sf")
Expand All @@ -58,7 +58,6 @@ select_within_circle_radius <- function(counts_df, radius = 300) {

# Calculate distances between observation locations (geometry)
# and count locations (geometry.point)
# Select data within radius distance
obs_to_point_distances <- counts_df %>%
full_join(sampling_points, by = join_by("plotnaam", "regio")) %>%
mutate(
Expand All @@ -68,8 +67,7 @@ select_within_circle_radius <- function(counts_df, radius = 300) {
calc_distance = round(units::drop_units(.data$calc_distance))
) %>%
select(-c("distance2plot", "geometry.point")) %>%
rename(distance2plot = "calc_distance") %>%
filter(.data$distance2plot <= radius)
rename(distance2plot = "calc_distance")

return(obs_to_point_distances)
}
14 changes: 10 additions & 4 deletions source/targets/data_preparation/_targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,20 @@ list(
iteration = "list"
),
tar_target(
name = select_within_radius,
command = select_within_circle_radius(
counts_df = select_time_periods,
radius = 300
name = calculate_obs_distance,
command = calculate_obs_dist(
counts_df = select_time_periods
),
pattern = map(select_time_periods),
iteration = "list"
),
tar_target(
name = select_within_radius,
command = calculate_obs_distance %>%
filter(.data$distance2plot <= 300),
pattern = map(calculate_obs_distance),
iteration = "list"
),
tar_target(
name = select_species_groups,
command = dplyr::filter(
Expand Down

0 comments on commit cd5d915

Please sign in to comment.