To generate new scenario files to import into A/B Street with theabstr R package, you need to have installed a stableversion ofRstudioand R.
Install thelatestbuild of A/B Street for your platform. Or if you prefer,build fromsource, but it’s not necessary for any integration with theabstr package.
abstrLoad the package as follows:
The input datasets includesf objects representingbuildings, origin-destination (OD) data represented as desire lines andadministrative zones representing the areas within which trips in thedesire lines start and end. With the exception of OD data, each of theinput datasets is readily available for most cities. The input datasetsare illustrated in the plots below, which show example data shipped inthe package, taken from the Seattle, U.S.
library(abstr)library(tmap)# for map makingtm_shape(montlake_zones)+tm_polygons(col ="grey")+tm_shape(montlake_buildings)+tm_polygons(col ="blue")+tm_style("classic")The map above is a graphical representation of the Montlakeresidential neighborhood in central Seattle, Washington. Here,montlake_zones represents neighborhood residential zonesdeclared by Seattle local government andmontlake_buildingsbeing the accumulation of buildings listed inOpenStreetMap
The final piece of theabstr puzzle is OD data.
head(montlake_od)#> o_id d_id Drive Transit Bike Walk#> 1 281 361 23 1 2 14#> 2 282 361 37 4 0 11#> 3 282 369 14 3 0 8#> 4 301 361 27 4 3 15#> 5 301 368 6 2 1 16#> 6 301 369 14 2 0 13In this example, the first two columns correspond to the origin anddestination zones in Montlake, with the subsequent columns representingthe transport mode share between these zones.
Let’s combine each of the elements outlined above, the zone, buildingand OD data. We do this using theab_scenario() function intheabstr package, which generates a data framerepresenting tavel between themontlake_buildings. Whilethe OD data contains information on origin and destination zone,ab_scenario() ‘disaggregates’ the data and randomly selectsbuilding within each origin and destination zone to simulate travel atthe individual level, as illustrated in the chunk below which uses onlya sample of themontlake_od data, showing travel betweenthree pairs of zones, to illustrate the process:
set.seed(42)montlake_od_minimal=subset(montlake_od, o_id=="373"|o_id=="402"| o_id=="281"| o_id=="588"| o_id=="301"| o_id=="314")output_sf=ab_scenario(od = montlake_od_minimal,zones = montlake_zones,zones_d =NULL,origin_buildings = montlake_buildings,destination_buildings = montlake_buildings,pop_var =3,time_fun = ab_time_normal,output ="sf",modes =c("Walk","Bike","Drive","Transit"))Theoutput_sf object created above can be furthertransformed to matchA/BStreet’s schema and visualised in A/B Street, or visualised in R(using thetmap package in the code chunk below):
tm_shape(output_sf)+ tmap::tm_lines(col ="mode",lwd = .8,lwd.legeld.col ="black")+tm_shape(montlake_zones)+ tmap::tm_borders(lwd =1.2,col ="gray")+tm_text("id",size =0.6)+tm_style("cobalt")#> [tm_lines()] Argument `lwd.legeld.col` unknown.Each line in the plot above represents a single trip, with the colorrepresenting each transport mode. Moreover, each trip is configured withan associated departure time, that can be represented in A/B Street.
Theab_save andab_json functions concludetheabstr workflow by outputting a local JSON file,matching theA/BStreet’s schema.
output_json=ab_json(output_sf,time_fun = ab_time_normal,scenario_name ="Montlake Example")ab_save(output_json,f ="montlake_scenarios.json")Let’s see what is in the file:
The first trip schedule should look something like this, matchingA/B Street’sschema.
After generating amontlake_scenario.json, you canimport and simulate it as follows.
montlake_scenario.json file.After you successfully import this file once, it will be available inthe list of scenarios, under the “Montlake Example” name, or whatevername specified by the JSON file.
abstrSeveral open source R packages enabled the creation ofabstr.
These include:
To further understand the methods and motivations behindabstr, it helps to have some context. The package builds onthe ecosystem of open source software for geospatial data (FOSS4G) and packages such asstplanr forworking with transport data in R.stplanr was developed tosupport development of the the Propensity to Cycle Tool (PCT), an open source transport planningsystem for England and Wales. The PCTpackage enables access to thedata generated by the PCT project, plus scenario of change modeling (notforecasting) at the origin-destination level, which can provide resultsat regions, local, route and route network levels.
The PCT provides a range of deterministic scenarios of change, suchasgo_dutch (where cycling levels matches that of theNetherlands),gender_eq (where there is equal levels ofcycling among Female and Males) andgov_target (wherecycling levels reflect that of UK government current targets). Anacademicpaper onthe PCT provides further detail on the motivations for and methodsunderlying the project. In 2018 the beastystplanr(sustainable transport planning) package and R journalarticlecame on the scene, and further provided functions for solving commonproblems in transport planning and modeling, as well as advocating atransparency in tool usage within the transport planning paradigm.
Finally, on the R side, in 2021 theod package wasreleased which provided functions for working with origin-destinationdata. A central focus in all of the packages and papers mentioned aboveis to provide open access transport tools to support data driventransport policies based on an objective and transparent evidencebase.
For more on the history motivating the development of theabstr package see thepct_to_abstrvignette