GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Sisotool and dynamic root locus zoom by icam0 · Pull Request #209 · python-control/python-control

Conversation

@icam0

@icam0 icam0 commented Jun 3, 2018

Copy link
Copy Markdown
Contributor

This pull request introduces two new features to the python-control package. A matlab inspired sisotool and dynamic recomputing of the root locus plot when zooming.

Sisotool
In the pictures below a comparison can be seen between the matlab sisotool, the sisotool for matlplotlib 1.x.x and matlplotlib 2.x.x respectively.

matlab
sisotool_matlab
matplotlib 1.x.x
sisotool_mpl1
matplotlib 2.x.x
sisotool_mpl2

The function is essentially a wrapper around the rootlocus, bode and step response functions. When a click is made on the rootlocus plot, the purple point(s) are moved and the other plots are updated as well. Note that a decision was made to keep most of the rootlocus plot update logic inside the rootlocus file and the logic behind updating the other 2 plots in _sisotoolupdate in sisotool.py. Also, use was made of **kwargs whenever neccessary in order to not confuse the end user with parameters in functions without documenting them. Also, this was tested on python 2.7, 3.3 and 3.6 and matplotlib 1.5.3 and 2.2.2 on mac os x. It would be greatly appreciated if more testers can try this on their machine.

**Dynamic zooming of the root locus plot **
Firstly, I want to point out an error in existing code in the following code snippet from _default_gains:

    while (indexes_too_far[0].size > 0) and (kvect.size < 5000):
        for index in indexes_too_far[0]:
            new_gains = np.linspace(kvect[index], kvect[index+1], 5)
            new_points = _RLFindRoots(num, den, new_gains[1:4])
            kvect = np.insert(kvect, index+1, new_gains[1:4])
            mymat = np.insert(mymat, index+1, new_points, axis=0)

Every iteration, 3 points are inserted at the index where the distance between 2 points is too large. What goes wrong however, is that the indexes are not updated. So when for example indexes_too_far = [0,1,2] and in the first iteration 3 points in between 0 and 1 are inserted. The next iteration the points will be inserted in between 1 and 2. However, this point has shifted its index with 3. This is fixed by the following:

    while (len(indexes_too_far) > 0) and (kvect.size < 5000):
        for counter,index in enumerate(indexes_too_far):
            index = index + counter*3
            new_gains = np.linspace(kvect[index], kvect[index + 1], 5)
            new_points = _RLFindRoots(num, den, new_gains[1:4])
            kvect = np.insert(kvect, index + 1, new_gains[1:4])
            mymat = np.insert(mymat, index + 1, new_points, axis=0)

Now a new function _indexes_filt is added which also takes into account if the user is zoomed in on a part of the plot and adds more points to indexes_too_far. If no initial points are within the zoom view, it detects at which point one of the points crosses an xlim or ylim of the zoombox and then more points are added until the zoom tolerance requirements are met.

This pull request also includes the #199 and #204 pull requests, because they are an integral part of the sisotool as well. Please note that the Travis CI build sometimes fails due to issue #194 . I was able to get the build passing (https://travis-ci.org/icam0/python-control/builds/387446241) by restarting 2 subbuilds once.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ilayn reacted with hooray emoji
All reactions
  • 🎉 1 reaction
icam0 added 20 commits May 23, 2018 15:02
@icam0
first sisotool chechpoint
54583d5
@icam0
second sisotool checkpoint
2e1bf7d
@icam0
changed matplotlib event handler
f4545dd
@icam0
improved sisotool readability
e3c1f31
@icam0
Merge branch 'bode_margins_plot' into sisotool_merge
72ffb63
	i Please enter a commit message to explain why this merge is necessaryskldfj,
@icam0
Added display of GM and PM in bode plot. Fixed Hz bug support. Fixed …
bde60f5
…phase limit bug.
@icam0
Added support for both matplotlib 1.x.x. and 2.x.x and fixed redrawin…
bc74a0a
…g issue.
@icam0
Added docstring and unittest
1e3a925
@icam0
removed bug where a pole or zero would be deleted if only 1 of them w…
94a0ea1
…as present
@icam0
root locus smooth with zoom bug
c0e533e
@icam0
Fixed zooming on plot. Now displays smoother root locus plot.
fe13ae1
@icam0
Fixed paning on plot and clicking on the root locus plot while zoomed
2ba8277
@icam0
Added unit test for rootlocus zoom functionality
c26187f
@icam0
Fixed sisotool unittest
9962cea
@icam0
Fixed frequency response unittest
938ae88
@icam0
small change to sisotool test
9f13a77
@icam0
small change to unittests
6e06a9c
@icam0
fixed python 2 integer division error in false gain of rootlocus
cdb9f42
@icam0
changed root locus test to a numerically more significant one.
90959bd
@icam0
changed root locus test indices.
70ec8be
@coveralls

coveralls commented Jun 3, 2018

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.0%) to 78.881% when pulling 70ec8be on icam0:sisotool_final into 601b581 on python-control:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 similar comment
@coveralls

coveralls commented Jun 3, 2018

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.0%) to 78.881% when pulling 70ec8be on icam0:sisotool_final into 601b581 on python-control:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coveralls

coveralls commented Jun 3, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.05%) to 78.222% when pulling 17c4a95 on icam0:sisotool_final into 1254ccb on python-control:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coveralls

coveralls commented Jun 3, 2018

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.0%) to 78.881% when pulling 70ec8be on icam0:sisotool_final into 601b581 on python-control:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@repagh

repagh commented Jun 24, 2018

Copy link
Copy Markdown
Member

I tested locally, and this works fine!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm murrayrm added this to the 0.8.1 milestone Jun 30, 2018
@repagh
Merge branch 'master' into sisotool_final
9f50e13
This was referenced Jul 14, 2018
Bode margins plot #199
Merged
Rlocus visual display of clicked point #204
Merged
murrayrm
murrayrm reviewed Jul 14, 2018
View reviewed changes

@murrayrm murrayrm left a comment

Copy link
Copy Markdown
Member

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.

Some small comments on docstrings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/timeresp.py Outdated
"""Return a SISO or SIMO state-space version of sys

If input is not specified, select first input and issue warning
If input is not sfpecified, select first input and issue warning

@murrayrm murrayrm Jul 14, 2018

Copy link
Copy Markdown
Member

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.

Please remove this change, which inserts a misspelling.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/sisotool.py Outdated

def sisotool(sys, kvect = None, xlim_rlocus = None, ylim_rlocus = None, plotstr_rlocus = 'b' if int(matplotlib.__version__[0]) == 1 else 'C0',rlocus_grid = False, omega = None, dB = None, Hz = None, deg = None, omega_limits = None, omega_num = None,margins_bode = True, tvect=None):

"""Sisotool

@murrayrm murrayrm Jul 14, 2018

Copy link
Copy Markdown
Member

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.

Documentation style is a bit nonstandard. I think the Sisotool on its own line can be removed. This will look odd on readthedocs since the function name will already be listed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/sisotool.py Outdated

"""Sisotool

Sisotool style collection of plots inspired by the matlab sisotool.

@murrayrm murrayrm Jul 14, 2018

Copy link
Copy Markdown
Member

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.

MATLAB should be in all caps.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@murrayrm

murrayrm commented Jul 14, 2018

Copy link
Copy Markdown
Member

Very nice tool. I tried it out on Python 3.5 on MacOS 10.13 (High Sierra) and it worked well.

If someone can test this on Linux (and Windows?) and confirm that it works, we can incorporate into the next release.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm murrayrm modified the milestones: 0.8.1, 0.8.2 Jul 18, 2018
@murrayrm murrayrm mentioned this pull request Dec 28, 2018
Interactive plots in IPython notebooks #50
Open
@murrayrm
Merge branch 'master' into sisotool_final
3e7cad6
@murrayrm

murrayrm commented Dec 31, 2018

Copy link
Copy Markdown
Member

I tried out the tool and it works most of the time. But there can be problems if changing the gain if the scale of the plot is too large. For example, try the following example:

import control
sys = control.tf([10,100], [1,5,9,5])
control.sisotool(sys)

This will generate a matplotlib window and you can click on the root locus branches on the right hand side to change the gain. But if you try to click on the left branch (on the negative real axis), it doesn't get recognized.

I think the problem is that the scaling parameters that are used to determine if you are close enough to the axis don't work for the scaling on this plot.

@icam0 If there is no easy fix, we can merge this change as is and update later. I'll wait for a few days to get your input.

gabrielbckr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@icam0

icam0 commented Jan 3, 2019

Copy link
Copy Markdown
Contributor Author

I suspect the gain tolerance to be too small for some reason (lines 455 and 457 of the rlocus.py file). I will get back to you during the weekend when I take a closer look at this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@icam0

icam0 commented Jan 13, 2019

Copy link
Copy Markdown
Contributor Author

I have looked into it, what happens is that because this plot generates a very skewed aspect ratio due to the automatic matplotlib scaling of the plot the left side of the plot 'does not seem to work'. This is due to the fact that I made a decision to vary the gain tolerance according to the zoom and xlimit and ylimit of the plot. It selects the smallest of these 2 and bases the gain tolerance on the smallest of these 2 margins. When having a skewed aspect ratio it makes it hard for the user to click because the margin becomes very small. In the original implementation, there was a 'fixed' 0.04 factor in there which meant that if you would zoom in a lot, you could click very far away from the plot resulting in floating dots far away from the plot line. Using a scaled gain factor fixed this problem.

If you were to just increase the gain tolerance the behaviour becomes more unreliable and the point sometimes snaps to the incorrect line from then a user would intend. Therefore, for now, I'd like to propose to scale axes of the root locus plot to the same length of the smallest axis. Which makes sure the initial plot is always clickable. Something like this would then be added to the end of the rlocus.py plot (an edge case for handling when the user specifies the xlim or ylim would still need to be added):

x0, x1 = ax.get_xlim()
y0, y1 = ax.get_ylim()
if abs(x0-x1) >= abs(y0-y1):
    ax.set_xlim(0. - 0.5*abs(y0-y1) ,0. +0.5*abs(y0-y1))
else:
    ax.set_ylim(0. - 0.5 * abs(x0 - x1), 0. + 0.5 * abs(x0 - x1))

However, when the user zooms in with a very skewed aspect ratio clicking the line would still be very difficult which is why I think in the future a more sophisticated algorithm for click detection would be a worthwhile enhancement. I'd like to get your thoughts on this @murrayrm

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm

murrayrm commented Apr 7, 2019

Copy link
Copy Markdown
Member

@icam0 Can you rebase this against the current master and resolve the conflicts. I think this is ready to go into release 0.8.2 as soon as that is done.

gabrielbckr reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm
Merge branch 'master' into sisotool_final
43d8b95
@murrayrm

murrayrm commented Apr 11, 2019

Copy link
Copy Markdown
Member

Did an inline correction of the conflicts. Will merge if tests run correctly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

murrayrm added 2 commits April 11, 2019 21:33
@murrayrm
Fix small typo from manual merge
03f87a3
@murrayrm
fixed issues identified in review
17c4a95
@murrayrm

murrayrm commented Apr 12, 2019

Copy link
Copy Markdown
Member

Fixed up remaining issues. Ready to merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm
murrayrm merged commit 908fabe into python-control:master Apr 16, 2019
@murrayrm murrayrm mentioned this pull request Jun 16, 2021
Two 'sgrid' functions when we only need one? #634
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@murrayrm murrayrm murrayrm left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

0.8.2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@icam0 @coveralls @repagh @murrayrm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.