Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Install dependencies
```
pip3 install OpenDSSDirect.py pandas
pip3 install OpenDSSDirect.py pandas altdss dss-python[plot]
```

## Set up
Expand Down
4 changes: 3 additions & 1 deletion base_circuit.dss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ new Load.load32 Bus1 = 32.1.2.3 Conn = Wye Model = 1 kv = 24 kw = 0 kvar = 0
new Load.load33 Bus1 = 33.1.2.3 Conn = Wye Model = 1 kv = 24 kw = 0 kvar = 0
new Load.load34 Bus1 = 34.1.2.3 Conn = Wye Model = 1 kv = 24 kw = 0 kvar = 0

new Load.Gen Bus1 = 29.1.2.3 Conn = Wye Model = 1 kv = 24 kw = -1500 kvar = 0

new Line.line1_2 phases = 3 bus1 = 1.1.2.3 bus2 = 2.1.2.3 Length = 0.38 units = mile R1=1.9 X1=1.4 Normamps=96.22504486493762 Emergamps=120.28130608117202
new Line.line2_3 phases = 3 bus1 = 2.1.2.3 bus2 = 3.1.2.3 Length = 0.36 units = mile R1=1.9 X1=1.4 Normamps=96.22504486493762 Emergamps=120.28130608117202
new Line.line3_4 phases = 3 bus1 = 3.1.2.3 bus2 = 4.1.2.3 Length = 0.36 units = mile R1=1.9 X1=1.4 Normamps=96.22504486493762 Emergamps=120.28130608117202
Expand All @@ -55,7 +57,7 @@ new Line.line11_12 phases = 3 bus1 = 11.1.2.3 bus2 = 12.1.2.3 Length = 0.48 unit
new Line.line9_13 phases = 3 bus1 = 9.1.2.3 bus2 = 13.1.2.3 Length = 0.42 units = mile R1=1.9 X1=1.4 Normamps=67.35753140545633 Emergamps=84.1969142568204
new Line.line13_14 phases = 3 bus1 = 13.1.2.3 bus2 = 14.1.2.3 Length = 0.36 units = mile R1=1.9 X1=1.4 Normamps=4.811252243246881 Emergamps=6.014065304058601
new Line.line13_15 phases = 3 bus1 = 13.1.2.3 bus2 = 15.1.2.3 Length = 1.82 units = mile R1=1.9 X1=1.4 Normamps=67.35753140545633 Emergamps=84.1969142568204
new Line.line15_16 phases = 3 bus1 = rg.1.2.3 bus2 = 16.1.2.3 Length = 0.46 units = mile R1=1.9 X1=1.4 Normamps=67.35753140545633 Emergamps=84.1969142568204
new Line.line15_16 phases = 3 bus1 = 15.1.2.3 bus2 = 16.1.2.3 Length = 0.46 units = mile R1=1.9 X1=1.4 Normamps=67.35753140545633 Emergamps=84.1969142568204
new Line.line16_17 phases = 3 bus1 = 16.1.2.3 bus2 = 17.1.2.3 Length = 0.52 units = mile R1=1.9 X1=1.4 Normamps=67.35753140545633 Emergamps=84.1969142568204
new Line.line17_18 phases = 3 bus1 = 17.1.2.3 bus2 = 18.1.2.3 Length = 0.72 units = mile R1=1.9 X1=1.4 Normamps=12.028130608117202 Emergamps=15.035163260146502
new Line.line17_19 phases = 3 bus1 = 17.1.2.3 bus2 = 19.1.2.3 Length = 1.44 units = mile R1=1.9 X1=1.4 Normamps=67.35753140545633 Emergamps=84.1969142568204
Expand Down
Binary file added generated_images/current0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added generated_images/current_base.mp4
Binary file not shown.
52 changes: 43 additions & 9 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# %%
from dss import plot
from opendssdirect import dss
import pandas as pd
import matplotlib.pyplot as plt
Expand All @@ -8,6 +9,12 @@
BASE_KV = 24 # kv (RMS, line to line)
PHASE_KV = BASE_KV / (3**0.5)

plt.rcParams["figure.dpi"] = 300
plt.rcParams["savefig.dpi"] = 300
plot.enable(show=False)

CREATE_ANIMATION = False


def load_dict_from_profiles(timestep: int):
loads = {}
Expand Down Expand Up @@ -37,12 +44,17 @@ def compute_results():
voltage_results = dss.Circuit.AllBusVMag()
return voltage_results


def solution_case():
dss.Commands('Edit Line.line1_2 Normamps=130 Emergamps=150')
dss.Commands('Edit Line.line2_3 Normamps=130 Emergamps=150')
dss.Commands('Edit Line.line23_25 Normamps=40 Emergamps=50')
dss.Commands('new Load.gen13 Bus1 = 13.1.2.3 Conn = Wye Model = 1 kv = 24 kw = -450 kvar = 0')
dss.Commands('new Load.gen29 Bus1 = 29.1.2.3 Conn = Wye Model = 1 kv = 24 kw = -1300 kvar = 0')
dss.Commands("Edit Line.line1_2 Normamps=130 Emergamps=150")
dss.Commands("Edit Line.line2_3 Normamps=130 Emergamps=150")
dss.Commands("Edit Line.line23_25 Normamps=40 Emergamps=50")
dss.Commands(
"new Load.gen13 Bus1 = 13.1.2.3 Conn = Wye Model = 1 kv = 24 kw = -450 kvar = 0"
)
dss.Commands(
"new Load.gen29 Bus1 = 29.1.2.3 Conn = Wye Model = 1 kv = 24 kw = -1300 kvar = 0"
)

dss.Commands("""
New Transformer.Reg1 phases=1 bank=reg1 XHL=0.01 kVAs=[800 800]
Expand All @@ -59,12 +71,21 @@ def solution_case():
""")


def plot_grid(ts):
dss.Text.Command("Buscoords data/node_positions.csv")
dss.Text.Command("plot circuit currents")
if CREATE_ANIMATION:
plt.title(ts)
plt.savefig(f"generated_images/current{ts}.png")

dss.Text.Command("plot scatter")


dss.Commands('Redirect "base_circuit.dss"')
dss.Solution.MaxControlIterations(20)

solution_case() #Edits OpenDSS model to include proposed improvements

# solution_case() # Edits OpenDSS model to include proposed improvements

dss.Solution.Solve()

Expand All @@ -87,6 +108,8 @@ def solution_case():

lines = dss.Lines.AllNames()

# plot_grid(ts)

# currents at this timestep
currents_ts = dict()
for line in lines:
Expand Down Expand Up @@ -126,8 +149,19 @@ def solution_case():
plt.ylabel("voltage [pu]")
plt.text(
0,
0.6,
0,
"Nodes increase in redness as they increase in number (number 34 is totally red)",
)
plt.legend()
# plt.legend()
# %%
# Must have ffmepg installed to run this part, can take a few minutes
# brew install ffmpeg
# Also need to add imageio and imageio-ffmpeg
# pip3 install imageio imageio-ffmpeg
import imageio

# filenames = glob.glob("./generated_images/current*.png")
images = []
for ts in range(0, 24):
images.append(imageio.imread(f"./generated_images/current{ts}.png"))
imageio.mimsave("./generated_images/current_base.mp4", images)