Skip to content

Commit e9df881

Browse files
committed
more files
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent 4fc442c commit e9df881

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/power_grid_model_ds/_core/data_source/generator/arrays/node.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ class NodeGenerator(BaseGenerator):
1616
def run(self, amount: int, voltage_level: int = 10_500):
1717
"""Generate nodes in a grid with two possible load scenarios"""
1818
node_array = self.grid.node.__class__.zeros(amount)
19-
node_array.id = 1 + self.grid.max_id + np.arange(amount)
20-
node_array.u_rated = voltage_level
19+
node_array["id"] = 1 + self.grid.max_id + np.arange(amount)
20+
node_array["u_rated"] = voltage_level
2121

2222
load_low_array = self.grid.sym_load.__class__.zeros(amount)
23-
load_low_array.id = 1 + node_array.id.max() + np.arange(amount)
24-
load_low_array.node = node_array.id
25-
load_low_array.status = 1
23+
load_low_array["id"] = 1 + node_array["id"].max() + np.arange(amount)
24+
load_low_array["node"] = node_array["id"]
25+
load_low_array["status"] = 1
2626
load_high_array = self.grid.sym_load.__class__.zeros(amount)
27-
load_high_array.id = 1 + load_low_array.id.max() + np.arange(amount)
28-
load_high_array.node = node_array.id
29-
load_high_array.status = 1
27+
load_high_array["id"] = 1 + load_low_array["id"].max() + np.arange(amount)
28+
load_high_array["node"] = node_array["id"]
29+
load_high_array["status"] = 1
3030

3131
# power consumption in Watt
32-
load_low_array.p_specified = np.round(self.rng.normal(200_000, 150_000, amount))
33-
load_low_array.q_specified = np.round(self.rng.normal(20_000, 15_000, amount))
34-
load_high_array.p_specified = np.round(self.rng.normal(-100_000, 350_000, amount))
35-
load_high_array.q_specified = np.round(self.rng.normal(-5_000, 35_000, amount))
32+
load_low_array["p_specified"] = np.round(self.rng.normal(200_000, 150_000, amount))
33+
load_low_array["q_specified"] = np.round(self.rng.normal(20_000, 15_000, amount))
34+
load_high_array["p_specified"] = np.round(self.rng.normal(-100_000, 350_000, amount))
35+
load_high_array["q_specified"] = np.round(self.rng.normal(-5_000, 35_000, amount))
3636

3737
return node_array, load_low_array, load_high_array

src/power_grid_model_ds/_core/visualizer/parsers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def parse_node_array(nodes: NodeArray) -> list[dict[str, Any]]:
1818
columns = nodes.columns
1919
for node in nodes:
2020
cyto_elements = {"data": _array_to_dict(node, columns)}
21-
cyto_elements["data"]["id"] = str(node.id.item())
21+
cyto_elements["data"]["id"] = str(node["id"].item())
2222
cyto_elements["data"]["group"] = "node"
2323
if with_coords:
24-
cyto_elements["position"] = {"x": node.x.item(), "y": -node.y.item()} # invert y-axis for visualization
24+
y_value = -node["y"].item() # invert y-axis for visualization
25+
cyto_elements["position"] = {"x": node["x"].item(), "y": y_value}
2526
parsed_nodes.append(cyto_elements)
2627
return parsed_nodes
2728

@@ -46,9 +47,9 @@ def parse_branch3_array(branches: Branch3Array, group: Literal["transformer"]) -
4647
cyto_elements["data"].update(
4748
{
4849
# IDs need to be unique, so we combine the branch ID with the from and to nodes
49-
"id": str(branch3.id.item()) + f"_{branch1.from_node.item()}_{branch1.to_node.item()}",
50-
"source": str(branch1.from_node.item()),
51-
"target": str(branch1.to_node.item()),
50+
"id": str(branch3["id"].item()) + f"_{branch1['from_node'].item()}_{branch1['to_node'].item()}",
51+
"source": str(branch1["from_node"].item()),
52+
"target": str(branch1["to_node"].item()),
5253
"group": group,
5354
}
5455
)
@@ -64,9 +65,9 @@ def parse_branch_array(branches: BranchArray, group: Literal["line", "link", "tr
6465
cyto_elements = {"data": _array_to_dict(branch, columns)}
6566
cyto_elements["data"].update(
6667
{
67-
"id": str(branch.id.item()),
68-
"source": str(branch.from_node.item()),
69-
"target": str(branch.to_node.item()),
68+
"id": str(branch["id"].item()),
69+
"source": str(branch["from_node"].item()),
70+
"target": str(branch["to_node"].item()),
7071
"group": group,
7172
}
7273
)

0 commit comments

Comments
 (0)