-
Notifications
You must be signed in to change notification settings - Fork 10
Usage: 7. Visualising Network
This page goes through examples of visualising networks in GeNet. Available as a jupyter notebook or wiki page.
# read sample network
from genet import read_matsim
import os
path_to_matsim_network = '../example_data/pt2matsim_network'
network = os.path.join(path_to_matsim_network, 'network.xml')
schedule = os.path.join(path_to_matsim_network, 'schedule.xml')
vehicles = os.path.join(path_to_matsim_network, 'vehicles.xml')
n = read_matsim(
path_to_network=network,
epsg='epsg:27700',
path_to_schedule=schedule,
path_to_vehicles=vehicles
)
# you don't need to read the vehicles file, but doing so ensures all vehicles
# in the schedule are of the expected type and the definition of the vehicle
# is preserved
n.print()
Graph info: Name:
Type: MultiDiGraph
Number of nodes: 1662
Number of edges: 3166
Average in degree: 1.9049
Average out degree: 1.9049
Schedule info: Schedule:
Number of services: 9
Number of routes: 68
Number of stops: 118
Each GeNet class has a plot
method, which depends on kepler
. Make sure to follow installation instructions to use in-notebook visualisations.
m = n.plot(data={'freespeed'})
m
User Guide: https://docs.kepler.gl/docs/keplergl-jupyter
/Users/kasia.kozlowska/PycharmProjects/CML/genet/venv_3_7/lib/python3.7/site-packages/pandas/core/dtypes/cast.py:118: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.
arr = construct_1d_object_array_from_listlike(values)
/Users/kasia.kozlowska/PycharmProjects/CML/genet/venv_3_7/lib/python3.7/site-packages/pandas/core/dtypes/cast.py:1990: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry.
result[:] = values
KeplerGl(config={'version': 'v1', 'config': {'visState': {'filters': [], 'layers': [{'id': 'network_links', 't…
You can use kepler's method to save the map object to html (this will save the current state so should include any changes you made to the map), or you can pass the output directory to the plot method.
n.plot(output_dir='../example_data/output_kepler/')
/Users/kasia.kozlowska/PycharmProjects/CML/genet/venv_3_7/lib/python3.7/site-packages/pandas/core/dtypes/cast.py:118: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.
arr = construct_1d_object_array_from_listlike(values)
/Users/kasia.kozlowska/PycharmProjects/CML/genet/venv_3_7/lib/python3.7/site-packages/pandas/core/dtypes/cast.py:1990: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry.
result[:] = values
User Guide: https://docs.kepler.gl/docs/keplergl-jupyter
Map saved to ../example_data/output_kepler/network_with_pt_routes.html!
KeplerGl(config={'version': 'v1', 'config': {'visState': {'filters': [], 'layers': [{'id': 'network_links', 't…
m.save_to_html(file_name='../example_data/output_kepler/kepler_map.html')
Map saved to ../example_data/output_kepler/kepler_map.html!
Due to github's restriction on file size, we supress outputs for the remain plots, to see them, you will need to remove #
from the beginning of the line.
# n.schedule.plot(data=True)
# n.schedule['12430'].plot()
# n.schedule.route('VJ948e8caa0f08b9c6bf6330927893942c474b5100').plot()
GeNet Network
can an additional two methods to
- just plot the underlying graph and
- to plot the un-routed schedule on top of the graph
# n.plot_graph()
# n.plot_schedule()
You can generate a long list of outputs which are useful for validating and visualising the network and its schedule.
n.generate_standard_outputs(output_dir='path/to/standard_outputs', gtfs_day='19700101')
Specifying gtfs_day
is optional and only useful for generating visualisations which don't rise eyebrows. In this bundle you get a number of outputs which you can drop into kepler.gl or qgis.
This method will output complete geojsons for the links and nodes of the Network.graph
and Schedule.graph()
(if present). These will usually be too large to put in kepler but can still be read back using geopandas
and worked with easily as GeoDataFrames
. These can be generated separately using save_network_to_geojson
method. In addition to this, the method will output a few geojsons which have been subsetted on mode or values, to be immediately useful, and other files with high-level Schedule stats: (note, for each geojson there are corresponding shapefiles in a shp_files
folder)
- geojsons for car mode featuring 'freespeed', 'capacity', 'permlanes' (separately, because these can get large)
- geojsons, featuring full data but each a subset of the graph on an OSM highway tag (e.g. all motorways)
- geojsons with geometry only for all other modal subgraphs
-
vehicles_per_hour
- geojsons featuring schedule graph with vehicles per hour for every mode separately and all together (with mode data present fo subsetting) in the schedule for all hours of the day, this can be used within kepler to animate across hours of the day. (Use 'filter' option on 'hour' field and click on the little clock)
- the same as above for all modes together but subsetted for am/inter/pm peak within hours 7, 8, 9, 13, 16, 17, 18 for convenience (in case the big geojson may be too large to load in kepler)
-
subgraphs
- links and nodes geojson modal subgraphs of theSchedule
graph, the same as the large geojson, but chopped by mode to make each file easier to handle in kepler for example -
speed
-
pt_network_speeds
- geojson with network geometry androuted_speed
based on distances between stops that use thelength
s of network links given in the network route for theRoute
. Note that it is not precise, as stops reference links, if the link is long this will throw off the speed (partial distance along a link with respect to the location of the stop is not considered). -
pt_speeds
- geojson with stop-to-stop, straight line, geometry. Thespeed
is based on crow-fly distance between each stop pair multiplied by aschedule_network_factor
which, if not passed explicitly, defaults to1.3
.
-
- CSVs - Stats:
-
trips_per_day_per_route.csv
- Number of trips made by eachRoute
object, complete with mode and huma-readable name if present -
trips_per_day_per_service.csv
- Number of trips made by eachService
object, complete with mode and huma-readable name if present. (This is an aggregation of theRoute
level output, as each Service is a list ofRoute
s) -
trips_per_day_per_route_aggregated_per_stop_id_pair.csv
- pairs of stops that exist as end-points ofRoute
s. Number of trains between those stops per mode, a record ofRoute
s in common. Respects stop IDs, human-readable names included but can be repeated if there are more stops inSchedule
with the same name (common for bigger stations). There is no directionality to the column namesstation_A
andstation_B
. The number given is betweenstation_A
andstation_B
andstation_B
andstation_A
w.r.t ID. Data is not repeated, it could be that if an expected station is not instation_A
column, it's in thestation_B
column instead. -
trips_per_day_per_route_aggregated_per_stop_name_pair.csv
- The same astrips_per_day_per_route_aggregated_per_stop_id_pair.csv
, but aggregated by stop names, so does not respect stop IDs. Again, The number given is betweenstation_A_name
andstation_B_name
andstation_B_name
andstation_A_name
w.r.t stop names. Data is not repeated, it could be that if an expected station is not instation_A_name
column, it's in thestation_B_name
column instead.
-
-
schedule_network_routes_geodataframe.geojson
- GeoJSON output, rows exist for eachRoute
that has non emptyroute
attribute - links in the network referring to the network route of thatRoute
. The geometry is a combined geometry of all links referenced in the route. Columns/Fields relating to corresponding service, route IDs and mode, as well as human-readable name (if available) are included.
You can also generate standard outputs for schedule only: n.schedule.generate_standard_outputs(output_dir='path/to/standard_outputs', gtfs_day='19700101')