From c4fa6dcf9f7892fa93ef2510f4382e330265c024 Mon Sep 17 00:00:00 2001 From: Stephen Knox Date: Thu, 26 Sep 2024 11:36:21 +0100 Subject: [PATCH] Remove non-alpha characters from node type names coming from the template, and make them lower caase, allowing for the template to display more user-friendly names, while maintaining compatibility in pywr --- hydra_pywr/exporter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hydra_pywr/exporter.py b/hydra_pywr/exporter.py index 03a0807..5cf1230 100644 --- a/hydra_pywr/exporter.py +++ b/hydra_pywr/exporter.py @@ -695,7 +695,8 @@ def build_node_and_references(self, nodedata, pywr_node_type): resource_attribute['name'] = f"__{nodedata['name']}__:{attribute_name}" self.data.attributes.append(resource_attribute) - nodedata["type"] = pywr_node_type['name'] + #Ensure the node type name is lower case, and has all spaces and non-characters removed. + nodedata["type"] = re.sub(r'[^a-zA-Z]', '', pywr_node_type['name']).lower() node_attr_data = {a:v for a,v in nodedata.items() if a not in self.exclude_hydra_attrs} position = {"geographic": [ nodedata.get("x",0), nodedata.get("y",0) ]} node_attr_data["position"] = position