-
Notifications
You must be signed in to change notification settings - Fork 458
Expand file tree
/
Copy pathnichols_test.py
More file actions
95 lines (67 loc) · 2.55 KB
/
Copy pathnichols_test.py
File metadata and controls
95 lines (67 loc) · 2.55 KB
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
"""nichols_test.py - test Nichols plot
RMM, 31 Mar 2011
"""
import matplotlib.pyplot as plt
import pytest
from control import StateSpace, nichols_plot, nichols, nichols_grid, pade, tf
@pytest.fixture()
def tsys():
"""Set up a system to test operations on."""
A = [[-3., 4., 2.], [-1., -3., 0.], [2., 5., 3.]]
B = [[1.], [-3.], [-2.]]
C = [[4., 2., -3.]]
D = [[0.]]
return StateSpace(A, B, C, D)
def test_nichols(tsys, mplcleanup):
"""Generate a Nichols plot."""
nichols_plot(tsys)
def test_nichols_alias(tsys, mplcleanup):
"""Test the control.nichols alias and the grid=False parameter"""
nichols(tsys, grid=False)
@pytest.mark.usefixtures("mplcleanup")
class TestNicholsGrid:
def test_ax(self):
# check grid is plotted into gca, or specified axis
fig, axs = plt.subplots(2,2)
plt.sca(axs[0,1])
cl_mag_lines = nichols_grid()[1]
assert cl_mag_lines[0].axes is axs[0, 1]
cl_mag_lines = nichols_grid(ax=axs[1,1])[1]
assert cl_mag_lines[0].axes is axs[1, 1]
# nichols_grid didn't change what the "current axes" are
assert plt.gca() is axs[0, 1]
def test_cl_phase_label_control(self):
# test label_cl_phases argument
cl_mag_lines, cl_phase_lines, cl_mag_labels, cl_phase_labels \
= nichols_grid()
assert len(cl_phase_labels) > 0
cl_mag_lines, cl_phase_lines, cl_mag_labels, cl_phase_labels \
= nichols_grid(label_cl_phases=False)
assert len(cl_phase_labels) == 0
def test_labels_clipped(self):
# regression test: check that contour labels are clipped
mcontours, ncontours, mlabels, nlabels = nichols_grid()
assert all(ml.get_clip_on() for ml in mlabels)
assert all(nl.get_clip_on() for nl in nlabels)
def test_minimal_phase(self):
# regression test: phase extent is minimal
g = tf([1],[1,1]) * tf([1],[1/1, 2*0.1/1, 1])
nichols(g)
ax = plt.gca()
assert ax.get_xlim()[1] <= 0
def test_fixed_view(self):
# respect xlim, ylim set by user
g = (tf([1],[1/1, 2*0.01/1, 1])
* tf([1],[1/100**2, 2*0.001/100, 1])
* tf(*pade(0.01, 5)))
# normally a broad axis
nichols(g)
assert(plt.xlim()[0] == -1440)
assert(plt.ylim()[0] <= -240)
nichols(g, grid=False)
# zoom in
plt.axis([-360,0,-40,50])
# nichols_grid doesn't expand limits
nichols_grid()
assert(plt.xlim()[0] == -360)
assert(plt.ylim()[1] >= -40)