From c3136852ffc798359f1d95313bfd38c947badbd8 Mon Sep 17 00:00:00 2001 From: Josh Cunningham Date: Tue, 3 Sep 2024 16:06:03 -0500 Subject: [PATCH 1/2] Fix regex to prevent double matching flowpaths and flowpath_attributes --- src/troute-network/troute/HYFeaturesNetwork.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/troute-network/troute/HYFeaturesNetwork.py b/src/troute-network/troute/HYFeaturesNetwork.py index fb8a19225..15a170a4b 100644 --- a/src/troute-network/troute/HYFeaturesNetwork.py +++ b/src/troute-network/troute/HYFeaturesNetwork.py @@ -35,8 +35,9 @@ def read_geopkg(file_path, compute_parameters, waterbody_parameters, cpu_pool): available_layers = fiona.listlayers(file_path) # patterns for the layers we want to find + # $ in flowpaths to avoid double matching with flowpath_attributes layer_patterns = { - 'flowpaths': r'flow[-_]?paths?|flow[-_]?lines?', + 'flowpaths': r'flow[-_]?paths?$|flow[-_]?lines?$', 'flowpath_attributes': r'flow[-_]?path[-_]?attributes?|flow[-_]?line[-_]?attributes?', 'lakes': r'lakes?', 'nexus': r'nexus?', From eeacca3744a1f4e31b7ae5c780ed085a5d462e56 Mon Sep 17 00:00:00 2001 From: Josh Cunningham Date: Tue, 3 Sep 2024 16:10:40 -0500 Subject: [PATCH 2/2] Fix flowpath dataframe merging --- .../troute/HYFeaturesNetwork.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/troute-network/troute/HYFeaturesNetwork.py b/src/troute-network/troute/HYFeaturesNetwork.py index 15a170a4b..32a4ac25b 100644 --- a/src/troute-network/troute/HYFeaturesNetwork.py +++ b/src/troute-network/troute/HYFeaturesNetwork.py @@ -93,13 +93,18 @@ def read_layer(layer_name): if 'link' in flowpath_attributes_df.columns: flowpath_attributes_df.rename(columns={'link': 'id'}, inplace=True) - # Merge flowpaths and flowpath_attributes - flowpaths = pd.merge( - flowpaths_df, - flowpath_attributes_df, - on='id', - how='inner' - ) + # Merge flowpaths and flowpath_attributes + if not flowpath_attributes_df.empty and not flowpaths_df.empty: + flowpaths = pd.merge( + flowpaths_df, + flowpath_attributes_df, + on='id', + how='inner' + ) + elif not flowpaths_df.empty: + flowpaths = flowpaths_df + elif not flowpath_attributes_df.empty: + flowpaths = flowpath_attributes_df lakes = table_dict.get('lakes', pd.DataFrame()) network = table_dict.get('network', pd.DataFrame())