Add missing labels when returning TimeResponseData#892
Add missing labels when returning TimeResponseData#892murrayrm merged 5 commits intopython-control:mainfrom
Conversation
a75a962 to
0a87017
Compare
murrayrm
left a comment
There was a problem hiding this comment.
Thanks for this nice contribution. I suggest using *_labels instead of *_index, which I think makes the code a bit more readable.
control/timeresp.py
Outdated
| output_labels=sys.output_index, input_labels=sys.input_index, | ||
| state_labels=sys.state_index, |
There was a problem hiding this comment.
This is OK, but it might be more clear to use sys.output_labels, etc.
| # Select only the given input and output, if any | ||
| input_index = sys.input_index if input is None else {k: 0 for k, v in sys.input_index.items() if v == input} | ||
| output_index = sys.output_index if output is None else {k: 0 for k, v in sys.output_index.items() if v == output} | ||
|
|
There was a problem hiding this comment.
Consider changing this to
input_labels = sys.input_labels if input is None \
else sys.input_labels[input]
output_labels = sys.output_labels if output is None else \
sys.output_labels[output]
which seems cleaner.
control/timeresp.py
Outdated
| output_labels=output_index, input_labels=input_index, | ||
| state_labels=sys.state_index, |
There was a problem hiding this comment.
output_labels=output_labels, input_labels=input_labels,
state_labels=sys.state_labels,
| # Select only the given output, if any | ||
| output_index = sys.output_index if output is None else {k: 0 for k, v in sys.output_index.items() if v == output} | ||
|
|
control/timeresp.py
Outdated
| output_labels=output_index, input_labels=None, | ||
| state_labels=sys.state_index, |
| # Select only the given input and output, if any | ||
| input_index = sys.input_index if input is None else {k: 0 for k, v in sys.input_index.items() if v == input} | ||
| output_index = sys.output_index if output is None else {k: 0 for k, v in sys.output_index.items() if v == output} | ||
|
|
control/timeresp.py
Outdated
| output_labels=output_index, input_labels=input_index, | ||
| state_labels=sys.state_index, |
Thanks, it surely makes it more readable, but I was unsure of using |
7b8db61 to
4ed8491
Compare
|
Hi @murrayrm, I did the changes regarding using |
4ed8491 to
7daed4b
Compare
control/timeresp.py
Outdated
| # Get labels for the inputs/outputs (prior to mimo -> simo conversion) | ||
| input_labels = sys.input_labels if input is None \ | ||
| else [sys.input_labels[input]] | ||
| output_labels = sys.output_labels if output is None \ | ||
| else [sys.output_labels[output]] | ||
|
|
There was a problem hiding this comment.
I was thinking about it. Should we move it to here, or should we make the mimo/siso/simo conversions to also propagate the labels (and name)?
There was a problem hiding this comment.
Either way works, but because _get_ss_simo is an internal function, it is fine for it to ignore labels.
There was a problem hiding this comment.
It's your PR, so feel free to revert the code moves that I made and put in your proposed commit. I was just trying to get something that passed the unit tests, since they were failing.
There was a problem hiding this comment.
Also: I think it should work to do sys.output_labels[output] instead of [sys.output_labels[output]] (eg, remove the outer list). The code underneath is smart enough to deal with getting passed a string for a single input/output.
There was a problem hiding this comment.
Also: I think it should work to do
sys.output_labels[output]instead of[sys.output_labels[output]](eg, remove the outer list). The code underneath is smart enough to deal with getting passed a string for a single input/output.
The _process_labels had a small bug, now it works with plain str instead of [str]
8d0fb10 to
bd83e8c
Compare
|
@murrayrm I'm good with the patch, let me know if you need any changes, otherwise feel free to merge it |
Fixes #891