From fec22e2fac3e17472cde29ec08f3b7b45cf1f08c Mon Sep 17 00:00:00 2001 From: Dobson Date: Mon, 29 Apr 2024 14:00:15 +0100 Subject: [PATCH 01/21] Update geospatial_utilities.py avoid double counting --- swmmanywhere/geospatial_utilities.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swmmanywhere/geospatial_utilities.py b/swmmanywhere/geospatial_utilities.py index 517a063d..0cdcc747 100644 --- a/swmmanywhere/geospatial_utilities.py +++ b/swmmanywhere/geospatial_utilities.py @@ -732,9 +732,12 @@ def derive_rc(subcatchments: gpd.GeoDataFrame, """ # Map buffered streets and buildings to subcatchments subcat_tree = subcatchments.sindex - impervious = gpd.overlay(streetcover[['geometry']], - building_footprints[['geometry']], - how='union') + impervious = gpd.GeoDataFrame( + pd.concat([building_footprints[['geometry']], + streetcover[['geometry']]]), + crs = building_footprints.crs + ) + impervious = impervious.dissolve() bf_pidx, sb_pidx = subcat_tree.query(impervious.geometry, predicate='intersects') sb_idx = subcatchments.iloc[sb_pidx].index From 562ef19a2e3c644da7424d49163f7e032909609b Mon Sep 17 00:00:00 2001 From: Dobson Date: Mon, 29 Apr 2024 14:46:13 +0100 Subject: [PATCH 02/21] Update geospatial_utilities.py Improve efficiency of area calc --- swmmanywhere/geospatial_utilities.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/swmmanywhere/geospatial_utilities.py b/swmmanywhere/geospatial_utilities.py index 0cdcc747..c5ebc782 100644 --- a/swmmanywhere/geospatial_utilities.py +++ b/swmmanywhere/geospatial_utilities.py @@ -699,12 +699,6 @@ def remove_(mp): return remove_zero_area_subareas(mp, removed_subareas) polys_gdf['width'] = polys_gdf['area'].div(np.pi).pow(0.5) return polys_gdf -def _intersection_area(gdf1: gpd.GeoDataFrame, gdf2: gpd.GeoDataFrame)-> np.array: - return shapely.area( - shapely.intersection( - gdf1.geometry.to_numpy(), - gdf2.geometry.to_numpy())) - def derive_rc(subcatchments: gpd.GeoDataFrame, building_footprints: gpd.GeoDataFrame, streetcover: gpd.GeoDataFrame) -> gpd.GeoDataFrame: @@ -728,7 +722,7 @@ def derive_rc(subcatchments: gpd.GeoDataFrame, 'geometry', 'area', 'id', 'impervious_area', and 'rc'. Author: - @cheginit + @cheginit, @barneydobson """ # Map buffered streets and buildings to subcatchments subcat_tree = subcatchments.sindex @@ -737,7 +731,6 @@ def derive_rc(subcatchments: gpd.GeoDataFrame, streetcover[['geometry']]]), crs = building_footprints.crs ) - impervious = impervious.dissolve() bf_pidx, sb_pidx = subcat_tree.query(impervious.geometry, predicate='intersects') sb_idx = subcatchments.iloc[sb_pidx].index @@ -745,18 +738,24 @@ def derive_rc(subcatchments: gpd.GeoDataFrame, # Calculate impervious area and runoff coefficient (rc) subcatchments["impervious_area"] = 0.0 - # Calculate all intersection-impervious areas - intersection_area = _intersection_area(subcatchments.iloc[sb_pidx], - impervious.iloc[bf_pidx]) + # Calculate all intersection-impervious geometries + intersection_area = shapely.intersection( + subcatchments.iloc[sb_pidx].geometry.to_numpy(), + impervious.iloc[bf_pidx].geometry.to_numpy()) # Indicate which catchment each intersection is part of intersections = pd.DataFrame([{'sb_idx': ix, - 'impervious_area': ia} + 'impervious_geometry': ia} for ix, ia in zip(sb_idx, intersection_area)] ) # Aggregate by catchment - areas = intersections.groupby('sb_idx').sum() + areas = ( + intersections + .groupby('sb_idx') + .apply(shapely.ops.unary_union) + .apply(shapely.area) + ) # Store as impervious area in subcatchments subcatchments["impervious_area"] = 0 From af2b7a3e1b2d1c0e1a7c1ed69bee70b8b28e19d2 Mon Sep 17 00:00:00 2001 From: Dobson Date: Mon, 29 Apr 2024 15:18:30 +0100 Subject: [PATCH 03/21] improve node merging --- swmmanywhere/geospatial_utilities.py | 19 +++++++++++++++---- swmmanywhere/parameters.py | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/swmmanywhere/geospatial_utilities.py b/swmmanywhere/geospatial_utilities.py index eaf7eaee..ed8d511f 100644 --- a/swmmanywhere/geospatial_utilities.py +++ b/swmmanywhere/geospatial_utilities.py @@ -791,12 +791,23 @@ def merge_points(coordinates: list[tuple[float, float]], # Merge pairs into families of points that are all nearby families: list = [] + for pair in pairs: - for family in families: - if pair[0] in family or pair[1] in family: - family.update(pair) - break + matched_families = [family for family in families + if pair[0] in family or pair[1] in family] + + if matched_families: + # Merge all matched families and add the current pair + new_family = set(pair) + for family in matched_families: + new_family.update(family) + + # Remove the old families and add the newly formed one + for family in matched_families: + families.remove(family) + families.append(new_family) else: + # No matching family found, so create a new one families.append(set(pair)) # Create a mapping of the original point to the merged point diff --git a/swmmanywhere/parameters.py b/swmmanywhere/parameters.py index d829e766..1bf37cf3 100644 --- a/swmmanywhere/parameters.py +++ b/swmmanywhere/parameters.py @@ -51,7 +51,7 @@ class SubcatchmentDerivation(BaseModel): unit = "m", description = "Distance to split streets into segments.") - node_merge_distance: float = Field(default = 20, + node_merge_distance: float = Field(default = 10, ge = 1, le = 20, # This should probably be less than max_street_length unit = 'm', From a00fc5d9ff75229403bf12742e84b27547142158 Mon Sep 17 00:00:00 2001 From: Dobson Date: Mon, 29 Apr 2024 15:18:30 +0100 Subject: [PATCH 04/21] improve node merging --- swmmanywhere/geospatial_utilities.py | 19 +++++++++++++++---- swmmanywhere/parameters.py | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/swmmanywhere/geospatial_utilities.py b/swmmanywhere/geospatial_utilities.py index c5ebc782..941ecf52 100644 --- a/swmmanywhere/geospatial_utilities.py +++ b/swmmanywhere/geospatial_utilities.py @@ -897,12 +897,23 @@ def merge_points(coordinates: list[tuple[float, float]], # Merge pairs into families of points that are all nearby families: list = [] + for pair in pairs: - for family in families: - if pair[0] in family or pair[1] in family: - family.update(pair) - break + matched_families = [family for family in families + if pair[0] in family or pair[1] in family] + + if matched_families: + # Merge all matched families and add the current pair + new_family = set(pair) + for family in matched_families: + new_family.update(family) + + # Remove the old families and add the newly formed one + for family in matched_families: + families.remove(family) + families.append(new_family) else: + # No matching family found, so create a new one families.append(set(pair)) # Create a mapping of the original point to the merged point diff --git a/swmmanywhere/parameters.py b/swmmanywhere/parameters.py index 3c8a3aa1..535cd318 100644 --- a/swmmanywhere/parameters.py +++ b/swmmanywhere/parameters.py @@ -51,7 +51,7 @@ class SubcatchmentDerivation(BaseModel): unit = "m", description = "Distance to split streets into segments.") - node_merge_distance: float = Field(default = 30, + node_merge_distance: float = Field(default = 10, ge = 1, le = 40, unit = 'm', From bd96e128044680276786d540cfd08a0263fecb5c Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 30 Apr 2024 09:16:13 +0100 Subject: [PATCH 05/21] Update graph_utilities.py Fix new double_directed --- swmmanywhere/graph_utilities.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index f24b7e85..535c1864 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -338,8 +338,22 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: Returns: G (nx.Graph): A graph """ + # Convert to directed G_new = G.copy() G_new = nx.MultiDiGraph(G_new) + + # MultiDiGraph adds edges in both directions, but rivers (and geometries) + # are only in one direction. So we remove the reverse edges and add them + # back in with the correct geometry. + # This assumes that 'id' is of format 'start-end' (see assign_id) + arcs_to_remove = [(u,v) for u,v,d in G_new.edges(data=True) + if f'{u}-{v}' != d.get('id')] + + # Remove the reverse edges + for u, v in arcs_to_remove: + G_new.remove_edge(u, v) + + # Add in reversed edges for streets only and with geometry for u, v, data in G.edges(data=True): include = data.get('edge_type', True) if isinstance(include, str): From e9ea99f27b351063d1629334bf57751d0f39387f Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 30 Apr 2024 09:16:13 +0100 Subject: [PATCH 06/21] Update graph_utilities.py Fix new double_directed --- swmmanywhere/graph_utilities.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 7b06b884..3e687c3a 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -371,8 +371,22 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: Returns: G (nx.Graph): A graph """ + # Convert to directed G_new = G.copy() G_new = nx.MultiDiGraph(G_new) + + # MultiDiGraph adds edges in both directions, but rivers (and geometries) + # are only in one direction. So we remove the reverse edges and add them + # back in with the correct geometry. + # This assumes that 'id' is of format 'start-end' (see assign_id) + arcs_to_remove = [(u,v) for u,v,d in G_new.edges(data=True) + if f'{u}-{v}' != d.get('id')] + + # Remove the reverse edges + for u, v in arcs_to_remove: + G_new.remove_edge(u, v) + + # Add in reversed edges for streets only and with geometry for u, v, data in G.edges(data=True): include = data.get('edge_type', True) if isinstance(include, str): From 7a80be0c0f5c39706a5d4bb18bf69a585f96b4be Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 30 Apr 2024 09:37:33 +0100 Subject: [PATCH 07/21] Update demo_config.yml --- tests/test_data/demo_config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_data/demo_config.yml b/tests/test_data/demo_config.yml index 7984230f..68ecfe77 100644 --- a/tests/test_data/demo_config.yml +++ b/tests/test_data/demo_config.yml @@ -20,6 +20,7 @@ graphfcn_list: - to_undirected - split_long_edges - merge_nodes + - assign_id - calculate_contributing_area - set_elevation - double_directed From 39c6771a875f376d5d5660590b05f530e06d3763 Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 30 Apr 2024 09:54:58 +0100 Subject: [PATCH 08/21] Update graph_utilities.py another bug --- swmmanywhere/graph_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 3e687c3a..1a3ca42b 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -391,7 +391,7 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: include = data.get('edge_type', True) if isinstance(include, str): include = include == 'street' - if ((v, u) not in G.edges) & include: + if ((v, u) not in G_new.edges) & include: reverse_data = data.copy() reverse_data['id'] = f"{data['id']}.reversed" new_geometry = shapely.LineString( From 6c71435a2bc01090178e92731973e3da78cd369f Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 30 Apr 2024 09:54:58 +0100 Subject: [PATCH 09/21] Update graph_utilities.py another bug --- swmmanywhere/graph_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 535c1864..2b190671 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -358,7 +358,7 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: include = data.get('edge_type', True) if isinstance(include, str): include = include == 'street' - if ((v, u) not in G.edges) & include: + if ((v, u) not in G_new.edges) & include: reverse_data = data.copy() reverse_data['id'] = f"{data['id']}.reversed" G_new.add_edge(v, u, **reverse_data) From 2968a0f42989958c51735667e7996f45f214a27a Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 30 Apr 2024 14:22:38 +0100 Subject: [PATCH 10/21] Update graph_utilities.py vectorise some operations --- swmmanywhere/graph_utilities.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 2b190671..3225173a 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -410,23 +410,15 @@ def __call__(self, """ max_length = subcatchment_derivation.max_street_length - new_edges = {} - new_nodes = set() - # Split edges - for u, v, d in G.edges(data=True): - # Get new geometry - new_linestring = shapely.segmentize(d['geometry'], max_length) - - # Create a node at each linestring segment - new_nodes.update( - [(x,y) for x,y in - np.reshape( - shapely.get_coordinates(new_linestring), - (-1, 2)) - ] - ) - + new_linestrings = shapely.segmentize([d['geometry'] + for u,v,d in G.edges(data=True)], + max_length) + new_nodes = shapely.get_coordinates(new_linestrings) + + + new_edges = {} + for new_linestring, (u,v,d) in zip(new_linestrings, G.edges(data=True)): # Create an arc for each segment for start, end in zip(new_linestring.coords[:-1], new_linestring.coords[1:]): @@ -443,7 +435,7 @@ def __call__(self, nx.set_edge_attributes(new_graph, new_edges) nx.set_node_attributes( new_graph, - {node: {'x': node[0], 'y': node[1]} for node in new_nodes} + {tuple(node): {'x': node[0], 'y': node[1]} for node in new_nodes} ) return nx.relabel_nodes(new_graph, {node: ix for ix, node in enumerate(new_graph.nodes)} From 41a1cb8437491f8e6a7dda5fbcc5eae26648a2a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 20:22:33 +0000 Subject: [PATCH 11/21] Bump mypy from 1.8.0 to 1.10.0 Bumps [mypy](https://github.com/python/mypy) from 1.8.0 to 1.10.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.8.0...v1.10.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 4bad4a92..3e3d2c37 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -134,7 +134,7 @@ matplotlib==3.8.2 # swmmanywhere (pyproject.toml) multiprocess==0.70.15 # via salib -mypy==1.8.0 +mypy==1.10.0 # via # pytest-mypy # swmmanywhere (pyproject.toml) From 139632776e5b667ba9097896961db0447d3296e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 20:22:47 +0000 Subject: [PATCH 12/21] Bump pydantic-core from 2.14.6 to 2.18.2 Bumps [pydantic-core](https://github.com/pydantic/pydantic-core) from 2.14.6 to 2.18.2. - [Release notes](https://github.com/pydantic/pydantic-core/releases) - [Commits](https://github.com/pydantic/pydantic-core/compare/v2.14.6...v2.18.2) --- updated-dependencies: - dependency-name: pydantic-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 4bad4a92..705973f3 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -217,7 +217,7 @@ pyarrow==14.0.2 # via swmmanywhere (pyproject.toml) pydantic==2.5.3 # via swmmanywhere (pyproject.toml) -pydantic-core==2.14.6 +pydantic-core==2.18.2 # via pydantic pyparsing==3.1.1 # via diff --git a/requirements.txt b/requirements.txt index 144d08cf..2f801044 100644 --- a/requirements.txt +++ b/requirements.txt @@ -177,7 +177,7 @@ pyarrow==14.0.2 # via swmmanywhere (pyproject.toml) pydantic==2.5.3 # via swmmanywhere (pyproject.toml) -pydantic-core==2.14.6 +pydantic-core==2.18.2 # via pydantic pyparsing==3.1.1 # via From 1697474a9075029a811715fffb0cecee02dd16a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 20:22:53 +0000 Subject: [PATCH 13/21] Bump swmm-toolkit from 0.15.3 to 0.15.5 Bumps [swmm-toolkit](https://github.com/pyswmm/swmm-python) from 0.15.3 to 0.15.5. - [Release notes](https://github.com/pyswmm/swmm-python/releases) - [Commits](https://github.com/pyswmm/swmm-python/compare/v0.15.3...v0.15.5) --- updated-dependencies: - dependency-name: swmm-toolkit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 4bad4a92..ab0168e6 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -301,7 +301,7 @@ smmap==5.0.1 # via gitdb snuggs==1.4.7 # via rasterio -swmm-toolkit==0.15.3 +swmm-toolkit==0.15.5 # via pyswmm tifffile==2024.1.30 # via scikit-image diff --git a/requirements.txt b/requirements.txt index 144d08cf..2dc6bcdb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -243,7 +243,7 @@ smmap==5.0.1 # via gitdb snuggs==1.4.7 # via rasterio -swmm-toolkit==0.15.3 +swmm-toolkit==0.15.5 # via pyswmm tifffile==2024.1.30 # via scikit-image From cdbdd4b45dbf9e8b9e4c38b3c614f6add0b9a76a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 20:23:03 +0000 Subject: [PATCH 14/21] Bump lazy-loader from 0.3 to 0.4 Bumps [lazy-loader](https://github.com/scientific-python/lazy_loader) from 0.3 to 0.4. - [Release notes](https://github.com/scientific-python/lazy_loader/releases) - [Changelog](https://github.com/scientific-python/lazy_loader/blob/main/CHANGELOG.md) - [Commits](https://github.com/scientific-python/lazy_loader/compare/v0.3...v0.4) --- updated-dependencies: - dependency-name: lazy-loader dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- dev-requirements.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 4bad4a92..6cceb11b 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -122,7 +122,7 @@ julian==0.14 # via pyswmm kiwisolver==1.4.5 # via matplotlib -lazy-loader==0.3 +lazy-loader==0.4 # via scikit-image llvmlite==0.41.1 # via numba diff --git a/requirements.txt b/requirements.txt index 144d08cf..9f4e39e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -100,7 +100,7 @@ julian==0.14 # via pyswmm kiwisolver==1.4.5 # via matplotlib -lazy-loader==0.3 +lazy-loader==0.4 # via scikit-image llvmlite==0.41.1 # via numba From 8bba151dbf7da172472c0e3811093b855027252c Mon Sep 17 00:00:00 2001 From: Dobson Date: Fri, 3 May 2024 13:03:34 +0100 Subject: [PATCH 15/21] remove need for geometry after merge-nodes --- swmmanywhere/graph_utilities.py | 22 +++++++++++----------- tests/test_data/demo_config.yml | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 3225173a..63407cf2 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -183,7 +183,8 @@ def iterate_graphfcns(G: nx.Graph, G = graphfcns[function](G, addresses = addresses, **params) logger.info(f"graphfcn: {function} completed.") if verbose: - save_graph(G, addresses.model / f"{function}_graph.json") + save_graph(graphfcns.fix_geometries(G), + addresses.model / f"{function}_graph.json") return G @register_graphfcn @@ -424,7 +425,6 @@ def __call__(self, new_linestring.coords[1:]): geom = shapely.LineString([start, end]) new_edges[(start, end, 0)] = {**d, - 'geometry' : geom, 'length' : geom.length } @@ -494,12 +494,6 @@ def __call__(self, self_loops = list(nx.selfloop_edges(G)) G.remove_edges_from(self_loops) - # Recalculate geometries - for u, v, data in G.edges(data=True): - data['geometry'] = shapely.LineString([(G.nodes[u]['x'], - G.nodes[u]['y']), - (G.nodes[v]['x'], - G.nodes[v]['y'])]) return G @register_graphfcn @@ -522,10 +516,16 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: """ G = G.copy() for u, v, data in G.edges(data=True): - start_point_node = (G.nodes[u]['x'], G.nodes[u]['y']) - start_point_edge = data['geometry'].coords[0] + if not data.get('geometry', None): + start_point_edge = (None,None) + end_point_edge = (None,None) + else: + start_point_edge = data['geometry'].coords[0] + end_point_edge = data['geometry'].coords[-1] + + start_point_node = (G.nodes[u]['x'], G.nodes[u]['y']) end_point_node = (G.nodes[v]['x'], G.nodes[v]['y']) - end_point_edge = data['geometry'].coords[-1] + if (start_point_edge == end_point_node) & \ (end_point_edge == start_point_node): data['geometry'] = data['geometry'].reverse() diff --git a/tests/test_data/demo_config.yml b/tests/test_data/demo_config.yml index 68ecfe77..a130b1e6 100644 --- a/tests/test_data/demo_config.yml +++ b/tests/test_data/demo_config.yml @@ -31,6 +31,7 @@ graphfcn_list: - identify_outlets - derive_topology - pipe_by_pipe + - fix_geometries - assign_id metric_list: - nc_deltacon0 From 59dea947089b0f5fd45d1e73a4ef00497e1cf8f9 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 3 May 2024 13:05:27 +0100 Subject: [PATCH 16/21] Update swmmanywhere/graph_utilities.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Diego Alonso Álvarez <6095790+dalonsoa@users.noreply.github.com> --- swmmanywhere/graph_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 63407cf2..7b6e691c 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -341,7 +341,7 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: """ # Convert to directed G_new = G.copy() - G_new = nx.MultiDiGraph(G_new) + G_new = nx.MultiDiGraph(G.copy()) # MultiDiGraph adds edges in both directions, but rivers (and geometries) # are only in one direction. So we remove the reverse edges and add them From f4b173e2c053086f56a8a19153285965e09a39ad Mon Sep 17 00:00:00 2001 From: Dobson Date: Fri, 3 May 2024 13:09:19 +0100 Subject: [PATCH 17/21] Update dev-requirements.txt --- dev-requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 4bad4a92..a4ecf180 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -63,9 +63,7 @@ colorama==0.4.6 contourpy==1.2.0 # via matplotlib coverage[toml]==7.3.2 - # via - # coverage - # pytest-cov + # via pytest-cov cramjam==2.7.0 # via fastparquet cycler==0.12.1 @@ -229,7 +227,9 @@ pyproj==3.6.1 # pysheds # rioxarray pyproject-hooks==1.0.0 - # via build + # via + # build + # pip-tools pysheds==0.3.5 # via swmmanywhere (pyproject.toml) pyswmm==1.5.1 From 400be9861578bcdfe4668f74f851104a43b11bb1 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 3 May 2024 13:21:33 +0100 Subject: [PATCH 18/21] Update dev-requirements.txt --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index a8fadc72..f8508132 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -217,7 +217,7 @@ pyarrow==14.0.2 # via swmmanywhere (pyproject.toml) pydantic==2.5.3 # via swmmanywhere (pyproject.toml) -pydantic-core==2.18.2 +pydantic-core==2.14.6 # via pydantic pyparsing==3.1.1 # via From 57f28e85f091c54d00d55d95a49fac97420557f3 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 3 May 2024 13:21:54 +0100 Subject: [PATCH 19/21] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f76b7190..ba74d2f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -177,7 +177,7 @@ pyarrow==14.0.2 # via swmmanywhere (pyproject.toml) pydantic==2.5.3 # via swmmanywhere (pyproject.toml) -pydantic-core==2.18.2 +pydantic-core==2.14.6 # via pydantic pyparsing==3.1.1 # via From a605a946c4cdc3e2689363455c7c3845433059ba Mon Sep 17 00:00:00 2001 From: Dobson Date: Fri, 3 May 2024 13:25:16 +0100 Subject: [PATCH 20/21] Update demo_config.yml --- tests/test_data/demo_config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_data/demo_config.yml b/tests/test_data/demo_config.yml index cd7e1bb3..fb9d769d 100644 --- a/tests/test_data/demo_config.yml +++ b/tests/test_data/demo_config.yml @@ -32,6 +32,7 @@ graphfcn_list: - identify_outlets # Identify potential street->river outlets - derive_topology # Shortest path to give network topology - pipe_by_pipe # Design pipe diameters and depths + - fix_geometries # Ensure geometries present before printing - assign_id # Final pass to ensure consistent 'id' and remove duplicates metric_list: - nc_deltacon0 From a08b9cd883836f8bf640c08f1ccb85bf645b4534 Mon Sep 17 00:00:00 2001 From: Dobson Date: Fri, 3 May 2024 13:32:19 +0100 Subject: [PATCH 21/21] update remove parlele --- swmmanywhere/graph_utilities.py | 4 ++-- tests/test_data/demo_config.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index c29b1275..ade8f7f8 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -222,8 +222,8 @@ def __call__(self, return G @register_graphfcn -class remove_isolated_nodes(BaseGraphFunction): - """remove_isolated_nodes class.""" +class remove_parallel_edges(BaseGraphFunction): + """remove_parallel_edges class.""" def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph: """Remove parallel edges from a street network. diff --git a/tests/test_data/demo_config.yml b/tests/test_data/demo_config.yml index fb9d769d..c9d166b5 100644 --- a/tests/test_data/demo_config.yml +++ b/tests/test_data/demo_config.yml @@ -17,6 +17,7 @@ graphfcn_list: - fix_geometries # Ensure consistent geometry directions - remove_non_pipe_allowable_links # Filter out things like bridges/motorways - calculate_streetcover # Create shapefile of impervious street cover + - remove_parallel_edges # Remove parallel edges retaining the shorter one - to_undirected # Convert graph to undirected to facilitate cleanup - split_long_edges # Set a maximum edge length - merge_nodes # Merge nodes that are too close together