From 8a893285706622fdf8d9fad9ac6a31ad95b0c878 Mon Sep 17 00:00:00 2001 From: Dobson Date: Mon, 29 Apr 2024 15:18:30 +0100 Subject: [PATCH] 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 e3600c99..c1184cf2 100644 --- a/swmmanywhere/geospatial_utilities.py +++ b/swmmanywhere/geospatial_utilities.py @@ -946,12 +946,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 cb46bcca..ce78d63b 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',