|
27 | 27 |
|
28 | 28 | from .conftest import editsdefaults
|
29 | 29 |
|
30 |
| -from . import linfnorm_mimo_testcases |
| 30 | +from .linfnorm_mimo_testcases import continuous_time_mimo, discrete_time_mimo |
31 | 31 |
|
32 | 32 | class TestStateSpace:
|
33 | 33 | """Tests for the StateSpace class."""
|
@@ -1102,72 +1102,69 @@ def test_latex_repr_testsize(editsdefaults):
|
1102 | 1102 | assert gstatic._repr_latex_() is None
|
1103 | 1103 |
|
1104 | 1104 |
|
1105 |
| -# these are relatively simple examples |
1106 |
| -# the underdamped gpeak and fpeak are found from |
1107 |
| -# gpeak = 1/(2*zeta*(1-zeta**2)**0.5 |
1108 |
| -# fpeak = wn*(1-2*zeta**2)**0.5 |
1109 |
| -@slycotonly |
1110 |
| -@pytest.mark.parametrize( |
1111 |
| - "name, sys, refgpeak, reffpeak", |
1112 |
| - [ |
1113 |
| - ('lpf', ct.tf([1],[1,1]), 1, 0), |
1114 |
| - ('static', ct.tf([1.23],[1]), 1.23, 0), |
1115 |
| - ('underdamped', ct.tf([100],[1, 2*0.1*10, 100]), 5.02518907629606, 9.89949493661), |
1116 |
| - ('hpf', ct.tf([1, 0], [1, 1]), 1, np.inf), |
1117 |
| - ('integrator', ct.tf([1],[1,0]), np.inf, 0), |
1118 |
| - ('undamped', ct.tf([1],[1, 0, 144]), np.inf, 12), |
1119 |
| - ('zero', ct.tf([0],[1, 0, 144]), 0, 0), |
1120 |
| - ]) |
1121 |
| -def test_linfnorm_siso_continuoustime(name, sys, refgpeak, reffpeak): |
1122 |
| - gpeak, fpeak = linfnorm(sys) |
1123 |
| - np.testing.assert_allclose(gpeak, refgpeak) |
1124 |
| - np.testing.assert_allclose(fpeak, reffpeak) |
1125 |
| - |
1126 |
| - |
1127 |
| -# these are the continuous-time examples with some tweaks |
1128 |
| -@slycotonly |
1129 |
| -@pytest.mark.parametrize( |
1130 |
| - "name, sys, refgpeak, reffpeak", |
1131 |
| - [ |
1132 |
| - ('lpf', ct.c2d(ct.tf([1],[1,1]), 0.1), 1, 0), |
1133 |
| - ('static', ct.c2d(ct.tf([1.23],[1]), 0.1), 1.23, 0), |
1134 |
| - # the gain and frequency don't quite match the continuous-time case, |
1135 |
| - # I assume due to c2d imperfection |
1136 |
| - ('underdamped', ct.c2d(ct.tf([100],[1, 2*0.1*10, 100]), 0.01), 5.023137, 9.899412), |
1137 |
| - # The HPF fpeak is the Nyquist frequency |
1138 |
| - # Assume gpeak mismatch is again c2d mismatch |
1139 |
| - ('hpf', ct.c2d(ct.tf([1, 0], [1, 1]), 0.1), 1.04995845, np.pi * 10), |
1140 |
| - ('integrator', ct.c2d(ct.tf([1],[1,0]), 0.1), np.inf, 0), |
1141 |
| - ('undamped', ct.c2d(ct.tf([1],[1, 0, 144]), 0.003), np.inf, 12), |
1142 |
| - # ss call works around Scipy's "Badly conditioned filter coefficients" warning |
1143 |
| - ('zero', ct.c2d(ct.ss(ct.tf([0],[1, 0, 144])), 0.003), 0, 0), |
1144 |
| - ]) |
1145 |
| -def test_linfnorm_siso_discretetime(name, sys, refgpeak, reffpeak): |
1146 |
| - gpeak, fpeak = linfnorm(sys) |
1147 |
| - np.testing.assert_allclose(gpeak, refgpeak) |
1148 |
| - np.testing.assert_allclose(fpeak, reffpeak) |
1149 |
| - |
1150 |
| - |
1151 |
| -@slycotonly |
1152 |
| -@pytest.mark.parametrize("name, sys, refgpeak, reffpeak", |
1153 |
| - linfnorm_mimo_testcases.continuous_time) |
1154 |
| -def test_linfnorm_mimo_continuoustime(name, sys, refgpeak, reffpeak): |
1155 |
| - gpeak, fpeak = linfnorm(sys) |
1156 |
| - np.testing.assert_allclose(gpeak, refgpeak) |
1157 |
| - np.testing.assert_allclose(fpeak, reffpeak) |
1158 |
| - |
1159 |
| - |
1160 |
| -@slycotonly |
1161 |
| -@pytest.mark.parametrize("name, sys, refgpeak, reffpeak", |
1162 |
| - linfnorm_mimo_testcases.discrete_time) |
1163 |
| -def test_linfnorm_mimo_discretetime(name, sys, refgpeak, reffpeak): |
1164 |
| - gpeak, fpeak = linfnorm(sys) |
1165 |
| - np.testing.assert_allclose(gpeak, refgpeak) |
1166 |
| - np.testing.assert_allclose(fpeak, reffpeak) |
1167 |
| - |
1168 |
| - |
1169 |
| -@slycotonly |
1170 |
| -def test_linfnorm_notimebase(): |
1171 |
| - g = ct.ss(-0.1,1,1,0,dt=None) |
1172 |
| - with pytest.raises(ValueError): |
1173 |
| - linfnorm(g) |
| 1105 | +class TestLinfnorm: |
| 1106 | + # these are relatively simple examples |
| 1107 | + # the underdamped gpeak and fpeak are found from |
| 1108 | + # gpeak = 1/(2*zeta*(1-zeta**2)**0.5 |
| 1109 | + # fpeak = wn*(1-2*zeta**2)**0.5 |
| 1110 | + @slycotonly |
| 1111 | + @pytest.mark.parametrize( |
| 1112 | + "name, sys, refgpeak, reffpeak", |
| 1113 | + [ |
| 1114 | + ('lpf', ct.tf([1],[1,1]), 1, 0), |
| 1115 | + ('static', ct.tf([1.23],[1]), 1.23, 0), |
| 1116 | + ('underdamped', ct.tf([100],[1, 2*0.1*10, 100]), 5.02518907629606, 9.89949493661), |
| 1117 | + ('hpf', ct.tf([1, 0], [1, 1]), 1, np.inf), |
| 1118 | + ('integrator', ct.tf([1],[1,0]), np.inf, 0), |
| 1119 | + ('undamped', ct.tf([1],[1, 0, 144]), np.inf, 12), |
| 1120 | + ('zero', ct.tf([0],[1, 0, 144]), 0, 0), |
| 1121 | + ]) |
| 1122 | + def test_linfnorm_siso_continuoustime(self, name, sys, refgpeak, reffpeak): |
| 1123 | + gpeak, fpeak = linfnorm(sys) |
| 1124 | + np.testing.assert_allclose(gpeak, refgpeak) |
| 1125 | + np.testing.assert_allclose(fpeak, reffpeak) |
| 1126 | + |
| 1127 | + |
| 1128 | + # these are the continuous-time examples with some tweaks |
| 1129 | + @slycotonly |
| 1130 | + @pytest.mark.parametrize( |
| 1131 | + "name, sys, refgpeak, reffpeak", |
| 1132 | + [ |
| 1133 | + ('lpf', ct.c2d(ct.tf([1],[1,1]), 0.1), 1, 0), |
| 1134 | + ('static', ct.c2d(ct.tf([1.23],[1]), 0.1), 1.23, 0), |
| 1135 | + # the gain and frequency don't quite match the continuous-time case, |
| 1136 | + # I assume due to c2d imperfection |
| 1137 | + ('underdamped', ct.c2d(ct.tf([100],[1, 2*0.1*10, 100]), 0.01), 5.023137, 9.899412), |
| 1138 | + # The HPF fpeak is the Nyquist frequency |
| 1139 | + # Assume gpeak mismatch is again c2d mismatch |
| 1140 | + ('hpf', ct.c2d(ct.tf([1, 0], [1, 1]), 0.1), 1.04995845, np.pi * 10), |
| 1141 | + ('integrator', ct.c2d(ct.tf([1],[1,0]), 0.1), np.inf, 0), |
| 1142 | + ('undamped', ct.c2d(ct.tf([1],[1, 0, 144]), 0.003), np.inf, 12), |
| 1143 | + # ss call works around Scipy's "Badly conditioned filter coefficients" warning |
| 1144 | + ('zero', ct.c2d(ct.ss(ct.tf([0],[1, 0, 144])), 0.003), 0, 0), |
| 1145 | + ]) |
| 1146 | + def test_linfnorm_siso_discretetime(self, name, sys, refgpeak, reffpeak): |
| 1147 | + gpeak, fpeak = linfnorm(sys) |
| 1148 | + np.testing.assert_allclose(gpeak, refgpeak) |
| 1149 | + np.testing.assert_allclose(fpeak, reffpeak) |
| 1150 | + |
| 1151 | + |
| 1152 | + @slycotonly |
| 1153 | + def test_linfnorm_mimo_continuoustime(self, continuous_time_mimo): |
| 1154 | + sys, refgpeak, reffpeak = continuous_time_mimo |
| 1155 | + gpeak, fpeak = linfnorm(sys) |
| 1156 | + np.testing.assert_allclose(gpeak, refgpeak) |
| 1157 | + np.testing.assert_allclose(fpeak, reffpeak) |
| 1158 | + |
| 1159 | + @slycotonly |
| 1160 | + def test_linfnorm_mimo_discretetime(self, discrete_time_mimo): |
| 1161 | + sys, refgpeak, reffpeak = discrete_time_mimo |
| 1162 | + gpeak, fpeak = linfnorm(sys) |
| 1163 | + np.testing.assert_allclose(gpeak, refgpeak) |
| 1164 | + np.testing.assert_allclose(fpeak, reffpeak) |
| 1165 | + |
| 1166 | + @slycotonly |
| 1167 | + def test_linfnorm_notimebase(self): |
| 1168 | + g = ct.ss(-0.1,1,1,0,dt=None) |
| 1169 | + with pytest.raises(ValueError): |
| 1170 | + linfnorm(g) |
0 commit comments