|
| 1 | +# timeplot_test.py - test out time response plots |
| 2 | +# RMM, 23 Jun 2023 |
| 3 | + |
| 4 | +import pytest |
| 5 | +import control as ct |
| 6 | +import matplotlib as mpl |
| 7 | +import matplotlib.pyplot as plt |
| 8 | + |
| 9 | +# Step responses |
| 10 | +@pytest.mark.parametrize("nin, nout", [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)]) |
| 11 | +@pytest.mark.parametrize("transpose", [True, False]) |
| 12 | +@pytest.mark.parametrize("plot_inputs", [None, True, False]) |
| 13 | +def test_simple_response(nout, nin, transpose, plot_inputs): |
| 14 | + sys = ct.rss(4, nout, nin) |
| 15 | + stepresp = ct.step_response(sys) |
| 16 | + stepresp.plot(plot_inputs=plot_inputs, transpose=transpose) |
| 17 | + |
| 18 | + # Add additional data (and provide infon in the title) |
| 19 | + ct.step_response(ct.rss(4, nout, nin), stepresp.time[-1]).plot( |
| 20 | + plot_inputs=plot_inputs, transpose=transpose, |
| 21 | + title=stepresp.title + f" [{plot_inputs=}, {transpose=}]") |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize("transpose", [True, False]) |
| 25 | +def test_combine_signals(transpose): |
| 26 | + sys = ct.rss(4, 2, 3) |
| 27 | + stepresp = ct.step_response(sys) |
| 28 | + stepresp.plot( |
| 29 | + combine_signals=True, transpose=transpose, |
| 30 | + title=f"Step response: combine_signals = True; transpose={transpose}") |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.parametrize("transpose", [True, False]) |
| 34 | +def test_combine_traces(transpose): |
| 35 | + sys = ct.rss(4, 2, 3) |
| 36 | + stepresp = ct.step_response(sys) |
| 37 | + stepresp.plot( |
| 38 | + combine_traces=True, transpose=transpose, |
| 39 | + title=f"Step response: combine_traces = True; transpose={transpose}") |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.parametrize("transpose", [True, False]) |
| 43 | +def test_combine_signals_traces(transpose): |
| 44 | + sys = ct.rss(4, 5, 3) |
| 45 | + stepresp = ct.step_response(sys) |
| 46 | + stepresp.plot( |
| 47 | + combine_signals=True, combine_traces=True, transpose=transpose, |
| 48 | + title=f"Step response: combine_signals/traces = True;" + |
| 49 | + f"transpose={transpose}") |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + # |
| 54 | + # Interactive mode: generate plots for manual viewing |
| 55 | + # |
| 56 | + # Running this script in python (or better ipython) will show a |
| 57 | + # collection of figures that should all look OK on the screeen. |
| 58 | + # |
| 59 | + |
| 60 | + # In interactive mode, turn on ipython interactive graphics |
| 61 | + plt.ion() |
| 62 | + |
| 63 | + # Start by clearing existing figures |
| 64 | + plt.close('all') |
| 65 | + |
| 66 | + print ("Simple step responses") |
| 67 | + for size in [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)]: |
| 68 | + for transpose in [False, True]: |
| 69 | + for plot_inputs in [None, True, False]: |
| 70 | + plt.figure() |
| 71 | + test_simple_response( |
| 72 | + *size, transpose=transpose, plot_inputs=plot_inputs) |
| 73 | + |
| 74 | + print ("Combine signals") |
| 75 | + for transpose in [False, True]: |
| 76 | + plt.figure() |
| 77 | + test_combine_signals(transpose) |
| 78 | + |
| 79 | + print ("Combine traces") |
| 80 | + for transpose in [False, True]: |
| 81 | + plt.figure() |
| 82 | + test_combine_traces(transpose) |
| 83 | + |
| 84 | + print ("Combine signals and traces") |
| 85 | + for transpose in [False, True]: |
| 86 | + plt.figure() |
| 87 | + test_combine_signals_traces(transpose) |
| 88 | + |
0 commit comments