GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — recalculate loci for sisotool and rlocus on axis scaling by repagh · Pull Request #1153 · python-control/python-control Conversation
Member
adds recalculate of loci for pan/zoom for the root_locus_map and sisotool . Fixes #1151
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
coverage: 94.759% (+0.01%) from 94.746% |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR enables dynamic recalculation of root locus and pole-zero plots when the user pans or zooms in sisotool and rlocus, fixing issue #1151.
add_loci_recalculate callback into sisotool and root_locus_plot for auto-replot on axis changesroot_locus_map signature to accept xlim, ylim and pass them through to gain calculationreplot support for pole-zero maps via a new pole_zero_replot functionCopilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| control/sisotool.py | Imported and invoked add_loci_recalculate, updated axis reference for root locus |
| control/rlocus.py | Added xlim/ylim parameters, defined add_loci_recalculate, wired callback in root_locus_plot |
| control/pzmap.py | Added replot method and pole_zero_replot for pole-zero redraw on zoom/pan |
control/sisotool.py:141
axes is undefined here; you likely meant to use fig.axes or the local axes variable instead of axes.ax_rlocus = axes[0,1] #fig.axes[1]
control/pzmap.py:552
ControlPlot instances expose their axes as cp.axes, not cp.ax. Update to cp.axes[0,0] to avoid AttributeError.cp.lines[idx,2].append(cp.ax[0,0].plot(
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if event.inaxes == ax.axes: | ||
|
|
||
| fig = ax.figure | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The original toolbar mode check for 'zoom rect' and 'pan/zoom' was removed, which may trigger click events during zooming or panning. Consider re-adding that guard to prevent unintended callbacks.
| if event.inaxes == ax.axes: | |
| fig = ax.figure | |
| fig = ax.figure | |
| toolbar = fig.canvas.toolbar | |
| if toolbar is not None and toolbar.mode in ['zoom rect', 'pan/zoom']: | |
| return | |
| if event.inaxes == ax.axes: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In my experience, the risk of interpreting a click as a valid gain selection is small, and in my testing (with a print statement indicating when the callback is invoked), the zoom and pan events did not propagate to this callback. Removing the zoom_rect and pan/zoom check also removes unintended mode change (updating of the remaining 3 plots is inhibited when zoom / pan is selected), which can be confusing to users.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Add a reaction to axis scale changes, if given LTI systems, and | ||
| # there is no set of pre-defined gains | ||
| if gains is None: | ||
| add_loci_recalculate(sysdata, cplt, cplt.axes[0,0]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Recalculating the entire locus on every xlim/ylim change can be expensive. Consider debouncing these callbacks or limiting the update frequency during continuous zooming.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This was no issue when interacting with the root-locus plot. Default number of points calculate is a measly 50, with the adaptive code in _default_gains typically a maximum between 100 and 200 points was produced. The callback will not be activated when the user manually specifies the gains.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I need to do a bit of testing, but here are some code style comments, mainly in docstrings (see online style guide, linked below).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Parameters | ||
| ---------- | ||
| cplt: ControlPlot | ||
| graphics handles of the existing plot |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For consistency with python-control docstring standards, this should start with a capital letter and end in a period. See https://python-control.readthedocs.io/en/latest/develop.html#documentation-guidelines
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
amended commit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| def pole_zero_replot(pzmap_responses, cp): | ||
| """Update the loci of a plot after zooming/panning |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should end in a period.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
amended commit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ---------- | ||
| pzmap_responses : PoleZeroMap list | ||
| Responses to update | ||
| cp : ControlPlot |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to use cp here instead of cplt, as above?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
amended commit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| def add_loci_recalculate(sysdata, cplt, axis): | ||
| """ Add a calback to re-calculate the loci data fitting a zoom action |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fix typo (callback) and end in period.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
amended commit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Gains to use in computing plot of closed-loop poles. If not given, | ||
| gains are chosen to include the main features of the root locus map. | ||
| xlim : array_like, 2 elements, optional | ||
| Plot range |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Add period. Perhaps also expand description (see other uses of xlim, for example in control.root_locus_plot.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
amended commit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # ax=fig.axes[1]) | ||
| ax_rlocus = fig.axes[1] | ||
| root_locus_map(sys[0, 0]).plot( | ||
| ax_rlocus = axes[0,1] #fig.axes[1] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
PEP8: two spaces before #, one space after.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
amended commit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Regression: root-locus plots may be coarse, and no longer react to zoom events
There was an error while loading. Please reload this page.