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

Multimodal access egress script #119

Merged
merged 7 commits into from
Jul 14, 2022
Merged

Conversation

KasiaKoz
Copy link
Collaborator

Adds a script that finds a link of mode X in the nearest neighbourhood of a PT stop (the stops can, but need not be filtered based on PT modes using the stops).

Works with a single mode in the network.xml graph, e.g. car. This results in new, additional attributes for relevant PT stops

'accessLinkId_car'
'carAccessible'
'distance_catchment'

following convention started in the multimodal access egress test data here. The param distance_catchment retains information about how far the link is (though it's not the exact distance to link).

Method:

Each stop of interest grows by step_size (metres) until it intersects with a link of specified mode, or until the distance_threshold is reached (if this parameter is set). Often there are multiple choices for links intersecting with stop neighbourhood. Right now we select the first link on the list, one day we might be more discerning about which link is the access/egress point of a mode to/from a stop.

Test:

Tested with a Matesto pipeline for Londinium [PR] which generates the network from osm and gtfs inputs with puma, simplifies with genet and (the new thing we're testing here) uses genet to find nearest car links to rail stops. This then gets run using MATSim with appropriate configuration.

Screenshot 2022-06-13 at 10 57 26

MATSim outputs show an agent driving to a PT stop and using a PT service:

Screenshot 2022-06-09 at 14 47 33

@KasiaKoz KasiaKoz requested review from fredshone and ana-kop June 13, 2022 11:35
Copy link

@fredshone fredshone left a comment

Choose a reason for hiding this comment

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

what's the motivation for stepping? Is it much faster than finding the closest and it's distance for every stop?

@ana-kop
Copy link
Contributor

ana-kop commented Jun 13, 2022

Just to confirm I understand this correctly, re question by @fredshone : you build a SpatialTree of all the links of a particular mode X, within a distance threshold for that step, and then you convert it to a gdf, and then you do a spatial join with a gdf of all the PT stop node locations; if some of the PT stop nodes remain unmatched, you increase the step, build a bigger tree and do the join again... until all the PT stop nodes are matched (or distance threshold is exceeded).

So since you probably end up matching multiple PT stop nodes with their closest link at every step iteration, you end up having to build the tree and do the spatial join fewer times than if you did it separately for every PT stop node, and so it should be faster? (I'm assuming building a tree + doing spatial join is slower than just doing a spatial join with a larger data frame)

Copy link
Contributor

@ana-kop ana-kop left a comment

Choose a reason for hiding this comment

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

this is really sleek! 👍

@KasiaKoz
Copy link
Collaborator Author

@fredshone I see it as the first step to finding a closest link (LineString) to a point. One day when we want to be more precise and find the closest link we can extend this by first: point-ising the links (split the linestring into series of points) and then: finding which point is the closest (be able to get the precise distance then) and what link it belongs to for snapping.

It's the least effort approach, using what have already been built for PT snapping with genet. We have a pretty snappy method for finding point - point closest neighbour and distance that would work well with the extras I described above. (cc @ana-kop for your reference: this is the snappy method I mean)

@KasiaKoz
Copy link
Collaborator Author

@ana-kop the spatial tree is built only once as it's the most expensive process. The stops grow their neighbourhoods by step_size until they hit some links.
BTW, the spatial tree has more functionality that is not being used here. Most notably, it's used for routing when snapping PT with genet.

@KasiaKoz
Copy link
Collaborator Author

Added some extras to this script and renamed it.

  • handling multiple modes - you can snap multiple modes to the PT stops of given modes
  • handling teleport modes - adds accessible tag only for the defined modes

e.g.

<stopFacility id="910GCLPHMJ1" x="527206.6904087012" y="175500.35337682866" name="Clapham Junction" linkRefId="5221366977632357115_5221366977632357115">
    <attributes>
        <attribute name="accessLinkId_car" class="java.lang.String">5221366976716902339_5221366976715137595</attribute>
        <attribute name="carAccessible" class="java.lang.String">true</attribute>
        <attribute name="car_distance_catchment_tag" class="java.lang.String">100.0</attribute>
        <attribute name="accessLinkId_bike" class="java.lang.String">5221366976716902339_5221366976715137595</attribute>
        <attribute name="bikeAccessible" class="java.lang.String">true</attribute>
        <attribute name="bike_distance_catchment_tag" class="java.lang.String">100.0</attribute>
        <attribute name="walkAccessible" class="java.lang.String">true</attribute>
    </attributes>
</stopFacility>

Re-ran an updated matesto test pipeline:

Update:

- id: genet-pt-rail-car-bike-walk-access-egress
  uses: docker://758645626094.dkr.ecr.eu-west-1.amazonaws.com/genet:KasiaKoz-multimodal_access_egress
  args: [
    "intermodal_access_egress_network.py",
    "--network", "working-dir/londinium/2_genet_simplified/network.xml",
    "--schedule", "working-dir/londinium/2_genet_simplified/schedule.xml",
    "--vehicles", "working-dir/londinium/2_genet_simplified/vehicles.xml",
    "--projection", "epsg:27700",
    "--pt_modes", "rail",
    "--network_snap_modes", "car,bike",
    "--teleport_modes", "walk",
    "--step_size", "50",
    "--distance_threshold", "200",
    "--output_dir", "working-dir/londinium/3_genet_mm_access_egress"
  ]
  dir: /

Success:
Screenshot 2022-07-13 at 16 21 48

@KasiaKoz KasiaKoz requested a review from ana-kop July 13, 2022 15:24
Copy link
Contributor

@ana-kop ana-kop left a comment

Choose a reason for hiding this comment

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

Great stuff!

@KasiaKoz KasiaKoz merged commit e7d979f into arbitrary-attribs Jul 14, 2022
@KasiaKoz KasiaKoz deleted the multimodal_access_egress branch July 14, 2022 09:29
KasiaKoz added a commit that referenced this pull request Jul 14, 2022
* add todos

* refactor additional attrib check method

* extract/isolate additional attrib save method

* extract/isolate general attrib save method

* refactor/generalise general attrib save method

* allow saving additional attribs for stops

* allow saving additional attribs for routes

* allow saving additional attribs for services

* allow saving additional attribs for schedule

* (add missing file) allow saving additional attribs for schedule

* general functions to prepare and check for optional and required xml attributes for nodes, links and stops

* fix var import oopsie

* add saving arbitrary additional attributes for network nodes

* tidy up consolidating stop projections

* refactor inputs_handler/outputs_handler

* refactor test file names inputs_handler/outputs_handler

* add read additional node attributes from xml

* refactor and add additional attrib read placeholders for schedule elems

* add additional attrib read for stops

* add additional attrib read for routes

* add additional attrib read for services

* add additional attrib read for schedule

* extend additional attrib read for global network attribs

* lint cleanup

* fix notebook import

* more notebook fixes

* fix up network level attributes, add read

* change to nested dict support for stop/route/service attribute setting

* tidy up todo

* add attributes as an always present attribute

* fix disappearing attribute values post save

* change simplified tag

* possible fix for pt attributes being read as None

* Magical java typing for additional attributes (#124)

* add assuming java types for additional attributes when writing to xml

* add assuming python types for additional java-typed attributes when reading from xml

* fix lingering dependence on long form attributes

* update notebooks with simple form attributes

* extra fixes, add dtype param to road pricing to match with OSM ID dtypes

* increase code coverage

* address PR comments

* PR update: enable forcing long form when reading matsim networks

* lint

* address PR comments

* Multimodal access egress script (#119)

* add example script for snapping pt stops to other parts of the network

* warn of unsnapped stops if distance threshold reached prematurely

* relax condition

* add handling multiple network modes and teleport (access only) modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants