Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite646370

Browse files
committed
add pzmap_test
1 parentbdbd198 commite646370

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

‎control/tests/conftest.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
# contest.py - pytest local plugins and fixtures
22

3-
importcontrol
43
importos
54

5+
importmatplotlibasmpl
66
importpytest
77

8+
importcontrol
9+
810

911
@pytest.fixture(scope="session",autouse=True)
1012
defuse_numpy_ndarray():
1113
"""Switch the config to use ndarray instead of matrix"""
1214
ifos.getenv("PYTHON_CONTROL_STATESPACE_ARRAY")=="1":
1315
control.config.defaults['statesp.use_numpy_matrix']=False
16+
17+
18+
@pytest.fixture(scope="function")
19+
defeditsdefaults():
20+
"""Make sure any changes to the defaults only last during a test"""
21+
restore=control.config.defaults.copy()
22+
yield
23+
control.config.defaults.update(restore)
24+
25+
26+
@pytest.fixture(scope="function")
27+
defmplcleanup():
28+
"""Workaround for python2
29+
30+
python 2 does not like to mix the original mpl decorator with pytest
31+
fixtures. So we roll our own.
32+
"""
33+
save=mpl.units.registry.copy()
34+
try:
35+
yield
36+
finally:
37+
mpl.units.registry.clear()
38+
mpl.units.registry.update(save)
39+
mpl.pyplot.close("all")

‎control/tests/pzmap_test.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- coding: utf-8 -*-
2+
""" pzmap_test.py - test pzmap()
3+
4+
Created on Thu Aug 20 20:06:21 2020
5+
6+
@author: bnavigator
7+
"""
8+
9+
importnumpyasnp
10+
importpytest
11+
frommatplotlibimportpyplotasplt
12+
13+
fromcontrolimportTransferFunction,config,pzmap
14+
15+
16+
@pytest.mark.parametrize("kwargs",
17+
[dict(),
18+
dict(plot=False),
19+
dict(plot=True),
20+
dict(grid=True),
21+
dict(title="Custom Title")],
22+
ids=["default",
23+
"noplot",
24+
"plotTrue",
25+
"grid",
26+
"title"])
27+
@pytest.mark.parametrize("setdefaults",# set by kw or config
28+
[False,True],
29+
ids=["kw","config"])
30+
@pytest.mark.parametrize("dt", [0,True],ids=["s","z"])
31+
deftest_pzmap(kwargs,setdefaults,dt,editsdefaults,mplcleanup):
32+
"""Test pzmap"""
33+
# T from from pvtol-nested example
34+
T=TransferFunction([-9.0250000e-01,-4.7200750e+01,-8.6812900e+02,
35+
+5.6261850e+03,+2.1258472e+05,+8.4724600e+05,
36+
+1.0192000e+06,+2.3520000e+05],
37+
[9.02500000e-03,9.92862812e-01,4.96974094e+01,
38+
1.35705659e+03,2.09294163e+04,1.64898435e+05,
39+
6.54572220e+05,1.25274600e+06,1.02420000e+06,
40+
2.35200000e+05])
41+
42+
Pref= [-23.8877+19.3837j,-23.8877-19.3837j,-23.8349+15.7846j,
43+
-23.8349-15.7846j,-5.2320+0.4117j,-5.2320-0.4117j,
44+
-2.2246+0.0000j,-1.5160+0.0000j,-0.3627+0.0000j]
45+
Zref= [-23.8877+19.3837j,-23.8877-19.3837j,+14.3637+0.0000j,
46+
-14.3637+0.0000j,-2.2246+0.0000j,-2.0000+0.0000j,
47+
-0.3000+0.0000j]
48+
49+
pzkwargs=kwargs.copy()
50+
ifsetdefaults:
51+
forkin ['plot','grid']:
52+
ifkinpzkwargs:
53+
v=pzkwargs.pop(k)
54+
config.set_defaults('pzmap',**{k:v})
55+
56+
P,Z=pzmap(T,**pzkwargs)
57+
58+
np.testing.assert_allclose(P,Pref,rtol=1e-3)
59+
np.testing.assert_allclose(Z,Zref,rtol=1e-3)
60+
61+
ifkwargs.get('plot',True):
62+
ax=plt.gca()
63+
assertax.get_title()==kwargs.get('title','Pole Zero Map')
64+
ifkwargs.get('grid',False):
65+
# TODO: check for correct grid
66+
pass
67+
68+
69+
deftest_pzmap_warns():
70+
withpytest.warns(FutureWarning):
71+
pzmap(TransferFunction([1], [1,2]),Plot=True)
72+
73+
74+
deftest_pzmap_raises():
75+
withpytest.raises(TypeError):
76+
# not an LTI system
77+
pzmap(([1], [1,2]))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp