Skip to content

Commit 58332dc

Browse files
authored
Merge pull request #35 from nptscot/checkpoint_path_cache_env
Checkpoint path cache env
2 parents 38b8d64 + 34c82a0 commit 58332dc

9 files changed

Lines changed: 845 additions & 189 deletions

File tree

.Rbuildignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@
88
zip
99
gpkg
1010
^Doc$
11+
^\.devcontainer$
12+
^code$
13+
^network_eval\.qmd$
14+
^network_eval_file$
15+
^plot$
16+
^requirements\.txt$

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ Doc
55
Test.Rmd
66
Test.R
77
cohesive_network_region_boundary.geojson
8-
inputdata/
8+
inputdata/
9+
network_eval_file/
10+
plot/
11+
..Rcheck/

DESCRIPTION

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ Imports:
2727
purrr,
2828
units,
2929
rlang,
30+
anime,
31+
stats,
32+
grDevices
3033
Suggests:
3134
tibble,
3235
tmaptools,
3336
zonebuilder,
34-
rsgeo
37+
rsgeo,
38+
fmsb
39+
Remotes:
40+
josiahparry/anime/r,
41+
josiahparry/rsgeo
3542
Encoding: UTF-8
3643
LazyData: true
3744
Roxygen: list(markdown = TRUE)

R/anime_join.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ anime_join = function(
108108
net_target_aggregated = net_source_matches |>
109109
dplyr::group_by(row_number = target_id) |>
110110
dplyr::summarise(
111-
!!rlang::sym(new_name) := agg_fun(!!mult_expr, na.rm = TRUE)
111+
!!rlang::sym(new_name) := agg_fun(!!mult_expr, na.rm = TRUE),
112+
.groups = "drop"
112113
)
113114

114115
# 6. If aggregator is max, round the result

R/corenet.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
utils::globalVariables(c("edge_paths", "influence_network", "all_fastest_bicycle_go_dutch",
33
"weight", "to_linegraph", "edges", "group", "mean_potential", "LAD23NM",
44
"road_function", "grid_id", "density",
5-
"max_value", "min_value", "arterialness", "road_score", "value", "key_attribute", "n_group",".data", "n_removeDangles", "path_type", "maxDistPts", "minDistPts","penalty_value","penalty", "use_stplanr", "group_column"))
6-
5+
"max_value", "min_value", "arterialness", "road_score", "value", "key_attribute", "n_group",".data", "n_removeDangles", "path_type", "maxDistPts", "minDistPts","penalty_value","penalty", "use_stplanr", "group_column",
6+
# Variables from net_eval.R functions
7+
"geometry", "InterZone", "TotPop2011", "StdAreaKm2", "ResPop2011", "W_i",
8+
"has_intersection", "covered_area", "covered_area_km2", "pop_density",
9+
"covered_population", "distance_to_network", "all", "length_m", "km",
10+
"target_id", "id"))
711
#' Prepare a cohesive cycling network using NPT data
812
#'
913
#' This function prepares the base network for generating a cohesive cycling network
@@ -193,9 +197,9 @@ corenet = function(influence_network, cohesive_base_network, target_zone, key_at
193197

194198
# Perform DBSCAN clustering
195199
coordinates = sf::st_coordinates(centroids)
196-
coordinates_clean = coordinates[complete.cases(coordinates), ]
200+
coordinates_clean = coordinates[stats::complete.cases(coordinates), ]
197201
clusters = dbscan::dbscan(coordinates_clean, eps = 18, minPts = 1)
198-
centroids_clean = centroids[complete.cases(coordinates), ]
202+
centroids_clean = centroids[stats::complete.cases(coordinates), ]
199203
centroids_clean$cluster = clusters$cluster
200204
unique_centroids = centroids_clean[!duplicated(centroids_clean$cluster), ]
201205

@@ -321,6 +325,9 @@ corenet = function(influence_network, cohesive_base_network, target_zone, key_at
321325
# Prepare network and calculate paths
322326
prepared_network = prepare_network(cohesive_base_network, key_attribute , road_scores, transform_crs = crs , penalty_value = penalty_value)
323327

328+
# Initialize cache environment for path calculations
329+
path_cache_env = new.env(parent = emptyenv())
330+
assign("path_cache_env", path_cache_env, envir = .GlobalEnv)
324331

325332
all_paths = purrr::map_dfr(
326333
seq_len(nrow(unique_centroids)),
@@ -479,12 +486,10 @@ prepare_network = function(network, key_attribute = "all_fastest_bicycle_go_dutc
479486
#' @param minDistPts The minimum distance (in meters) to consider for path calculations.
480487
#' @param centroids An sf object containing centroids to which paths are calculated.
481488
#' @param path_type A character string indicating the type of path calculation: 'shortest', 'all_shortest', or 'all_simple'.
482-
#' @param max_path_weight
489+
#' @param max_path_weight Maximum weight allowed for paths in network calculations.
490+
#' @param crs_transform The coordinate reference system to transform to, default is 27700 (British National Grid).
483491
#'
484-
#' - 'shortest': Calculates the shortest path considering weights.
485-
#' - 'all_shortest': Calculates all paths that tie for the shortest distance, considering weights.
486-
#' - 'all_simple': Calculates all simple paths, ignoring weights.
487-
#' @return An sf object containing the paths that meet the criteria or NULL if no paths meet the criteria.
492+
#' @return A list containing the computed paths and their associated weights.
488493
#' @export
489494

490495
calculate_paths_from_point_dist = function(

0 commit comments

Comments
 (0)