/
name_attributes.py
66 lines (48 loc) · 2.08 KB
/
name_attributes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (c) 2023, RTE (https://www.rte-france.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
# you can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.
import numpy as np
def _line_name(row, id_obj):
return f"{row['from_bus']}_{row['to_bus']}_{id_obj}"
def _trafo_name(row, id_obj):
return f"{row['hv_bus']}_{row['lv_bus']}_{id_obj}"
def _gen_name(row, id_obj):
return f"gen_{row['bus']}_{id_obj}"
def _load_name(row, id_obj):
return f"load_{row['bus']}_{id_obj}"
def _storage_name(row, id_obj):
return f"storage_{row['bus']}_{id_obj}"
def _sub_name(row, id_obj):
return f"sub_{id_obj}"
def _shunt_name(row, id_obj):
return f"shunt_{row['bus']}_{id_obj}"
def _aux_get_names(grid, grid_attrs):
res = []
obj_id = 0
for (attr, fun_to_name) in grid_attrs:
df = getattr(grid, attr)
if (
"name" in df.columns
and not df["name"].isnull().values.any()
):
res += [name for name in df["name"]]
else:
res += [
fun_to_name(row, id_obj=obj_id + i)
for i, (_, row) in enumerate(df.iterrows())
]
obj_id += df.shape[0]
res = np.array(res)
return res
def get_pandapower_default_names(pp_grid):
sub_names = ["sub_{}".format(i) for i, row in pp_grid.bus.iterrows()]
load_names = _aux_get_names(pp_grid, [("load", _load_name)])
shunt_names = _aux_get_names(pp_grid, [("shunt", _shunt_name)])
gen_names = _aux_get_names(pp_grid, [("gen", _gen_name), ("ext_grid", _gen_name)])
line_names = _aux_get_names(pp_grid, [("line", _line_name), ("trafo", _trafo_name)])
storage_names = _aux_get_names(pp_grid, [("storage", _storage_name)])
return sub_names, load_names, shunt_names, gen_names, line_names, storage_names