-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathtest_output.py
129 lines (95 loc) · 3.41 KB
/
test_output.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
"""
Test output selection.
"""
import os
import numpy as np
import unittest
import andes
class TestOutput(unittest.TestCase):
"""
Class for Output test.
"""
def test_output_xyname(self):
"""
Test x_name and y_name for Output
"""
ss = andes.load(andes.get_case("5bus/pjm5bus.json"),
no_output=True,
setup=False,
default_config=True)
ss.add("Output", {"model": "GENCLS", "varname": "omega"})
ss.add("Output", {"model": "GENCLS", "varname": "delta", "dev": 2})
ss.add("Output", {"model": "Bus"})
ss.setup()
ss.PFlow.run()
ss.TDS.config.tf = 0.1
ss.TDS.run()
ss.TDS.load_plotter()
nt = len(ss.dae.ts.t)
nx = 5
ny = 10
self.assertEqual(len(ss.dae.x_name_output), nx)
self.assertEqual(len(ss.dae.y_name_output), ny)
self.assertEqual(ss.dae.ts.x.shape[1], nx)
self.assertEqual(ss.dae.ts.y.shape[1], ny)
np.testing.assert_array_equal(ss.Output.xidx, [1, 4, 5, 6, 7])
np.testing.assert_array_equal(ss.Output.yidx, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# test loaded data by plot
self.assertEqual(ss.TDS.plt._data.shape, (nt, nx + ny + 1))
np.testing.assert_array_equal(
ss.TDS.plt._process_yidx(ss.GENCLS.omega, a=None),
[2, 3, 4, 5])
np.testing.assert_array_equal(
ss.TDS.plt._process_yidx(ss.GENCLS.delta, a=None),
[1])
np.testing.assert_array_equal(
ss.TDS.plt._process_yidx(ss.TG2.pout, a=None),
[])
# test `DAE.ts.get_data`
np.testing.assert_equal(
ss.dae.ts.get_data(ss.GENCLS.omega, a=None).shape[1],
4)
np.testing.assert_equal(
ss.dae.ts.get_data(ss.GENCLS.delta, a=None).shape[1],
1)
np.testing.assert_equal(
ss.dae.ts.get_data(ss.TG2.pout, a=None).shape[1],
0)
def test_from_csv(self):
"""
Test from_csv when loading selected output from csv file.
"""
case = andes.get_case("5bus/pjm5bus.json")
ss = andes.load(case,
no_output=True,
setup=False,
default_config=True)
ss.add("Output", {"model": "Bus", "varname": "v"})
ss.setup()
ss.PFlow.run()
ss.TDS.config.tf = 0.1
ss.TDS.run()
ss.TDS.load_plotter()
ss.TDS.plt.export_csv("pjm5bus_selec_out.csv")
# Test assign CSV in TDS.run()
ss2 = andes.load(case,
no_output=True,
setup=False,
default_config=True)
ss2.add("Output", {"model": "Bus", "varname": "v"})
ss2.setup()
ss2.PFlow.run()
ss2.TDS.run(from_csv="pjm5bus_selec_out.csv")
self.assertTrue(ss2.TDS.converged)
# Test assign CSV in andes.load()
ss3 = andes.load(case,
no_output=True,
setup=False,
default_config=True,
from_csv="pjm5bus_selec_out.csv")
ss3.add("Output", {"model": "Bus", "varname": "v"})
ss3.setup()
ss3.PFlow.run()
ss3.TDS.run()
self.assertTrue(ss3.TDS.converged)
os.remove("pjm5bus_selec_out.csv")