|
| 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])) |