10000 add back ss2io and tf2io, with deprecation warnings · python-control/python-control@fc19cd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc19cd6

Browse files
committed
add back ss2io and tf2io, with deprecation warnings
1 parent a0c7884 commit fc19cd6

File tree

3 files changed

+133
-8
lines changed

3 files changed

+133
-8
lines changed

control/statesp.py

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
except ImportError:
7575
ab13dd = None
7676

77-
__all__ = ['StateSpace', 'LinearICSystem', 'tf2ss', 'ssdata',
77+
__all__ = ['StateSpace', 'LinearICSystem', 'ss2io', 'tf2io', 'tf2ss', 'ssdata',
7878
'linfnorm', 'ss', 'rss', 'drss', 'summing_junction']
7979

8080
# Define module default parameter values
@@ -1598,7 +1598,7 @@ def ss(*args, **kwargs):
15981598
and not isinstance(args[0], (InputOutputSystem, LTI)):
15991599
# Function as first (or second) argument => assume nonlinear IO system
16001600
warn("using ss to create nonlinear I/O systems is deprecated; "
1601-
"use nlsys", DeprecationWarning)
1601+
"use nlsys()", DeprecationWarning)
16021602
return NonlinearIOSystem(*args, **kwargs)
16031603

16041604
elif len(args) == 4 or len(args) == 5:
@@ -1630,6 +1630,99 @@ def ss(*args, **kwargs):
16301630
return sys
16311631

16321632

1633+
# Convert a state space system into an input/output system (wrapper)
1634+
def ss2io(*args, **kwargs):
1635+
"""ss2io(sys[, ...])
1636+
1637+
Create an I/O system from a state space linear system.
1638+
1639+
.. deprecated:: 0.10.0
1640+
This function will be removed in a future version of python-control.
1641+
The `ss` function can be used directly to produce an I/O system.
1642+
1643+
Create an :class:`~control.StateSpace` system with the given signal
1644+
and system names. See :func:`~control.ss` for more details.
1645+
"""
1646+
warn("ss2io is deprecated; use ss()", DeprecationWarning)
1647+
return StateSpace(*args, **kwargs)
1648+
1649+
1650+
# Convert a transfer function into an input/output system (wrapper)
1651+
def tf2io(*args, **kwargs):
1652+
"""tf2io(sys[, ...])
1653+
1654+
Convert a transfer function into an I/O system.
1655+
1656+
.. deprecated:: 0.10.0
1657+
This function will be removed in a future version of python-control.
1658+
The `tf2ss` function can be used to produce a state space I/O system.
1659+
1660+
The function accepts either 1 or 2 parameters:
1661+
1662+
``tf2io(sys)``
1663+
Convert a linear system into space space form. Always creates
1664+
a new system, even if sys is already a StateSpace object.
1665+
1666+
``tf2io(num, den)``
1667+
Create a linear I/O system from its numerator and denominator
1668+
polynomial coefficients.
1669+
1670+
For details see: :func:`tf`
1671+
1672+
Parameters
1673+
----------
1674+
sys : LTI (StateSpace or TransferFunction)
1675+
A linear system.
1676+
num : array_like, or list of list of array_like
1677+
Polynomial coefficients of the numerator.
1678+
den : array_like, or list of list of array_like
1679+
Polynomial coefficients of the denominator.
1680+
1681+
Returns
1682+
-------
1683+
out : StateSpace
1684+
New I/O system (in state space form).
1685+
1686+
Other Parameters
1687+
----------------
1688+
inputs, outputs : str, or list of str, optional
1689+
List of strings that name the individual signals of the transformed
1690+
system. If not given, the inputs and outputs are the same as the
1691+
original system.
1692+
name : string, optional
1693+
System name. If unspecified, a generic name <sys[id]> is generated
1694+
with a unique integer id.
1695+
1696+
Raises
1697+
------
1698+
ValueError
1699+
if `num` and `den` have invalid or unequal dimensions, or if an
1700+
invalid number of arguments is passed in.
1701+
TypeError
1702+
if `num` or `den` are of incorrect type, or if sys is not a
1703+
TransferFunction object.
1704+
1705+
See Also
1706+
--------
1707+
ss2io
1708+
tf2ss
1709+
1710+
Examples
1711+
--------
1712+
>>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
1713+
>>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
1714+
>>> sys1 = ct.tf2ss(num, den)
1715+
1716+
>>> sys_tf = ct.tf(num, den)
1717+
>>> G = ct.tf2ss(sys_tf)
1718+
>>> G.ninputs, G.noutputs, G.nstates
1719+
(2, 2, 8)
1720+
1721+
"""
1722+
warn("tf2io is deprecated; use tf2ss() or tf()", DeprecationWarning)
1723+
return tf2ss(*args, **kwargs)
1724+
1725+
16331726
def tf2ss(*args, **kwargs):
16341727
"""tf2ss(sys)
16351728

control/tests/iosys_test.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def test_tf2io(self, tsys):
7777
# Create a transfer function from the state space system
7878
linsys = tsys.siso_linsys
7979
tfsys = ct.ss2tf(linsys)
80-
iosys = ct.ss(tfsys)
80+
with pytest.warns(DeprecationWarning, match="use tf2ss"):
81+
iosys = ct.tf2io(tfsys)
8182

8283
# Verify correctness via simulation
8384
T, U, X0 = tsys.T, tsys.U, tsys.X0
@@ -89,15 +90,23 @@ def test_tf2io(self, tsys):
8990
# Make sure that non-proper transfer functions generate an error
9091
tfsys = ct.tf('s')
9192
with pytest.raises(ValueError):
92-
iosys=ct.ss(tfsys)
93+
with pytest.warns(DeprecationWarning, match="use tf2ss"):
94+
iosys=ct.tf2io(tfsys)
9395

9496
def test_ss2io(self, tsys):
9597
# Create an input/output system from the linear system
9698
linsys = tsys.siso_linsys
99+
with pytest.warns(DeprecationWarning, match="use ss"):
100+
iosys = ct.ss2io(linsys)
101+
np.testing.assert_allclose(linsys.A, iosys.A)
102+
np.testing.assert_allclose(linsys.B, iosys.B)
103+
np.testing.assert_allclose(linsys.C, iosys.C)
104+
np.testing.assert_allclose(linsys.D, iosys.D)
97105

98106
# Try adding names to things
99-
iosys_named = ct.ss(linsys, inputs='u', outputs='y',
100-
states=['x1', 'x2'], name='iosys_named')
107+
with pytest.warns(DeprecationWarning, match="use ss"):
108+
iosys_named = ct.ss2io(linsys, inputs='u', outputs='y',
109+
states=['x1', 'x2'], name='iosys_named')
101110
assert iosys_named.find_input('u') == 0
102111
assert iosys_named.find_input('x') is None
103112
assert iosys_named.find_output('y') == 0
@@ -110,6 +119,21 @@ def test_ss2io(self, tsys):
110119
np.testing.assert_allclose(linsys.C, iosys_named.C)
111120
np.testing.assert_allclose(linsys.D, iosys_named.D)
112121

122+
def test_sstf_rename(self):
123+
# Create a state space system
124+
sys = ct.rss(4, 1, 1)
125+
126+
sys_ss = ct.ss(sys, inputs=['u1'], outputs=['y1'])
127+
assert sys_ss.input_labels == ['u1']
128+
assert sys_ss.output_labels == ['y1']
129+
assert sys_ss.name == sys.name
130+
131+
# Convert to transfer function with renaming
132+
sys_tf = ct.tf(sys, inputs=['a'], outputs=['c'])
133+
assert sys_tf.input_labels == ['a']
134+
assert sys_tf.output_labels == ['c']
135+
assert sys_tf.name != sys_ss.name
136+
113137
def test_iosys_unspecified(self, tsys):
114138
"""System with unspecified inputs and outputs"""
115139
sys = ct.NonlinearIOSystem(secord_update, secord_output)

control/tests/kwargs_test.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ def test_kwarg_search(module, prefix):
9797
(control.rss, 0, 0, (2, 1, 1), {}),
9898
(control.set_defaults, 0, 0, ('control',), {'default_dt': True}),
9999
(control.ss, 0, 0, (0, 0, 0, 0), {'dt': 1}),
100+
(control.ss2io, 1, 0, (), {}),
100101
(control.ss2tf, 1, 0, (), {}),
101102
(control.summing_junction, 0, 0, (2,), {}),
102103
(control.tf, 0, 0, ([1], [1, 1]), {}),
104+
(control.tf2io, 0, 1, (), {}),
103105
(control.tf2ss, 0, 1, (), {}),
104106
(control.zpk, 0, 0, ([1], [2, 3], 4), {}),
105107
(control.flatsys.FlatSystem, 0, 0,
@@ -122,11 +124,15 @@ def test_unrecognized_kwargs(function, nsssys, ntfsys, moreargs, kwargs,
122124
args = (sssys, )*nsssys + (tfsys, )*ntfsys + moreargs
123125

124126
# Call the function normally and make sure it works
125-
function(*args, **kwargs)
127+
with warnings.catch_warnings():
128+
warnings.simplefilter("ignore") # catch any warnings elsewhere
129+
function(*args, **kwargs)
126130

127131
# Now add an unrecognized keyword and make sure there is an error
128132
with pytest.raises(TypeError, match="unrecognized keyword"):
129-
function(*args, **kwargs, unknown=None)
133+
with warnings.catch_warnings():
134+
warnings.simplefilter("ignore") # catch any warnings elsewhere
135+
function(*args, **kwargs, unknown=None)
130136

131137

132138
@pytest.mark.parametrize(
@@ -192,9 +198,11 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
192198
'set_defaults': test_unrecognized_kwargs,
193199
'singular_values_plot': test_matplotlib_kwargs,
194200
'ss': test_unrecognized_kwargs,
201+
'ss2io': test_unrecognized_kwargs,
195202
'ss2tf': test_unrecognized_kwargs,
196203
'summing_junction': interconnect_test.test_interconnect_exceptions,
197204
'tf': test_unrecognized_kwargs,
205+
'tf2io' : test_unrecognized_kwargs,
198206
'tf2ss' : test_unrecognized_kwargs,
199207
'sample_system' : test_unrecognized_kwargs,
200208
'c2d' : test_unrecognized_kwargs,

0 commit comments

Comments
 (0)
0