-
Notifications
You must be signed in to change notification settings - Fork 14
/
readingpickle (Sayonsoms-MacBook-Pro.local's conflicted copy 2017-04-26).py
228 lines (169 loc) · 6.24 KB
/
readingpickle (Sayonsoms-MacBook-Pro.local's conflicted copy 2017-04-26).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
"""Usage:
readingpickle.py <model> [--verbose]
readingpickle.py <model> getinfo [--verbose]
readingpickle.py <model> flipbusbreaker <busnumber>
readingpickle.py <model> changeLineStatus <linename>
readingpickle.py <model> fliploadbreaker <linename>
readingpickle.py <model> changeTranformerStatus <trafoname>
Options:
-h --help This file us used to operate the power system model.
--version This is part of Canvass 0.1
--verbose This prints out a very detailed log of whats going on.
Helpful for debugging purposes.
"""
import pprint
import cPickle as pickle
import os
import pandas as pd
from shutil import *
from docopt import docopt
import os
import pandapower as pp
import pandapower.networks as pn
import pandapower.plotting as plot
pd.options.mode.chained_assignment = None # default='warn'
#create a copy of the model
def createBackUpCopy():
pass
#dst = "".join(("Datafiles/OriginalModel/",fname))
#copy(fname, dst)
#x = open( "case14.p", "rb" )
#data1 = pickle.load(x)
#pprint.pprint(data1)
#os.system("clear")
#jj = data1["_is_elements"]["gen"].loc[:,"in_service"]
#busesInService = data1["_is_elements"]["bus"][["name","in_service"]]
#jj = data1#["bus"]
#jj[0] = 10
#jj["name"][0] = 99
#print(jj["name"][0])
#print jj
#loadInfo = []
def changegeneratorstatus(choice, data1):
"""
Modify the substation bus breaker status.
"""
print("Here Now")
i = int(choice) - 1
loadInfo = data1["load"][["bus","p_kw","q_kvar","in_service"]].values
changeLoadServiceStatus(data1,loadInfo,choice)
def getInfo(data1, *args, **kwargs):
"""
This function gets information about the model.
"""
try:
print args
except:
print "No extra argument passed"
loadInfo = data1["load"][["bus","p_kw","q_kvar","in_service"]].values
print loadInfo[0][0]
choice = 3
changeLoadServiceStatus(data1,loadInfo,choice)
pass
def printPFResults(fname):
xyz = pp.from_pickle(fname)
#print xyz
pp.runpp(xyz)
print("\nBus Flows\n-----------------\n")
print xyz.res_bus
print("\nLine Flows\n----------------\n")
print xyz.res_line
print("\nLoad Measurements\n------------------\n")
#print xyz.res_load
print xyz.line.index
try:
import seaborn
colors = seaborn.color_palette()
except:
colors = ["b", "g", "r", "c", "y"]
#plot.fuse_geodata(xyz)
#plot.simple_plot(xyz, bus_size=0.7)
cmap_list=[(20, "green"), (50, "yellow"), (60, "red")]
cmap, norm = plot.cmap_continous(cmap_list)
plot.create_generic_coordinates(xyz, respect_switches=True)
lc = plot.create_line_collection(xyz, xyz.line.index, zorder=1, cmap=cmap, norm=norm, linewidths=2)
plot.draw_collections([lc], figsize=(8,6))
# plot.create_generic_coordinates(xyz, respect_switches=True)
# plot.fuse_geodata(xyz)
# bc = plot.create_bus_collection(xyz, xyz.bus.index, size=.2, color=colors[0], zorder=10)
# tc = plot.create_trafo_collection(xyz, xyz.trafo.index, color="g")
# lcd = plot.create_line_collection(xyz, xyz.line.index, color="grey", linewidths=0.5, use_line_geodata=False)
# sc = plot.create_bus_collection(xyz, xyz.ext_grid.bus.values, patch_type="rect", size=.5, color="y", zorder=11)
# # plot.draw_collections([lcd, bc, tc, sc], figsize=(8,6))
#
# closed_lines = set(xyz.line.index) - set(xyz.switch[(xyz.switch.et=="l") & (xyz.switch.closed==False)].element.values)
# lcd = plot.create_line_collection(xyz, closed_lines, color="grey", linewidths=0.5, use_line_geodata=False)
# plot.draw_collections([lcd, bc, tc, sc], figsize=(8,6))
#plot.show()
# cmap_list=[((0.975, 0.985), "blue"), ((0.985, 1.0), "green"), ((1.0, 1.03), "red")]
# cmap, norm = plot.cmap_discrete(cmap_list)
# bc = plot.create_bus_collection(xyz, xyz.bus.index, size=80, zorder=2, cmap=cmap, norm=norm)
#plot.simple_plot(xyz, bus_size=0.7)
#plot.show()
def changeLoadServiceStatus(data1,loadInfo,choice):
"""
This function changes the load status from being connected to disconnected.
"""
if loadInfo[choice][3] == True:
data1["load"]["in_service"][choice] = False
elif loadInfo[choice][3] == False:
data1["load"]["in_service"][choice] = True
modifyFile = raw_input("Do you want to modify the file? [1 to CONFIRM] ")
if modifyFile == "1":
print("Modifying the model to reflect changes ...")
pickle.dump(data1, open("case14.p", "wb"))
y = open( "case14.p", "rb" )
data1 = pickle.load(y)
print(data1["load"][["bus","p_kw","q_kvar","in_service"]])
#ask to run power flow
runPF = raw_input("Do you want to run power flow after new changes? [1 to CONFIRM] ")
#if yes, create new model and run power Flow
if runPF == "1":
print("Building Model ...")
printPFResults("case14.p")
#net = pn.case14()
#jj = net.load[["bus","p_kw","q_kvar","in_service"]].values
#print jj
#net = pn.case14()
#pp.runpp(net)
#print xyz#net.res_bus
#else leave
def changeLoadPValue():
pass
def changeLoadQValue():
pass
def makeModifiedModel():
pass
#getInfo(x)
#getInfo(data1)
#pprint.pprint(data1)
#pickle.dump(data1, open("case14mod.p", "wb"))
#case14 = pp.from_pickle("case14.p")
#net = pn.case14()
#pp.runpp(net)
#print net.res_bus
if __name__ == '__main__':
v = 0
arguments = docopt(__doc__, version='Canvass 0.0.1')
options = docopt(__doc__, version='Canvass 0.0.1')
filename = "".join([arguments['<model>'],".p"])
#if options['--verbose']:
# v = 1
os.system("clear")
print(" - - - - - - - - - - - - - - - -")
print(" - Canvass 0.0.1 DEMO Version -")
print(" - - - - - - - - - - - - - - - -")
x = open(filename, "rb")
data1 = pickle.load(x)
#getInfo(data1)
choice = arguments['<busnumber>']
print choice
if arguments['flipbusbreaker']:
print("This action will change the status of bus breakers")
changegeneratorstatus(choice, data1)
x.close()
#function to get all data
#getAllData(filename)
#change service status of generator
#change service status of line
#change service status of transformer