Skip to content

Commit 2644874

Browse files
committed
Add default for xferfcn.display_format
1 parent 521a306 commit 2644874

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

control/xferfcn.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969

7070

7171
# Define module default parameter values
72-
_xferfcn_defaults = {}
72+
_xferfcn_defaults = {
73+
'xferfcn.display_format': 'poly',
74+
}
7375

7476

7577
class TransferFunction(LTI):
@@ -94,7 +96,8 @@ class TransferFunction(LTI):
9496
continuous or discrete time).
9597
display_format: None, 'poly' or 'zpk'
9698
Set the display format used in printing the TransferFunction object.
97-
Default behavior is polynomial display.
99+
Default behavior is polynomial display and can be changed by
100+
changing config.defaults['xferfcn.display_format'].
98101
99102
Attributes
100103
----------
@@ -152,7 +155,7 @@ class TransferFunction(LTI):
152155
# Give TransferFunction._rmul_() priority for ndarray * TransferFunction
153156
__array_priority__ = 11 # override ndarray and matrix types
154157

155-
def __init__(self, *args, display_format=None, **kwargs):
158+
def __init__(self, *args, **kwargs):
156159
"""TransferFunction(num, den[, dt])
157160
158161
Construct a transfer function.
@@ -201,14 +204,17 @@ def __init__(self, *args, display_format=None, **kwargs):
201204
#
202205
# Process keyword arguments
203206
#
204-
if display_format is None:
205-
display_format = 'poly'
207+
# During module init, TransferFunction.s and TransferFunction.z
208+
# get initialized when defaults are not fully initialized yet.
209+
# Use 'poly' in these cases.
206210

207-
if display_format not in ('poly', 'zpk'):
208-
raise ValueError("display_format must be 'poly' or 'zpk',"
209-
" got '%s'" % display_format)
211+
self.display_format = kwargs.pop(
212+
'display_format',
213+
config.defaults.get('xferfcn.display_format', 'poly'))
210214

211-
self.display_format = display_format
215+
if self.display_format not in ('poly', 'zpk'):
216+
raise ValueError("display_format must be 'poly' or 'zpk',"
217+
" got '%s'" % self.display_format)
212218

213219
# Determine if the transfer function is static (needed for dt)
214220
static = True
@@ -447,9 +453,7 @@ def __str__(self, var=None):
447453
448454
Based on the display_format property, the output will be formatted as
449455
either polynomials or in zpk form.
450-
451456
"""
452-
453457
mimo = not self.issiso()
454458
if var is None:
455459
var = 's' if self.isctime() else 'z'
@@ -481,8 +485,8 @@ def __str__(self, var=None):
481485

482486
outstr += "\n" + numstr + "\n" + dashes + "\n" + denstr + "\n"
483487

484-
# See if this is a discrete time system with specific sampling time
485-
if not (self.dt is None) and type(self.dt) != bool and self.dt > 0:
488+
# If this is a strict discrete time system, print the sampling time
489+
if self.isdtime(strict=True):
486490
outstr += "\ndt = " + str(self.dt) + "\n"
487491

488492
return outstr
@@ -1554,7 +1558,8 @@ def tf(*args, **kwargs):
15541558
Polynomial coefficients of the denominator
15551559
display_format: None, 'poly' or 'zpk'
15561560
Set the display format used in printing the TransferFunction object.
1557-
Default behavior is polynomial display.
1561+
Default behavior is polynomial display and can be changed by
1562+
changing config.defaults['xferfcn.display_format']..
15581563
15591564
Returns
15601565
-------
@@ -1680,7 +1685,8 @@ def zpk(zeros, poles, gain, *args, **kwargs):
16801685
name <sys[id]> is generated with a unique integer id.
16811686
display_format: None, 'poly' or 'zpk'
16821687
Set the display format used in printing the TransferFunction object.
1683-
Default behavior is zpk display.
1688+
Default behavior is polynomial display and can be changed by
1689+
changing config.defaults['xferfcn.display_format'].
16841690
16851691
Returns
16861692
-------
@@ -1690,15 +1696,13 @@ def zpk(zeros, poles, gain, *args, **kwargs):
16901696
Examples
16911697
--------
16921698
>>> from control import tf
1693-
>>> G = zpk([1],[2, 3], gain=1)
1699+
>>> G = zpk([1],[2, 3], gain=1, display_format='zpk')
16941700
>>> G
16951701
s - 1
16961702
---------------
16971703
(s - 2) (s - 3)
16981704
"""
16991705
num, den = zpk2tf(zeros, poles, gain)
1700-
if 'display_format' not in kwargs:
1701-
kwargs['display_format'] = 'zpk'
17021706
return TransferFunction(num, den, *args, **kwargs)
17031707

17041708

0 commit comments

Comments
 (0)