Skip to content

Commit

Permalink
fixes order of disconnected components removal
Browse files Browse the repository at this point in the history
  • Loading branch information
songololo committed Nov 29, 2024
1 parent 1ca5d42 commit 3b77530
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ cityseer/_version.py
# temporary working directories
**/temp/**

# geopackages
*.gpkg
*.gpkg*

# uv
uv.lock

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cityseer"
version = '4.16.26'
version = '4.16.27'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.14"
Expand Down
12 changes: 6 additions & 6 deletions pysrc/cityseer/tools/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,22 +289,22 @@ def nx_remove_dangling_nodes(

# finds connected components - this behaviour changed with networkx v2.4
# do this after to prevent creation of new isolated components after dropping tunnels
connected_components: list[list[NodeKey]] = list(nx.algorithms.components.connected_components(g_multi_copy))
connected_components = list(nx.algorithms.components.connected_components(g_multi_copy))
# keep connected components greater than remove_disconnected param
large_components = [component for component in connected_components if len(component) >= remove_disconnected]
large_subgraphs = [nx.MultiGraph(g_multi_copy.subgraph(component)) for component in large_components]
large_subgraphs = [g_multi_copy.subgraph(component).copy() for component in large_components]
if not large_subgraphs:
logger.warning(
f"An empty graph will be returned because all graph components had fewer than {remove_disconnected} nodes. "
"Decrease the remove_disconnected parameter or set to zero to retain graph components."
)
# make a copy of the graph using the largest component
g_multi_copy = nx.MultiGraph()
g_multi_large = nx.MultiGraph()
for subgraph in large_subgraphs:
g_multi_copy.add_nodes_from(subgraph.nodes(data=True))
g_multi_copy.add_edges_from(subgraph.edges(data=True))
g_multi_large.add_nodes_from(subgraph.nodes(data=True))
g_multi_large.add_edges_from(subgraph.edges(data=True))

return g_multi_copy
return g_multi_large


def _extract_tags_to_set(
Expand Down
3 changes: 2 additions & 1 deletion pysrc/cityseer/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,9 @@ def _auto_clean_network(
)
G = graphs.nx_remove_filler_nodes(G)
G = graphs.nx_merge_parallel_edges(G, merge_edges_by_midline=True, contains_buffer_dist=50)
G = graphs.nx_remove_dangling_nodes(G, despine=25)
G = graphs.nx_iron_edges(G, min_self_loop_length=100, max_foot_tunnel_length=50)
# do this last to clean up any orphaned sub components
G = graphs.nx_remove_dangling_nodes(G, despine=25)

return G

Expand Down

0 comments on commit 3b77530

Please sign in to comment.