-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets.R
137 lines (114 loc) · 5.19 KB
/
_targets.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Created by use_targets().
# Follow the comments below to fill in this target script.
# Then follow the manual to check and run the pipeline:
# https://books.ropensci.org/targets/walkthrough.html#inspect-the-pipeline # nolint
# Set defaults HERE ######################
CITY_input = "Lisboa" # Municipality name in Portugal
GEOJSON = FALSE # use a different limit? made with https://geojson.io/ and saved in inputdata/*.geojson
GEOJSON_input = "map1" # name of the file if GEOJSON = TRUE. default: "map1"
cellsize_input = c(400, 400)# in meters
square_input = TRUE # TRUE = squares, FALSE = hexagons
use_h3 = TRUE # use h3 to create universal grid?
h3_res = 9 # h3 resolution. default: 9 (400m diameter). 8 = 1060m diameter, 10 = 150m diameter
build_osm = FALSE # clean osm road network again?
analysis = TRUE # export input parameters and results to a xls file? default: FALSE
# Thresholds
population_min = median # mean or median? default: mean
degree_min = mean # mean or median? default: mean
betweeness_range = 0.40 # percentile to exclude (upper and lower) default: 0.25
closeness_range = 0.25 # value to exclude (upper and lower) default: 0.25
entropy_min = 0.35 # value to exclude (lower) default: 0.5
freq_bus = c(4, 10, 20) # frequency of bus stops to define level of service. last 2 will remain. default: c(4, 10, 20)
#########################################
# Load packages required to define the pipeline:
library(targets)
# library(crew)
# library(tarchetypes) # Load other packages as needed. # nolint
# Set target options:
tar_option_set(
packages = c("tibble", "dplyr", "tidyr", "sf", "sfheaders", "stplanr", "osmdata", "sfnetworks",
"tidygraph", "scales", "qgisprocess", "h3jsr"), # packages that your targets need to run
format = "rds", # default storage format
storage = "worker",
retrieval = "worker",
# controller = crew_controller_local(workers = 3) #change here number of paralell process
# Set other options as needed.
)
# tar_make_clustermq() configuration (okay to leave alone):
# options(clustermq.scheduler = "multicore")
# tar_make_future() configuration (okay to leave alone):
# Install packages {{future}}, {{future.callr}}, and {{future.batchtools}} to allow use_targets() to configure tar_make_future() options.
# Run the R scripts in the R/ folder with your custom functions:
tar_source()
# source("R/functions.R")
# source("other_functions.R") # Source other scripts as needed. # nolint
# Create outuput data
if(!file.exists("outputdata")){
dir.create("outputdata")
}
# Replace the target list below with your own:
list(
tar_target(
name = CITY,
command = select_city(CITY = CITY_input, GEOJSON_name = GEOJSON_input, GEOJSON)),
tar_target(
name = CITYlimit,
command = get_citylimit(CITY, GEOJSON, GEOJSON_name = GEOJSON_input)),
tar_target(
name = grid,
command = make_grid(CITYlimit, CITY, cellsize = cellsize_input, square = square_input, h3_hex = use_h3, h3_res = h3_res)),
tar_target(
name = road_network,
command = get_osm(CITYlimit, CITY)),
tar_target(
name = road_network_clean,
command = clean_osm(road_network, CITY, build_osm),
# deployment = "worker", #paralell processing
),
tar_target(
name = centrality_nodes,
command = get_centrality(road_network_clean, CITY)),
tar_target(
name = centrality_grid,
command = get_centrality_grid(centrality_nodes, grid)),
tar_target(
name = CITYcensus,
command = get_census(CITYlimit)),
tar_target(
name = points_transit,
command = get_transit(CITYlimit)),
tar_target(
name = transit_grid,
command = get_transit_grid(grid, points_transit)),
tar_target(
name = density_grid,
command = get_density_grid(grid, CITYcensus)),
tar_target(
name = landuse_grid,
command = get_landuse(grid, CITYcensus)),
tar_target(
name = classify_candidates_centrality,
command = find_centrality_candidates(centrality_grid, degree_min, betweeness_range, closeness_range)),
tar_target(
name = classify_candidates_density,
command = find_density_candidates(density_grid, population_min)),
tar_target(
name = classify_candidates_landuse,
command = find_landuse_candidates(landuse_grid, entropy_min)),
tar_target(
name = classify_candidates_transit,
command = find_transit_candidates(transit_grid, freq_bus)),
tar_target(
name = grid_all,
command = make_grid_all(grid, CITY = CITY_input, GEOJSON_name = GEOJSON_input, GEOJSON, use_h3,
classify_candidates_transit, classify_candidates_landuse,
classify_candidates_centrality, classify_candidates_density)),
tar_target(
name = site_selection,
command = get_site_selection(CITY = CITY_input, grid_all, GEOJSON_name = GEOJSON_input, GEOJSON)),
tar_target(
name = analysis_save,
command = export_analysis(grid_all, site_selection, CITY_input, GEOJSON, GEOJSON_input, analysis,
cellsize_input, square_input, use_h3, build_osm, degree_min, betweeness_range,
closeness_range, population_min, entropy_min, freq_bus))
)