power-grid-model-io 1.2.101__py3-none-any.whl → 1.2.102__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of power-grid-model-io might be problematic. Click here for more details.
- power_grid_model_io/converters/pandapower_converter.py +98 -24
- power_grid_model_io/converters/tabular_converter.py +104 -28
- power_grid_model_io/converters/vision_excel_converter.py +2 -2
- power_grid_model_io/functions/phase_to_phase.py +1 -1
- {power_grid_model_io-1.2.101.dist-info → power_grid_model_io-1.2.102.dist-info}/METADATA +2 -2
- {power_grid_model_io-1.2.101.dist-info → power_grid_model_io-1.2.102.dist-info}/RECORD +9 -9
- {power_grid_model_io-1.2.101.dist-info → power_grid_model_io-1.2.102.dist-info}/WHEEL +1 -1
- {power_grid_model_io-1.2.101.dist-info → power_grid_model_io-1.2.102.dist-info}/LICENSE +0 -0
- {power_grid_model_io-1.2.101.dist-info → power_grid_model_io-1.2.102.dist-info}/top_level.txt +0 -0
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"""
|
|
6
6
|
Panda Power Converter
|
|
7
7
|
"""
|
|
8
|
+
|
|
8
9
|
import logging
|
|
9
10
|
from functools import lru_cache
|
|
10
11
|
from typing import Dict, List, MutableMapping, Optional, Tuple, Type, Union
|
|
@@ -39,9 +40,21 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
39
40
|
Panda Power Converter
|
|
40
41
|
"""
|
|
41
42
|
|
|
42
|
-
__slots__ = (
|
|
43
|
+
__slots__ = (
|
|
44
|
+
"pp_input_data",
|
|
45
|
+
"pgm_input_data",
|
|
46
|
+
"idx",
|
|
47
|
+
"idx_lookup",
|
|
48
|
+
"next_idx",
|
|
49
|
+
"system_frequency",
|
|
50
|
+
)
|
|
43
51
|
|
|
44
|
-
def __init__(
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
system_frequency: float = 50.0,
|
|
55
|
+
trafo_loading: str = "current",
|
|
56
|
+
log_level: int = logging.INFO,
|
|
57
|
+
):
|
|
45
58
|
"""
|
|
46
59
|
Prepare some member variables
|
|
47
60
|
|
|
@@ -60,7 +73,12 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
60
73
|
self.idx_lookup: Dict[Tuple[str, Optional[str]], pd.Series] = {}
|
|
61
74
|
self.next_idx = 0
|
|
62
75
|
|
|
63
|
-
def _parse_data(
|
|
76
|
+
def _parse_data(
|
|
77
|
+
self,
|
|
78
|
+
data: PandaPowerData,
|
|
79
|
+
data_type: str,
|
|
80
|
+
extra_info: Optional[ExtraInfo] = None,
|
|
81
|
+
) -> Dataset:
|
|
64
82
|
"""
|
|
65
83
|
Set up for conversion from PandaPower to power-grid-model
|
|
66
84
|
|
|
@@ -172,7 +190,13 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
172
190
|
for (pp_table, name), indices in self.idx_lookup.items():
|
|
173
191
|
for pgm_id, pp_idx in zip(indices.index, indices):
|
|
174
192
|
if name:
|
|
175
|
-
extra_info[pgm_id] = {
|
|
193
|
+
extra_info[pgm_id] = {
|
|
194
|
+
"id_reference": {
|
|
195
|
+
"table": pp_table,
|
|
196
|
+
"name": name,
|
|
197
|
+
"index": pp_idx,
|
|
198
|
+
}
|
|
199
|
+
}
|
|
176
200
|
else:
|
|
177
201
|
extra_info[pgm_id] = {"id_reference": {"table": pp_table, "index": pp_idx}}
|
|
178
202
|
|
|
@@ -850,8 +874,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
850
874
|
# Default vector group for odd clocks_12 = Yndx, for odd clocks_13 = Ynxd and for even clocks = YNxyn or YNynx
|
|
851
875
|
no_vector_groups = (
|
|
852
876
|
np.isnan(winding_types["winding_1"])
|
|
853
|
-
|
|
854
|
-
|
|
877
|
+
& np.isnan(winding_types["winding_2"])
|
|
878
|
+
& np.isnan(winding_types["winding_3"])
|
|
855
879
|
)
|
|
856
880
|
no_vector_groups_ynd2 = no_vector_groups & (clocks_12 % 2)
|
|
857
881
|
no_vector_groups_ynd3 = no_vector_groups & (clocks_13 % 2)
|
|
@@ -860,7 +884,9 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
860
884
|
winding_types.loc[no_vector_groups_ynd3, "winding_3"] = WindingType.delta
|
|
861
885
|
|
|
862
886
|
pgm_3wtransformers = initialize_array(
|
|
863
|
-
data_type="input",
|
|
887
|
+
data_type="input",
|
|
888
|
+
component_type="three_winding_transformer",
|
|
889
|
+
shape=len(pp_trafo3w),
|
|
864
890
|
)
|
|
865
891
|
pgm_3wtransformers["id"] = self._generate_ids("trafo3w", pp_trafo3w.index)
|
|
866
892
|
|
|
@@ -995,7 +1021,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
995
1021
|
if "sym_load" in self.pgm_input_data:
|
|
996
1022
|
symload_dtype = self.pgm_input_data["sym_load"].dtype
|
|
997
1023
|
self.pgm_input_data["sym_load"] = np.concatenate( # pylint: disable=unexpected-keyword-arg
|
|
998
|
-
[self.pgm_input_data["sym_load"], pgm_sym_loads_from_ward],
|
|
1024
|
+
[self.pgm_input_data["sym_load"], pgm_sym_loads_from_ward],
|
|
1025
|
+
dtype=symload_dtype,
|
|
999
1026
|
)
|
|
1000
1027
|
else:
|
|
1001
1028
|
self.pgm_input_data["sym_load"] = pgm_sym_loads_from_ward
|
|
@@ -1036,7 +1063,10 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1036
1063
|
p_spec = pgm_sym_loads_from_motor["p_specified"]
|
|
1037
1064
|
cos_phi = self._get_pp_attr("motor", "cos_phi", expected_type="f8")
|
|
1038
1065
|
valid = np.logical_and(np.not_equal(cos_phi, 0.0), np.isfinite(cos_phi))
|
|
1039
|
-
q_spec = np.sqrt(
|
|
1066
|
+
q_spec = np.sqrt(
|
|
1067
|
+
np.power(np.divide(p_spec, cos_phi, where=valid), 2, where=valid) - p_spec**2,
|
|
1068
|
+
where=valid,
|
|
1069
|
+
)
|
|
1040
1070
|
q_spec[np.logical_not(valid)] = np.nan
|
|
1041
1071
|
pgm_sym_loads_from_motor["q_specified"] = q_spec
|
|
1042
1072
|
|
|
@@ -1045,7 +1075,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1045
1075
|
if "sym_load" in self.pgm_input_data:
|
|
1046
1076
|
symload_dtype = self.pgm_input_data["sym_load"].dtype
|
|
1047
1077
|
self.pgm_input_data["sym_load"] = np.concatenate( # pylint: disable=unexpected-keyword-arg
|
|
1048
|
-
[self.pgm_input_data["sym_load"], pgm_sym_loads_from_motor],
|
|
1078
|
+
[self.pgm_input_data["sym_load"], pgm_sym_loads_from_motor],
|
|
1079
|
+
dtype=symload_dtype,
|
|
1049
1080
|
)
|
|
1050
1081
|
else:
|
|
1051
1082
|
self.pgm_input_data["sym_load"] = pgm_sym_loads_from_motor
|
|
@@ -1112,8 +1143,15 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1112
1143
|
component_sides = {
|
|
1113
1144
|
"line": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")],
|
|
1114
1145
|
"link": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")],
|
|
1115
|
-
"transformer": [
|
|
1116
|
-
|
|
1146
|
+
"transformer": [
|
|
1147
|
+
("from_node", "p_from", "q_from"),
|
|
1148
|
+
("to_node", "p_to", "q_to"),
|
|
1149
|
+
],
|
|
1150
|
+
"three_winding_transformer": [
|
|
1151
|
+
("node_1", "p_1", "q_1"),
|
|
1152
|
+
("node_2", "p_2", "q_2"),
|
|
1153
|
+
("node_3", "p_3", "q_3"),
|
|
1154
|
+
],
|
|
1117
1155
|
}
|
|
1118
1156
|
|
|
1119
1157
|
# Set the initial powers to zero
|
|
@@ -1229,7 +1267,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1229
1267
|
pgm_output_sources = self.pgm_output_data["source"]
|
|
1230
1268
|
|
|
1231
1269
|
pp_output_ext_grids = pd.DataFrame(
|
|
1232
|
-
columns=["p_mw", "q_mvar"],
|
|
1270
|
+
columns=["p_mw", "q_mvar"],
|
|
1271
|
+
index=self._get_pp_ids("ext_grid", pgm_output_sources["id"]),
|
|
1233
1272
|
)
|
|
1234
1273
|
pp_output_ext_grids["p_mw"] = pgm_output_sources["p"] * 1e-6
|
|
1235
1274
|
pp_output_ext_grids["q_mvar"] = pgm_output_sources["q"] * 1e-6
|
|
@@ -1256,7 +1295,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1256
1295
|
at_nodes = self.pgm_nodes_lookup.loc[pgm_input_shunts["node"]]
|
|
1257
1296
|
|
|
1258
1297
|
pp_output_shunts = pd.DataFrame(
|
|
1259
|
-
columns=["p_mw", "q_mvar", "vm_pu"],
|
|
1298
|
+
columns=["p_mw", "q_mvar", "vm_pu"],
|
|
1299
|
+
index=self._get_pp_ids("shunt", pgm_output_shunts["id"]),
|
|
1260
1300
|
)
|
|
1261
1301
|
pp_output_shunts["p_mw"] = pgm_output_shunts["p"] * 1e-6
|
|
1262
1302
|
pp_output_shunts["q_mvar"] = pgm_output_shunts["q"] * 1e-6
|
|
@@ -1280,7 +1320,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1280
1320
|
pgm_output_sym_gens = self.pgm_output_data["sym_gen"]
|
|
1281
1321
|
|
|
1282
1322
|
pp_output_sgens = pd.DataFrame(
|
|
1283
|
-
columns=["p_mw", "q_mvar"],
|
|
1323
|
+
columns=["p_mw", "q_mvar"],
|
|
1324
|
+
index=self._get_pp_ids("sgen", pgm_output_sym_gens["id"]),
|
|
1284
1325
|
)
|
|
1285
1326
|
pp_output_sgens["p_mw"] = pgm_output_sym_gens["p"] * 1e-6
|
|
1286
1327
|
pp_output_sgens["q_mvar"] = pgm_output_sym_gens["q"] * 1e-6
|
|
@@ -1707,12 +1748,22 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1707
1748
|
Returns:
|
|
1708
1749
|
accumulated power for each bus
|
|
1709
1750
|
"""
|
|
1710
|
-
power_columns = [
|
|
1751
|
+
power_columns = [
|
|
1752
|
+
"p_a_mw",
|
|
1753
|
+
"p_b_mw",
|
|
1754
|
+
"p_c_mw",
|
|
1755
|
+
"q_a_mvar",
|
|
1756
|
+
"q_b_mvar",
|
|
1757
|
+
"q_c_mvar",
|
|
1758
|
+
]
|
|
1711
1759
|
# Let's define all the components and sides where nodes can be connected
|
|
1712
1760
|
component_sides = {
|
|
1713
1761
|
"line": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")],
|
|
1714
1762
|
"link": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")],
|
|
1715
|
-
"transformer": [
|
|
1763
|
+
"transformer": [
|
|
1764
|
+
("from_node", "p_from", "q_from"),
|
|
1765
|
+
("to_node", "p_to", "q_to"),
|
|
1766
|
+
],
|
|
1716
1767
|
}
|
|
1717
1768
|
|
|
1718
1769
|
# Set the initial powers to zero
|
|
@@ -1902,7 +1953,8 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1902
1953
|
pgm_output_sym_gens = self.pgm_output_data["sym_gen"]
|
|
1903
1954
|
|
|
1904
1955
|
pp_output_sgens = pd.DataFrame(
|
|
1905
|
-
columns=["p_mw", "q_mvar"],
|
|
1956
|
+
columns=["p_mw", "q_mvar"],
|
|
1957
|
+
index=self._get_pp_ids("sgen", pgm_output_sym_gens["id"]),
|
|
1906
1958
|
)
|
|
1907
1959
|
pp_output_sgens["p_mw"] = np.sum(pgm_output_sym_gens["p"], axis=1) * 1e-6
|
|
1908
1960
|
pp_output_sgens["q_mvar"] = np.sum(pgm_output_sym_gens["q"], axis=1) * 1e-6
|
|
@@ -1938,15 +1990,24 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
1938
1990
|
loading = np.maximum(np.sum(ui_from, axis=1), np.sum(ui_to, axis=1)) / pgm_input_transformers["sn"]
|
|
1939
1991
|
elif self.trafo_loading == "power":
|
|
1940
1992
|
loading_a_percent = (
|
|
1941
|
-
np.maximum(
|
|
1993
|
+
np.maximum(
|
|
1994
|
+
pgm_output_transformers["s_from"][:, 0],
|
|
1995
|
+
pgm_output_transformers["s_to"][:, 0],
|
|
1996
|
+
)
|
|
1942
1997
|
/ pgm_output_transformers["s_n"]
|
|
1943
1998
|
)
|
|
1944
1999
|
loading_b_percent = (
|
|
1945
|
-
np.maximum(
|
|
2000
|
+
np.maximum(
|
|
2001
|
+
pgm_output_transformers["s_from"][:, 1],
|
|
2002
|
+
pgm_output_transformers["s_to"][:, 1],
|
|
2003
|
+
)
|
|
1946
2004
|
/ pgm_output_transformers["s_n"]
|
|
1947
2005
|
)
|
|
1948
2006
|
loading_c_percent = (
|
|
1949
|
-
np.maximum(
|
|
2007
|
+
np.maximum(
|
|
2008
|
+
pgm_output_transformers["s_from"][:, 2],
|
|
2009
|
+
pgm_output_transformers["s_to"][:, 2],
|
|
2010
|
+
)
|
|
1950
2011
|
/ pgm_output_transformers["s_n"]
|
|
1951
2012
|
)
|
|
1952
2013
|
loading = pgm_output_transformers["loading"]
|
|
@@ -2136,7 +2197,10 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
2136
2197
|
return pgm_idx
|
|
2137
2198
|
|
|
2138
2199
|
def _get_pgm_ids(
|
|
2139
|
-
self,
|
|
2200
|
+
self,
|
|
2201
|
+
pp_table: str,
|
|
2202
|
+
pp_idx: Optional[Union[pd.Series, np.ndarray]] = None,
|
|
2203
|
+
name: Optional[str] = None,
|
|
2140
2204
|
) -> pd.Series:
|
|
2141
2205
|
"""
|
|
2142
2206
|
Get numerical power-grid-model IDs for a PandaPower component
|
|
@@ -2155,7 +2219,12 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
2155
2219
|
return self.idx[key]
|
|
2156
2220
|
return self.idx[key][pp_idx]
|
|
2157
2221
|
|
|
2158
|
-
def _get_pp_ids(
|
|
2222
|
+
def _get_pp_ids(
|
|
2223
|
+
self,
|
|
2224
|
+
pp_table: str,
|
|
2225
|
+
pgm_idx: Optional[pd.Series] = None,
|
|
2226
|
+
name: Optional[str] = None,
|
|
2227
|
+
) -> pd.Series:
|
|
2159
2228
|
"""
|
|
2160
2229
|
Get numerical PandaPower IDs for a PandaPower component
|
|
2161
2230
|
|
|
@@ -2348,7 +2417,12 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]):
|
|
|
2348
2417
|
pp_3_switches = self.get_individual_switch_states(trafo3w[["index", bus3]], pp_switches, bus3)
|
|
2349
2418
|
|
|
2350
2419
|
return pd.DataFrame(
|
|
2351
|
-
data={
|
|
2420
|
+
data={
|
|
2421
|
+
"side_1": pp_1_switches,
|
|
2422
|
+
"side_2": pp_2_switches,
|
|
2423
|
+
"side_3": pp_3_switches,
|
|
2424
|
+
},
|
|
2425
|
+
index=trafo3w.index,
|
|
2352
2426
|
)
|
|
2353
2427
|
|
|
2354
2428
|
def get_trafo_winding_types(self) -> pd.DataFrame:
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"""
|
|
5
5
|
Tabular Data Converter: Load data from multiple tables and use a mapping file to convert the data to PGM
|
|
6
6
|
"""
|
|
7
|
+
|
|
7
8
|
import inspect
|
|
8
9
|
import logging
|
|
9
10
|
from pathlib import Path
|
|
@@ -141,8 +142,7 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
141
142
|
)
|
|
142
143
|
return input_data
|
|
143
144
|
|
|
144
|
-
# pylint: disable = too-many-arguments
|
|
145
|
-
def _convert_table_to_component(
|
|
145
|
+
def _convert_table_to_component( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
146
146
|
self,
|
|
147
147
|
data: TabularData,
|
|
148
148
|
data_type: str,
|
|
@@ -197,7 +197,10 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
197
197
|
|
|
198
198
|
# Make sure that the "id" column is always parsed first (at least before "extra" is parsed)
|
|
199
199
|
attributes_without_filter = {k: v for k, v in attributes.items() if k != "filters"}
|
|
200
|
-
sorted_attributes = sorted(
|
|
200
|
+
sorted_attributes = sorted(
|
|
201
|
+
attributes_without_filter.items(),
|
|
202
|
+
key=lambda x: "" if x[0] == "id" else x[0],
|
|
203
|
+
)
|
|
201
204
|
|
|
202
205
|
for attr, col_def in sorted_attributes:
|
|
203
206
|
self._convert_col_def_to_attribute(
|
|
@@ -224,8 +227,7 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
224
227
|
table_mask &= cast(pd.DataFrame, data[table]).apply(fn_ptr, axis=1, **kwargs).values
|
|
225
228
|
return table_mask
|
|
226
229
|
|
|
227
|
-
# pylint: disable = too-many-arguments
|
|
228
|
-
def _convert_col_def_to_attribute(
|
|
230
|
+
def _convert_col_def_to_attribute( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
229
231
|
self,
|
|
230
232
|
data: TabularData,
|
|
231
233
|
pgm_data: np.ndarray,
|
|
@@ -282,7 +284,11 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
282
284
|
return
|
|
283
285
|
|
|
284
286
|
attr_data = self._parse_col_def(
|
|
285
|
-
data=data,
|
|
287
|
+
data=data,
|
|
288
|
+
table=table,
|
|
289
|
+
table_mask=table_mask,
|
|
290
|
+
col_def=col_def,
|
|
291
|
+
extra_info=extra_info,
|
|
286
292
|
)
|
|
287
293
|
|
|
288
294
|
if len(attr_data.columns) != 1:
|
|
@@ -290,7 +296,7 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
290
296
|
|
|
291
297
|
pgm_data[attr] = attr_data.iloc[:, 0]
|
|
292
298
|
|
|
293
|
-
def _handle_extra_info(
|
|
299
|
+
def _handle_extra_info( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
294
300
|
self,
|
|
295
301
|
data: TabularData,
|
|
296
302
|
table: str,
|
|
@@ -322,7 +328,11 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
322
328
|
return
|
|
323
329
|
|
|
324
330
|
extra = self._parse_col_def(
|
|
325
|
-
data=data,
|
|
331
|
+
data=data,
|
|
332
|
+
table=table,
|
|
333
|
+
table_mask=table_mask,
|
|
334
|
+
col_def=col_def,
|
|
335
|
+
extra_info=None,
|
|
326
336
|
).to_dict(orient="records")
|
|
327
337
|
for i, xtr in zip(uuids, extra):
|
|
328
338
|
xtr = {
|
|
@@ -369,7 +379,7 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
369
379
|
raise NotImplementedError("Batch data can not (yet) be stored for tabular data")
|
|
370
380
|
return TabularData(logger=self._log, **data)
|
|
371
381
|
|
|
372
|
-
def _parse_col_def(
|
|
382
|
+
def _parse_col_def( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
373
383
|
self,
|
|
374
384
|
data: TabularData,
|
|
375
385
|
table: str,
|
|
@@ -394,7 +404,11 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
394
404
|
return self._parse_col_def_column_name(data=data, table=table, col_def=col_def, table_mask=table_mask)
|
|
395
405
|
if isinstance(col_def, dict):
|
|
396
406
|
return self._parse_col_def_filter(
|
|
397
|
-
data=data,
|
|
407
|
+
data=data,
|
|
408
|
+
table=table,
|
|
409
|
+
table_mask=table_mask,
|
|
410
|
+
col_def=col_def,
|
|
411
|
+
extra_info=extra_info,
|
|
398
412
|
)
|
|
399
413
|
if isinstance(col_def, list):
|
|
400
414
|
return self._parse_col_def_composite(data=data, table=table, col_def=col_def, table_mask=table_mask)
|
|
@@ -402,7 +416,10 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
402
416
|
|
|
403
417
|
@staticmethod
|
|
404
418
|
def _parse_col_def_const(
|
|
405
|
-
data: TabularData,
|
|
419
|
+
data: TabularData,
|
|
420
|
+
table: str,
|
|
421
|
+
col_def: Union[int, float],
|
|
422
|
+
table_mask: Optional[np.ndarray] = None,
|
|
406
423
|
) -> pd.DataFrame:
|
|
407
424
|
"""Create a single column pandas DataFrame containing the const value.
|
|
408
425
|
|
|
@@ -423,7 +440,11 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
423
440
|
return const_df
|
|
424
441
|
|
|
425
442
|
def _parse_col_def_column_name(
|
|
426
|
-
self,
|
|
443
|
+
self,
|
|
444
|
+
data: TabularData,
|
|
445
|
+
table: str,
|
|
446
|
+
col_def: str,
|
|
447
|
+
table_mask: Optional[np.ndarray] = None,
|
|
427
448
|
) -> pd.DataFrame:
|
|
428
449
|
"""Extract a column from the data. If the column doesn't exist, check if the col_def is a special float value,
|
|
429
450
|
like 'inf'. If that's the case, create a single column pandas DataFrame containing the const value.
|
|
@@ -471,7 +492,7 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
471
492
|
except KeyError:
|
|
472
493
|
return data
|
|
473
494
|
|
|
474
|
-
def _parse_reference(
|
|
495
|
+
def _parse_reference( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
475
496
|
self,
|
|
476
497
|
data: TabularData,
|
|
477
498
|
table: str,
|
|
@@ -502,7 +523,7 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
502
523
|
result = queries.merge(other, how="left", left_on=query_column, right_on=key_column)
|
|
503
524
|
return result[[value_column]]
|
|
504
525
|
|
|
505
|
-
def _parse_col_def_filter(
|
|
526
|
+
def _parse_col_def_filter( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
506
527
|
self,
|
|
507
528
|
data: TabularData,
|
|
508
529
|
table: str,
|
|
@@ -553,18 +574,26 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
553
574
|
)
|
|
554
575
|
elif isinstance(sub_def, list):
|
|
555
576
|
col_data = self._parse_pandas_function(
|
|
556
|
-
data=data,
|
|
577
|
+
data=data,
|
|
578
|
+
table=table,
|
|
579
|
+
table_mask=table_mask,
|
|
580
|
+
fn_name=name,
|
|
581
|
+
col_def=sub_def,
|
|
557
582
|
)
|
|
558
583
|
elif isinstance(sub_def, dict):
|
|
559
584
|
col_data = self._parse_function(
|
|
560
|
-
data=data,
|
|
585
|
+
data=data,
|
|
586
|
+
table=table,
|
|
587
|
+
table_mask=table_mask,
|
|
588
|
+
function=name,
|
|
589
|
+
col_def=sub_def,
|
|
561
590
|
)
|
|
562
591
|
else:
|
|
563
592
|
raise TypeError(f"Invalid {name} definition: {sub_def}")
|
|
564
593
|
data_frames.append(col_data)
|
|
565
594
|
return pd.concat(data_frames, axis=1)
|
|
566
595
|
|
|
567
|
-
def _parse_auto_id(
|
|
596
|
+
def _parse_auto_id( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
568
597
|
self,
|
|
569
598
|
data: TabularData,
|
|
570
599
|
table: str,
|
|
@@ -606,7 +635,11 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
606
635
|
raise TypeError(f"Invalid key definition type '{type(key_col_def).__name__}': {key_col_def}")
|
|
607
636
|
|
|
608
637
|
col_data = self._parse_col_def(
|
|
609
|
-
data=data,
|
|
638
|
+
data=data,
|
|
639
|
+
table=table,
|
|
640
|
+
table_mask=table_mask,
|
|
641
|
+
col_def=key_col_def,
|
|
642
|
+
extra_info=None,
|
|
610
643
|
)
|
|
611
644
|
|
|
612
645
|
def auto_id(row: np.ndarray):
|
|
@@ -622,7 +655,13 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
622
655
|
# the first argument to be parsed.
|
|
623
656
|
if extra_info is not None and ref_table_str == table and pgm_id not in extra_info:
|
|
624
657
|
if ref_name is not None:
|
|
625
|
-
extra_info[pgm_id] = {
|
|
658
|
+
extra_info[pgm_id] = {
|
|
659
|
+
"id_reference": {
|
|
660
|
+
"table": ref_table_str,
|
|
661
|
+
"name": ref_name,
|
|
662
|
+
"key": key,
|
|
663
|
+
}
|
|
664
|
+
}
|
|
626
665
|
else:
|
|
627
666
|
extra_info[pgm_id] = {"id_reference": {"table": ref_table_str, "key": key}}
|
|
628
667
|
|
|
@@ -632,8 +671,13 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
632
671
|
return col_data
|
|
633
672
|
return col_data.apply(auto_id, axis=1, raw=True)
|
|
634
673
|
|
|
635
|
-
def _parse_pandas_function(
|
|
636
|
-
self,
|
|
674
|
+
def _parse_pandas_function( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
675
|
+
self,
|
|
676
|
+
data: TabularData,
|
|
677
|
+
table: str,
|
|
678
|
+
fn_name: str,
|
|
679
|
+
col_def: List[Any],
|
|
680
|
+
table_mask: Optional[np.ndarray],
|
|
637
681
|
) -> pd.DataFrame:
|
|
638
682
|
"""Special vectorized functions.
|
|
639
683
|
|
|
@@ -652,7 +696,13 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
652
696
|
if fn_name == "multiply":
|
|
653
697
|
fn_name = "prod"
|
|
654
698
|
|
|
655
|
-
col_data = self._parse_col_def(
|
|
699
|
+
col_data = self._parse_col_def(
|
|
700
|
+
data=data,
|
|
701
|
+
table=table,
|
|
702
|
+
col_def=col_def,
|
|
703
|
+
table_mask=table_mask,
|
|
704
|
+
extra_info=None,
|
|
705
|
+
)
|
|
656
706
|
|
|
657
707
|
try:
|
|
658
708
|
fn_ptr = getattr(col_data, fn_name)
|
|
@@ -675,8 +725,13 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
675
725
|
|
|
676
726
|
return pd.DataFrame(fn_ptr(axis=1))
|
|
677
727
|
|
|
678
|
-
def _parse_function(
|
|
679
|
-
self,
|
|
728
|
+
def _parse_function( # pylint: disable = too-many-arguments,too-many-positional-arguments
|
|
729
|
+
self,
|
|
730
|
+
data: TabularData,
|
|
731
|
+
table: str,
|
|
732
|
+
function: str,
|
|
733
|
+
col_def: Dict[str, Any],
|
|
734
|
+
table_mask: Optional[np.ndarray],
|
|
680
735
|
) -> pd.DataFrame:
|
|
681
736
|
"""Import the function by name and apply it to each row.
|
|
682
737
|
|
|
@@ -694,7 +749,13 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
694
749
|
fn_ptr = get_function(function)
|
|
695
750
|
key_words = list(col_def.keys())
|
|
696
751
|
sub_def = list(col_def.values())
|
|
697
|
-
col_data = self._parse_col_def(
|
|
752
|
+
col_data = self._parse_col_def(
|
|
753
|
+
data=data,
|
|
754
|
+
table=table,
|
|
755
|
+
col_def=sub_def,
|
|
756
|
+
table_mask=table_mask,
|
|
757
|
+
extra_info=None,
|
|
758
|
+
)
|
|
698
759
|
|
|
699
760
|
if col_data.empty:
|
|
700
761
|
raise ValueError(f"Cannot apply function {function} to an empty DataFrame")
|
|
@@ -703,7 +764,11 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
703
764
|
return pd.DataFrame(col_data)
|
|
704
765
|
|
|
705
766
|
def _parse_col_def_composite(
|
|
706
|
-
self,
|
|
767
|
+
self,
|
|
768
|
+
data: TabularData,
|
|
769
|
+
table: str,
|
|
770
|
+
col_def: list,
|
|
771
|
+
table_mask: Optional[np.ndarray],
|
|
707
772
|
) -> pd.DataFrame:
|
|
708
773
|
"""Select multiple columns (each is created from a column definition) and return them as a new DataFrame.
|
|
709
774
|
|
|
@@ -717,7 +782,13 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
717
782
|
"""
|
|
718
783
|
assert isinstance(col_def, list)
|
|
719
784
|
columns = [
|
|
720
|
-
self._parse_col_def(
|
|
785
|
+
self._parse_col_def(
|
|
786
|
+
data=data,
|
|
787
|
+
table=table,
|
|
788
|
+
col_def=sub_def,
|
|
789
|
+
table_mask=table_mask,
|
|
790
|
+
extra_info=None,
|
|
791
|
+
)
|
|
721
792
|
for sub_def in col_def
|
|
722
793
|
]
|
|
723
794
|
return pd.concat(columns, axis=1)
|
|
@@ -748,7 +819,12 @@ class TabularConverter(BaseConverter[TabularData]):
|
|
|
748
819
|
raise KeyError((table, key, name))
|
|
749
820
|
return self._auto_id(item=(table, key, name), key=auto_id_key)
|
|
750
821
|
|
|
751
|
-
def get_ids(
|
|
822
|
+
def get_ids(
|
|
823
|
+
self,
|
|
824
|
+
keys: pd.DataFrame,
|
|
825
|
+
table: Optional[str] = None,
|
|
826
|
+
name: Optional[str] = None,
|
|
827
|
+
) -> List[int]:
|
|
752
828
|
"""
|
|
753
829
|
Get a the numerical ID previously associated with the supplied name / key combination
|
|
754
830
|
Args:
|
|
@@ -35,14 +35,14 @@ class VisionExcelConverter(TabularConverter):
|
|
|
35
35
|
Vision Excel Converter: Load data from a Vision Excel export file and use a mapping file to convert the data to PGM
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
|
-
def __init__(
|
|
38
|
+
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
39
39
|
self,
|
|
40
40
|
source_file: Optional[Union[Path, str]] = None,
|
|
41
41
|
language: str = LANGUAGE_EN,
|
|
42
42
|
terms_changed: Optional[dict] = None,
|
|
43
43
|
mapping_file: Optional[Union[Path, str]] = None,
|
|
44
44
|
log_level: int = logging.INFO,
|
|
45
|
-
):
|
|
45
|
+
):
|
|
46
46
|
_mapping_file = Path(
|
|
47
47
|
mapping_file if mapping_file is not None else str(DEFAULT_MAPPING_FILE).format(language=language)
|
|
48
48
|
)
|
|
@@ -33,7 +33,7 @@ def reactive_power(p: float, cos_phi: float) -> float:
|
|
|
33
33
|
return p * math.sqrt(1 - cos_phi**2) / cos_phi
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def power_wind_speed( # pylint: disable=too-many-arguments
|
|
36
|
+
def power_wind_speed( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
37
37
|
p_nom: float,
|
|
38
38
|
wind_speed: float,
|
|
39
39
|
cut_in_wind_speed: float = 3.0,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: power-grid-model-io
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.102
|
|
4
4
|
Summary: Power Grid Model Input/Output
|
|
5
5
|
Author-email: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
6
6
|
License: MPL-2.0
|
|
@@ -144,4 +144,4 @@ If you are using Power Grid Model IO in your research work, please consider citi
|
|
|
144
144
|
|
|
145
145
|
## Contact
|
|
146
146
|
|
|
147
|
-
Please read [SUPPORT](https://github.com/PowerGridModel/.github/blob/main/SUPPORT.md) for how to connect and get into contact with the Power
|
|
147
|
+
Please read [SUPPORT](https://github.com/PowerGridModel/.github/blob/main/SUPPORT.md) for how to connect and get into contact with the Power Grid Model IO project.
|
|
@@ -9,10 +9,10 @@ power_grid_model_io/config/excel/vision_en_9_7.yaml,sha256=yXClnsAxy2cIey6fW6pcm
|
|
|
9
9
|
power_grid_model_io/config/excel/vision_nl.yaml,sha256=hALPcS4RjPYxNodnC5-FTCE7djnLVSAtnsayeOhUuRY,21333
|
|
10
10
|
power_grid_model_io/converters/__init__.py,sha256=kmbjFW6kVr30fmHb6mAoD7DQAqmbrsOuF1ewd8b0Q3M,408
|
|
11
11
|
power_grid_model_io/converters/base_converter.py,sha256=TICEXyG7PtimAUvhAmpSoZUqwa0shiDdwbWpiM2Ur7o,6048
|
|
12
|
-
power_grid_model_io/converters/pandapower_converter.py,sha256=
|
|
12
|
+
power_grid_model_io/converters/pandapower_converter.py,sha256=c7wXV_T6zHZKa1ZlPtREDIzElDIsrNaiUy2HU-HnOpg,115797
|
|
13
13
|
power_grid_model_io/converters/pgm_json_converter.py,sha256=GdesepDPVl1oX_F35Dtjz6kzrkiGfvQA55rBzWJYhA4,13343
|
|
14
|
-
power_grid_model_io/converters/tabular_converter.py,sha256=
|
|
15
|
-
power_grid_model_io/converters/vision_excel_converter.py,sha256=
|
|
14
|
+
power_grid_model_io/converters/tabular_converter.py,sha256=bLy6e0Mut1KEHkQ4ogjvs-yTAkNf9CcrZJzO-UdoA90,35125
|
|
15
|
+
power_grid_model_io/converters/vision_excel_converter.py,sha256=ahAhynkHp_rchDIS0xEYRj4MmcJtc5YPcQTItNXa7tI,4185
|
|
16
16
|
power_grid_model_io/data_stores/__init__.py,sha256=qwbj1j-Aa_yRB-E3j35pEVtF3mgH8CVIXAnog5mOry0,138
|
|
17
17
|
power_grid_model_io/data_stores/base_data_store.py,sha256=DJfLtRwvx_tXKnpjtBdfbMqPjWc324Eo5WeKTXjWXqc,1706
|
|
18
18
|
power_grid_model_io/data_stores/csv_dir_store.py,sha256=H8ICXZRLDvp9OkbjkfHnoh4y7uNSXNepHAW6W53VsIw,1877
|
|
@@ -25,7 +25,7 @@ power_grid_model_io/data_types/tabular_data.py,sha256=sV6S4kqCEuQiNZTOdKS7CiA2M8
|
|
|
25
25
|
power_grid_model_io/functions/__init__.py,sha256=pamhvKX5c_5fkVMRrUp6zhHWex2R63otRJk1Sfsw6y0,495
|
|
26
26
|
power_grid_model_io/functions/_functions.py,sha256=tqwwZ0G8AeDza0IiS6CSMwKB0lV1hDo2D8e9-ARHXQM,2843
|
|
27
27
|
power_grid_model_io/functions/filters.py,sha256=T_Gsy1FPxMx9eQn0rxuok2hXC8sJwb2O2EZsMk_Ccrw,1311
|
|
28
|
-
power_grid_model_io/functions/phase_to_phase.py,sha256=
|
|
28
|
+
power_grid_model_io/functions/phase_to_phase.py,sha256=IZ_5VqiNvM1zNnHAyq7tUPHN0B62j7Iz0twMgBwUyAI,4489
|
|
29
29
|
power_grid_model_io/mappings/__init__.py,sha256=qwbj1j-Aa_yRB-E3j35pEVtF3mgH8CVIXAnog5mOry0,138
|
|
30
30
|
power_grid_model_io/mappings/field_mapping.py,sha256=YfrwKolNG06kIC1sbUYnYmxuOrbNbNo1dYtnF8rNItw,1659
|
|
31
31
|
power_grid_model_io/mappings/multiplier_mapping.py,sha256=mQ112SMbuIgCZ1haMOxMtfbn2kMsaMaYSfEGv73gSGQ,910
|
|
@@ -42,8 +42,8 @@ power_grid_model_io/utils/modules.py,sha256=a4IdozSL-sOZcmIQON_aQS7-cpnCyt-3p7zs
|
|
|
42
42
|
power_grid_model_io/utils/parsing.py,sha256=XB1QSHnslIieFJBKFXZCtiydqpOqQBiX_CXDbItXgAQ,4522
|
|
43
43
|
power_grid_model_io/utils/uuid_excel_cvtr.py,sha256=H1iWhW_nluJBUJ3hK-Gc0xJjGnH5e35WrBz_fA3YXZs,7626
|
|
44
44
|
power_grid_model_io/utils/zip.py,sha256=VXHX4xWPPZbhOlZUAbMDy3MgQFzK6_l7sRvGXihNUY4,3875
|
|
45
|
-
power_grid_model_io-1.2.
|
|
46
|
-
power_grid_model_io-1.2.
|
|
47
|
-
power_grid_model_io-1.2.
|
|
48
|
-
power_grid_model_io-1.2.
|
|
49
|
-
power_grid_model_io-1.2.
|
|
45
|
+
power_grid_model_io-1.2.102.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
|
|
46
|
+
power_grid_model_io-1.2.102.dist-info/METADATA,sha256=9X0NCi_7e6SoAfZXvwCcQXf5eruSI285wOojfLApmzk,8020
|
|
47
|
+
power_grid_model_io-1.2.102.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
48
|
+
power_grid_model_io-1.2.102.dist-info/top_level.txt,sha256=7sq9VveemMm2R0RgTBa4tH8y_xF4_1hxbufmX9OjCTo,20
|
|
49
|
+
power_grid_model_io-1.2.102.dist-info/RECORD,,
|
|
File without changes
|
{power_grid_model_io-1.2.101.dist-info → power_grid_model_io-1.2.102.dist-info}/top_level.txt
RENAMED
|
File without changes
|