forked from U-Shift/cyclingpotential-hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhack-slides.Rmd
496 lines (331 loc) · 14.8 KB
/
hack-slides.Rmd
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
---
title: "Cycling potential hackathon"
subtitle: '`r emojifont::emoji("bike")`<br/>The Propensity to Cycle Tool approach: reproducible methods with free and open source software'
author: "Robin Lovelace and Rosa Felix"
date: '<img class="img-footer" alt="" src="https://www.pct.bike/www/static/01_logos/pct-logo.png">'
output:
xaringan::moon_reader:
# css: ["default", "its.css"]
# chakra: libs/remark-latest.min.js
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
# bibliography:
# - ../vignettes/ref.bib
# - ../vignettes/ref_training.bib
---
```{r, eval=FALSE, echo=FALSE}
cp -Rv hack-slides* ~/blog/rstudio.robinlovelace.io/presentations
```
```{r setup, include=FALSE, eval=TRUE}
# get citations
refs = RefManageR::ReadZotero(group = "418217", .params = list(collection = "JFR868KJ", limit = 100))
refs_df = as.data.frame(refs)
# View(refs_df)
# citr::insert_citation(bib_file = "vignettes/refs_training.bib")
RefManageR::WriteBib(refs, "refs.bib")
# citr::tidy_bib_file(rmd_file = "vignettes/pct_training.Rmd", messy_bibliography = "vignettes/refs_training.bib")
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(message = FALSE)
library(RefManageR)
BibOptions(check.entries = FALSE,
bib.style = "authoryear",
cite.style = 'alphabetic',
style = "markdown",
first.inits = FALSE,
hyperlink = FALSE,
dashed = FALSE)
my_bib = refs
```
```{r, include=FALSE}
library(RefManageR)
my_bib = RefManageR::ReadBib("refs.bib")
```
# Agenda and sign-up
- Introduction to the hackathon: 10:00 - 10:40 (Rosa Felix and Robin Lovelace)
<!-- How we started the collaboration, why Lisbon, aims (importance of free, open and participatory solutions) -->
<!-- Robin on the methods and software underlying the PCT. -->
- Participant introductions: 10:40 - 10:45 (participants)
- Talks: methods for modelling cycling networks: 10:45 - 11:15 (Crispin Cooper and Lorena Abad)
<!-- Crispin to talk about approaches for modelling active transport -->
<!-- Lorena to talk about cycle network analysis in R -->
- Live, interactive demo of data and hack rules: 11:15 - 11:45 (Rosa and Robin)
- Topic pitches 11:45 - 12:00 (participants proposing topics)
Lunch break and finalising teams 12:00 to 13:00
- Hackathon 13:00 - 15:30
- Presentation of results 15:30 - 16:00
<!-- ? someone to assess / 'most creative', best technicallay? -->
<!-- 215.1371 -->
<!-- - 09:30 - 10:00: Arrival and set-up -->
<!-- - 10:00 - 11:00: Data and methods underlying the PCT -->
<!-- - 11:00 - 12:30: Getting and analysing PCT data -->
<!-- - Comparing PCT results with existing road infrastructure -->
<!-- - Getting data from the CyIPT -->
<!-- - Identfying 'weak links' -->
<!-- - Identify gaps in the network -->
<!-- Lunch break -->
<!-- - 13:30 - 15:30: Extending the PCT: minihack -->
<!-- - Alternative scenarios of cycling uptake -->
<!-- - A 'replace short car trips' scenario -->
<!-- - New input data -->
<!-- - Travel to stations -->
<!-- - Other extensions of the PCT -->
<!-- Break and presentation of results -->
<!-- - 16:00 - 16:30: Policy implementation -->
---
## Learning outcomes
- Understand the data and code underlying the PCT
- Download data from the PCT at various geographic levels
- Use R as a tool for data analysis to support evidence-based planning
--
It's about free and open source software for a sustainable future `r emojifont::emoji("rocket")`

---
background-image: url(https://media.giphy.com/media/YlQQYUIEAZ76o/giphy.gif)
background-size: cover
class: center, middle
# How the PCT works
---
## The first prototype of the PCT
- 1st prototype: Hackathon at ODI Leeds in February 2015
- We identifying key routes and mapped them
- For early description of aims, see Lovelace et al. (2017)
```{r, echo=FALSE}
knitr::include_graphics("https://raw.githubusercontent.com/npct/pct-team/master/figures/early.png")
```
---
# The PCT in 2020
- Now the go-to tool for strategic cycle network planning in England and Wales, used by most local authorities with cycling plans ([source](https://npct.github.io/pct-shiny/regions_www/www/static/03d_other_reports/2019-use-of-pct-report.pdf)).
.pull-left[
## Geographic levels in the PCT
- Generate and analyse route networks for transport planning with reference to:
- Zones
- Origin-destination (OD) data
- Geographic desire lines
- Route allocation using different routing services
- Route network generation and analysis
]
.pull-right[

See these levels at [www.pct.bike](https://www.pct.bike)
]
---
## Let's look at zones

```{r, eval=FALSE, echo=FALSE}
qtm(od_data_zones_min)
```
---
## OD data
```{r, echo=FALSE, message=FALSE}
library(tmap)
library(od)
tmap_mode("plot")
od_test = od::od_data_df
od_test$id = 1:nrow(od_test)
od_test$perc_cycle = round(od_test$bicycle / od_test$all, 3) * 100
knitr::kable(od_test, caption = "Origin-destination data. Open MSOA-MSOA commute data from the 2011 census, accessed using the R package pct.")
```
---
## Desire lines
```{r, echo=FALSE, message=FALSE}
l = od_to_sf(od_test, od_data_centroids)
l = dplyr::select(l, id, foot, bicycle, car_driver, perc_cycle)
p = od_data_centroids
p = p[l, ]
tm_shape(l) +
tm_lines("perc_cycle", palette = "viridis", lwd = "car_driver", legend.lwd.show = FALSE, scale = 9, alpha = 0.5) +
tm_text("id") +
tm_shape(p) +
tm_text("geo_code")
```
---
## Routes
```{r, echo=FALSE, eval=TRUE}
library(cyclestreets)
r = stplanr::route(l = l, route_fun = journey)
# saveRDS(r, "routes_od_data_df_df.Rds")
# piggyback::pb_upload("routes_od_data_df_df.Rds")
# file.remove("routes_od_data_df_df.Rds")
```
```{r, eval=FALSE, echo=FALSE}
tm_shape(r) +
tm_lines("perc_cycle", palette = "viridis", lwd = "car_driver", legend.lwd.show = FALSE, scale = 9, alpha = 0.5) +
tm_shape(p) +
tm_text("geo_code")
```

---
### Route networks
```{r}
rnet = stplanr::overline(r, "bicycle")
plot(rnet, lwd = rnet$bicycle / 10)
```
---
#### Cycling uptake

--
Dose/response modelling: about cycling in response to distance, hilliness and other factors. Source: [pct R package website](https://itsleeds.github.io/pct/reference/uptake_pct_govtarget.html)
---
background-image: url(https://media.giphy.com/media/YlQQYUIEAZ76o/giphy.gif)
# Coding
```{r, eval=FALSE}
od_test$perc_cycle = round(od_test$bicycle / od_test$all) * 100
l = od_to_sf(od_test, od_data_centroids)
r = stplanr::route(l = l, route_fun = journey)
rnet = overline(r, "bicycle")
```
--

---
## Key stages of PCT approach
- Reproducible, open, scripted, enabling modifications, e.g.:
- Find short routes in which more people drive than cycle
--
- Stage 1: get data
```{r, message=FALSE}
# Set-up, after installing pct and checking out www.pct.bike:
library(dplyr)
library(sf)
od_data = readr::read_csv("https://github.com/U-Shift/cyclingpotential-hack/releases/download/2.0.0/od_data_final.csv")
centroids = read_sf("https://github.com/U-Shift/cyclingpotential-hack/releases/download/2.0.0/centroids.geojson")
desire_lines_all = od::od_to_sf(x = od_data, z = centroids)
nrow(desire_lines_all)
```
---
## Stage II: Subset data of interest
- Interested only in major lines
```{r}
desire_lines = desire_lines_all %>%
filter(Total > 500)
nrow(desire_lines)
plot(desire_lines)
```
---
## Stage III: Visualisation
<!-- A fundamental part of data science is being able to understand your data. -->
<!-- That requires visualisation, R is great for that: -->
```{r, warning=FALSE, eval=FALSE, echo=FALSE}
.pull-left[
plot(desire_lines)
]
.pull-right[
]
```
<!-- - Interactively: -->
```{r, message=FALSE}
library(tmap)
tmap_mode("view")
tm_shape(desire_lines) +
tm_lines("Total", scale = 9) +
tm_basemap(server = leaflet::providers$OpenStreetMap)
```
---
## Stage IV: Origin-destination data analysis
- Now we have data in our computer, and verified it works, we can use it
- Which places are most car dependent?
```{r}
car_dependent_routes = desire_lines %>%
mutate(percent_drive = Car / Total * 100) %>%
filter(percent_drive > 50)
nrow(car_dependent_routes)
```
- Get routes
```{r, eval=FALSE}
routes = stplanr::route(
l = car_dependent_routes,
route_fun = cyclestreets::journey,
plan = "balanced"
)
saveRDS(routes, "routes_car_dependent.Rds")
```
<!-- -- -->
<!-- - Any questions? -->
<!-- -- -->
<!-- - Everyone happy with RStudio? -->
<!-- --- -->
<!-- # Supporting reference materials -->
<!-- All interactive programming/analysis with command line interface involves frequent reference to documentation, and data science is no exception. Places to look for help (in roughly descending order): -->
<!-- -- -->
<!-- - Your colleague -->
<!-- - R's internal help (e.g. with `?functonname` or `vignettes(package = "packagename)`) -->
<!-- - Online documentation, e.g. for the pct package: https://itsleeds.github.io/pct/ -->
<!-- - *Transport and Geographic Data Science with R*: An introduction to R aimed at transport planners: https://git.io/tds2dayex -->
<!-- - The transport chapter ([12](https://geocompr.robinlovelace.net/transport.html)) in the open source book [*Geocomputation with R*](https://geocompr.robinlovelace.net/) -->
<!-- - R for Data Science -->
<!-- --- -->
<!-- # Exercises -->
<!-- - If you're happy with R, work through G1 to G8 in the [exercises](https://itsleeds.github.io/pct/articles/pct_training.html#exercises), starting: -->
<!-- - G1: Using the PCT's online interface, hosted at [www.pct.bike/m/?r=isle-of-wight](https://www.pct.bike/m/?r=isle-of-wight), identify the MSOA **zone** that has the highest number of people who cycle to work. -->
<!-- - If you're just getting started with RStudio: Work through Section 1 of https://git.io/tds2dayex -->
<!-- - Getting up to speed with data manipulation in the tidyverse: Work through and reproduce the code in Section [5.2](https://r4ds.had.co.nz/transform.html#filter-rows-with-filter) of R for Data Science. -->
<!-- --- -->
<!-- # The PCT hackathon -->
<!-- -- -->
<!-- Overall aim: generate ideas related to and extending the PCT -->
<!-- -- -->
<!-- Ideas: -->
<!-- - Create a route network reflecting where you would invest if the priority was reducing car trips of less than 5 km -->
<!-- -- -->
<!-- - Design interventions to replace short car trips across West Yorkshire (or another region of your choice) using the PCT methods/data to support your decisions -->
<!-- -- -->
<!-- - Identify quiet routes and design a quiet route network for city/region of your choice, e.g. Leeds -->
<!-- -- -->
<!-- - Import alternative origin-destination datasets and use those as the basis for propensity to cycle analysis for trip purposes other than single stage commutes, encapsulated in the commut layer in the PCT -->
<!-- - Any other layers/scenarios/hacks: welcome! Comments in this repo's [issue tracker](https://github.com/ITSLeeds/pct/issues) also welcome. -->
<!-- --- -->
<!-- # References -->
```{r, 'refs', results="asis", echo=FALSE, eval=FALSE}
PrintBibliography(my_bib)
# RefManageR::WriteBib(my_bib, "refs-geostat.bib")
```
---
# Other topics
---
## Transport software - which do you use?
```{r, echo=FALSE, message=FALSE, warning=FALSE}
u = "https://github.com/ITSLeeds/TDS/raw/master/transport-software.csv"
tms = readr::read_csv(u)[1:5]
tms = dplyr::arrange(tms, dplyr::desc(Citations))
knitr::kable(tms, booktabs = TRUE, caption = "Sample of transport modelling software in use by practitioners. Note: citation counts based on searches for company/developer name, the product name and 'transport'. Data source: Google Scholar searches, October 2018.", format = "html")
```
---
## Data science and the tidyverse
- Inspired by Introduction to data science with R (available free [online](https://r4ds.had.co.nz/)) `r Citep(my_bib, "grolemund_r_2016", .opts = list(cite.style = "authoryear"))`
```{r tds-cover, echo=FALSE, out.width="30%"}
knitr::include_graphics("https://d33wubrfki0l68.cloudfront.net/b88ef926a004b0fce72b2526b0b5c4413666a4cb/24a30/cover.png")
```
---
## A geographic perspective
- See https://github.com/ITSLeeds/TDS/blob/master/catalogue.md
- Paper on the **stplanr** paper for transport planning (available [online](https://cran.r-project.org/web/packages/stplanr/vignettes/stplanr-paper.html)) `r Citep(my_bib, "lovelace_stplanr:_2018", .opts = list(cite.style = "authoryear"))`
- Introductory and advanced content on geographic data in R, especially the [transport chapter](https://geocompr.robinlovelace.net/transport.html) (available free [online](https://geocompr.robinlovelace.net/)) `r Citep(my_bib, "lovelace_geocomputation_2019", .opts = list(cite.style = "authoryear"))`
- Paper on analysing OSM data in Python `r Citep(my_bib, "boeing_osmnx_2017", .opts = list(cite.style = "authoryear"))` (available [online](https://arxiv.org/pdf/1611.01890))
---
# Getting support
--
With open source software, the world is your support network!
--
- Recent example: https://stackoverflow.com/questions/57235601/
--
- [gis.stackexchange.com](https://gis.stackexchange.com/questions) has 21,314 questions
- [r-sig-geo](https://r-sig-geo.2731867.n2.nabble.com/) has 1000s of posts
- RStudio's Discourse community has 65,000+ posts already!
--
- No transport equivalent (e.g. earthscience.stackexchange.com is in beta)
- Potential for a Discourse forum or similar: transport is not (just) GIS
<!-- --- -->
<!-- ## Transport planning software -->
<!-- Transport modelling software products are a vital component of modern transport planning *and* research. -->
<!-- - They generate the evidence base on which strategic investments are made and, furthermore, -->
<!-- - provide a powerful mechanism for researching alternative futures. -->
<!-- -- -->
<!-- It would not be an overstatement to say that software determines the range of futures that are visible to policymakers. This makes status of transport modelling software and how it may evolve in the future important questions. -->
<!-- What will transport software look like? What will their capabilities be? And who will control? Answers to each of these questions will affect the future of transport systems. -->
<!-- -- -->
<!-- - Premise: transport planning/modelling software used in practice ~~will become~~ is becoming increasingly data-driven, modular and open. -->
<!-- --- -->
<!-- ```{r geocompr-cover, echo=FALSE, out.width="20%"} -->
<!-- knitr::include_graphics("https://geocompr.robinlovelace.net/images/cover.png") -->
<!-- ``` -->