1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Tests for C{loadcase}
18 """
19
20 import os
21
22 from os.path import dirname, join
23
24 from numpy import zeros
25
26 from scipy.io import savemat
27
28 from pypower.loadcase import loadcase
29 from pypower.ppoption import ppoption
30 from pypower.runpf import runpf
31
32 from pypower.idx_gen import PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX
33 from pypower.idx_brch import ANGMAX, ANGMIN
34
35 from pypower.t.t_case9_pf import t_case9_pf
36 from pypower.t.t_case9_pfv2 import t_case9_pfv2
37 from pypower.t.t_case9_opf import t_case9_opf
38 from pypower.t.t_case9_opfv2 import t_case9_opfv2
39
40 from pypower.t.t_begin import t_begin
41 from pypower.t.t_is import t_is
42 from pypower.t.t_ok import t_ok
43 from pypower.t.t_end import t_end
44
45
47 """Test that C{loadcase} works with an object as well as case file.
48
49 @author: Ray Zimmerman (PSERC Cornell)
50 @author: Richard Lincoln
51 """
52 t_begin(240, quiet)
53
54
55 tdir = dirname(__file__)
56 casefile = join(tdir, 't_case9_opf')
57 matfile = join(tdir, 't_mat9_opf')
58 pfcasefile = join(tdir, 't_case9_pf')
59 pfmatfile = join(tdir, 't_mat9_pf')
60 casefilev2 = join(tdir, 't_case9_opfv2')
61 matfilev2 = join(tdir, 't_mat9_opfv2')
62 pfcasefilev2 = join(tdir, 't_case9_pfv2')
63 pfmatfilev2 = join(tdir, 't_mat9_pfv2')
64
65
66 baseMVA, bus, gen, branch, areas, gencost = t_case9_opf()
67
68 savemat(matfile + '.mat', {'baseMVA': baseMVA, 'bus': bus, 'gen': gen,
69 'branch': branch, 'areas': areas, 'gencost': gencost}, oned_as='row')
70
71
72 ppc = t_case9_opfv2()
73
74 savemat(matfilev2 + '.mat', {'ppc': ppc}, oned_as='column')
75
76
77
78 tmp1 = (ppc['baseMVA'], ppc['bus'].copy(), ppc['gen'].copy(), ppc['branch'].copy(),
79 ppc['areas'].copy(), ppc['gencost'].copy())
80 tmp2 = (ppc['baseMVA'], ppc['bus'].copy(), ppc['gen'].copy(), ppc['branch'].copy(),
81 ppc['areas'].copy(), ppc['gencost'].copy())
82
83 tmp1[2][1:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]] = zeros((2,6))
84 tmp1[3][0, ANGMAX] = 360
85 tmp1[3][8, ANGMIN] = -360
86
87 baseMVA, bus, gen, branch, areas, gencost = tmp1
88
89
90 t = 'loadcase(opf_PY_file_v1) without .py extension : '
91 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
92 loadcase(casefile, False)
93 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
94 t_is(bus1, bus, 12, [t, 'bus'])
95 t_is(gen1, gen, 12, [t, 'gen'])
96 t_is(branch1, branch, 12, [t, 'branch'])
97 t_is(areas1, areas, 12, [t, 'areas'])
98 t_is(gencost1, gencost, 12, [t, 'gencost'])
99
100 t = 'loadcase(opf_PY_file_v1) with .py extension : '
101 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
102 loadcase(casefile + '.py', False)
103 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
104 t_is(bus1, bus, 12, [t, 'bus'])
105 t_is(gen1, gen, 12, [t, 'gen'])
106 t_is(branch1, branch, 12, [t, 'branch'])
107 t_is(areas1, areas, 12, [t, 'areas'])
108 t_is(gencost1, gencost, 12, [t, 'gencost'])
109
110 t = 'loadcase(opf_MAT_file_v1) without .mat extension : '
111 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
112 loadcase(matfile, False)
113 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
114 t_is(bus1, bus, 12, [t, 'bus'])
115 t_is(gen1, gen, 12, [t, 'gen'])
116 t_is(branch1, branch, 12, [t, 'branch'])
117 t_is(areas1, areas, 12, [t, 'areas'])
118 t_is(gencost1, gencost, 12, [t, 'gencost'])
119
120 t = 'loadcase(opf_MAT_file_v1) with .mat extension : '
121 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
122 loadcase(matfile + '.mat', False)
123 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
124 t_is(bus1, bus, 12, [t, 'bus'])
125 t_is(gen1, gen, 12, [t, 'gen'])
126 t_is(branch1, branch, 12, [t, 'branch'])
127 t_is(areas1, areas, 12, [t, 'areas'])
128 t_is(gencost1, gencost, 12, [t, 'gencost'])
129
130
131 baseMVA, bus, gen, branch, areas, gencost = tmp2
132
133 t = 'loadcase(opf_PY_file_v2) without .py extension : '
134 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
135 loadcase(casefilev2, False)
136 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
137 t_is(bus1, bus, 12, [t, 'bus'])
138 t_is(gen1, gen, 12, [t, 'gen'])
139 t_is(branch1, branch, 12, [t, 'branch'])
140 t_is(areas1, areas, 12, [t, 'areas'])
141 t_is(gencost1, gencost, 12, [t, 'gencost'])
142
143 t = 'loadcase(opf_PY_file_v2) with .py extension : '
144 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
145 loadcase(casefilev2 + '.py', False)
146 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
147 t_is(bus1, bus, 12, [t, 'bus'])
148 t_is(gen1, gen, 12, [t, 'gen'])
149 t_is(branch1, branch, 12, [t, 'branch'])
150 t_is(areas1, areas, 12, [t, 'areas'])
151 t_is(gencost1, gencost, 12, [t, 'gencost'])
152
153 t = 'loadcase(opf_MAT_file_v2) without .mat extension : '
154 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
155 loadcase(matfilev2, False)
156 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
157 t_is(bus1, bus, 12, [t, 'bus'])
158 t_is(gen1, gen, 12, [t, 'gen'])
159 t_is(branch1, branch, 12, [t, 'branch'])
160 t_is(areas1, areas, 12, [t, 'areas'])
161 t_is(gencost1, gencost, 12, [t, 'gencost'])
162
163 t = 'loadcase(opf_MAT_file_v2) with .mat extension : '
164 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
165 loadcase(matfilev2 + '.mat', False)
166 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
167 t_is(bus1, bus, 12, [t, 'bus'])
168 t_is(gen1, gen, 12, [t, 'gen'])
169 t_is(branch1, branch, 12, [t, 'branch'])
170 t_is(areas1, areas, 12, [t, 'areas'])
171 t_is(gencost1, gencost, 12, [t, 'gencost'])
172
173
174 baseMVA, bus, gen, branch, areas, gencost = tmp1
175
176 t = 'loadcase(opf_struct_v1) (no version): '
177 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = t_case9_opf()
178 c = {}
179 c['baseMVA'] = baseMVA1
180 c['bus'] = bus1.copy()
181 c['gen'] = gen1.copy()
182 c['branch'] = branch1.copy()
183 c['areas'] = areas1.copy()
184 c['gencost'] = gencost1.copy()
185 baseMVA2, bus2, gen2, branch2, areas2, gencost2 = loadcase(c, False)
186 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
187 t_is(bus2, bus, 12, [t, 'bus'])
188 t_is(gen2, gen, 12, [t, 'gen'])
189 t_is(branch2, branch, 12, [t, 'branch'])
190 t_is(areas2, areas, 12, [t, 'areas'])
191 t_is(gencost2, gencost, 12, [t, 'gencost'])
192
193 t = 'loadcase(opf_struct_v1) (version=\'1\'): '
194 c['version'] = '1'
195 baseMVA2, bus2, gen2, branch2, areas2, gencost2 = loadcase(c, False)
196 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
197 t_is(bus2, bus, 12, [t, 'bus'])
198 t_is(gen2, gen, 12, [t, 'gen'])
199 t_is(branch2, branch, 12, [t, 'branch'])
200 t_is(areas2, areas, 12, [t, 'areas'])
201 t_is(gencost2, gencost, 12, [t, 'gencost'])
202
203
204 baseMVA, bus, gen, branch, areas, gencost = tmp2
205
206 t = 'loadcase(opf_struct_v2) (no version): '
207 c = {}
208 c['baseMVA'] = baseMVA
209 c['bus'] = bus.copy()
210 c['gen'] = gen.copy()
211 c['branch'] = branch.copy()
212 c['areas'] = areas.copy()
213 c['gencost'] = gencost.copy()
214 baseMVA2, bus2, gen2, branch2, areas2, gencost2 = loadcase(c, False)
215 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
216 t_is(bus2, bus, 12, [t, 'bus'])
217 t_is(gen2, gen, 12, [t, 'gen'])
218 t_is(branch2, branch, 12, [t, 'branch'])
219 t_is(areas2, areas, 12, [t, 'areas'])
220 t_is(gencost2, gencost, 12, [t, 'gencost'])
221
222 t = 'loadcase(opf_struct_v2) (version=''2''): '
223 c = {}
224 c['baseMVA'] = baseMVA
225 c['bus'] = bus.copy()
226 c['gen'] = gen.copy()
227 c['branch'] = branch.copy()
228 c['areas'] = areas.copy()
229 c['gencost'] = gencost.copy()
230 c['version'] = '2'
231 baseMVA2, bus2, gen2, branch2, areas2, gencost2 = loadcase(c, False)
232 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
233 t_is(bus2, bus, 12, [t, 'bus'])
234 t_is(gen2, gen, 12, [t, 'gen'])
235 t_is(branch2, branch, 12, [t, 'branch'])
236 t_is(areas2, areas, 12, [t, 'areas'])
237 t_is(gencost2, gencost, 12, [t, 'gencost'])
238
239
240
241 baseMVA, bus, gen, branch, areas, gencost = tmp1
242
243 t = 'ppc = loadcase(opf_PY_file_v1) without .py extension : '
244 ppc1 = loadcase(casefile)
245 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
246 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
247 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
248 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
249 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
250 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
251
252 t = 'ppc = loadcase(opf_PY_file_v1) with .py extension : '
253 ppc1 = loadcase(casefile + '.py')
254 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
255 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
256 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
257 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
258 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
259 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
260
261 t = 'ppc = loadcase(opf_MAT_file_v1) without .mat extension : '
262 ppc1 = loadcase(matfile)
263 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
264 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
265 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
266 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
267 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
268 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
269
270 t = 'ppc = loadcase(opf_MAT_file_v1) with .mat extension : '
271 ppc1 = loadcase(matfile + '.mat')
272 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
273 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
274 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
275 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
276 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
277 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
278
279
280 baseMVA, bus, gen, branch, areas, gencost = tmp2
281
282 t = 'ppc = loadcase(opf_PY_file_v2) without .m extension : '
283 ppc1 = loadcase(casefilev2)
284 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
285 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
286 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
287 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
288 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
289 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
290
291 t = 'ppc = loadcase(opf_PY_file_v2) with .py extension : '
292 ppc1 = loadcase(casefilev2 + '.py')
293 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
294 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
295 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
296 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
297 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
298 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
299
300 t = 'ppc = loadcase(opf_MAT_file_v2) without .mat extension : '
301 ppc1 = loadcase(matfilev2)
302 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
303 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
304 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
305 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
306 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
307 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
308
309 t = 'ppc = loadcase(opf_MAT_file_v2) with .mat extension : '
310 ppc1 = loadcase(matfilev2 + '.mat')
311 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
312 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
313 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
314 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
315 t_is(ppc1['areas'], areas, 12, [t, 'areas'])
316 t_is(ppc1['gencost'], gencost, 12, [t, 'gencost'])
317
318
319 baseMVA, bus, gen, branch, areas, gencost = tmp1
320
321 t = 'ppc = loadcase(opf_struct_v1) (no version): '
322 baseMVA1, bus1, gen1, branch1, areas1, gencost1 = t_case9_opf()
323 c = {}
324 c['baseMVA'] = baseMVA1
325 c['bus'] = bus1.copy()
326 c['gen'] = gen1.copy()
327 c['branch'] = branch1.copy()
328 c['areas'] = areas1.copy()
329 c['gencost'] = gencost1.copy()
330 ppc2 = loadcase(c)
331 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
332 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
333 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
334 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
335 t_is(ppc2['areas'], areas, 12, [t, 'areas'])
336 t_is(ppc2['gencost'], gencost, 12, [t, 'gencost'])
337
338 t = 'ppc = loadcase(opf_struct_v1) (version=''1''): '
339 c['version'] = '1'
340 ppc2 = loadcase(c)
341 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
342 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
343 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
344 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
345 t_is(ppc2['areas'], areas, 12, [t, 'areas'])
346 t_is(ppc2['gencost'], gencost, 12, [t, 'gencost'])
347
348
349 baseMVA, bus, gen, branch, areas, gencost = tmp2
350
351 t = 'ppc = loadcase(opf_struct_v2) (no version): '
352 c = {}
353 c['baseMVA'] = baseMVA
354 c['bus'] = bus.copy()
355 c['gen'] = gen.copy()
356 c['branch'] = branch.copy()
357 c['areas'] = areas.copy()
358 c['gencost'] = gencost.copy()
359 ppc2 = loadcase(c)
360 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
361 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
362 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
363 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
364 t_is(ppc2['areas'], areas, 12, [t, 'areas'])
365 t_is(ppc2['gencost'], gencost, 12, [t, 'gencost'])
366 t_ok(ppc2['version'] == '2', [t, 'version'])
367
368 t = 'ppc = loadcase(opf_struct_v2) (version=''2''): '
369 c = {}
370 c['baseMVA'] = baseMVA
371 c['bus'] = bus.copy()
372 c['gen'] = gen.copy()
373 c['branch'] = branch.copy()
374 c['areas'] = areas.copy()
375 c['gencost'] = gencost.copy()
376 c['version'] = '2'
377 ppc2 = loadcase(c)
378 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
379 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
380 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
381 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
382 t_is(ppc2['areas'], areas, 12, [t, 'areas'])
383 t_is(ppc2['gencost'], gencost, 12, [t, 'gencost'])
384
385
386
387 baseMVA, bus, gen, branch = t_case9_pf()
388 savemat(pfmatfile + '.mat',
389 {'baseMVA': baseMVA, 'bus': bus, 'gen': gen, 'branch': branch},
390 oned_as='column')
391
392
393 ppc = t_case9_pfv2()
394 tmp = (ppc['baseMVA'], ppc['bus'].copy(),
395 ppc['gen'].copy(), ppc['branch'].copy())
396 baseMVA, bus, gen, branch = tmp
397
398 savemat(pfmatfilev2 + '.mat', {'ppc': ppc}, oned_as='column')
399
400
401 t = 'loadcase(pf_PY_file_v1) without .py extension : '
402 baseMVA1, bus1, gen1, branch1 = \
403 loadcase(pfcasefile, False, False, False)
404 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
405 t_is(bus1, bus, 12, [t, 'bus'])
406 t_is(gen1, gen, 12, [t, 'gen'])
407 t_is(branch1, branch, 12, [t, 'branch'])
408
409 t = 'loadcase(pf_PY_file_v1) with .py extension : '
410 baseMVA1, bus1, gen1, branch1 = \
411 loadcase(pfcasefile + '.py', False, False, False)
412 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
413 t_is(bus1, bus, 12, [t, 'bus'])
414 t_is(gen1, gen, 12, [t, 'gen'])
415 t_is(branch1, branch, 12, [t, 'branch'])
416
417 t = 'loadcase(pf_MAT_file_v1) without .mat extension : '
418 baseMVA1, bus1, gen1, branch1 = \
419 loadcase(pfmatfile, False, False, False)
420 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
421 t_is(bus1, bus, 12, [t, 'bus'])
422 t_is(gen1, gen, 12, [t, 'gen'])
423 t_is(branch1, branch, 12, [t, 'branch'])
424
425 t = 'loadcase(pf_MAT_file_v1) with .mat extension : '
426 baseMVA1, bus1, gen1, branch1 = \
427 loadcase(pfmatfile + '.mat', False, False, False)
428 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
429 t_is(bus1, bus, 12, [t, 'bus'])
430 t_is(gen1, gen, 12, [t, 'gen'])
431 t_is(branch1, branch, 12, [t, 'branch'])
432
433 t = 'loadcase(pf_PY_file_v2) without .py extension : '
434 baseMVA1, bus1, gen1, branch1 = \
435 loadcase(pfcasefilev2, False, False, False)
436 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
437 t_is(bus1, bus, 12, [t, 'bus'])
438 t_is(gen1, gen, 12, [t, 'gen'])
439 t_is(branch1, branch, 12, [t, 'branch'])
440
441 t = 'loadcase(pf_PY_file_v2) with .py extension : '
442 baseMVA1, bus1, gen1, branch1 = \
443 loadcase(pfcasefilev2 + '.py', False, False, False)
444 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
445 t_is(bus1, bus, 12, [t, 'bus'])
446 t_is(gen1, gen, 12, [t, 'gen'])
447 t_is(branch1, branch, 12, [t, 'branch'])
448
449 t = 'loadcase(pf_MAT_file_v2) without .mat extension : '
450 baseMVA1, bus1, gen1, branch1 = \
451 loadcase(pfmatfilev2, False, False, False)
452 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
453 t_is(bus1, bus, 12, [t, 'bus'])
454 t_is(gen1, gen, 12, [t, 'gen'])
455 t_is(branch1, branch, 12, [t, 'branch'])
456
457 t = 'loadcase(pf_MAT_file_v2) with .mat extension : '
458 baseMVA1, bus1, gen1, branch1 = \
459 loadcase(pfmatfilev2 + '.mat', False, False, False)
460 t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
461 t_is(bus1, bus, 12, [t, 'bus'])
462 t_is(gen1, gen, 12, [t, 'gen'])
463 t_is(branch1, branch, 12, [t, 'branch'])
464
465 t = 'loadcase(pf_struct_v1) (no version): '
466 baseMVA1, bus1, gen1, branch1 = t_case9_pf()
467 c = {}
468 c['baseMVA'] = baseMVA1
469 c['bus'] = bus1.copy()
470 c['gen'] = gen1.copy()
471 c['branch'] = branch1.copy()
472 baseMVA2, bus2, gen2, branch2 = loadcase(c, False, False, False)
473 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
474 t_is(bus2, bus, 12, [t, 'bus'])
475 t_is(gen2, gen, 12, [t, 'gen'])
476 t_is(branch2, branch, 12, [t, 'branch'])
477
478 t = 'loadcase(pf_struct_v1) (version=''1''): '
479 c['version'] = '1'
480 baseMVA2, bus2, gen2, branch2 = loadcase(c, False, False, False)
481 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
482 t_is(bus2, bus, 12, [t, 'bus'])
483 t_is(gen2, gen, 12, [t, 'gen'])
484 t_is(branch2, branch, 12, [t, 'branch'])
485
486 t = 'loadcase(pf_struct_v2) : '
487 c = {}
488 c['baseMVA'] = baseMVA
489 c['bus'] = bus.copy()
490 c['gen'] = gen.copy()
491 c['branch'] = branch.copy()
492 c['version'] = '2'
493 baseMVA2, bus2, gen2, branch2 = loadcase(c, False, False, False)
494 t_is(baseMVA2, baseMVA, 12, [t, 'baseMVA'])
495 t_is(bus2, bus, 12, [t, 'bus'])
496 t_is(gen2, gen, 12, [t, 'gen'])
497 t_is(branch2, branch, 12, [t, 'branch'])
498
499
500
501
502
503
504
505 t = 'ppc = loadcase(pf_PY_file_v1) without .py extension : '
506 ppc1 = loadcase(pfcasefile)
507 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
508 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
509 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
510 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
511
512 t = 'ppc = loadcase(pf_PY_file_v1) with .py extension : '
513 ppc1 = loadcase(pfcasefile + '.py')
514 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
515 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
516 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
517 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
518
519 t = 'ppc = loadcase(pf_MAT_file_v1) without .mat extension : '
520 ppc1 = loadcase(pfmatfile)
521 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
522 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
523 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
524 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
525
526 t = 'ppc = loadcase(pf_MAT_file_v1) with .mat extension : '
527 ppc1 = loadcase(pfmatfile + '.mat')
528 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
529 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
530 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
531 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
532
533 t = 'ppc = loadcase(pf_PY_file_v2) without .py extension : '
534 ppc1 = loadcase(pfcasefilev2)
535 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
536 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
537 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
538 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
539
540 t = 'ppc = loadcase(pf_PY_file_v2) with .py extension : '
541 ppc1 = loadcase(pfcasefilev2 + '.py')
542 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
543 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
544 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
545 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
546
547 t = 'ppc = loadcase(pf_MAT_file_v2) without .mat extension : '
548 ppc1 = loadcase(pfmatfilev2)
549 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
550 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
551 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
552 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
553
554 t = 'ppc = loadcase(pf_MAT_file_v2) with .mat extension : '
555 ppc1 = loadcase(pfmatfilev2 + '.mat')
556 t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
557 t_is(ppc1['bus'], bus, 12, [t, 'bus'])
558 t_is(ppc1['gen'], gen, 12, [t, 'gen'])
559 t_is(ppc1['branch'], branch, 12, [t, 'branch'])
560
561 t = 'ppc = loadcase(pf_struct_v1) (no version): '
562 baseMVA1, bus1, gen1, branch1 = t_case9_pf()
563 c = {}
564 c['baseMVA'] = baseMVA1
565 c['bus'] = bus1.copy()
566 c['gen'] = gen1.copy()
567 c['branch'] = branch1.copy()
568 ppc2 = loadcase(c)
569 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
570 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
571 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
572 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
573
574 t = 'ppc = loadcase(pf_struct_v1) (version=''1''): '
575 c['version'] = '1'
576 ppc2 = loadcase(c)
577 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
578 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
579 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
580 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
581
582 t = 'ppc = loadcase(pf_struct_v2) : '
583 c = {}
584 c['baseMVA'] = baseMVA
585 c['bus'] = bus.copy()
586 c['gen'] = gen.copy()
587 c['branch'] = branch.copy()
588 c['version'] = '2'
589 ppc2 = loadcase(c)
590 t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
591 t_is(ppc2['bus'], bus, 12, [t, 'bus'])
592 t_is(ppc2['gen'], gen, 12, [t, 'gen'])
593 t_is(ppc2['branch'], branch, 12, [t, 'branch'])
594
595
596 os.remove(matfile + '.mat')
597 os.remove(pfmatfile + '.mat')
598 os.remove(matfilev2 + '.mat')
599 os.remove(pfmatfilev2 + '.mat')
600
601 t = 'runpf(my_PY_file)'
602 ppopt = ppoption(VERBOSE=0, OUT_ALL=0)
603 results3, success = runpf(pfcasefile, ppopt)
604 baseMVA3, bus3, gen3, branch3 = results3['baseMVA'], results3['bus'], \
605 results3['gen'], results3['branch']
606 t_ok( success, t )
607
608 t = 'runpf(my_object)'
609 results4, success = runpf(c, ppopt)
610 baseMVA4, bus4, gen4, branch4 = results4['baseMVA'], results4['bus'], \
611 results4['gen'], results4['branch']
612 t_ok( success, t )
613
614 t = 'runpf result comparison : '
615 t_is(baseMVA3, baseMVA4, 12, [t, 'baseMVA'])
616 t_is(bus3, bus4, 12, [t, 'bus'])
617 t_is(gen3, gen4, 12, [t, 'gen'])
618 t_is(branch3, branch4, 12, [t, 'branch'])
619
620 t = 'runpf(modified_struct)'
621 c['gen'][2, 1] = c['gen'][2, 1] + 1
622 results5, success = runpf(c, ppopt)
623 gen5 = results5['gen']
624 t_is(gen5[0, 1], gen4[0, 1] - 1, 1, t)
625
626 t_end()
627
628
629 if __name__ == '__main__':
630 t_loadcase(False)
631