From a00fc5d9ff75229403bf12742e84b27547142158 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 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',