Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Nyquist plot improvements#534

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
murrayrm merged 8 commits intopython-control:masterfrommurrayrm:improve_nyquist
Feb 12, 2021

Conversation

murrayrm
Copy link
Member

This PR provides improvements to Nyquist plots:

  • Thenyquist_plot command now returns the number of encirclements of the -1 point and (optionally) the contour used to generate the plot instead of the magnitude, phase, and frequency values. (The system response can be generated from the contour by simply evaluating the LTI system along the contour).
  • Nyquist plots now automatically create a small indentation around poles on the imaginary access, along Nyquist plots to be closed curves. Options are available to change the size of the indentation (indent_radius) and the direction of the indentation for the case of poles exactly on the imaginary axis (setindent_direction to 'left' or 'right'). Indentation can be turned off by settingindent_direction tonone).
  • Arrows are now generated usingFancyArrowPatch, which provides a fixed size and aspect ratio in display coordinates (so zooming in doesn't not change the size and shape of arrows). The default arrow style can be overridden using the optionarrow_size parameter or thearrow_style parameters.
  • The number (or specific location) of arrows can be specified using thearrows keyword, which allows you to specify the number of arrows or the specific locations (via a list of relative positions on the primary segment).
  • The line style for mirror image of the primary segment can be set using themirror_style parameter and defaults to a dashed line. The mirror image segment can be omitted by settingmirror_style=False.
  • The MATLAB version ofnyquist retains its original call signature and return values.

Before:

After:

Other notes:

  • Themirror_style parameter will conflict with themirror parameter in PRDescribing functions #521 (describing functions). The functionality is basically the same, but there will be a merge conflict in whichever gets merged second. (I think we should usemirror_style).
  • The various default settings can now be set usingconfig.defaults with module namenyquist.
  • Thecontrol/tests/nyquist_test.py unit test file serves as a pretty complete unit test, but can also be run in python/ipython to generate plots that you can see (and make sure they look OK).
  • I pulled the code for processing arguments for the MATLAB version ofbode into a separate function (_parse_freqplot_args) that is used for bothbode andnyquist.
  • Added unit tests, docstrings, some PEP8 cleanup.

@coveralls
Copy link

coveralls commentedFeb 6, 2021
edited
Loading

Coverage Status

Coverage increased (+0.5%) to 88.798% when pullinge0521b9 on murrayrm:improve_nyquist intoeb62d80 on python-control:master.

# If argument was a singleton, turn it into a list
if not hasattr(syslist, '__iter__'):
isscalar = not hasattr(syslist, '__iter__')
Copy link
Contributor

Choose a reason for hiding this comment

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

IsScalar sounds like it could be referring to the system. ‘Is_Single_system’?

from ..freqplot import nyquist_plot

# If first argument is a list, assume python-control calling format
if (getattr(args[0], '__iter__', False)):
Copy link
Contributor

@sawyerbfullersawyerbfullerFeb 7, 2021
edited
Loading

Choose a reason for hiding this comment

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

I have seen this style elsewhere in the library so I am curious: isn’t hasattr(args[0], ‘iter’) both more readable and compact? (I can’t do backticks from my phone so underscores appear as bold)

Copy link
Contributor

@bnavigatorbnavigatorFeb 7, 2021
edited
Loading

Choose a reason for hiding this comment

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

hasattr also returns True ifargs[0] is an iterable sequence, but empty. This code only branches ifargs[0] is iterable and the sequence does not cast to False (is empty).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks!

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

getattr([], '__iter__', False) returns <method-wrapper '__iter__' of list object .... So looks like both of them would follow the branch?

@sawyerbfuller
Copy link
Contributor

Very nice! Plots look great and I think the new return values make sense.

Comment on lines 37 to 41
@pytest.fixture(scope="function")
def figure_cleanup():
plt.close('all')
yield
plt.close('all')
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try to use the existingmplcleanup (automatically loaded fromconftest.py)?

@pytest.fixture(scope="function")
defmplcleanup():
"""Workaround for python2
python 2 does not like to mix the original mpl decorator with pytest
fixtures. So we roll our own.
"""
save=mpl.units.registry.copy()
try:
yield
finally:
mpl.units.registry.clear()
mpl.units.registry.update(save)
mpl.pyplot.close("all")

Now that we don't test python2 anymore, we could directly map it tomatplotlib.testing.decorators.cleanup

@bnavigator
Copy link
Contributor

Hmm, I wonder why the nichols_test xlim warning is back here. The test is runbefore nyquist test and already uses the mplcleanup fixture.

* regularize argument parsing by using _parse_freqplot_args* fix bug in exception handling (ControlArgument not defined)* change printed warning to use warnings.warn* add unit tests for exceptions, warnings
* start tracing from omega = 0* add support for indenting around imaginary poles* change return value to number of encirclements (+ contour, if desired)* update MATLAB interface to retain legacy format* new unit tests
@murrayrmmurrayrm mentioned this pull requestFeb 11, 2021
@murrayrmmurrayrm linked an issueFeb 11, 2021 that may beclosed by this pull request
@murrayrmmurrayrm merged commit9c6c619 intopython-control:masterFeb 12, 2021
@murrayrmmurrayrm deleted the improve_nyquist branchMarch 3, 2021 02:56
@murrayrmmurrayrm added this to the0.9.0 milestoneMar 20, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@bnavigatorbnavigatorbnavigator left review comments

@sawyerbfullersawyerbfullersawyerbfuller approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
0.9.0
Development

Successfully merging this pull request may close these issues.

arrows in nyquist plot
4 participants
@murrayrm@coveralls@sawyerbfuller@bnavigator

[8]ページ先頭

©2009-2025 Movatter.jp