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 — Feature print zpk by henklaak · Pull Request #869 · python-control/python-control Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage: 94.841% (-0.04%) from 94.883% when pulling 6933973 on henklaak:feature_print_zpk into 08dcc95 on python-control:main. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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 would be a very nice feature. I am not sure there are any plans to have a new object class that stores things in zpk form directly, so having convenient methods like this to access that data seems to me like the way to go.
A few suggestions/thoughts:
zpkdata that serves as a direct way to access zpk numerical values.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@sawyerbfuller Thanks for the review! The nice-to-have latex would be difficult, since Jupyter eventually calls Maybe a specific subclass for ZPK, but that would be an invasive change. Let me mull it over. Otherwise it will have to stay nice-to-have ;-) I'll have a look to see what's possible/convenient for the other suggestions/thoughts. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@henklaak one possibility that might not break anything might be to add a field to TransferFunction, maybe ‘representation’?, that could be set to either ‘poly’ or ‘zpk’ in init. Might be automatically set to ‘zpk’ if instantiated with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the invaluable comments. The PR has become so much better now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -463,8 +483,7 @@ def __str__(self, var=None): | |||
|
|
|||
| # See if this is a discrete time system with specific sampling time | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| # See if this is a discrete time system with specific sampling time | |
| # print value of dt only if this is a discrete-time system with dt not 'True' (unspecified samplign time) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -92,6 +92,9 @@ class TransferFunction(LTI): | |||
| time, positive number is discrete time with specified | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I can't suggest changes above this line so I am suggsting them here:
_xferfcn_defaults = { 'xferfcn.display_format': 'poly', }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # | ||
| # Process keyword arguments | ||
| # | ||
| if display_format is None: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if display_format is None: | |
| self.display_format = kwargs.pop('display_format', | |
| config.defaults['xferfcn.display_format']) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Process keyword arguments | ||
| # | ||
| if display_format is None: | ||
| display_format = 'poly' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| display_format = 'poly' |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if display_format is None: | ||
| display_format = 'poly' | ||
|
|
||
| if display_format not in ('poly', 'zpk'): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if display_format not in ('poly', 'zpk'): | |
| if self.display_format not in ('poly', 'zpk'): |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| if display_format not in ('poly', 'zpk'): | ||
| raise ValueError("display_format must be 'poly' or 'zpk'," | ||
| " got '%s'" % display_format) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| " got '%s'" % display_format) | |
| " got '%s'" % self.display_format) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| raise ValueError("display_format must be 'poly' or 'zpk'," | ||
| " got '%s'" % display_format) | ||
|
|
||
| self.display_format = display_format |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| self.display_format = display_format |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| __array_priority__ = 11 # override ndarray and matrix types | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| def __init__(self, *args, display_format=None, **kwargs): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| def __init__(self, *args, display_format=None, **kwargs): | |
| def __init__(self, *args, **kwargs): |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| continuous or discrete time). | ||
| display_format: None, 'poly' or 'zpk' | ||
| Set the display format used in printing the TransferFunction object. | ||
| Default behavior is polynomial display. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Default behavior is polynomial display. | |
| Default behavior is polynomial display and can be changed by | |
| changing config.defaults['xferfcn.display_format']. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Polynomial coefficients of the denominator | ||
| display_format: None, 'poly' or 'zpk' | ||
| Set the display format used in printing the TransferFunction object. | ||
| Default behavior is polynomial display. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Default behavior is polynomial display. | |
| Default behavior is polynomial display and can be changed by | |
| changing config.defaults['xferfcn.display_format']. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think we have solved this quite nicely. -edit- On the other hand, now we have defaults, we could also make the floating point format (currently '%.4g') a configurable default. -edit- Couldn't resist. Added it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
In statesp the number format option is |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I considered that, but the screen space requirements that lead to the format specifiers are rather unrelated. There are actually a lot of places where one would like to customize the precision, e.g. also in plots. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 'xferfcn.floating_point_format': '.4g' | ||
| } | ||
|
|
||
| def _float2str(value): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would suggest against doing this. It's anti-pattern for Python and also there is a simpler way to grab the default at the code level and reuse.
>>> _num_format = config.defaults.get('xferfcn.floating_point_format', ':.4g') >>> print(f"Bla {0.232654684684654654:{_num_format}}") Bla 0.232655
So you don't need to inject f-string machinery to the string representation.
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.
@henklaak If you can fix up this final issue, I think this PR is ready to post.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@henklaak re display format for text vs latex: makes sense I agree they have different requirements, if I understand what you’re saying. In that case we should have setttings for both latex and text. Should they then have otherwise consistent names with only “latex” vs “print” identifiers that distinguish? That would suggest making this one if you think it should have a different name then hapoy to leave that discussion to a different PR. Otherwise this looks good to me |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Down with the flu. Will continue end of the week. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @murrayrm for taking this one. |
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.
Feature request pretty printing zpk form
There was an error while loading. Please reload this page.