forked from e2nIEE/pandapower
-
Notifications
You must be signed in to change notification settings - Fork 9
/
create.py
4106 lines (3029 loc) · 182 KB
/
create.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
# -*- coding: utf-8 -*-
# Copyright (c) 2016-2022 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.
from operator import itemgetter
import pandas as pd
from numpy import nan, isnan, arange, dtype, isin, any as np_any, zeros, array, bool_, \
all as np_all, float64, intersect1d
from pandapower import __version__
from pandapower.auxiliary import pandapowerNet, get_free_id, _preserve_dtypes
from pandapower.results import reset_results
from pandapower.std_types import add_basic_std_types, load_std_type, check_entry_in_std_type
import numpy as np
try:
import pandaplan.core.pplog as logging
except ImportError:
import logging
logger = logging.getLogger(__name__)
def create_empty_network(name="", f_hz=50., sn_mva=1, add_stdtypes=True):
"""
This function initializes the pandapower datastructure.
OPTIONAL:
**f_hz** (float, 50.) - power system frequency in hertz
**name** (string, None) - name for the network
**sn_mva** (float, 1e3) - reference apparent power for per unit system
**add_stdtypes** (boolean, True) - Includes standard types to net
OUTPUT:
**net** (attrdict) - PANDAPOWER attrdict with empty tables:
EXAMPLE:
net = create_empty_network()
"""
net = pandapowerNet({
# structure data
"bus": [('name', dtype(object)),
('vn_kv', 'f8'),
('type', dtype(object)),
('zone', dtype(object)),
('in_service', 'bool'), ],
"load": [("name", dtype(object)),
("bus", "u4"),
("p_mw", "f8"),
("q_mvar", "f8"),
("const_z_percent", "f8"),
("const_i_percent", "f8"),
("sn_mva", "f8"),
("scaling", "f8"),
("in_service", 'bool'),
("type", dtype(object))],
"sgen": [("name", dtype(object)),
("bus", "i8"),
("p_mw", "f8"),
("q_mvar", "f8"),
("sn_mva", "f8"),
("scaling", "f8"),
("in_service", 'bool'),
("type", dtype(object)),
("current_source", "bool")],
"motor": [("name", dtype(object)),
("bus", "i8"),
("pn_mech_mw", "f8"),
("loading_percent", "f8"),
("cos_phi", "f8"),
("cos_phi_n", "f8"),
("efficiency_percent", "f8"),
("efficiency_n_percent", "f8"),
("lrc_pu", "f8"),
("vn_kv", "f8"),
("scaling", "f8"),
("in_service", 'bool'),
("rx", 'f8')
],
"asymmetric_load": [("name", dtype(object)),
("bus", "u4"),
("p_a_mw", "f8"),
("q_a_mvar", "f8"),
("p_b_mw", "f8"),
("q_b_mvar", "f8"),
("p_c_mw", "f8"),
("q_c_mvar", "f8"),
("sn_mva", "f8"),
("scaling", "f8"),
("in_service", 'bool'),
("type", dtype(object))],
"asymmetric_sgen": [("name", dtype(object)),
("bus", "i8"),
("p_a_mw", "f8"),
("q_a_mvar", "f8"),
("p_b_mw", "f8"),
("q_b_mvar", "f8"),
("p_c_mw", "f8"),
("q_c_mvar", "f8"),
("sn_mva", "f8"),
("scaling", "f8"),
("in_service", 'bool'),
("type", dtype(object)),
("current_source", "bool")],
"storage": [("name", dtype(object)),
("bus", "i8"),
("p_mw", "f8"),
("q_mvar", "f8"),
("sn_mva", "f8"),
("soc_percent", "f8"),
("min_e_mwh", "f8"),
("max_e_mwh", "f8"),
("scaling", "f8"),
("in_service", 'bool'),
("type", dtype(object))],
"gen": [("name", dtype(object)),
("bus", "u4"),
("p_mw", "f8"),
("vm_pu", "f8"),
("sn_mva", "f8"),
("min_q_mvar", "f8"),
("max_q_mvar", "f8"),
("scaling", "f8"),
("slack", "bool"),
("in_service", 'bool'),
("slack_weight", 'f8'),
("type", dtype(object))],
"switch": [("bus", "i8"),
("element", "i8"),
("et", dtype(object)),
("type", dtype(object)),
("closed", "bool"),
("name", dtype(object)),
("z_ohm", "f8"),
("in_ka", "f8")],
"shunt": [("bus", "u4"),
("name", dtype(object)),
("q_mvar", "f8"),
("p_mw", "f8"),
("vn_kv", "f8"),
("step", "u4"),
("max_step", "u4"),
("in_service", "bool")],
"ext_grid": [("name", dtype(object)),
("bus", "u4"),
("vm_pu", "f8"),
("va_degree", "f8"),
("slack_weight", 'f8'),
("in_service", 'bool')],
"line": [("name", dtype(object)),
("std_type", dtype(object)),
("from_bus", "u4"),
("to_bus", "u4"),
("length_km", "f8"),
("r_ohm_per_km", "f8"),
("x_ohm_per_km", "f8"),
("c_nf_per_km", "f8"),
("g_us_per_km", "f8"),
("max_i_ka", "f8"),
("df", "f8"),
("parallel", "u4"),
("type", dtype(object)),
("in_service", 'bool')],
"trafo": [("name", dtype(object)),
("std_type", dtype(object)),
("hv_bus", "u4"),
("lv_bus", "u4"),
("sn_mva", "f8"),
("vn_hv_kv", "f8"),
("vn_lv_kv", "f8"),
("vk_percent", "f8"),
("vkr_percent", "f8"),
("pfe_kw", "f8"),
("i0_percent", "f8"),
("shift_degree", "f8"),
("tap_side", dtype(object)),
("tap_neutral", "i4"),
("tap_min", "i4"),
("tap_max", "i4"),
("tap_step_percent", "f8"),
("tap_step_degree", "f8"),
("tap_pos", "i4"),
("tap_phase_shifter", 'bool'),
("parallel", "u4"),
("df", "f8"),
("in_service", 'bool')],
"trafo3w": [("name", dtype(object)),
("std_type", dtype(object)),
("hv_bus", "u4"),
("mv_bus", "u4"),
("lv_bus", "u4"),
("sn_hv_mva", "f8"),
("sn_mv_mva", "f8"),
("sn_lv_mva", "f8"),
("vn_hv_kv", "f8"),
("vn_mv_kv", "f8"),
("vn_lv_kv", "f8"),
("vk_hv_percent", "f8"),
("vk_mv_percent", "f8"),
("vk_lv_percent", "f8"),
("vkr_hv_percent", "f8"),
("vkr_mv_percent", "f8"),
("vkr_lv_percent", "f8"),
("pfe_kw", "f8"),
("i0_percent", "f8"),
("shift_mv_degree", "f8"),
("shift_lv_degree", "f8"),
("tap_side", dtype(object)),
("tap_neutral", "i4"),
("tap_min", "i4"),
("tap_max", "i4"),
("tap_step_percent", "f8"),
("tap_step_degree", "f8"),
("tap_pos", "i4"),
("tap_at_star_point", 'bool'),
("in_service", 'bool')],
"impedance": [("name", dtype(object)),
("from_bus", "u4"),
("to_bus", "u4"),
("rft_pu", "f8"),
("xft_pu", "f8"),
("rtf_pu", "f8"),
("xtf_pu", "f8"),
("sn_mva", "f8"),
("in_service", 'bool')],
"dcline": [("name", dtype(object)),
("from_bus", "u4"),
("to_bus", "u4"),
("p_mw", "f8"),
("loss_percent", 'f8'),
("loss_mw", 'f8'),
("vm_from_pu", "f8"),
("vm_to_pu", "f8"),
("max_p_mw", "f8"),
("min_q_from_mvar", "f8"),
("min_q_to_mvar", "f8"),
("max_q_from_mvar", "f8"),
("max_q_to_mvar", "f8"),
("in_service", 'bool')],
"ward": [("name", dtype(object)),
("bus", "u4"),
("ps_mw", "f8"),
("qs_mvar", "f8"),
("qz_mvar", "f8"),
("pz_mw", "f8"),
("in_service", "bool")],
"xward": [("name", dtype(object)),
("bus", "u4"),
("ps_mw", "f8"),
("qs_mvar", "f8"),
("qz_mvar", "f8"),
("pz_mw", "f8"),
("r_ohm", "f8"),
("x_ohm", "f8"),
("vm_pu", "f8"),
("slack_weight", 'f8'),
("in_service", "bool")],
"measurement": [("name", dtype(object)),
("measurement_type", dtype(object)),
("element_type", dtype(object)),
("element", "uint32"),
("value", "float64"),
("std_dev", "float64"),
("side", dtype(object))],
"pwl_cost": [("power_type", dtype(object)),
("element", "u4"),
("et", dtype(object)),
("points", dtype(object))],
"poly_cost": [("element", "u4"),
("et", dtype(object)),
("cp0_eur", dtype("f8")),
("cp1_eur_per_mw", dtype("f8")),
("cp2_eur_per_mw2", dtype("f8")),
("cq0_eur", dtype("f8")),
("cq1_eur_per_mvar", dtype("f8")),
("cq2_eur_per_mvar2", dtype("f8"))
],
'characteristic': [
('object', dtype(object))
],
'controller': [
('object', dtype(object)),
('in_service', "bool"),
('order', "float64"),
('level', dtype(object)),
('initial_run', "bool"),
("recycle", dtype(object))
],
# geodata
"line_geodata": [("coords", dtype(object))],
"bus_geodata": [("x", "f8"), ("y", "f8"), ("coords", dtype(object))],
# result tables
"_empty_res_bus": [("vm_pu", "f8"),
("va_degree", "f8"),
("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_ext_grid": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_line": [("p_from_mw", "f8"),
("q_from_mvar", "f8"),
("p_to_mw", "f8"),
("q_to_mvar", "f8"),
("pl_mw", "f8"),
("ql_mvar", "f8"),
("i_from_ka", "f8"),
("i_to_ka", "f8"),
("i_ka", "f8"),
("vm_from_pu", "f8"),
("va_from_degree", "f8"),
("vm_to_pu", "f8"),
("va_to_degree", "f8"),
("loading_percent", "f8")],
"_empty_res_trafo": [("p_hv_mw", "f8"),
("q_hv_mvar", "f8"),
("p_lv_mw", "f8"),
("q_lv_mvar", "f8"),
("pl_mw", "f8"),
("ql_mvar", "f8"),
("i_hv_ka", "f8"),
("i_lv_ka", "f8"),
("vm_hv_pu", "f8"),
("va_hv_degree", "f8"),
("vm_lv_pu", "f8"),
("va_lv_degree", "f8"),
("loading_percent", "f8")],
"_empty_res_load": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_asymmetric_load": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_asymmetric_sgen": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_motor": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_sgen": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_shunt": [("p_mw", "f8"),
("q_mvar", "f8"),
("vm_pu", "f8")],
"_empty_res_switch": [("i_ka", "f8"),
("loading_percent", "f8")],
"_empty_res_impedance": [("p_from_mw", "f8"),
("q_from_mvar", "f8"),
("p_to_mw", "f8"),
("q_to_mvar", "f8"),
("pl_mw", "f8"),
("ql_mvar", "f8"),
("i_from_ka", "f8"),
("i_to_ka", "f8")],
"_empty_res_dcline": [("p_from_mw", "f8"),
("q_from_mvar", "f8"),
("p_to_mw", "f8"),
("q_to_mvar", "f8"),
("pl_mw", "f8"),
("vm_from_pu", "f8"),
("va_from_degree", "f8"),
("vm_to_pu", "f8"),
("va_to_degree", "f8")],
"_empty_res_ward": [("p_mw", "f8"),
("q_mvar", "f8"),
("vm_pu", "f8")],
"_empty_res_xward": [("p_mw", "f8"),
("q_mvar", "f8"),
("vm_pu", "f8"),
("va_internal_degree", "f8"),
("vm_internal_pu", "f8")],
"_empty_res_trafo_3ph": [("p_a_hv_mw", "f8"),
("q_a_hv_mvar", "f8"),
("p_b_hv_mw", "f8"),
("q_b_hv_mvar", "f8"),
("p_c_hv_mw", "f8"),
("q_c_hv_mvar", "f8"),
("p_a_lv_mw", "f8"),
("q_a_lv_mvar", "f8"),
("p_b_lv_mw", "f8"),
("q_b_lv_mvar", "f8"),
("p_c_lv_mw", "f8"),
("q_c_lv_mvar", "f8"),
("p_a_l_mw", "f8"),
("q_a_l_mvar", "f8"),
("p_b_l_mw", "f8"),
("q_b_l_mvar", "f8"),
("p_c_l_mw", "f8"),
("q_c_l_mvar", "f8"),
("i_a_hv_ka", "f8"),
("i_a_lv_ka", "f8"),
("i_b_hv_ka", "f8"),
("i_b_lv_ka", "f8"),
("i_c_hv_ka", "f8"),
("i_c_lv_ka", "f8"),
# ("i_n_hv_ka", "f8"),
# ("i_n_lv_ka", "f8"),
("loading_a_percent", "f8"),
("loading_b_percent", "f8"),
("loading_c_percent", "f8"),
("loading_percent", "f8")],
"_empty_res_trafo3w": [("p_hv_mw", "f8"),
("q_hv_mvar", "f8"),
("p_mv_mw", "f8"),
("q_mv_mvar", "f8"),
("p_lv_mw", "f8"),
("q_lv_mvar", "f8"),
("pl_mw", "f8"),
("ql_mvar", "f8"),
("i_hv_ka", "f8"),
("i_mv_ka", "f8"),
("i_lv_ka", "f8"),
("vm_hv_pu", "f8"),
("va_hv_degree", "f8"),
("vm_mv_pu", "f8"),
("va_mv_degree", "f8"),
("vm_lv_pu", "f8"),
("va_lv_degree", "f8"),
("va_internal_degree", "f8"),
("vm_internal_pu", "f8"),
("loading_percent", "f8")],
"_empty_res_bus_3ph": [("vm_a_pu", "f8"),
("va_a_degree", "f8"),
("vm_b_pu", "f8"),
("va_b_degree", "f8"),
("vm_c_pu", "f8"),
("va_c_degree", "f8"),
("p_a_mw", "f8"),
("q_a_mvar", "f8"),
("p_b_mw", "f8"),
("q_b_mvar", "f8"),
("p_c_mw", "f8"),
("q_c_mvar", "f8")],
"_empty_res_ext_grid_3ph": [("p_a_mw", "f8"),
("q_a_mvar", "f8"),
("p_b_mw", "f8"),
("q_b_mvar", "f8"),
("p_c_mw", "f8"),
("q_c_mvar", "f8")],
"_empty_res_line_3ph": [("p_a_from_mw", "f8"),
("q_a_from_mvar", "f8"),
("p_b_from_mw", "f8"),
("q_b_from_mvar", "f8"),
("q_c_from_mvar", "f8"),
("p_a_to_mw", "f8"),
("q_a_to_mvar", "f8"),
("p_b_to_mw", "f8"),
("q_b_to_mvar", "f8"),
("p_c_to_mw", "f8"),
("q_c_to_mvar", "f8"),
("p_a_l_mw", "f8"),
("q_a_l_mvar", "f8"),
("p_b_l_mw", "f8"),
("q_b_l_mvar", "f8"),
("p_c_l_mw", "f8"),
("q_c_l_mvar", "f8"),
("i_a_from_ka", "f8"),
("i_a_to_ka", "f8"),
("i_b_from_ka", "f8"),
("i_b_to_ka", "f8"),
("i_c_from_ka", "f8"),
("i_c_to_ka", "f8"),
("i_a_ka", "f8"),
("i_b_ka", "f8"),
("i_c_ka", "f8"),
("i_n_from_ka", "f8"),
("i_n_to_ka", "f8"),
("i_n_ka", "f8"),
("loading_a_percent", "f8"),
("loading_b_percent", "f8"),
("loading_c_percent", "f8")],
"_empty_res_asymmetric_load_3ph": [("p_a_mw", "f8"),
("q_a_mvar", "f8"),
("p_b_mw", "f8"),
("q_b_mvar", "f8"),
("p_c_mw", "f8"),
("q_c_mvar", "f8")],
"_empty_res_asymmetric_sgen_3ph": [("p_a_mw", "f8"),
("q_a_mvar", "f8"),
("p_b_mw", "f8"),
("q_b_mvar", "f8"),
("p_c_mw", "f8"),
("q_c_mvar", "f8")],
"_empty_res_storage": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_storage_3ph": [("p_a_mw", "f8"), ("p_b_mw", "f8"), ("p_c_mw", "f8"),
("q_a_mvar", "f8"), ("q_b_mvar", "f8"), ("q_c_mvar", "f8")],
"_empty_res_gen": [("p_mw", "f8"),
("q_mvar", "f8"),
("va_degree", "f8"),
("vm_pu", "f8")],
# internal
"_ppc": None,
"_ppc0": None,
"_ppc1": None,
"_ppc2": None,
"_is_elements": None,
"_pd2ppc_lookups": {"bus": None,
"ext_grid": None,
"gen": None,
"branch": None},
"version": __version__,
"converged": False,
"OPF_converged": False,
"name": name,
"f_hz": f_hz,
"sn_mva": sn_mva
})
net._empty_res_load_3ph = net._empty_res_load
net._empty_res_sgen_3ph = net._empty_res_sgen
net._empty_res_storage_3ph = net._empty_res_storage
if add_stdtypes:
add_basic_std_types(net)
else:
net.std_types = {"line": {}, "trafo": {}, "trafo3w": {}}
for mode in ["pf", "se", "sc", "pf_3ph"]:
reset_results(net, mode)
net['user_pf_options'] = dict()
return net
def create_bus(net, vn_kv, name=None, index=None, geodata=None, type="b", zone=None,
in_service=True, max_vm_pu=nan, min_vm_pu=nan, coords=None, **kwargs):
"""
Adds one bus in table net["bus"].
Busses are the nodes of the network that all other elements connect to.
INPUT:
**net** (pandapowerNet) - The pandapower network in which the element is created
OPTIONAL:
**name** (string, default None) - the name for this bus
**index** (int, default None) - Force a specified ID if it is available. If None, the \
index one higher than the highest already existing index is selected.
**vn_kv** (float) - The grid voltage level.
**geodata** ((x,y)-tuple, default None) - coordinates used for plotting
**type** (string, default "b") - Type of the bus. "n" - node,
"b" - busbar, "m" - muff
**zone** (string, None) - grid region
**in_service** (boolean) - True for in_service or False for out of service
**max_vm_pu** (float, NAN) - Maximum bus voltage in p.u. - necessary for OPF
**min_vm_pu** (float, NAN) - Minimum bus voltage in p.u. - necessary for OPF
**coords** (list (len=2) of tuples (len=2), default None) - busbar coordinates to plot
the bus with multiple points. coords is typically a list of tuples (start and endpoint of
the busbar) - Example: [(x1, y1), (x2, y2)]
OUTPUT:
**index** (int) - The unique ID of the created element
EXAMPLE:
create_bus(net, name = "bus1")
"""
index = _get_index_with_check(net, "bus", index)
entries = dict(zip(["name", "vn_kv", "type", "zone", "in_service"],
[name, vn_kv, type, zone, bool(in_service)]))
_set_entries(net, "bus", index, True, **entries, **kwargs)
if geodata is not None:
if len(geodata) != 2:
raise UserWarning("geodata must be given as (x, y) tuple")
net["bus_geodata"].loc[index, ["x", "y"]] = geodata
if coords is not None:
net["bus_geodata"].at[index, "coords"] = coords
# column needed by OPF. 0. and 2. are the default maximum / minimum voltages
_create_column_and_set_value(net, index, min_vm_pu, "min_vm_pu", "bus", default_val=0.)
_create_column_and_set_value(net, index, max_vm_pu, "max_vm_pu", "bus", default_val=2.)
return index
def create_buses(net, nr_buses, vn_kv, index=None, name=None, type="b", geodata=None,
zone=None, in_service=True, max_vm_pu=None, min_vm_pu=None, coords=None, **kwargs):
"""
Adds several buses in table net["bus"] at once.
Busses are the nodal points of the network that all other elements connect to.
Input:
**net** (pandapowerNet) - The pandapower network in which the element is created
**nr_buses** (int) - The number of buses that is created
OPTIONAL:
**name** (string, default None) - the name for this bus
**index** (int, default None) - Force specified IDs if available. If None, the indices \
higher than the highest already existing index are selected.
**vn_kv** (float) - The grid voltage level.
**geodata** ((x,y)-tuple or list of tuples with length == nr_buses, default None) -
coordinates used for plotting
**type** (string, default "b") - Type of the bus. "n" - auxilary node,
"b" - busbar, "m" - muff
**zone** (string, None) - grid region
**in_service** (boolean) - True for in_service or False for out of service
**max_vm_pu** (float, NAN) - Maximum bus voltage in p.u. - necessary for OPF
**min_vm_pu** (float, NAN) - Minimum bus voltage in p.u. - necessary for OPF
**coords** (list (len=nr_buses) of list (len=2) of tuples (len=2), default None) - busbar
coordinates to plot the bus with multiple points. coords is typically a list of tuples
(start and endpoint of the busbar) - Example for 3 buses:
[[(x11, y11), (x12, y12)], [(x21, y21), (x22, y22)], [(x31, y31), (x32, y32)]]
OUTPUT:
**index** (int) - The unique indices ID of the created elements
EXAMPLE:
create_bus(net, name = "bus1")
"""
index = _get_multiple_index_with_check(net, "bus", index, nr_buses)
entries = {"vn_kv": vn_kv, "type": type, "zone": zone, "in_service": in_service, "name": name}
_add_series_to_entries(entries, index, "min_vm_pu", min_vm_pu)
_add_series_to_entries(entries, index, "max_vm_pu", max_vm_pu)
_set_multiple_entries(net, "bus", index, **entries, **kwargs)
if geodata is not None:
# works with a 2-tuple or a matching array
net.bus_geodata = pd.concat([net.bus_geodata,
pd.DataFrame(zeros((len(index), len(net.bus_geodata.columns)), dtype=int),
index=index, columns=net.bus_geodata.columns)])
net.bus_geodata.loc[index, :] = nan
net.bus_geodata.loc[index, ["x", "y"]] = geodata
if coords is not None:
net.bus_geodata = pd.concat([net.bus_geodata, pd.DataFrame(index=index, columns=net.bus_geodata.columns)])
net["bus_geodata"].loc[index, "coords"] = coords
return index
def create_load(net, bus, p_mw, q_mvar=0, const_z_percent=0, const_i_percent=0, sn_mva=nan,
name=None, scaling=1., index=None, in_service=True, type='wye', max_p_mw=nan,
min_p_mw=nan, max_q_mvar=nan, min_q_mvar=nan, controllable=nan, **kwargs):
"""
Adds one load in table net["load"].
All loads are modelled in the consumer system, meaning load is positive and generation is
negative active power. Please pay attention to the correct signing of the reactive power as
well.
INPUT:
**net** - The net within this load should be created
**bus** (int) - The bus id to which the load is connected
OPTIONAL:
**p_mw** (float, default 0) - The active power of the load
- postive value -> load
- negative value -> generation
**q_mvar** (float, default 0) - The reactive power of the load
**const_z_percent** (float, default 0) - percentage of p_mw and q_mvar that will be \
associated to constant impedance load at rated voltage
**const_i_percent** (float, default 0) - percentage of p_mw and q_mvar that will be \
associated to constant current load at rated voltage
**sn_mva** (float, default None) - Nominal power of the load
**name** (string, default None) - The name for this load
**scaling** (float, default 1.) - An OPTIONAL scaling factor to be set customly.
Multiplys with p_mw and q_mvar.
**type** (string, 'wye') - type variable to classify the load: wye/delta
**index** (int, None) - Force a specified ID if it is available. If None, the index one \
higher than the highest already existing index is selected.
**in_service** (boolean) - True for in_service or False for out of service
**max_p_mw** (float, default NaN) - Maximum active power load - necessary for controllable \
loads in for OPF
**min_p_mw** (float, default NaN) - Minimum active power load - necessary for controllable \
loads in for OPF
**max_q_mvar** (float, default NaN) - Maximum reactive power load - necessary for \
controllable loads in for OPF
**min_q_mvar** (float, default NaN) - Minimum reactive power load - necessary for \
controllable loads in OPF
**controllable** (boolean, default NaN) - States, whether a load is controllable or not. \
Only respected for OPF; defaults to False if "controllable" column exists in DataFrame
OUTPUT:
**index** (int) - The unique ID of the created element
EXAMPLE:
create_load(net, bus=0, p_mw=10., q_mvar=2.)
"""
_check_node_element(net, bus)
index = _get_index_with_check(net, "load", index)
entries = dict(zip(["name", "bus", "p_mw", "const_z_percent", "const_i_percent", "scaling",
"q_mvar", "sn_mva", "in_service", "type"],
[name, bus, p_mw, const_z_percent, const_i_percent, scaling, q_mvar, sn_mva,
bool(in_service), type]))
_set_entries(net, "load", index, True, **entries, **kwargs)
_create_column_and_set_value(net, index, min_p_mw, "min_p_mw", "load")
_create_column_and_set_value(net, index, max_p_mw, "max_p_mw", "load")
_create_column_and_set_value(net, index, min_q_mvar, "min_q_mvar", "load")
_create_column_and_set_value(net, index, max_q_mvar, "max_q_mvar", "load")
_create_column_and_set_value(net, index, controllable, "controllable", "load", dtyp=bool_,
default_val=False, default_for_nan=True)
return index
def create_loads(net, buses, p_mw, q_mvar=0, const_z_percent=0, const_i_percent=0, sn_mva=nan,
name=None, scaling=1., index=None, in_service=True, type=None, max_p_mw=None,
min_p_mw=None, max_q_mvar=None, min_q_mvar=None, controllable=None, **kwargs):
"""
Adds a number of loads in table net["load"].
All loads are modelled in the consumer system, meaning load is positive and generation is
negative active power. Please pay attention to the correct signing of the reactive power as
well.
INPUT:
**net** - The net within this load should be created
**buses** (list of int) - A list of bus ids to which the loads are connected
OPTIONAL:
**p_mw** (list of floats) - The active power of the loads
- postive value -> load
- negative value -> generation
**q_mvar** (list of floats, default 0) - The reactive power of the loads
**const_z_percent** (list of floats, default 0) - percentage of p_mw and q_mvar that will \
be associated to constant impedance loads at rated voltage
**const_i_percent** (list of floats, default 0) - percentage of p_mw and q_mvar that will \
be associated to constant current load at rated voltage
**sn_mva** (list of floats, default None) - Nominal power of the loads
**name** (list of strings, default None) - The name for this load
**scaling** (list of floats, default 1.) - An OPTIONAL scaling factor to be set customly.
Multiplys with p_mw and q_mvar.
**type** (string, None) - type variable to classify the load
**index** (list of int, None) - Force a specified ID if it is available. If None, the index\
is set to a range between one higher than the highest already existing index and the \
length of loads that shall be created.
**in_service** (list of boolean) - True for in_service or False for out of service
**max_p_mw** (list of floats, default NaN) - Maximum active power load - necessary for \
controllable loads in for OPF
**min_p_mw** (list of floats, default NaN) - Minimum active power load - necessary for \
controllable loads in for OPF
**max_q_mvar** (list of floats, default NaN) - Maximum reactive power load - necessary for \
controllable loads in for OPF
**min_q_mvar** (list of floats, default NaN) - Minimum reactive power load - necessary for \
controllable loads in OPF
**controllable** (list of boolean, default NaN) - States, whether a load is controllable \
or not. Only respected for OPF
Defaults to False if "controllable" column exists in DataFrame
OUTPUT:
**index** (int) - The unique IDs of the created elements
EXAMPLE:
create_loads(net, buses=[0, 2], p_mw=[10., 5.], q_mvar=[2., 0.])
"""
_check_multiple_node_elements(net, buses)
index = _get_multiple_index_with_check(net, "load", index, len(buses))
entries = {"bus": buses, "p_mw": p_mw, "q_mvar": q_mvar, "sn_mva": sn_mva,
"const_z_percent": const_z_percent, "const_i_percent": const_i_percent,
"scaling": scaling, "in_service": in_service, "name": name, "type": type}
_add_series_to_entries(entries, index, "min_p_mw", min_p_mw)
_add_series_to_entries(entries, index, "max_p_mw", max_p_mw)
_add_series_to_entries(entries, index, "min_q_mvar", min_q_mvar)
_add_series_to_entries(entries, index, "max_q_mvar", max_q_mvar)
_add_series_to_entries(entries, index, "controllable", controllable, dtyp=bool_,
default_val=False)
_set_multiple_entries(net, "load", index, **entries, **kwargs)
return index
def create_asymmetric_load(net, bus, p_a_mw=0, p_b_mw=0, p_c_mw=0, q_a_mvar=0, q_b_mvar=0,
q_c_mvar=0, sn_mva=nan, name=None, scaling=1., index=None,
in_service=True, type="wye", **kwargs):
"""
Adds one 3 phase load in table net["asymmetric_load"].
All loads are modelled in the consumer system, meaning load is positive and generation is
negative active power. Please pay attention to the correct signing of the reactive power as
well.
INPUT:
**net** - The net within this load should be created
**bus** (int) - The bus id to which the load is connected
OPTIONAL:
**p_a_mw** (float, default 0) - The active power for Phase A load
**p_b_mw** (float, default 0) - The active power for Phase B load
**p_c_mw** (float, default 0) - The active power for Phase C load
**q_a_mvar** float, default 0) - The reactive power for Phase A load
**q_b_mvar** float, default 0) - The reactive power for Phase B load
**q_c_mvar** (float, default 0) - The reactive power for Phase C load
**sn_kva** (float, default: None) - Nominal power of the load
**name** (string, default: None) - The name for this load
**scaling** (float, default: 1.) - An OPTIONAL scaling factor to be set customly
Multiplys with p_mw and q_mvar of all phases.
**type** (string,default: wye) - type variable to classify three ph load: delta/wye
**index** (int,default: None) - Force a specified ID if it is available. If None, the index\
one higher than the highest already existing index is selected.
**in_service** (boolean) - True for in_service or False for out of service
OUTPUT:
**index** (int) - The unique ID of the created element
EXAMPLE:
**create_asymmetric_load(net, bus=0, p_c_mw = 9., q_c_mvar = 1.8)**
"""
_check_node_element(net, bus)
index = _get_index_with_check(net, "asymmetric_load", index, name="3 phase asymmetric_load")
entries = dict(zip(["name", "bus", "p_a_mw", "p_b_mw", "p_c_mw", "scaling", "q_a_mvar",
"q_b_mvar", "q_c_mvar", "sn_mva", "in_service", "type"],
[name, bus, p_a_mw, p_b_mw, p_c_mw, scaling, q_a_mvar, q_b_mvar, q_c_mvar,
sn_mva, bool(in_service), type]))
_set_entries(net, "asymmetric_load", index, True, **entries, **kwargs)
return index
# =============================================================================
# def create_impedance_load(net, bus, r_A , r_B , r_C, x_A=0, x_B=0, x_C=0,
# sn_mva=nan, name=None, scaling=1.,
# index=None, in_service=True, type=None,
# ):
# """
# Creates a constant impedance load element ABC.
#
# INPUT:
# **net** - The net within this constant impedance load should be created
#
# **bus** (int) - The bus id to which the load is connected
#
# **sn_mva** (float) - rated power of the load
#
# **r_A** (float) - Resistance in Phase A
# **r_B** (float) - Resistance in Phase B
# **r_C** (float) - Resistance in Phase C
# **x_A** (float) - Reactance in Phase A
# **x_B** (float) - Reactance in Phase B
# **x_C** (float) - Reactance in Phase C
#
#
# **kwargs are passed on to the create_load function
#
# OUTPUT:
# **index** (int) - The unique ID of the created load
#
# Load elements are modeled from a consumer point of view. Active power will therefore always be
# positive, reactive power will be positive for under-excited behavior (Q absorption, decreases voltage) and negative for over-excited behavior (Q injection, increases voltage)
# """
# if bus not in net["bus"].index.values:
# raise UserWarning("Cannot attach to bus %s, bus does not exist" % bus)
#
# if index is None:
# index = get_free_id(net["asymmetric_load"])
# if index in net["impedance_load"].index:
# raise UserWarning("A 3 phase asymmetric_load with the id %s already exists" % index)
#
# # store dtypes
# dtypes = net.impedance_load.dtypes
#
# net.impedance_load.loc[index, ["name", "bus", "r_A","r_B","r_C", "scaling",
# "x_A","x_B","x_C","sn_mva", "in_service", "type"]] = \
# [name, bus, r_A,r_B,r_C, scaling,
# x_A,x_B,x_C,sn_mva, bool(in_service), type]
#
# # and preserve dtypes
# _preserve_dtypes(net.impedance_load, dtypes)
#
# return index
#
# =============================================================================
def create_load_from_cosphi(net, bus, sn_mva, cos_phi, mode, **kwargs):
"""
Creates a load element from rated power and power factor cos(phi).
INPUT:
**net** - The net within this static generator should be created
**bus** (int) - The bus id to which the load is connected
**sn_mva** (float) - rated power of the load
**cos_phi** (float) - power factor cos_phi
**mode** (str) - "underexcited" (Q absorption, decreases voltage) or "overexcited" (Q injection, increases voltage)
OPTIONAL:
same as in create_load, keyword arguments are passed to the create_load function
OUTPUT:
**index** (int) - The unique ID of the created load
Load elements are modeled from a consumer point of view. Active power will therefore always be
positive, reactive power will be positive for underexcited behavior (Q absorption, decreases voltage) and negative for
overexcited behavior (Q injection, increases voltage).
"""
from pandapower.toolbox import pq_from_cosphi
p_mw, q_mvar = pq_from_cosphi(sn_mva, cos_phi, qmode=mode, pmode="load")
return create_load(net, bus, sn_mva=sn_mva, p_mw=p_mw, q_mvar=q_mvar, **kwargs)
def create_sgen(net, bus, p_mw, q_mvar=0, sn_mva=nan, name=None, index=None,
scaling=1., type='wye', in_service=True, max_p_mw=nan, min_p_mw=nan,
max_q_mvar=nan, min_q_mvar=nan, controllable=nan, k=nan, rx=None,
current_source=True, generator_type=None, max_ik_ka=nan, kappa=nan, lrc_pu=nan, **kwargs):
"""
Adds one static generator in table net["sgen"].
Static generators are modelled as positive and constant PQ power. This element is used to model
generators with a constant active and reactive power feed-in. If you want to model a voltage
controlled generator, use the generator element instead.
gen, sgen and ext_grid in the grid are modelled in the generator system!
If you want to model the generation of power, you have to assign a positive active power
to the generator. Please pay attention to the correct signing of the
reactive power as well (positive for injection and negative for consumption).
INPUT:
**net** - The net within this static generator should be created
**bus** (int) - The bus id to which the static generator is connected
**p_mw** (float) - The active power of the static generator (positive for generation!)