Skip to content

Commit 42c6fb1

Browse files
authored
Merge pull request #920 from murrayrm/time_plots-20Jun2023
Time response plots
2 parents cf27186 + bab5071 commit 42c6fb1

15 files changed

+1578
-24
lines changed

control/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
from .xferfcn import *
7878
from .frdata import *
7979

80+
# Time responses and plotting
81+
from .timeresp import *
82+
from .timeplot import *
83+
8084
from .bdalg import *
8185
from .delay import *
8286
from .descfcn import *
@@ -91,7 +95,6 @@
9195
from .rlocus import *
9296
from .statefbk import *
9397
from .stochsys import *
94-
from .timeresp import *
9598
from .ctrlutil import *
9699
from .canonical import *
97100
from .robust import *

control/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def reset_defaults():
135135
from .optimal import _optimal_defaults
136136
defaults.update(_optimal_defaults)
137137

138+
from .timeplot import _timeplot_defaults
139+
defaults.update(_timeplot_defaults)
140+
138141

139142
def _get_param(module, param, argval=None, defval=None, pop=False, last=False):
140143
"""Return the default value for a configuration option.

control/nlsys.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,7 @@ def ufun(t):
14881488
return TimeResponseData(
14891489
t_eval, y, None, u, issiso=sys.issiso(),
14901490
output_labels=sys.output_labels, input_labels=sys.input_labels,
1491+
title="Input/output response for " + sys.name, sysname=sys.name,
14911492
transpose=transpose, return_x=return_x, squeeze=squeeze)
14921493

14931494
# Create a lambda function for the right hand side
@@ -1567,7 +1568,8 @@ def ivp_rhs(t, x):
15671568
return TimeResponseData(
15681569
soln.t, y, soln.y, u, issiso=sys.issiso(),
15691570
output_labels=sys.output_labels, input_labels=sys.input_labels,
1570-
state_labels=sys.state_labels,
1571+
state_labels=sys.state_labels, sysname=sys.name,
1572+
title="Input/output response for " + sys.name,
15711573
transpose=transpose, return_x=return_x, squeeze=squeeze)
15721574

15731575

control/tests/kwargs_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import control.tests.statefbk_test as statefbk_test
2727
import control.tests.stochsys_test as stochsys_test
2828
import control.tests.trdata_test as trdata_test
29+
import control.tests.timeplot_test as timeplot_test
2930

3031
@pytest.mark.parametrize("module, prefix", [
3132
(control, ""), (control.flatsys, "flatsys."), (control.optimal, "optimal.")
@@ -74,7 +75,8 @@ def test_kwarg_search(module, prefix):
7475
# @parametrize messes up the check, but we know it is there
7576
pass
7677

77-
elif source and source.find('unrecognized keyword') < 0:
78+
elif source and source.find('unrecognized keyword') < 0 and \
79+
source.find('unexpected keyword') < 0:
7880
warnings.warn(
7981
f"'unrecognized keyword' not found in unit test "
8082
f"for {name}")
@@ -161,7 +163,21 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
161163
function(*args, **kwargs, unknown=None)
162164

163165

166+
@pytest.mark.parametrize(
167+
"function", [control.time_response_plot, control.TimeResponseData.plot])
168+
def test_time_response_plot_kwargs(function):
169+
# Create a system for testing
170+
response = control.step_response(control.rss(4, 2, 2))
171+
172+
# Call the plotting function normally and make sure it works
173+
function(response)
164174

175+
# Now add an unrecognized keyword and make sure there is an error
176+
with pytest.raises(AttributeError,
177+
match="(has no property|unexpected keyword)"):
178+
function(response, unknown=None)
179+
180+
165181
#
166182
# List of all unit tests that check for unrecognized keywords
167183
#
@@ -185,6 +201,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
185201
'gangof4_plot': test_matplotlib_kwargs,
186202
'input_output_response': test_unrecognized_kwargs,
187203
'interconnect': interconnect_test.test_interconnect_exceptions,
204+
'time_response_plot': timeplot_test.test_errors,
188205
'linearize': test_unrecognized_kwargs,
189206
'lqe': test_unrecognized_kwargs,
190207
'lqr': test_unrecognized_kwargs,
@@ -230,6 +247,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
230247
'StateSpace.__init__': test_unrecognized_kwargs,
231248
'StateSpace.sample': test_unrecognized_kwargs,
232249
'TimeResponseData.__call__': trdata_test.test_response_copy,
250+
'TimeResponseData.plot': timeplot_test.test_errors,
233251
'TransferFunction.__init__': test_unrecognized_kwargs,
234252
'TransferFunction.sample': test_unrecognized_kwargs,
235253
'optimal.OptimalControlProblem.__init__':

0 commit comments

Comments
 (0)