-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exeter example #65
Merged
Merged
Exeter example #65
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4c91357
Increment version number
natesheehan c003b77
Create exeter.r
natesheehan f6d303e
Âscenario of change for exeter
natesheehan 596e518
remove distance calc
natesheehan e44bfa1
update vignette
natesheehan eab20f7
new section vignette
natesheehan bd9488a
update rmd file and move exeter.r file #45
natesheehan 05209eb
Update pct_to_abstr.Rmd
natesheehan 0fb8cf8
Change title, switch to sentence per line
Robinlovelace 084a528
Update with todo on paper
Robinlovelace b1d920e
Update history of R packages
Robinlovelace 4278490
Explain how A/B Street overcomes PCT limitations
Robinlovelace d238a0e
Fix typo
Robinlovelace dc0b4e5
Move abstr.Rmd to montlake.Rmd
Robinlovelace d5b4985
Create placeholder for new get started vignette
Robinlovelace 8977256
Shift intro content to get started vignette
Robinlovelace 0e9c625
Update installation instructions
Robinlovelace 15a904f
Duplicate content in README for mvp of abstr.Rmd
Robinlovelace 8a397b7
remotes not devtools
Robinlovelace 181150f
Generalise: make region_name an object set at outset
Robinlovelace f3bebf2
Dont use pct::
Robinlovelace 414228a
Generalise: set lad_name
Robinlovelace e9f499b
General refactoring
Robinlovelace 93f2caf
Dont dplyr:: - less typing
Robinlovelace 0b7d45b
Generalising refactor + pub_upload json
Robinlovelace cb8d1f6
Instructions on import
Robinlovelace cac087e
Complete edits to new vignette
Robinlovelace c5017f5
Merge pull request #66 from a-b-street/exeter_updates
Robinlovelace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
^README\.Rmd$ | ||
^ab_scenario\.json$ | ||
^cran-comments\.md$ | ||
^CRAN-RELEASE$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This package was submitted to CRAN on 2021-08-18. | ||
Once it is accepted, delete this file and tag the release (commit 6543bdc). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: abstr | ||
Title: R Interface to the A/B Street Transport System Simulation Software | ||
Version: 0.3.0 | ||
Version: 0.3.0.9000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Authors@R: | ||
c(person(given = "Nathanael", | ||
family = "Sheehan", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
#### | ||
#### | ||
#### AIM: Use PCT data to create scenario of change where commuting cycling levels increase and car journeys decrease which can be imported | ||
#### into A/B Street city simulation software. This method should be fully reproducible for all other pct_regions. | ||
#### | ||
#### | ||
|
||
#### LIBRARYS #### | ||
library(pct) | ||
library(sf) | ||
library(tidyverse) | ||
library(abstr) | ||
|
||
# for plotting | ||
# library(tmap) | ||
# library (mapview) | ||
|
||
#### READ DATA #### | ||
devon_zones = pct::get_pct_zones(region = "devon", geography = "msoa") # get zone data | ||
exeter_zones = devon_zones %>% filter(lad_name == "Exeter") %>% select(geo_code) # filter for exeter | ||
|
||
exeter_commute_od = pct::get_pct_lines(region = "devon", geography = "msoa") %>% # get commute od data | ||
filter(lad_name1 == "Exeter" & | ||
lad_name2 == "Exeter") # filter for exeter | ||
|
||
|
||
#### CLEAN DATA , CALCULATE EUCLIDEAN DISTANCE & GENERATE SCENARIOS OF CHANGE #### | ||
exeter_commute_od = exeter_commute_od %>% | ||
mutate(cycle_base = bicycle) %>% | ||
mutate(walk_base = foot) %>% | ||
mutate(transit_base = bus + train_tube) %>% # bunch of renaming -_- | ||
mutate(drive_base = car_driver + car_passenger + motorbike + taxi_other) %>% | ||
mutate(all_base = all) %>% | ||
mutate( | ||
# create new columns | ||
pcycle_godutch_uptake = pct::uptake_pct_godutch_2020(distance = rf_dist_km, gradient = rf_avslope_perc), | ||
cycle_godutch_additional = pcycle_godutch_uptake * drive_base, | ||
cycle_godutch = cycle_base + cycle_godutch_additional, | ||
pcycle_godutch = cycle_godutch / all_base, | ||
drive__godutch = drive_base - cycle_godutch_additional, | ||
across(c(drive__godutch, cycle_godutch), round, 0), | ||
all_go_dutch = drive__godutch + cycle_godutch + transit_base + walk_base | ||
) %>% | ||
select( | ||
# select variables for new df | ||
geo_code1, | ||
geo_code2, | ||
cycle_base, | ||
drive_base, | ||
walk_base, | ||
transit_base, | ||
all_base, | ||
all_go_dutch, | ||
drive__godutch, | ||
cycle_godutch, | ||
cycle_godutch_additional, | ||
pcycle_godutch | ||
) | ||
|
||
identical(exeter_commute_od$all_base, exeter_commute_od$all_go_dutch) # sanity check: make sure total remains the same (not a dynamic model where population change is factored in) | ||
|
||
#### DOWNLOAD OSM BUILDING DATA #### | ||
osm_polygons = osmextract::oe_read( | ||
"https://download.geofabrik.de/europe/great-britain/england/devon-latest.osm.pbf", | ||
# download osm buildings for region using geofabrik | ||
layer = "multipolygons" | ||
) | ||
|
||
building_types = c( | ||
"yes", | ||
"house", | ||
"detached", | ||
"residential", | ||
"apartments", | ||
"commercial", | ||
"retail", | ||
"school", | ||
"industrial", | ||
"semidetached_house", | ||
"church", | ||
"hangar", | ||
"mobile_home", | ||
"warehouse", | ||
"office", | ||
"college", | ||
"university", | ||
"public", | ||
"garages", | ||
"cabin", | ||
"hospital", | ||
"dormitory", | ||
"hotel", | ||
"service", | ||
"parking", | ||
"manufactured", | ||
"civic", | ||
"farm", | ||
"manufacturing", | ||
"floating_home", | ||
"government", | ||
"bungalow", | ||
"transportation", | ||
"motel", | ||
"manufacture", | ||
"kindergarten", | ||
"house_boat", | ||
"sports_centre" | ||
) | ||
osm_buildings = osm_polygons %>% | ||
dplyr::filter(building %in% building_types) %>% | ||
dplyr::select(osm_way_id, name, building) | ||
|
||
osm_buildings_valid = osm_buildings[sf::st_is_valid(osm_buildings), ] | ||
|
||
exeter_osm_buildings_all = osm_buildings_valid[exeter_zones, ] | ||
|
||
#mapview(exeter_osm_buildings_all) | ||
|
||
# Filter down large objects for package ----------------------------------- | ||
exeter_osm_buildings_all_joined = exeter_osm_buildings_all %>% | ||
sf::st_join(exeter_zones) | ||
|
||
set.seed(2021) | ||
exeter_osm_buildings_sample = exeter_osm_buildings_all_joined %>% | ||
dplyr::filter(!is.na(osm_way_id)) | ||
|
||
exeter_osm_buildings_tbl = exeter_osm_buildings_all %>% | ||
dplyr::filter(osm_way_id %in% exeter_osm_buildings_sample$osm_way_id) | ||
|
||
|
||
#### LOGIC GATE #### | ||
# Logic gate for go_dutch scenario of change, where cycling levels increase to a proportion reflecting the Netherlands. | ||
#Switch to FALSE if you want census commuting OD | ||
go_dutch = TRUE | ||
if (go_dutch == TRUE) { | ||
exeter_od = exeter_commute_od %>% | ||
mutate(All = all_go_dutch) %>% | ||
mutate(Bike = cycle_godutch) %>% | ||
mutate(Transit = transit_base) %>% | ||
mutate(Drive = drive_base) %>% | ||
mutate(Walk = walk_base) %>% | ||
select(geo_code1, geo_code2, All, Bike, Transit, Drive, Walk,geometry) | ||
} else { | ||
exeter_od = exeter_commute_od %>% | ||
mutate(All = all_base) %>% | ||
mutate(Bike = cycle_base) %>% | ||
mutate(Drive = drive_base) %>% | ||
mutate(Transit = transit_base) %>% | ||
mutate(Walk = walk_base) %>% | ||
select(geo_code1, geo_code2, All, Bike, Transit, Drive, Walk, geometry) | ||
} | ||
|
||
#### GENERATE A/B STREET SCENARIO #### | ||
output_sf = ab_scenario( | ||
od = exeter_od, | ||
zones = exeter_zones, | ||
zones_d = NULL, | ||
origin_buildings = exeter_osm_buildings_tbl, | ||
destination_buildings = exeter_osm_buildings_tbl, | ||
pop_var = 3, | ||
time_fun = ab_time_normal, | ||
output = "sf", | ||
modes = c("Walk", "Bike", "Drive", "Transit") | ||
) | ||
|
||
# make map using tmap | ||
# tm_shape(output_sf) + tmap::tm_lines(col = "mode", lwd = .8, lwd.legeld.col = "black") + | ||
# tm_shape(exeter_zones) + tmap::tm_borders(lwd = 1.2, col = "gray") + | ||
# tm_text("geo_code", size = 0.6, col = "black") + | ||
# tm_style("cobalt") | ||
|
||
#### SAVE JSON FILE #### | ||
output_json = ab_json(output_sf, time_fun = ab_time_normal, scenario_name = "Exeter Example") | ||
ab_save(output_json, f = "../../Desktop/exeter.json") | ||
|
||
#### COMMANDS FOR AB STREET | ||
# $ cargo run | ||
# $ cargo run --bin import_traffic -- --map=PATH/TO/MAP --input=/PATH/TO/JSON.json |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this can be deleted now.