-
Notifications
You must be signed in to change notification settings - Fork 10
/
pandapower_converter.py
2549 lines (2157 loc) · 113 KB
/
pandapower_converter.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
#
# SPDX-License-Identifier: MPL-2.0
# pylint: disable = too-many-lines
"""
Panda Power Converter
"""
import logging
from functools import lru_cache
from typing import Dict, List, MutableMapping, Optional, Tuple, Type, Union
import numpy as np
import pandas as pd
import structlog
from power_grid_model import (
Branch3Side,
BranchSide,
DatasetType,
LoadGenType,
WindingType,
initialize_array,
power_grid_meta_data,
)
from power_grid_model.data_types import Dataset, SingleDataset
from power_grid_model_io.converters.base_converter import BaseConverter
from power_grid_model_io.data_types import ExtraInfo
from power_grid_model_io.functions import get_winding
from power_grid_model_io.utils.parsing import is_node_ref, parse_trafo3_connection, parse_trafo_connection
PandaPowerData = MutableMapping[str, pd.DataFrame]
logger = structlog.get_logger(__file__)
# pylint: disable=too-many-instance-attributes
class PandaPowerConverter(BaseConverter[PandaPowerData]):
"""
Panda Power Converter
"""
__slots__ = (
"pp_input_data",
"pgm_input_data",
"idx",
"idx_lookup",
"next_idx",
"system_frequency",
)
def __init__(
self,
system_frequency: float = 50.0,
trafo_loading: str = "current",
log_level: int = logging.INFO,
):
"""
Prepare some member variables
Args:
system_frequency: fundamental frequency of the alternating current and voltage in the Network measured in Hz
"""
super().__init__(source=None, destination=None, log_level=log_level)
self.trafo_loading = trafo_loading
self.system_frequency: float = system_frequency
self.pp_input_data: PandaPowerData = {}
self.pgm_input_data: SingleDataset = {}
self.pp_output_data: PandaPowerData = {}
self.pgm_output_data: SingleDataset = {}
self.pgm_nodes_lookup: pd.DataFrame = pd.DataFrame()
self.idx: Dict[Tuple[str, Optional[str]], pd.Series] = {}
self.idx_lookup: Dict[Tuple[str, Optional[str]], pd.Series] = {}
self.next_idx = 0
def _parse_data(
self,
data: PandaPowerData,
data_type: str,
extra_info: Optional[ExtraInfo] = None,
) -> Dataset:
"""
Set up for conversion from PandaPower to power-grid-model
Args:
data: PandaPowerData, i.e. a dictionary with the components as keys and pd.DataFrames as values, with
attribute names as columns and their values in the table
data_type: power-grid-model data type, i.e. "input" or "update"
extra_info: an optional dictionary where extra component info (that can't be specified in
power-grid-model data) can be specified
Returns:
Converted power-grid-model data
"""
# Clear pgm data
self.pgm_input_data = {}
self.idx_lookup = {}
self.next_idx = 0
# Set pandas data
self.pp_input_data = data
# Convert
if data_type == "input":
self._create_input_data()
else:
raise ValueError(f"Data type: '{data_type}' is not implemented")
# Construct extra_info
if extra_info is not None:
self._fill_pgm_extra_info(extra_info=extra_info)
self._fill_pp_extra_info(extra_info=extra_info)
return self.pgm_input_data
def _serialize_data(self, data: Dataset, extra_info: Optional[ExtraInfo]) -> PandaPowerData:
"""
Set up for conversion from power-grid-model to PandaPower
Args:
data: a structured array of power-grid-model data.
extra_info: an optional dictionary where extra component info (that can't be specified in
power-grid-model data) can be specified
Returns:
Converted PandaPower data
"""
# Clear pp data
self.pgm_nodes_lookup = pd.DataFrame()
self.pp_output_data = {}
self.pgm_output_data = data
# If extra_info is supplied, index lookups and node lookups should be created accordingly
if extra_info is not None:
self._extra_info_to_idx_lookup(extra_info)
self._extra_info_to_pgm_input_data(extra_info)
# Convert
def pgm_output_dtype_checker(check_type: DatasetType | str) -> bool:
return all(
(
comp_array.dtype == power_grid_meta_data[DatasetType[check_type]][component]
for component, comp_array in self.pgm_output_data.items()
)
)
# Convert
if pgm_output_dtype_checker("sym_output"):
self._create_output_data()
elif pgm_output_dtype_checker("asym_output"):
self._create_output_data_3ph()
else:
raise TypeError("Invalid output data dictionary supplied.")
return self.pp_output_data
def _create_input_data(self):
"""
Performs the conversion from PandaPower to power-grid-model by calling individual conversion functions
"""
self._create_pgm_input_nodes()
self._create_pgm_input_lines()
self._create_pgm_input_sources()
self._create_pgm_input_sym_loads()
self._create_pgm_input_shunts()
self._create_pgm_input_transformers()
self._create_pgm_input_sym_gens()
self._create_pgm_input_three_winding_transformers()
self._create_pgm_input_links()
self._create_pgm_input_asym_loads()
self._create_pgm_input_asym_gens()
self._create_pgm_input_wards()
self._create_pgm_input_motors()
self._create_pgm_input_storages()
self._create_pgm_input_impedances()
self._create_pgm_input_xwards()
self._create_pgm_input_generators()
self._create_pgm_input_dclines()
def _fill_pgm_extra_info(self, extra_info: ExtraInfo):
"""
Fills in extra information of power-grid-model input after conversion from pandapower to the extra_info dict
Args:
extra_info: The extra info dict
"""
for (pp_table, name), indices in self.idx_lookup.items():
for pgm_id, pp_idx in zip(indices.index, indices):
if name:
extra_info[pgm_id] = {
"id_reference": {
"table": pp_table,
"name": name,
"index": pp_idx,
}
}
else:
extra_info[pgm_id] = {"id_reference": {"table": pp_table, "index": pp_idx}}
extra_cols = ["i_n"]
for component_data in self.pgm_input_data.values():
for attr_name in component_data.dtype.names:
if not is_node_ref(attr_name) and attr_name not in extra_cols:
continue
for pgm_id, node_id in component_data[["id", attr_name]]:
if pgm_id not in extra_info:
extra_info[pgm_id] = {}
if "pgm_input" not in extra_info[pgm_id]:
extra_info[pgm_id]["pgm_input"] = {}
extra_info[pgm_id]["pgm_input"][attr_name] = node_id
def _fill_pp_extra_info(self, extra_info: ExtraInfo):
"""
Fills extra information from pandapower input dataframes not available in power-grid-model input
to the extra_info dict.
Currently, it is possible to only store the derating factor (df) of trafo.
Args:
extra_info: The extra info dict
"""
pp_input = {"trafo": {"df"}}
for pp_table, pp_attr in pp_input.items():
if (
pp_table in self.pp_input_data
and pp_attr & set(self.pp_input_data[pp_table].columns)
and len(self.pp_input_data[pp_table]) > 0
):
pgm_ids = self._get_pgm_ids(pp_table=pp_table)
pp_extra_data = self.pp_input_data[pp_table][list(pp_attr)]
pp_extra_data.index = pgm_ids
for pgm_id, pp_element in pp_extra_data.iterrows():
if pgm_id not in extra_info:
extra_info[pgm_id] = {}
if "pp_input" not in extra_info[pgm_id]:
extra_info[pgm_id]["pp_input"] = {}
for attr in pp_attr:
extra_info[pgm_id]["pp_input"][attr] = pp_element[attr]
def _extra_info_to_idx_lookup(self, extra_info: ExtraInfo):
"""
Converts extra component info into idx_lookup
Args:
extra_info: a dictionary where the original panda power ids are stored
"""
self.idx = {}
self.idx_lookup = {}
pgm_to_pp_id: Dict[Tuple[str, Optional[str]], List[Tuple[int, int]]] = {}
for pgm_idx, extra in extra_info.items():
if "id_reference" not in extra:
continue
assert isinstance(extra["id_reference"], dict)
pp_table = extra["id_reference"]["table"]
pp_index = extra["id_reference"]["index"]
pp_name = extra["id_reference"].get("name")
key = (pp_table, pp_name)
if key not in pgm_to_pp_id:
pgm_to_pp_id[key] = []
pgm_to_pp_id[key].append((pgm_idx, pp_index))
for key, table_pgm_to_pp_id in pgm_to_pp_id.items():
pgm_ids, pp_indices = zip(*table_pgm_to_pp_id)
self.idx[key] = pd.Series(pgm_ids, index=pp_indices)
self.idx_lookup[key] = pd.Series(pp_indices, index=pgm_ids)
def _extra_info_to_pgm_input_data(self, extra_info: ExtraInfo): # pylint: disable-msg=too-many-locals
"""
Converts extra component info into node_lookup
Args:
extra_info: a dictionary where the node reference ids are stored
"""
assert not self.pgm_input_data
assert self.pgm_output_data
dtype = np.int32
other_cols_dtype = np.float64
nan = np.iinfo(dtype).min
all_other_cols = ["i_n"]
for component, data in self.pgm_output_data.items():
input_cols = power_grid_meta_data[DatasetType.input][component].dtype.names
if input_cols is None:
input_cols = tuple()
node_cols = [col for col in input_cols if is_node_ref(col)]
other_cols = [col for col in input_cols if col in all_other_cols]
if not node_cols + other_cols:
continue
num_cols = 1 + len(node_cols)
num_other_cols = len(other_cols)
ref = np.full(
shape=len(data),
fill_value=nan,
dtype={
"names": ["id"] + node_cols + other_cols,
"formats": [dtype] * num_cols + [other_cols_dtype] * num_other_cols,
},
)
for i, pgm_id in enumerate(data["id"]):
extra = extra_info[pgm_id].get("pgm_input", {})
ref[i] = (pgm_id,) + tuple(extra[col] for col in node_cols + other_cols)
self.pgm_input_data[component] = ref
def _extra_info_to_pp_input_data(self, extra_info: ExtraInfo):
"""
Converts extra component info into node_lookup
Currently, it is possible to only retrieve the derating factor (df) of trafo.
Args:
extra_info: a dictionary where the node reference ids are stored
"""
assert not self.pp_input_data
assert self.pgm_output_data
if "transformer" not in self.pgm_output_data:
return
pgm_ids = self.pgm_output_data["transformer"]["id"]
pp_ids = self._get_pp_ids(pp_table="trafo", pgm_idx=pgm_ids)
derating_factor = (extra_info.get(pgm_id, {}).get("pp_input", {}).get("df", np.nan) for pgm_id in pgm_ids)
self.pp_input_data = {"trafo": pd.DataFrame(derating_factor, columns=["df"], index=pp_ids)}
def _create_output_data(self):
"""
Performs the conversion from power-grid-model to PandaPower by calling individual conversion functions.
Furthermore, creates a global node lookup table, which stores nodes' voltage magnitude per unit and the voltage
angle in degrees
"""
# Many pp components store the voltage magnitude per unit and the voltage angle in degrees,
# so let's create a global lookup table (indexed on the pgm ids)
self.pgm_nodes_lookup = pd.DataFrame(
{
"u_pu": self.pgm_output_data["node"]["u_pu"],
"u_degree": self.pgm_output_data["node"]["u_angle"] * (180.0 / np.pi),
},
index=self.pgm_output_data["node"]["id"],
)
self._pp_buses_output()
self._pp_lines_output()
self._pp_ext_grids_output()
self._pp_loads_output()
self._pp_shunts_output()
self._pp_trafos_output()
self._pp_sgens_output()
self._pp_trafos3w_output()
self._pp_ward_output()
self._pp_motor_output()
self._pp_asym_gens_output()
self._pp_asym_loads_output()
# Switches derive results from branches pp_output_data and pgm_output_data of links. Hence, placed in the end.
self._pp_switches_output()
def _create_output_data_3ph(self):
"""
Performs the conversion from power-grid-model to PandaPower by calling individual conversion functions.
Furthermore, creates a global node lookup table, which stores nodes' voltage magnitude per unit and the voltage
angle in degrees
"""
self._pp_buses_output_3ph()
self._pp_lines_output_3ph()
self._pp_ext_grids_output_3ph()
self._pp_loads_output_3ph()
self._pp_trafos_output_3ph()
self._pp_sgens_output_3ph()
self._pp_asym_gens_output_3ph()
self._pp_asym_loads_output_3ph()
def _create_pgm_input_nodes(self):
"""
This function converts a Bus Dataframe of PandaPower to a power-grid-model Node input array.
Returns:
a power-grid-model structured array for the Node component
"""
pp_busses = self.pp_input_data["bus"]
if pp_busses.empty:
return
pgm_nodes = initialize_array(data_type="input", component_type="node", shape=len(pp_busses))
pgm_nodes["id"] = self._generate_ids("bus", pp_busses.index)
pgm_nodes["u_rated"] = self._get_pp_attr("bus", "vn_kv", expected_type="f8") * 1e3
assert "node" not in self.pgm_input_data
self.pgm_input_data["node"] = pgm_nodes
def _create_pgm_input_lines(self):
"""
This function converts a Line Dataframe of PandaPower to a power-grid-model Line input array.
Returns:
a power-grid-model structured array for the Line component
"""
pp_lines = self.pp_input_data["line"]
if pp_lines.empty:
return
switch_states = self.get_switch_states("line")
in_service = self._get_pp_attr("line", "in_service", expected_type="bool", default=True)
length_km = self._get_pp_attr("line", "length_km", expected_type="f8")
parallel = self._get_pp_attr("line", "parallel", expected_type="u4", default=1)
c_nf_per_km = self._get_pp_attr("line", "c_nf_per_km", expected_type="f8")
c0_nf_per_km = self._get_pp_attr("line", "c0_nf_per_km", expected_type="f8", default=np.nan)
multiplier = length_km / parallel
pgm_lines = initialize_array(data_type="input", component_type="line", shape=len(pp_lines))
pgm_lines["id"] = self._generate_ids("line", pp_lines.index)
pgm_lines["from_node"] = self._get_pgm_ids("bus", self._get_pp_attr("line", "from_bus", expected_type="u4"))
pgm_lines["from_status"] = in_service & switch_states["from"]
pgm_lines["to_node"] = self._get_pgm_ids("bus", self._get_pp_attr("line", "to_bus", expected_type="u4"))
pgm_lines["to_status"] = in_service & switch_states["to"]
pgm_lines["r1"] = self._get_pp_attr("line", "r_ohm_per_km", expected_type="f8") * multiplier
pgm_lines["x1"] = self._get_pp_attr("line", "x_ohm_per_km", expected_type="f8") * multiplier
pgm_lines["c1"] = c_nf_per_km * length_km * parallel * 1e-9
# The formula for tan1 = R_1 / Xc_1 = (g * 1e-6) / (2 * pi * f * c * 1e-9) = g / (2 * pi * f * c * 1e-3)
pgm_lines["tan1"] = (
self._get_pp_attr("line", "g_us_per_km", expected_type="f8", default=0)
/ c_nf_per_km
/ (2 * np.pi * self.system_frequency * 1e-3)
)
pgm_lines["i_n"] = (
(self._get_pp_attr("line", "max_i_ka", expected_type="f8", default=np.nan) * 1e3)
* self._get_pp_attr("line", "df", expected_type="f8", default=1)
* parallel
)
pgm_lines["r0"] = self._get_pp_attr("line", "r0_ohm_per_km", expected_type="f8", default=np.nan) * multiplier
pgm_lines["x0"] = self._get_pp_attr("line", "x0_ohm_per_km", expected_type="f8", default=np.nan) * multiplier
pgm_lines["c0"] = c0_nf_per_km * length_km * parallel * 1e-9
pgm_lines["tan0"] = (
self._get_pp_attr("line", "g0_us_per_km", expected_type="f8", default=0)
/ c0_nf_per_km
/ (2 * np.pi * self.system_frequency * 1e-3)
)
assert "line" not in self.pgm_input_data
self.pgm_input_data["line"] = pgm_lines
def _create_pgm_input_sources(self):
"""
This function converts External Grid Dataframe of PandaPower to a power-grid-model Source input array.
Returns:
a power-grid-model structured array for the Source component
"""
pp_ext_grid = self.pp_input_data["ext_grid"]
if pp_ext_grid.empty:
return
rx_max = self._get_pp_attr("ext_grid", "rx_max", expected_type="f8", default=np.nan)
r0x0_max = self._get_pp_attr("ext_grid", "r0x0_max", expected_type="f8", default=np.nan)
x0x_max = self._get_pp_attr("ext_grid", "x0x_max", expected_type="f8", default=np.nan)
# Source Asym parameter check
checks = {
"r0x0_max": np.isnan(r0x0_max).all() or np.array_equal(rx_max, r0x0_max),
"x0x_max": np.isnan(x0x_max).all() or all(x0x_max == 1),
}
if not all(checks.values()):
failed_checks = ", ".join([key for key, value in checks.items() if not value])
logger.warning(f"Zero sequence parameters given in external grid shall be ignored:{failed_checks}")
pgm_sources = initialize_array(data_type="input", component_type="source", shape=len(pp_ext_grid))
pgm_sources["id"] = self._generate_ids("ext_grid", pp_ext_grid.index)
pgm_sources["node"] = self._get_pgm_ids("bus", self._get_pp_attr("ext_grid", "bus", expected_type="u4"))
pgm_sources["status"] = self._get_pp_attr("ext_grid", "in_service", expected_type="bool", default=True)
pgm_sources["u_ref"] = self._get_pp_attr("ext_grid", "vm_pu", expected_type="f8", default=1.0)
pgm_sources["rx_ratio"] = rx_max
pgm_sources["u_ref_angle"] = self._get_pp_attr("ext_grid", "va_degree", expected_type="f8", default=0.0) * (
np.pi / 180
)
pgm_sources["sk"] = self._get_pp_attr("ext_grid", "s_sc_max_mva", expected_type="f8", default=np.nan) * 1e6
assert "source" not in self.pgm_input_data
self.pgm_input_data["source"] = pgm_sources
def _create_pgm_input_shunts(self):
"""
This function converts a Shunt Dataframe of PandaPower to a power-grid-model Shunt input array.
Returns:
a power-grid-model structured array for the Shunt component
"""
pp_shunts = self.pp_input_data["shunt"]
if pp_shunts.empty:
return
vn_kv = self._get_pp_attr("shunt", "vn_kv", expected_type="f8")
vn_kv_2 = vn_kv * vn_kv
step = self._get_pp_attr("shunt", "step", expected_type="u4", default=1)
g1_shunt = self._get_pp_attr("shunt", "p_mw", expected_type="f8") * step / vn_kv_2
b1_shunt = -self._get_pp_attr("shunt", "q_mvar", expected_type="f8") * step / vn_kv_2
pgm_shunts = initialize_array(data_type="input", component_type="shunt", shape=len(pp_shunts))
pgm_shunts["id"] = self._generate_ids("shunt", pp_shunts.index)
pgm_shunts["node"] = self._get_pgm_ids("bus", self._get_pp_attr("shunt", "bus", expected_type="u4"))
pgm_shunts["status"] = self._get_pp_attr("shunt", "in_service", expected_type="bool", default=True)
pgm_shunts["g1"] = g1_shunt
pgm_shunts["b1"] = b1_shunt
pgm_shunts["g0"] = g1_shunt
pgm_shunts["b0"] = b1_shunt
assert "shunt" not in self.pgm_input_data
self.pgm_input_data["shunt"] = pgm_shunts
def _create_pgm_input_sym_gens(self):
"""
This function converts a Static Generator Dataframe of PandaPower to a power-grid-model
Symmetrical Generator input array.
Returns:
a power-grid-model structured array for the Symmetrical Generator component
"""
pp_sgens = self.pp_input_data["sgen"]
if pp_sgens.empty:
return
scaling = self._get_pp_attr("sgen", "scaling", expected_type="f8", default=1.0)
pgm_sym_gens = initialize_array(data_type="input", component_type="sym_gen", shape=len(pp_sgens))
pgm_sym_gens["id"] = self._generate_ids("sgen", pp_sgens.index)
pgm_sym_gens["node"] = self._get_pgm_ids("bus", self._get_pp_attr("sgen", "bus", expected_type="i8"))
pgm_sym_gens["status"] = self._get_pp_attr("sgen", "in_service", expected_type="bool", default=True)
pgm_sym_gens["p_specified"] = self._get_pp_attr("sgen", "p_mw", expected_type="f8") * (1e6 * scaling)
pgm_sym_gens["q_specified"] = self._get_pp_attr("sgen", "q_mvar", expected_type="f8", default=0.0) * (
1e6 * scaling
)
pgm_sym_gens["type"] = LoadGenType.const_power
assert "sym_gen" not in self.pgm_input_data
self.pgm_input_data["sym_gen"] = pgm_sym_gens
def _create_pgm_input_asym_gens(self):
"""
This function converts an Asymmetric Static Generator Dataframe of PandaPower to a power-grid-model
Asymmetrical Generator input array.
Returns:
a power-grid-model structured array for the Asymmetrical Generator component
"""
# TODO: create unit tests for asym_gen conversion
pp_asym_gens = self.pp_input_data["asymmetric_sgen"]
if pp_asym_gens.empty:
return
scaling = self._get_pp_attr("asymmetric_sgen", "scaling", expected_type="f8")
multiplier = 1e6 * scaling
pgm_asym_gens = initialize_array(data_type="input", component_type="asym_gen", shape=len(pp_asym_gens))
pgm_asym_gens["id"] = self._generate_ids("asymmetric_sgen", pp_asym_gens.index)
pgm_asym_gens["node"] = self._get_pgm_ids(
"bus", self._get_pp_attr("asymmetric_sgen", "bus", expected_type="i8")
)
pgm_asym_gens["status"] = self._get_pp_attr("asymmetric_sgen", "in_service", expected_type="bool", default=True)
pgm_asym_gens["p_specified"] = np.transpose(
np.array(
(
self._get_pp_attr("asymmetric_sgen", "p_a_mw", expected_type="f8"),
self._get_pp_attr("asymmetric_sgen", "p_b_mw", expected_type="f8"),
self._get_pp_attr("asymmetric_sgen", "p_c_mw", expected_type="f8"),
)
)
* multiplier
)
pgm_asym_gens["q_specified"] = np.transpose(
np.array(
(
self._get_pp_attr("asymmetric_sgen", "q_a_mvar", expected_type="f8"),
self._get_pp_attr("asymmetric_sgen", "q_b_mvar", expected_type="f8"),
self._get_pp_attr("asymmetric_sgen", "q_c_mvar", expected_type="f8"),
)
)
* multiplier
)
pgm_asym_gens["type"] = LoadGenType.const_power
assert "asym_gen" not in self.pgm_input_data
self.pgm_input_data["asym_gen"] = pgm_asym_gens
def _create_pgm_input_sym_loads(self):
"""
This function converts a Load Dataframe of PandaPower to a power-grid-model
Symmetrical Load input array. For one load in PandaPower there are three loads in
power-grid-model created.
Returns:
a power-grid-model structured array for the Symmetrical Load component
"""
pp_loads = self.pp_input_data["load"]
if pp_loads.empty:
return
if self._get_pp_attr("load", "type", expected_type="O", default=None).any() == "delta":
raise NotImplementedError("Delta loads are not implemented, only wye loads are supported in PGM.")
scaling = self._get_pp_attr("load", "scaling", expected_type="f8", default=1.0)
in_service = self._get_pp_attr("load", "in_service", expected_type="bool", default=True)
p_mw = self._get_pp_attr("load", "p_mw", expected_type="f8", default=0.0)
q_mvar = self._get_pp_attr("load", "q_mvar", expected_type="f8", default=0.0)
bus = self._get_pp_attr("load", "bus", expected_type="u4")
n_loads = len(pp_loads)
pgm_sym_loads = initialize_array(data_type="input", component_type="sym_load", shape=3 * n_loads)
const_i_multiplier = (
self._get_pp_attr("load", "const_i_percent", expected_type="f8", default=0) * scaling * (1e-2 * 1e6)
)
const_z_multiplier = (
self._get_pp_attr("load", "const_z_percent", expected_type="f8", default=0) * scaling * (1e-2 * 1e6)
)
const_p_multiplier = (1e6 - const_i_multiplier - const_z_multiplier) * scaling
pgm_sym_loads["id"][:n_loads] = self._generate_ids("load", pp_loads.index, name="const_power")
pgm_sym_loads["node"][:n_loads] = self._get_pgm_ids("bus", bus)
pgm_sym_loads["status"][:n_loads] = in_service
pgm_sym_loads["type"][:n_loads] = LoadGenType.const_power
pgm_sym_loads["p_specified"][:n_loads] = const_p_multiplier * p_mw
pgm_sym_loads["q_specified"][:n_loads] = const_p_multiplier * q_mvar
pgm_sym_loads["id"][n_loads : 2 * n_loads] = self._generate_ids("load", pp_loads.index, name="const_impedance")
pgm_sym_loads["node"][n_loads : 2 * n_loads] = self._get_pgm_ids("bus", bus)
pgm_sym_loads["status"][n_loads : 2 * n_loads] = in_service
pgm_sym_loads["type"][n_loads : 2 * n_loads] = LoadGenType.const_impedance
pgm_sym_loads["p_specified"][n_loads : 2 * n_loads] = const_z_multiplier * p_mw
pgm_sym_loads["q_specified"][n_loads : 2 * n_loads] = const_z_multiplier * q_mvar
pgm_sym_loads["id"][-n_loads:] = self._generate_ids("load", pp_loads.index, name="const_current")
pgm_sym_loads["node"][-n_loads:] = self._get_pgm_ids("bus", bus)
pgm_sym_loads["status"][-n_loads:] = in_service
pgm_sym_loads["type"][-n_loads:] = LoadGenType.const_current
pgm_sym_loads["p_specified"][-n_loads:] = const_i_multiplier * p_mw
pgm_sym_loads["q_specified"][-n_loads:] = const_i_multiplier * q_mvar
assert "sym_load" not in self.pgm_input_data
self.pgm_input_data["sym_load"] = pgm_sym_loads
def _create_pgm_input_asym_loads(self):
"""
This function converts an asymmetric_load Dataframe of PandaPower to a power-grid-model asym_load input array.
Returns:
a power-grid-model structured array for the asym_load component
"""
# TODO: create unit tests for asym_load conversion
pp_asym_loads = self.pp_input_data["asymmetric_load"]
if pp_asym_loads.empty:
return
if self._get_pp_attr("asymmetric_load", "type", expected_type="O", default=None).any() == "delta":
raise NotImplementedError("Delta loads are not implemented, only wye loads are supported in PGM.")
scaling = self._get_pp_attr("asymmetric_load", "scaling", expected_type="f8")
multiplier = 1e6 * scaling
pgm_asym_loads = initialize_array(data_type="input", component_type="asym_load", shape=len(pp_asym_loads))
pgm_asym_loads["id"] = self._generate_ids("asymmetric_load", pp_asym_loads.index)
pgm_asym_loads["node"] = self._get_pgm_ids(
"bus", self._get_pp_attr("asymmetric_load", "bus", expected_type="u4")
)
pgm_asym_loads["status"] = self._get_pp_attr(
"asymmetric_load", "in_service", expected_type="bool", default=True
)
pgm_asym_loads["p_specified"] = np.transpose(
np.array(
[
self._get_pp_attr("asymmetric_load", "p_a_mw", expected_type="f8"),
self._get_pp_attr("asymmetric_load", "p_b_mw", expected_type="f8"),
self._get_pp_attr("asymmetric_load", "p_c_mw", expected_type="f8"),
]
)
* multiplier
)
pgm_asym_loads["q_specified"] = np.transpose(
np.array(
[
self._get_pp_attr("asymmetric_load", "q_a_mvar", expected_type="f8"),
self._get_pp_attr("asymmetric_load", "q_b_mvar", expected_type="f8"),
self._get_pp_attr("asymmetric_load", "q_c_mvar", expected_type="f8"),
]
)
* multiplier
)
pgm_asym_loads["type"] = LoadGenType.const_power
assert "asym_load" not in self.pgm_input_data
self.pgm_input_data["asym_load"] = pgm_asym_loads
def _create_pgm_input_transformers(self): # pylint: disable=too-many-statements, disable-msg=too-many-locals
"""
This function converts a Transformer Dataframe of PandaPower to a power-grid-model
Transformer input array.
Returns:
a power-grid-model structured array for the Transformer component
"""
pp_trafo = self.pp_input_data["trafo"]
if pp_trafo.empty:
return
# Check for unsupported pandapower features
if "tap_dependent_impedance" in pp_trafo.columns and any(pp_trafo["tap_dependent_impedance"]):
raise RuntimeError("Tap dependent impedance is not supported in Power Grid Model")
# Attribute retrieval
i_no_load = self._get_pp_attr("trafo", "i0_percent", expected_type="f8")
pfe = self._get_pp_attr("trafo", "pfe_kw", expected_type="f8")
vk_percent = self._get_pp_attr("trafo", "vk_percent", expected_type="f8")
vkr_percent = self._get_pp_attr("trafo", "vkr_percent", expected_type="f8")
in_service = self._get_pp_attr("trafo", "in_service", expected_type="bool", default=True)
parallel = self._get_pp_attr("trafo", "parallel", expected_type="u4", default=1)
sn_mva = self._get_pp_attr("trafo", "sn_mva", expected_type="f8")
switch_states = self.get_switch_states("trafo")
tap_side = self._get_pp_attr("trafo", "tap_side", expected_type="O", default=None)
tap_nom = self._get_pp_attr("trafo", "tap_neutral", expected_type="f8", default=np.nan)
tap_pos = self._get_pp_attr("trafo", "tap_pos", expected_type="f8", default=np.nan)
tap_size = self._get_tap_size(pp_trafo)
winding_types = self.get_trafo_winding_types()
clocks = np.round(self._get_pp_attr("trafo", "shift_degree", expected_type="f8", default=0.0) / 30) % 12
# Asym parameters retrival and check. For PGM, manual zero sequence params are not supported yet.
vk0_percent = self._get_pp_attr("trafo", "vk0_percent", expected_type="f8", default=np.nan)
vkr0_percent = self._get_pp_attr("trafo", "vkr0_percent", expected_type="f8", default=np.nan)
mag0_percent = self._get_pp_attr("trafo", "mag0_percent", expected_type="f8", default=np.nan)
mag0_rx = self._get_pp_attr("trafo", "mag0_rx", expected_type="f8", default=np.nan)
# Calculate rx ratio of magnetising branch
valid = np.logical_and(np.not_equal(sn_mva, 0.0), np.isfinite(sn_mva))
mag_g = np.divide(pfe, sn_mva * 1000, where=valid)
mag_g[np.logical_not(valid)] = np.nan
rx_mag = mag_g / np.sqrt(i_no_load * i_no_load * 1e-4 - mag_g * mag_g)
# positive and zero sequence magnetising impedance must be equal.
# mag0_percent = z0mag / z0.
checks = {
"vk0_percent": np.allclose(vk_percent, vk0_percent) or np.isnan(vk0_percent).all(),
"vkr0_percent": np.allclose(vkr_percent, vkr0_percent) or np.isnan(vkr0_percent).all(),
"mag0_percent": np.allclose(i_no_load * 1e-2, 1e4 / (vk0_percent * mag0_percent))
or np.isnan(mag0_percent).all(),
"mag0_rx": np.allclose(rx_mag, mag0_rx) or np.isnan(mag0_rx).all(),
"si0_hv_partial": np.isnan(
self._get_pp_attr("trafo", "si0_hv_partial", expected_type="f8", default=np.nan)
).all(),
}
if not all(checks.values()):
failed_checks = ", ".join([key for key, value in checks.items() if not value])
logger.warning(f"Zero sequence parameters given in trafo shall be ignored:{failed_checks}")
# Do not use taps when mandatory tap data is not available
no_taps = np.equal(tap_side, None) | np.isnan(tap_pos) | np.isnan(tap_nom) | np.isnan(tap_size)
tap_nom[no_taps] = 0
tap_pos[no_taps] = 0
tap_size[no_taps] = 0
tap_side[no_taps] = "hv"
# Default vector group for odd clocks = DYn and for even clocks = YNyn
no_vector_groups = np.isnan(winding_types["winding_from"]) | np.isnan(winding_types["winding_to"])
no_vector_groups_dyn = no_vector_groups & (clocks % 2)
winding_types.loc[no_vector_groups] = WindingType.wye_n
winding_types.loc[no_vector_groups_dyn, "winding_from"] = WindingType.delta
# Create PGM array
pgm_transformers = initialize_array(data_type="input", component_type="transformer", shape=len(pp_trafo))
pgm_transformers["id"] = self._generate_ids("trafo", pp_trafo.index)
pgm_transformers["from_node"] = self._get_pgm_ids(
"bus", self._get_pp_attr("trafo", "hv_bus", expected_type="u4")
)
pgm_transformers["from_status"] = in_service & switch_states["from"].values
pgm_transformers["to_node"] = self._get_pgm_ids("bus", self._get_pp_attr("trafo", "lv_bus", expected_type="u4"))
pgm_transformers["to_status"] = in_service & switch_states["to"].values
pgm_transformers["u1"] = self._get_pp_attr("trafo", "vn_hv_kv", expected_type="f8") * 1e3
pgm_transformers["u2"] = self._get_pp_attr("trafo", "vn_lv_kv", expected_type="f8") * 1e3
pgm_transformers["sn"] = sn_mva * parallel * 1e6
pgm_transformers["uk"] = vk_percent * 1e-2
pgm_transformers["pk"] = vkr_percent * sn_mva * parallel * (1e6 * 1e-2)
pgm_transformers["p0"] = pfe * parallel * 1e3
pgm_transformers["i0"] = i_no_load * 1e-2
i0_min_threshold = pgm_transformers["p0"] / pgm_transformers["sn"]
if any(np.less(pgm_transformers["i0"], i0_min_threshold)):
logger.warning("Minimum value of i0_percent is clipped to p0/sn")
pgm_transformers["i0"] = np.clip(pgm_transformers["i0"], a_min=i0_min_threshold, a_max=None)
pgm_transformers["clock"] = clocks
pgm_transformers["winding_from"] = winding_types["winding_from"]
pgm_transformers["winding_to"] = winding_types["winding_to"]
pgm_transformers["tap_nom"] = tap_nom.astype("i4")
pgm_transformers["tap_pos"] = tap_pos.astype("i4")
pgm_transformers["tap_side"] = self._get_transformer_tap_side(tap_side)
pgm_transformers["tap_min"] = self._get_pp_attr("trafo", "tap_min", expected_type="i4", default=0)
pgm_transformers["tap_max"] = self._get_pp_attr("trafo", "tap_max", expected_type="i4", default=0)
pgm_transformers["tap_size"] = tap_size
assert "transformer" not in self.pgm_input_data
self.pgm_input_data["transformer"] = pgm_transformers
def _create_pgm_input_three_winding_transformers(self):
# pylint: disable=too-many-statements, disable-msg=too-many-locals
"""
This function converts a Three Winding Transformer Dataframe of PandaPower to a power-grid-model
Three Winding Transformer input array.
Returns:
a power-grid-model structured array for the Three Winding Transformer component
"""
pp_trafo3w = self.pp_input_data["trafo3w"]
if pp_trafo3w.empty:
return
# Check for unsupported pandapower features
if "tap_dependent_impedance" in pp_trafo3w.columns and any(pp_trafo3w["tap_dependent_impedance"]):
raise RuntimeError("Tap dependent impedance is not supported in Power Grid Model") # pragma: no cover
if "tap_at_star_point" in pp_trafo3w.columns and any(pp_trafo3w["tap_at_star_point"]):
raise RuntimeError("Tap at star point is not supported in Power Grid Model")
# Attributes retrieval
sn_hv_mva = self._get_pp_attr("trafo3w", "sn_hv_mva", expected_type="f8")
sn_mv_mva = self._get_pp_attr("trafo3w", "sn_mv_mva", expected_type="f8")
sn_lv_mva = self._get_pp_attr("trafo3w", "sn_lv_mva", expected_type="f8")
in_service = self._get_pp_attr("trafo3w", "in_service", expected_type="bool", default=True)
switch_states = self.get_trafo3w_switch_states(pp_trafo3w)
tap_side = self._get_pp_attr("trafo3w", "tap_side", expected_type="O", default=None)
tap_nom = self._get_pp_attr("trafo3w", "tap_neutral", expected_type="f8", default=np.nan)
tap_pos = self._get_pp_attr("trafo3w", "tap_pos", expected_type="f8", default=np.nan)
tap_size = self._get_3wtransformer_tap_size(pp_trafo3w)
vk_hv_percent = self._get_pp_attr("trafo3w", "vk_hv_percent", expected_type="f8")
vkr_hv_percent = self._get_pp_attr("trafo3w", "vkr_hv_percent", expected_type="f8")
vk_mv_percent = self._get_pp_attr("trafo3w", "vk_mv_percent", expected_type="f8")
vkr_mv_percent = self._get_pp_attr("trafo3w", "vkr_mv_percent", expected_type="f8")
vk_lv_percent = self._get_pp_attr("trafo3w", "vk_lv_percent", expected_type="f8")
vkr_lv_percent = self._get_pp_attr("trafo3w", "vkr_lv_percent", expected_type="f8")
winding_types = self.get_trafo3w_winding_types()
clocks_12 = (
np.round(self._get_pp_attr("trafo3w", "shift_mv_degree", expected_type="f8", default=0.0) / 30.0) % 12
)
clocks_13 = (
np.round(self._get_pp_attr("trafo3w", "shift_lv_degree", expected_type="f8", default=0.0) / 30.0) % 12
)
vk0_hv_percent = self._get_pp_attr("trafo3w", "vk0_hv_percent", expected_type="f8", default=np.nan)
vkr0_hv_percent = self._get_pp_attr("trafo3w", "vkr0_hv_percent", expected_type="f8", default=np.nan)
vk0_mv_percent = self._get_pp_attr("trafo3w", "vk0_mv_percent", expected_type="f8", default=np.nan)
vkr0_mv_percent = self._get_pp_attr("trafo3w", "vkr0_mv_percent", expected_type="f8", default=np.nan)
vk0_lv_percent = self._get_pp_attr("trafo3w", "vk0_lv_percent", expected_type="f8", default=np.nan)
vkr0_lv_percent = self._get_pp_attr("trafo3w", "vkr0_lv_percent", expected_type="f8", default=np.nan)
# Asym parameters. For PGM, manual zero sequence params are not supported yet.
checks = {
"vk0_hv_percent": np.array_equal(vk_hv_percent, vk0_hv_percent) or np.isnan(vk0_hv_percent).all(),
"vkr0_hv_percent": np.array_equal(vkr_hv_percent, vkr0_hv_percent) or np.isnan(vkr0_hv_percent).all(),
"vk0_mv_percent": np.array_equal(vk_mv_percent, vk0_mv_percent) or np.isnan(vk0_mv_percent).all(),
"vkr0_mv_percent": np.array_equal(vkr_mv_percent, vkr0_mv_percent) or np.isnan(vkr0_mv_percent).all(),
"vk0_lv_percent": np.array_equal(vk_lv_percent, vk0_lv_percent) or np.isnan(vk0_lv_percent).all(),
"vkr0_lv_percent": np.array_equal(vkr_lv_percent, vkr0_lv_percent) or np.isnan(vkr0_lv_percent).all(),
}
if not all(checks.values()):
failed_checks = ", ".join([key for key, value in checks.items() if not value])
logger.warning(f"Zero sequence parameters given in trafo3w are ignored: {failed_checks}")
# Do not use taps when mandatory tap data is not available
no_taps = np.equal(tap_side, None) | np.isnan(tap_pos) | np.isnan(tap_nom) | np.isnan(tap_size)
tap_nom[no_taps] = 0
tap_pos[no_taps] = 0
tap_size[no_taps] = 0
tap_side[no_taps] = "hv"
# Default vector group for odd clocks_12 = Yndx, for odd clocks_13 = Ynxd and for even clocks = YNxyn or YNynx
no_vector_groups = (
np.isnan(winding_types["winding_1"])
& np.isnan(winding_types["winding_2"])
& np.isnan(winding_types["winding_3"])
)
no_vector_groups_ynd2 = no_vector_groups & (clocks_12 % 2)
no_vector_groups_ynd3 = no_vector_groups & (clocks_13 % 2)
winding_types[no_vector_groups] = WindingType.wye_n
winding_types.loc[no_vector_groups_ynd2, "winding_2"] = WindingType.delta
winding_types.loc[no_vector_groups_ynd3, "winding_3"] = WindingType.delta
pgm_3wtransformers = initialize_array(
data_type="input",
component_type="three_winding_transformer",
shape=len(pp_trafo3w),
)
pgm_3wtransformers["id"] = self._generate_ids("trafo3w", pp_trafo3w.index)
pgm_3wtransformers["node_1"] = self._get_pgm_ids(
"bus", self._get_pp_attr("trafo3w", "hv_bus", expected_type="u4")
)
pgm_3wtransformers["node_2"] = self._get_pgm_ids(
"bus", self._get_pp_attr("trafo3w", "mv_bus", expected_type="u4")
)
pgm_3wtransformers["node_3"] = self._get_pgm_ids(
"bus", self._get_pp_attr("trafo3w", "lv_bus", expected_type="u4")
)
pgm_3wtransformers["status_1"] = in_service & switch_states["side_1"].values
pgm_3wtransformers["status_2"] = in_service & switch_states["side_2"].values
pgm_3wtransformers["status_3"] = in_service & switch_states["side_3"].values
pgm_3wtransformers["u1"] = self._get_pp_attr("trafo3w", "vn_hv_kv", expected_type="f8") * 1e3
pgm_3wtransformers["u2"] = self._get_pp_attr("trafo3w", "vn_mv_kv", expected_type="f8") * 1e3
pgm_3wtransformers["u3"] = self._get_pp_attr("trafo3w", "vn_lv_kv", expected_type="f8") * 1e3
pgm_3wtransformers["sn_1"] = sn_hv_mva * 1e6
pgm_3wtransformers["sn_2"] = sn_mv_mva * 1e6
pgm_3wtransformers["sn_3"] = sn_lv_mva * 1e6
pgm_3wtransformers["uk_12"] = vk_hv_percent * 1e-2
pgm_3wtransformers["uk_13"] = vk_lv_percent * 1e-2
pgm_3wtransformers["uk_23"] = vk_mv_percent * 1e-2
pgm_3wtransformers["pk_12"] = vkr_hv_percent * np.minimum(sn_hv_mva, sn_mv_mva) * (1e-2 * 1e6)
pgm_3wtransformers["pk_13"] = vkr_lv_percent * np.minimum(sn_hv_mva, sn_lv_mva) * (1e-2 * 1e6)
pgm_3wtransformers["pk_23"] = vkr_mv_percent * np.minimum(sn_mv_mva, sn_lv_mva) * (1e-2 * 1e6)
pgm_3wtransformers["p0"] = self._get_pp_attr("trafo3w", "pfe_kw", expected_type="f8") * 1e3
pgm_3wtransformers["i0"] = self._get_pp_attr("trafo3w", "i0_percent", expected_type="f8") * 1e-2
i0_min_threshold = pgm_3wtransformers["p0"] / pgm_3wtransformers["sn_1"]
if any(np.less(pgm_3wtransformers["i0"], i0_min_threshold)):
logger.warning("Minimum value of i0_percent is clipped to p0/sn_1")
pgm_3wtransformers["i0"] = np.clip(pgm_3wtransformers["i0"], a_min=i0_min_threshold, a_max=None)
pgm_3wtransformers["clock_12"] = clocks_12
pgm_3wtransformers["clock_13"] = clocks_13
pgm_3wtransformers["winding_1"] = winding_types["winding_1"]
pgm_3wtransformers["winding_2"] = winding_types["winding_2"]
pgm_3wtransformers["winding_3"] = winding_types["winding_3"]
pgm_3wtransformers["tap_nom"] = tap_nom.astype("i4") # TODO(mgovers) shouldn't this be rounded?
pgm_3wtransformers["tap_pos"] = tap_pos.astype("i4") # TODO(mgovers) shouldn't this be rounded?
pgm_3wtransformers["tap_side"] = self._get_3wtransformer_tap_side(tap_side)
pgm_3wtransformers["tap_min"] = self._get_pp_attr("trafo3w", "tap_min", expected_type="i4", default=0)
pgm_3wtransformers["tap_max"] = self._get_pp_attr("trafo3w", "tap_max", expected_type="i4", default=0)
pgm_3wtransformers["tap_size"] = tap_size
assert "three_winding_transformer" not in self.pgm_input_data
self.pgm_input_data["three_winding_transformer"] = pgm_3wtransformers
def _create_pgm_input_links(self):
"""
This function takes a Switch Dataframe of PandaPower, extracts the Switches which have Bus to Bus
connection and converts them to a power-grid-model Link input array.
Returns:
a power-grid-model structured array for the Link component
"""
pp_switches = self.pp_input_data["switch"]
if pp_switches.empty:
return
# This should take all the switches which are b2b
pp_switches = pp_switches[pp_switches["et"] == "b"]
pgm_links = initialize_array(data_type="input", component_type="link", shape=len(pp_switches))
pgm_links["id"] = self._generate_ids("switch", pp_switches.index, name="b2b_switches")
pgm_links["from_node"] = self._get_pgm_ids("bus", pp_switches["bus"])
pgm_links["to_node"] = self._get_pgm_ids("bus", pp_switches["element"])
pgm_links["from_status"] = pp_switches["closed"]
pgm_links["to_status"] = pp_switches["closed"]
assert "link" not in self.pgm_input_data
self.pgm_input_data["link"] = pgm_links
def _create_pgm_input_storages(self):
# TODO: create unit tests for the function
# 3ph output to be made available too
pp_storage = self.pp_input_data["storage"]
if pp_storage.empty:
return
raise NotImplementedError("Storage is not implemented yet!")
def _create_pgm_input_impedances(self):
# TODO: create unit tests for the function
pp_impedance = self.pp_input_data["impedance"]
if pp_impedance.empty:
return
raise NotImplementedError("Impedance is not implemented yet!")
def _create_pgm_input_wards(self):
# TODO: create unit tests for the function
pp_wards = self.pp_input_data["ward"]
if pp_wards.empty:
return
n_wards = len(pp_wards)
in_service = self._get_pp_attr("ward", "in_service", expected_type="bool", default=True)
bus = self._get_pp_attr("ward", "bus", expected_type="u4")
pgm_sym_loads_from_ward = initialize_array(data_type="input", component_type="sym_load", shape=n_wards * 2)
pgm_sym_loads_from_ward["id"][:n_wards] = self._generate_ids(
"ward", pp_wards.index, name="ward_const_power_load"
)
pgm_sym_loads_from_ward["node"][:n_wards] = self._get_pgm_ids("bus", bus)