Skip to content
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 28 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4c91357
Increment version number
natesheehan Aug 19, 2021
c003b77
Create exeter.r
natesheehan Aug 20, 2021
f6d303e
Âscenario of change for exeter
natesheehan Aug 25, 2021
596e518
remove distance calc
natesheehan Aug 31, 2021
e44bfa1
update vignette
natesheehan Aug 31, 2021
eab20f7
new section vignette
natesheehan Aug 31, 2021
bd9488a
update rmd file and move exeter.r file #45
natesheehan Aug 31, 2021
05209eb
Update pct_to_abstr.Rmd
natesheehan Aug 31, 2021
0fb8cf8
Change title, switch to sentence per line
Robinlovelace Aug 31, 2021
084a528
Update with todo on paper
Robinlovelace Aug 31, 2021
b1d920e
Update history of R packages
Robinlovelace Aug 31, 2021
4278490
Explain how A/B Street overcomes PCT limitations
Robinlovelace Aug 31, 2021
d238a0e
Fix typo
Robinlovelace Aug 31, 2021
dc0b4e5
Move abstr.Rmd to montlake.Rmd
Robinlovelace Aug 31, 2021
d5b4985
Create placeholder for new get started vignette
Robinlovelace Aug 31, 2021
8977256
Shift intro content to get started vignette
Robinlovelace Aug 31, 2021
0e9c625
Update installation instructions
Robinlovelace Aug 31, 2021
15a904f
Duplicate content in README for mvp of abstr.Rmd
Robinlovelace Aug 31, 2021
8a397b7
remotes not devtools
Robinlovelace Aug 31, 2021
181150f
Generalise: make region_name an object set at outset
Robinlovelace Aug 31, 2021
f3bebf2
Dont use pct::
Robinlovelace Aug 31, 2021
414228a
Generalise: set lad_name
Robinlovelace Aug 31, 2021
e9f499b
General refactoring
Robinlovelace Aug 31, 2021
93f2caf
Dont dplyr:: - less typing
Robinlovelace Aug 31, 2021
0b7d45b
Generalising refactor + pub_upload json
Robinlovelace Aug 31, 2021
cb8d1f6
Instructions on import
Robinlovelace Aug 31, 2021
cac087e
Complete edits to new vignette
Robinlovelace Aug 31, 2021
c5017f5
Merge pull request #66 from a-b-street/exeter_updates
Robinlovelace Aug 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
^README\.Rmd$
^ab_scenario\.json$
^cran-comments\.md$
^CRAN-RELEASE$
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2021-08-18.
Copy link
Collaborator

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.

Once it is accepted, delete this file and tag the release (commit 6543bdc).
2 changes: 1 addition & 1 deletion DESCRIPTION
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Authors@R:
c(person(given = "Nathanael",
family = "Sheehan",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# abstr (development version)

# abstr 0.3.0

* New Vignette to reproduce the datasets based on the Montlake area in Seattle
Expand Down
178 changes: 178 additions & 0 deletions data-raw/exeter.r
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
Loading