Skip to content

Commit 752f22e

Browse files
committed
Adding course examples
1 parent 318bc47 commit 752f22e

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

1-buses_min_max_v.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
# @Author : Paulo Radatz
3+
4+
# @File : 1-buses_min_max_v.py
5+
# @Software: PyCharm
6+
7+
import py_dss_interface
8+
import os
9+
import pathlib
10+
import numpy as np
11+
12+
script_path = os.path.dirname(os.path.abspath(__file__))
13+
14+
dss_file = pathlib.Path(script_path).joinpath("../feeders", "123Bus", "IEEE123Master.dss")
15+
16+
dss = py_dss_interface.DSS() # using OpenDSS provided in the package
17+
dss.text(f"compile [{dss_file}]")
18+
dss.text("buscoords buscoords.dat")
19+
dss.text("solve")
20+
21+
nodes = dss.circuit.nodes_names
22+
voltages = dss.circuit.buses_vmag_pu
23+
max_voltage = max(voltages)
24+
max_voltage_index = voltages.index(max_voltage)
25+
bus_max_voltages = nodes[max_voltage_index].split(".")[0]
26+
27+
min_voltage = min(voltages)
28+
min_voltage_index = voltages.index(min_voltage)
29+
bus_min_voltages = nodes[min_voltage_index].split(".")[0]
30+
# bus_min = dss.circuit.nodes_names[dss.circuit.buses_vmag_pu.index(min(dss.circuit.buses_vmag_pu))].split(".")[0]
31+
32+
dss.text("set markcapacitor=yes")
33+
dss.text("set markregulator=yes")
34+
dss.text(f"AddBusMarker Bus={bus_min_voltages} code=7 color=red size=10")
35+
dss.text(f"AddBusMarker Bus={bus_max_voltages} code=7 color=green size=10")
36+
dss.text("plot circuit Power max=2000 n n C1=$00FF0000")
37+
38+
39+
voltages_array = np.array(voltages)
40+
nodes_array = np.array(nodes)
41+
42+
# Bus.Node with voltage less than 0.98 pu
43+
buses = nodes_array[voltages_array < 0.98]

2-futher_3ph_bus.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
# @Author : Paulo Radatz
3+
4+
# @File : 2-futher_3ph_bus.py
5+
# @Software: PyCharm
6+
7+
import py_dss_interface
8+
import os
9+
import pathlib
10+
11+
script_path = os.path.dirname(os.path.abspath(__file__))
12+
13+
dss_file = pathlib.Path(script_path).joinpath("../feeders", "123Bus", "IEEE123Master.dss")
14+
15+
dss = py_dss_interface.DSS() # using OpenDSS provided in the package
16+
dss.text(f"compile [{dss_file}]")
17+
dss.text("New EnergyMeter.Feeder Line.L115 1")
18+
dss.text("buscoord buscoords.dat")
19+
dss.text("solve")
20+
21+
bus_dist_actual = 0
22+
bus_name = None
23+
for bus in dss.circuit.buses_names:
24+
dss.circuit.set_active_bus(bus)
25+
if len(dss.bus.nodes) >= 3:
26+
bus_dist = dss.bus.distance
27+
if bus_dist > bus_dist_actual:
28+
bus_dist_actual = bus_dist
29+
bus_name = bus
30+
31+
print(f"Bus: {bus_name} with distance: {bus_dist_actual} is the furthest Three-phase bus")
32+
33+
dss.text(f"AddBusMarker Bus={bus_name} code=7 color=Red size=10")
34+
dss.text("plot circuit Power max=2000 n n C1=$00FF0000")

3-max_load_mult.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
# @Author : Paulo Radatz
3+
4+
# @File : 3-max_load_mult.py
5+
# @Software: PyCharm
6+
7+
import py_dss_interface
8+
import os
9+
import pathlib
10+
11+
script_path = os.path.dirname(os.path.abspath(__file__))
12+
13+
dss_file = pathlib.Path(script_path).joinpath("../feeders", "123Bus", "IEEE123Master.dss")
14+
15+
dss = py_dss_interface.DSS() # using OpenDSS provided in the package
16+
17+
under_voltage = False
18+
i = 0
19+
while not under_voltage and i < 100:
20+
i = i + 1
21+
load_mult = 1 + i / 100
22+
dss.text(f"compile [{dss_file}]")
23+
dss.text("New EnergyMeter.Feeder Line.L115 1")
24+
dss.text(f"set loadmult={load_mult}")
25+
dss.text("solve")
26+
27+
if min(dss.circuit.buses_vmag_pu) < 0.95:
28+
under_voltage = True
29+
load_mult = 1 + (i - 1) / 100
30+
31+
if under_voltage:
32+
print(f"The max loadmult: {load_mult}")
33+
else:
34+
print(f"No problem with max loadmult of: {load_mult}")

4-line_dataframe.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
# @Author : Paulo Radatz
3+
4+
# @File : 4-line_dataframe.py
5+
# @Software: PyCharm
6+
7+
import py_dss_interface
8+
import os
9+
import pathlib
10+
import pandas as pd
11+
12+
script_path = os.path.dirname(os.path.abspath(__file__))
13+
14+
dss_file = pathlib.Path(script_path).joinpath("../feeders", "123Bus", "IEEE123Master.dss")
15+
16+
dss = py_dss_interface.DSS()
17+
dss.text(f"compile [{dss_file}]")
18+
19+
dss.lines.first()
20+
line_properties = dss.cktelement.property_names
21+
22+
dict_to_df = dict()
23+
24+
line_name_list = list()
25+
dss.lines.first()
26+
for _ in range(dss.lines.count):
27+
line_name_list.append(dss.lines.name)
28+
dss.lines.next()
29+
dict_to_df["name"] = line_name_list
30+
31+
for line_property in line_properties:
32+
property_list = list()
33+
34+
dss.lines.first()
35+
for _ in range(dss.lines.count):
36+
property_list.append(dss.dssproperties.value_read(str(dss.cktelement.property_names.index(line_property) + 1)))
37+
dss.lines.next()
38+
39+
dict_to_df[line_property] = property_list
40+
41+
42+
df = pd.DataFrame().from_dict(dict_to_df).set_index("name")
43+
print("This is cool!")

0 commit comments

Comments
 (0)