-
Notifications
You must be signed in to change notification settings - Fork 438
a first implementation of the singular value plot as discussed in #592 #593
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
a first implementation of the singular value plot as discussed in #592 #593
Conversation
forgi86
commented
Mar 27, 2021
- added singular values plot (function singular_values_plot in freqplot.py)
- added a test of the new function (test_singular_values_plot in freqresp_test.py)
- added an example jupyter notebook (singular-values-plot.ipynb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
I left some comments in the code.
The Notebook looks like omega exceeds the Nyquist frequency
The test suite failure is unrelated and will be fixed by #588 |
Co-authored-by: Ben Greiner <code@bnavigator.de>
Co-authored-by: Ben Greiner <code@bnavigator.de>
use |
Something strange about the return shape of the frequency response. For a square 2x2 system: sys(np.array(0.0), squeeze=False).shape sys(0.0, squeeze=False).shape Is it expected? Perhaps I should do an np.atleast_1d(omega) inside singular_values_plot anyways? |
Nope. Opened #594. You can work around with |
…ency response in freqplot.py
Whishlist: |
Sounds reasonable. From a control perspective they correspond to the output/input directions associated with the corresponding singular value. There's no way to plot them in a nice way, but they can indeed be optionally returned. |
control/freqplot.py
Outdated
'singular_values_plot.dB': False, # Plot singular values in dB | ||
'singular_values_plot.deg': True, # Plot phase in degrees | ||
'singular_values_plot.Hz': False, # Plot frequency in Hertz | ||
'singular_values_plot.grid': True, # Turn on grid for gain and phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit odd to me to have to set these separately from the equivalent bode
configuration variable. Is someone going to use one set of defaults for Bode and a separate one for singular values? (Also note that gang_of_four
uses the Bode plot defaults.)
If we don't want to use bode.dB
, etc, we could also change all of them to freqplot.dB
(though perhaps with some backward compatibility??).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add the properties dB, Hz, and grid to freqplot and use these for bode, singular_values_plot, and gang_of_four.
The property _singular_values_plot_default would then disappear, and _bode_defaults would still contain bode.deg and bode.wrap_phase (and maybe unused dB, Hz, grid for backward compatibility, at least for the moment).
Is this OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems fine. Make sure also to update the use_matlab_defaults
and use_fbs_defaults
functions in config.py
. I'm not sure about what to do with bode.deg
. On the one hand, it is true that this is the only function that plots phase, but at the same time seems odd to use freqplot
for everything except that. I would probably just use freqplot
for everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a new version where all the settings for bode_plot and singular_values_plot are in _freqplot_defaults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see a _singular_values_plot_default
with a comment for "Bode" above the definition and then used with_get_param('freqplot'). That's very confusing.
Also, personally, I would still prefer that we provide some backwards compatibility through an alias of config.defaults['bode'], so that old code does not break right away. Maybe including a warning message. I am not sure how to achieve this with a dict outside of set_defaults
and _get_param
in an elegant way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to remove all references to the previous structure _singular_values_plot_default (new push).
Still have to handle backward compatibility in some way.
- changed line plot = config._get_param('bode', 'grid', plot, True) to config._get_param('bode', 'grid', plot, True) - changed logic in _determine_omega_vector: if Hz = True, omega_in is interpreted in Hz units (as it is with omega_limits) - jupyter notebook singular-values-plot.ipynb output fixed
DEV: improved color cycling logic for superimposed singular_values_plot on the same axes: do not repeat the same color
TST: tests in config_test modified to interpret omega in Hz if the option Hz is set to True
Co-authored-by: Ben Greiner <code@bnavigator.de>
…y affects the plot (input/outputs are always in rad/sec)
Variables renamed in conventions.rst (bode -> freqplot) |
… make it doctest compliant
… make it doctest compliant
… make it doctest compliant
Thank you @forgi86 for the hard work and also for the patience with all the picky reviews. I will submit a PR shortly which addresses the backwards compatibility with the old name for the bode defaults. |
Thank you for the review and for your kind message, @bnavigator. Was my first PR to python-control, I hope I will be able to contribute again in the future! |