diff --git a/examples/run_power_flow.py b/examples/run_power_flow.py index 4c77d74..7d8b91a 100644 --- a/examples/run_power_flow.py +++ b/examples/run_power_flow.py @@ -6,7 +6,7 @@ import requests import glob -from cgmes_pgm_converter import System +from src.pgm_service.power_grid.cgmes_pgm_converter import System logging.basicConfig(filename='run_powerflow.log', level=logging.INFO, filemode='w') diff --git a/pyproject.toml b/pyproject.toml index 747d9ad..372070b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ classifiers=[ "Operating System :: MacOS", "Topic :: Scientific/Engineering :: Physics", ] -requires-python = ">=3.12" +requires-python = ">=3.10" dependencies = [ "numpy>=1.20", "power_grid_model>=1.6", diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/cgmes_pgm_converter.py b/src/pgm_service/power_grid/cgmes_pgm_converter.py similarity index 60% rename from examples/cgmes_pgm_converter.py rename to src/pgm_service/power_grid/cgmes_pgm_converter.py index 8bc624a..9cee8a1 100644 --- a/examples/cgmes_pgm_converter.py +++ b/src/pgm_service/power_grid/cgmes_pgm_converter.py @@ -23,8 +23,8 @@ def load_cim_data(self, res): # list_SvPowerFlow = [elem for elem in res.values() if elem.__class__.__name__ == "SvPowerFlow"] # list_EnergySources = [elem for elem in res.values() if elem.__class__.__name__ == "EnergySource"] # list_EnergyConsumer = [elem for elem in res.values() if elem.__class__.__name__ == "EnergyConsumer"] - # list_ACLineSegment = [elem for elem in res.values() if elem.__class__.__name__ == "ACLineSegment"] - # list_Terminals = [elem for elem in res.values() if elem.__class__.__name__ == "Terminal"] + list_ACLineSegment = [elem for elem in res['topology'].values() if elem.__class__.__name__ == "ACLineSegment"] + list_Terminals = [elem for elem in res['topology'].values() if elem.__class__.__name__ == "Terminal"] # list_Terminals_ES = [elem for elem in list_Terminals if # elem.ConductingEquipment.__class__.__name__ == "EnergySource"] # list_Terminals_EC = [elem for elem in list_Terminals if @@ -35,11 +35,16 @@ def load_cim_data(self, res): self.nodes.append(TPNode.mRID) self.voltages.append(dict_VoltageLevel[TPNode]) - # # create branches type ACLineSegment - # for ACLineSegment in list_ACLineSegment: - # self.lines[ACLineSegment] + # create branches type ACLineSegment + for ACLineSegment in list_ACLineSegment: + uuid_ACLineSegment = ACLineSegment.mRID + connected_nodes = self._get_nodes(list_Terminals, uuid_ACLineSegment) + node_ids = list[connected_nodes.keys()] + status = list[connected_nodes.values()] + # self.lines[ACLineSegment.mRID] = {"from_node": node_ids[0], + # "to_node": node_ids[1]} - # line = initialize_array("input", "line", len(self.lines)) + line = initialize_array("input", "line", len(self.lines)) # line["id"] = # line["from_node"] = # line["to_node"] = @@ -60,3 +65,23 @@ def create_pgm_input(self): print("debug") return {"node": node} + + def _get_nodes(self, list_Terminals, elem_uuid): + start_node_uuid = None + end_node_uuid = None + start_node_connected = None + end_node_connected = None + + for terminal in list_Terminals: + if terminal.ConductingEquipment.mRID != elem_uuid: + continue + sequence_number = terminal.sequenceNumber + if sequence_number == 1: + start_node_uuid = terminal.TopologicalNode.mRID + start_node_connected = terminal.connected + elif sequence_number == 2: + end_node_uuid = terminal.TopologicalNode.mRID + end_node_connected = terminal.connected + + + return {start_node_uuid: start_node_connected, end_node_uuid: end_node_connected}