Skip to content

Update timeplot.py #1030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions control/tests/timeplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_combine_time_responses():
sys_mimo = ct.rss(4, 2, 2)
timepts = np.linspace(0, 10, 100)

# Combine two response with ntrace = 0
# Combine two responses with ntrace = 0
U = np.vstack([np.sin(timepts), np.cos(2*timepts)])
resp1 = ct.input_output_response(sys_mimo, timepts, U)

Expand Down Expand Up @@ -293,6 +293,7 @@ def test_combine_time_responses():
combresp4 = ct.combine_time_responses(
[resp1, resp2, resp3], trace_labels=labels)
assert combresp4.trace_labels == labels
assert combresp4.trace_types == [None, None, 'step', 'step']

# Automatically generated trace label names and types
resp5 = ct.step_response(sys_mimo, timepts)
Expand All @@ -302,7 +303,13 @@ def test_combine_time_responses():
combresp5 = ct.combine_time_responses([resp1, resp5])
assert combresp5.trace_labels == [resp1.title] + \
["test, trace 0", "test, trace 1"]
assert combresp4.trace_types == [None, None, 'step', 'step']
assert combresp5.trace_types == [None, None, None]

# ntraces = 0 with trace_types != None
# https://github.com/python-control/python-control/issues/1025
resp6 = ct.forced_response(sys_mimo, timepts, U)
combresp6 = ct.combine_time_responses([resp1, resp6])
assert combresp6.trace_types == [None, 'forced']

with pytest.raises(ValueError, match="must have the same number"):
resp = ct.step_response(ct.rss(4, 2, 3), timepts)
Expand Down
3 changes: 2 additions & 1 deletion control/timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ def combine_time_responses(response_list, trace_labels=None, title=None):
if generate_trace_labels:
trace_labels.append(response.title)
trace_types.append(
None if response.trace_types is None else response.types[0])
None if response.trace_types is None
else response.trace_types[0])

else:
# Save the data
Expand Down
Loading