|
| 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 | +import numpy as np |
| 10 | +import pytest |
| 11 | +from matplotlib import pyplot as plt |
| 12 | + |
| 13 | +from control import TransferFunction, config, pzmap |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.parametrize("kwargs", |
| 17 | + [pytest.param(dict(), id="default"), |
| 18 | + pytest.param(dict(plot=False), id="plot=False"), |
| 19 | + pytest.param(dict(plot=True), id="plot=True"), |
| 20 | + pytest.param(dict(grid=True), id="grid=True"), |
| 21 | + pytest.param(dict(title="My Title"), id="title")]) |
| 22 | +@pytest.mark.parametrize("setdefaults", [False, True], ids=["kw", "config"]) |
| 23 | +@pytest.mark.parametrize("dt", [0, 1], ids=["s", "z"]) |
| 24 | +def test_pzmap(kwargs, setdefaults, dt, editsdefaults, mplcleanup): |
| 25 | + """Test pzmap""" |
| 26 | + # T from from pvtol-nested example |
| 27 | + T = TransferFunction([-9.0250000e-01, -4.7200750e+01, -8.6812900e+02, |
| 28 | + +5.6261850e+03, +2.1258472e+05, +8.4724600e+05, |
| 29 | + +1.0192000e+06, +2.3520000e+05], |
| 30 | + [9.02500000e-03, 9.92862812e-01, 4.96974094e+01, |
| 31 | + 1.35705659e+03, 2.09294163e+04, 1.64898435e+05, |
| 32 | + 6.54572220e+05, 1.25274600e+06, 1.02420000e+06, |
| 33 | + 2.35200000e+05], |
| 34 | + dt) |
| 35 | + |
| 36 | + Pref = [-23.8877+19.3837j, -23.8877-19.3837j, -23.8349+15.7846j, |
| 37 | + -23.8349-15.7846j, -5.2320 +0.4117j, -5.2320 -0.4117j, |
| 38 | + -2.2246 +0.0000j, -1.5160 +0.0000j, -0.3627 +0.0000j] |
| 39 | + Zref = [-23.8877+19.3837j, -23.8877-19.3837j, +14.3637 +0.0000j, |
| 40 | + -14.3637 +0.0000j, -2.2246 +0.0000j, -2.0000 +0.0000j, |
| 41 | + -0.3000 +0.0000j] |
| 42 | + |
| 43 | + pzkwargs = kwargs.copy() |
| 44 | + if setdefaults: |
| 45 | + for k in ['plot', 'grid']: |
| 46 | + if k in pzkwargs: |
| 47 | + v = pzkwargs.pop(k) |
| 48 | + config.set_defaults('pzmap', **{k: v}) |
| 49 | + |
| 50 | + P, Z = pzmap(T, **pzkwargs) |
| 51 | + |
| 52 | + np.testing.assert_allclose(P, Pref, rtol=1e-3) |
| 53 | + np.testing.assert_allclose(Z, Zref, rtol=1e-3) |
| 54 | + |
| 55 | + if kwargs.get('plot', True): |
| 56 | + ax = plt.gca() |
| 57 | + assert ax.get_title() == kwargs.get('title', 'Pole Zero Map') |
| 58 | + if kwargs.get('grid', False): |
| 59 | + # TODO: check for correct grid |
| 60 | + pass |
| 61 | + |
| 62 | + |
| 63 | +def test_pzmap_warns(): |
| 64 | + with pytest.warns(FutureWarning): |
| 65 | + pzmap(TransferFunction([1], [1, 2]), Plot=True) |
| 66 | + |
| 67 | + |
| 68 | +def test_pzmap_raises(): |
| 69 | + with pytest.raises(TypeError): |
| 70 | + # not an LTI system |
| 71 | + pzmap(([1], [1,2])) |
0 commit comments