feat(networks): add load_osm_network and load_sumo_network#154
feat(networks): add load_osm_network and load_sumo_network#154FrancescoUmberto wants to merge 1 commit into
Conversation
|
@FrancescoUmberto thanks so much for the pull request! First of all, I like the idea of enhancing the data source inputs.
I'm looking forward to hearing more info and your thoughts for the next actions! |
|
Thank you for the feedback, your points make sense, and I agree that clarifying the architecture before moving further is the right next step. Regarding the For the module location, your suggestion to place the SUMO importer under the transportation package is reasonable. Since this work is specifically about importing transportation-related sources, moving it into that namespace would align better with the existing package structure and avoid introducing an unnecessary /network module. I also agree on the naming concern around the term network. To keep the terminology consistent with the rest of the package, I will avoid using network where graph is the intended concept. In practice, I am planning to separate the workflow into two explicit steps:
This should make the responsibilities clearer than a single monolithic On the graph definition itself, my current assumption is:
This seems to be the most natural mapping into the existing For the loading stage, I am considering keeping the preprocessing layer lightweight by converting the raw XML into intermediate structured objects first (for example dictionaries or tabular objects), so the graph construction stage can remain independent from the source format. During graph construction I will reuse the existing public graph APIs and internal helpers as much as possible so that we avoid duplicating logic already implemented elsewhere in My proposed next steps are:
If this direction matches your expectations, I can prepare the revised structure accordingly and share the updated implementation for review. |
|
Thanks for the further comments! I understood that the nodes and edges would be junctions and their segments, like a primary graph of streets. I assume the users would use SUMO to obtain the simulation outcomes with summary metrics (e.g., simulated traffics, travel times, waiting times, etc.). If so, could they be mapped to the nodes and edges as their attributes? I think the expectation of SUMO users to use If these design is applied, the funciton could be |
|
We can work on this. I will explain you better what's in my mind by the end of this weekend. I anticipate that it is possible to add simulation data to the graph. |
|
Good morning. I agree that the real value here is not only converting the SUMO road topology into a c2g graph, but also making the simulation outputs available as graph attributes so that users can immediately reuse the resulting graph for downstream spatial and network analysis. Based on your suggestion, the graph structure would remain:
and the simulation metrics could then be attached to those nodes or edges as attributes, for example:
This would make the resulting graph directly usable with libraries such as GeoPandas, NetworkX, or PyTorch Geometric without requiring users to manually remap the SUMO outputs afterward. Initial implementation scope
The reason is that The workflow would then be separated into two stages:
That would keep the loading logic separate from the graph construction logic while leaving room to support other simulation frameworks later, such as MATSim, under the same higher-level interface. At the end of this initial step, I expect this results: raw_data = load_sumo_data(network_file, metrics_file)
graph = simulation_summary_graph(raw_data)For a first implementation, my suggestion would be:
Once that foundation is in place, we could then extend the importer to support more complex SUMO outputs such as If this scope sounds good, I can prepare the revised structure around that initial implementation. |
|
That sounds nice to me! If so, Parse raw SUMO outputs into a standardised, simulator-agnostic intermediate representation, so that future loaders for other simulators (e.g., { "edges": "node_metrics": "edge_metrics": "metadata": Then, One thing to note that It's my apologies for confusion, but previously I said these operations could be in Does this direction match what you had in mind? |
Description
This PR adds a new networks module that enables importing road networks from two widely-used file formats: OpenStreetMap (.osm, .osm.gz) and SUMO (.net.xml).
Previously, city2graph could only load geospatial data from Overture Maps (via API) or GTFS feeds. Users working with locally stored OSM exports or SUMO simulation networks had no supported import path.
Approach:
city2graph/networks.pyexposing two public functions that follow the same (nodes_gdf,edges_gdf) |nx.Graphconvention used throughout the library (matchingtravel_summary_graphintransportation.py)load_osm_network(path, *, retain_all, simplify, as_nx, directed)- delegates parsing toosmnx.graph_from_xml(already a core dependency), then normalises the result into indexedGeoDataFrameswith `CRS EPSG:4326load_sumo_network(path, *, as_nx, directed)- parses.net.xmlusingstdlib xml.etree.ElementTree(no new hard dependency), extracts junctions as nodes and edges with lane-level attributes, and reprojects from SUMO's local Cartesian CRS toEPSG:4326viapyproj(transitive dependency through geopandas)sumo = ["sumolib>=1.20.0"]added topyproject.tomlfor users who need advanced SUMO network introspection beyond what the XML parser providesdirectedandas_nxflags, skip internal SUMO elements, and fall back gracefully when projection or geometry data is missingRelated Issues
N/A
Checklist