/
create.py
2815 lines (2055 loc) · 108 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-2020 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.
import pandas as pd
from numpy import nan, isnan, arange, dtype, zeros, isin, float64, all as np_all, any as np_any
from packaging 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
from pandapower import __version__
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")],
"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'),
("type", dtype(object))],
"switch": [("bus", "i8"),
("element", "i8"),
("et", dtype(object)),
("type", dtype(object)),
("closed", "bool"),
("name", dtype(object)),
("z_ohm", "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"),
("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"),
("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"))
],
'controller': [
('object', dtype(object)),
('in_service', "bool"),
('order', "float64"),
('level', dtype(object)),
("recycle", "bool"),
],
# 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_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_load": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_sgen": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_storage": [("p_mw", "f8"),
("q_mvar", "f8")],
"_empty_res_gen": [("p_mw", "f8"),
("q_mvar", "f8"),
("va_degree", "f8"),
("vm_pu", "f8")],
"_empty_res_shunt": [("p_mw", "f8"),
("q_mvar", "f8"),
("vm_pu", "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")],
# internal
"_ppc": None,
"_is_elements": None,
"_pd2ppc_lookups": {"bus": None,
"ext_grid": None,
"gen": None},
"version": __version__,
"converged": False,
"name": name,
"f_hz": f_hz,
"sn_mva": sn_mva
})
for s in net:
if isinstance(net[s], list):
net[s] = pd.DataFrame(zeros(0, dtype=net[s]), index=pd.Int64Index([]))
if add_stdtypes:
add_basic_std_types(net)
else:
net.std_types = {"line": {}, "trafo": {}, "trafo3w": {}}
reset_results(net)
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** (array, default None, shape= (,2L)) - busbar coordinates to plot the bus with multiple points.
coords is typically a list of tuples (start and endpoint of the busbar) [(x1, y1), (x2, y2)]
OUTPUT:
**index** (int) - The unique ID of the created element
EXAMPLE:
create_bus(net, name = "bus1")
"""
if index is not None and index in net["bus"].index:
raise UserWarning("A bus with index %s already exists" % index)
if index is None:
index = get_free_id(net["bus"])
# store dtypes
dtypes = net.bus.dtypes
net.bus.loc[index, ["name", "vn_kv", "type", "zone", "in_service"]] = \
[name, vn_kv, type, zone, bool(in_service)]
# and preserve dtypes
_preserve_dtypes(net.bus, dtypes)
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"].loc[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=nan, min_vm_pu=nan, coords=None):
"""
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, 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
OUTPUT:
**index** (int) - The unique indices ID of the created elements
EXAMPLE:
create_bus(net, name = "bus1")
"""
if index is not None:
for idx in index:
if idx in net.bus.index:
raise UserWarning("A bus with index %s already exists" % index)
else:
bid = get_free_id(net["bus"])
index = arange(bid, bid + nr_buses, 1)
# TODO: not needed when concating anyways?
# store dtypes
# dtypes = net.bus.dtypes
dd = pd.DataFrame(index=index, columns=net.bus.columns)
dd["vn_kv"] = vn_kv
dd["type"] = type
dd["zone"] = zone
dd["in_service"] = in_service
dd["name"] = name
net["bus"] = net["bus"].append(dd)[net["bus"].columns.tolist()]
# and preserve dtypes
# _preserve_dtypes(net.bus, dtypes)
if geodata is not None:
# works with a 2-tuple or a matching array
net.bus_geodata = net.bus_geodata.append(pd.DataFrame(index=index,
columns=net.bus_geodata.columns))
net.bus_geodata.loc[index, ["x", "y"]] = geodata
if coords is not None:
net.bus_geodata = net.bus_geodata.append(pd.DataFrame(index=index,
columns=net.bus_geodata.columns))
net["bus_geodata"].loc[index, "coords"] = coords
min_vm_pu = min_vm_pu if hasattr(min_vm_pu, "__iter__") else [min_vm_pu]*nr_buses
min_vm_pu = pd.Series(min_vm_pu, dtype=float)
if not min_vm_pu.isnull().all():
if "min_vm_pu" not in net.bus.columns:
net.bus.loc[:, "min_vm_pu"] = pd.Series()
net.bus.loc[index, "min_vm_pu"] = min_vm_pu
max_vm_pu = max_vm_pu if hasattr(max_vm_pu, "__iter__") else [max_vm_pu]*nr_buses
max_vm_pu = pd.Series(max_vm_pu, dtype=float)
if not max_vm_pu.isnull().all():
if "max_vm_pu" not in net.bus.columns:
net.bus.loc[:, "max_vm_pu"] = pd.Series()
net.bus.loc[index, "max_vm_pu"] = max_vm_pu
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=None, max_p_mw=nan, min_p_mw=nan,
max_q_mvar=nan, min_q_mvar=nan, controllable=nan):
"""
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 real 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
**type** (string, None) - type variable to classify the load
**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
OUTPUT:
**index** (int) - The unique ID of the created element
EXAMPLE:
create_load(net, bus=0, p_mw=10., q_mvar=2.)
"""
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["load"])
if index in net["load"].index:
raise UserWarning("A load with the id %s already exists" % index)
# store dtypes
dtypes = net.load.dtypes
net.load.loc[index, ["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]
# and preserve dtypes
_preserve_dtypes(net.load, dtypes)
if not isnan(min_p_mw):
if "min_p_mw" not in net.load.columns:
net.load.loc[:, "min_p_mw"] = pd.Series()
net.load.loc[index, "min_p_mw"] = float(min_p_mw)
if not isnan(max_p_mw):
if "max_p_mw" not in net.load.columns:
net.load.loc[:, "max_p_mw"] = pd.Series()
net.load.loc[index, "max_p_mw"] = float(max_p_mw)
if not isnan(min_q_mvar):
if "min_q_mvar" not in net.load.columns:
net.load.loc[:, "min_q_mvar"] = pd.Series()
net.load.loc[index, "min_q_mvar"] = float(min_q_mvar)
if not isnan(max_q_mvar):
if "max_q_mvar" not in net.load.columns:
net.load.loc[:, "max_q_mvar"] = pd.Series()
net.load.loc[index, "max_q_mvar"] = float(max_q_mvar)
if not isnan(controllable):
if "controllable" not in net.load.columns:
net.load.loc[:, "controllable"] = pd.Series()
net.load.loc[index, "controllable"] = bool(controllable)
else:
if "controllable" in net.load.columns:
net.load.loc[index, "controllable"] = False
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=nan, min_p_mw=nan,
max_q_mvar=nan, min_q_mvar=nan, controllable=nan):
"""
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 real 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
**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
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.])
"""
if np_any(~isin(buses, net["bus"].index.values)):
raise UserWarning("Cannot attach to buses %s, they does not exist"
% net["bus"].index.values[~isin(net["bus"].index.values, buses)])
if index is None:
bid = get_free_id(net["load"])
index = arange(bid, bid + len(buses), 1)
elif np_any(isin(index, net["load"].index.values)):
raise UserWarning("Loads with the ids %s already exists"
% net["load"].index.values[isin(net["load"].index.values, index)])
# store dtypes
dtypes = net.load.dtypes
dd = pd.DataFrame(index=index, columns=net.load.columns)
dd["bus"] = buses
dd["p_mw"] = p_mw
dd["q_mvar"] = q_mvar
dd["sn_mva"] = sn_mva
dd["const_z_percent"] = const_z_percent
dd["const_i_percent"] = const_i_percent
dd["scaling"] = scaling
dd["in_service"] = in_service
dd["name"] = name
dd["type"] = type
net["load"] = net["load"].append(dd)[net["load"].columns.tolist()]
# and preserve dtypes
_preserve_dtypes(net.load, dtypes)
if not isnan(min_p_mw):
if "min_p_mw" not in net.load.columns:
net.load.loc[:, "min_p_mw"] = pd.Series()
net.load.loc[index, "min_p_mw"] = min_p_mw.astype(float64)
if not isnan(max_p_mw):
if "max_p_mw" not in net.load.columns:
net.load.loc[:, "max_p_mw"] = pd.Series()
net.load.loc[index, "max_p_mw"] = max_p_mw.astype(float64)
if not isnan(min_q_mvar):
if "min_q_mvar" not in net.load.columns:
net.load.loc[:, "min_q_mvar"] = pd.Series()
net.load.loc[index, "min_q_mvar"] = min_q_mvar.astype(float64)
if not isnan(max_q_mvar):
if "max_q_mvar" not in net.load.columns:
net.load.loc[:, "max_q_mvar"] = pd.Series()
net.load.loc[index, "max_q_mvar"] = max_q_mvar.astype(float64)
if not np_all(isnan(controllable)):
if "controllable" not in net.load.columns:
net.load.loc[:, "controllable"] = pd.Series()
net.load.loc[index, "controllable"] = controllable.astype(bool)
else:
if "controllable" in net.load.columns:
net.load.loc[index, "controllable"] = False
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) - "ind" for inductive or "cap" for capacitive behaviour
**kwargs are passed on to the create_load function
OUTPUT:
**index** (int) - The unique ID of the created load
All elements are modeled from a consumer point of view. Active power will therefore always be
positive, reactive power will be negative for inductive behaviour and positive for capacitive
behaviour.
"""
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=None, in_service=True, max_p_mw=nan, min_p_mw=nan,
max_q_mvar=nan, min_q_mvar=nan, controllable=nan, k=nan, rx=nan,
current_source=True):
"""
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 real power of the static generator (positive for generation!)
OPTIONAL:
**q_mvar** (float, 0) - The reactive power of the sgen
**sn_mva** (float, None) - Nominal power of the sgen
**name** (string, None) - The name for this sgen
**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.
**scaling** (float, 1.) - An OPTIONAL scaling factor to be set customly
**type** (string, None) - type variable to classify the static generator (no impact on \
calculations)
**in_service** (boolean) - True for in_service or False for out of service
**max_p_mw** (float, NaN) - Maximum active power injection - necessary for \
controllable sgens in OPF
**min_p_mw** (float, NaN) - Minimum active power injection - necessary for \
controllable sgens in OPF
**max_q_mvar** (float, NaN) - Maximum reactive power injection - necessary for \
controllable sgens in OPF
**min_q_mvar** (float, NaN) - Minimum reactive power injection - necessary for \
controllable sgens in OPF
**controllable** (bool, NaN) - Whether this generator is controllable by the optimal
powerflow
**k** (float, NaN) - Ratio of nominal current to short circuit current
**rx** (float, NaN) - R/X ratio for short circuit impedance. Only relevant if type is \
specified as motor so that sgen is treated as asynchronous motor
**current_source** (bool, True) - Model this sgen as a current source during short-\
circuit calculations; useful in some cases, for example the simulation of full-\
size converters per IEC 60909-0:2016.
OUTPUT:
**index** (int) - The unique ID of the created sgen
EXAMPLE:
create_sgen(net, 1, p_mw = -120)
"""
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["sgen"])
if index in net["sgen"].index:
raise UserWarning("A static generator with the id %s already exists" % index)
# store dtypes
dtypes = net.sgen.dtypes
net.sgen.loc[index, ["name", "bus", "p_mw", "scaling",
"q_mvar", "sn_mva", "in_service", "type",
"current_source"]] = \
[name, bus, p_mw, scaling, q_mvar, sn_mva, bool(in_service), type, current_source]
# and preserve dtypes
_preserve_dtypes(net.sgen, dtypes)
if not isnan(min_p_mw):
if "min_p_mw" not in net.sgen.columns:
net.sgen.loc[:, "min_p_mw"] = pd.Series()
net.sgen.loc[index, "min_p_mw"] = float(min_p_mw)
if not isnan(max_p_mw):
if "max_p_mw" not in net.sgen.columns:
net.sgen.loc[:, "max_p_mw"] = pd.Series()
net.sgen.loc[index, "max_p_mw"] = float(max_p_mw)
if not isnan(min_q_mvar):
if "min_q_mvar" not in net.sgen.columns:
net.sgen.loc[:, "min_q_mvar"] = pd.Series()
net.sgen.loc[index, "min_q_mvar"] = float(min_q_mvar)
if not isnan(max_q_mvar):
if "max_q_mvar" not in net.sgen.columns:
net.sgen.loc[:, "max_q_mvar"] = pd.Series()
net.sgen.loc[index, "max_q_mvar"] = float(max_q_mvar)
if not isnan(controllable):
if "controllable" not in net.sgen.columns:
net.sgen.loc[:, "controllable"] = pd.Series()
net.sgen.loc[index, "controllable"] = bool(controllable)
else:
if "controllable" in net.sgen.columns:
net.sgen.loc[index, "controllable"] = False
if not isnan(k):
if "k" not in net.sgen.columns:
net.sgen.loc[:, "k"] = pd.Series()
net.sgen.loc[index, "k"] = float(k)
if not isnan(rx):
if "rx" not in net.sgen.columns:
net.sgen.loc[:, "rx"] = pd.Series()
net.sgen.loc[index, "rx"] = float(rx)
return index
def create_sgen_from_cosphi(net, bus, sn_mva, cos_phi, mode, **kwargs):
"""
Creates an sgen 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 static generator is connected
**sn_mva** (float) - rated power of the generator
**cos_phi** (float) - power factor cos_phi
**mode** (str) - "ind" for inductive or "cap" for capacitive behaviour
OUTPUT:
**index** (int) - The unique ID of the created sgen
gen, sgen, and ext_grid are modelled in the generator point of view. Active power
will therefore be postive por generation, and reactive power will be negative for consumption behaviour and
positive for generation behaviour.
"""
from pandapower.toolbox import pq_from_cosphi
p_mw, q_mvar = pq_from_cosphi(sn_mva, cos_phi, qmode=mode, pmode="gen")
return create_sgen(net, bus, sn_mva=sn_mva, p_mw=p_mw, q_mvar=q_mvar, **kwargs)
def create_storage(net, bus, p_mw, max_e_mwh, q_mvar=0, sn_mva=nan, soc_percent=nan, min_e_mwh=0.0,
name=None, index=None, scaling=1., type=None, in_service=True, max_p_mw=nan,
min_p_mw=nan, max_q_mvar=nan, min_q_mvar=nan, controllable=nan):
"""
Adds a storage to the network.
In order to simulate a storage system it is possible to use sgens or loads to model the
discharging or charging state. The power of a storage can be positive or negative, so the use
of either a sgen or a load is (per definition of the elements) not correct.
To overcome this issue, a storage element can be created.
As pandapower is not a time dependend simulation tool and there is no time domain parameter in
default power flow calculations, the state of charge (SOC) is not updated during any power flow
calculation.
The implementation of energy content related parameters in the storage element allows to create
customized, time dependend simulations by running several power flow calculations and updating
variables manually.
INPUT:
**net** - The net within this storage should be created
**bus** (int) - The bus id to which the storage is connected
**p_mw** (float) - The momentary real power of the storage \
(positive for charging, negative for discharging)
**max_e_mwh** (float) - The maximum energy content of the storage \
(maximum charge level)
OPTIONAL:
**q_mvar** (float, default 0) - The reactive power of the storage