Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix TimeResponseData.to_pandas() for multi-trace responses #1088

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
Jan 2, 2025

Conversation

murrayrm
Copy link
Member

This PR addresses issue #1087. Multi-trace data (e.g., the output from a MIMO step response) was not being processed correctly. This PR creates a new column 'trace' for multi-trace responses and reshapes the data appropriately. Unit tests and updated documentation are included.

Thanks to @joaoantoniocardoso for finding this bug and providing a fix (modified only slightly here).

@joaoantoniocardoso: if you have time to try this out and confirm that it works for your use case, that would be great. I think the only difference is that I used 'trace' for the column label instead of 'trace_label'. I also had to do things a bit differently for the case where there were multiple traces (your example was "multi-trace" but with sys.ntrace=1 since you selected an input).

@murrayrm murrayrm linked an issue Dec 31, 2024 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Dec 31, 2024

Coverage Status

coverage: 94.731% (+0.001%) from 94.73%
when pulling 7707ea8 on murrayrm:fix_topandas-30Dec2024
into 859ece6 on python-control:main.

@slivingston slivingston self-requested a review December 31, 2024 18:20
Comment on lines 1279 to 1282
np.testing.assert_equal(
df[df['trace'] == 'From u0']['time'], res.time)
np.testing.assert_equal(
df[df['trace'] == 'From u0']['y1'], res.outputs['y1', 0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
np.testing.assert_equal(
df[df['trace'] == 'From u0']['time'], res.time)
np.testing.assert_equal(
df[df['trace'] == 'From u0']['y1'], res.outputs['y1', 0])
np.testing.assert_equal(
df[df['trace'] == 'From u0']['time'], res.time)
np.testing.assert_equal(
df[df['trace'] == 'From u0']['u0'], res.inputs['u0', 0])
np.testing.assert_equal(
df[df['trace'] == 'From u0']['y1'], res.outputs['y1', 0])

Include comparison of inputs here to be symmetric with comparisons in the for-loop below.

Comment on lines 1287 to 1290
np.testing.assert_equal(
df[df['trace'] == label]['time'], res.time)
np.testing.assert_equal(
df[df['trace'] == label]['u0'], res.inputs['u0', i])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
np.testing.assert_equal(
df[df['trace'] == label]['time'], res.time)
np.testing.assert_equal(
df[df['trace'] == label]['u0'], res.inputs['u0', i])
np.testing.assert_equal(
df[df['trace'] == label]['time'], res.time)
np.testing.assert_equal(
df[df['trace'] == label]['u0'], res.inputs['u0', i])
np.testing.assert_equal(
df[df['trace'] == label]['y1'], res.outputs['y1', i])

Include comparison of outputs here to be symmetric with comparisons for the case of single-trace above.

Copy link
Contributor

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, that one was quick!

I've just tested it here, and it worked as a charm!

Thank you so much for keeping this lib, awesome work! And happy New Year! =D

@murrayrm murrayrm merged commit 21c8f31 into python-control:main Jan 2, 2025
23 checks passed
@murrayrm murrayrm added this to the 0.10.2 milestone Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

control.timeresp.TimeResponseData.to_pandas() failing
4 participants