Merge pull request #884 from sawyerbfuller/static-signal-names · python-control/python-control@184d83d
@@ -90,8 +90,10 @@ def test_named_ss():
9090 (lambda t, x, u, params: -x, None),
9191 {'inputs': 2, 'outputs':2, 'states':2}],
9292 [ct.ss, ([[1, 2], [3, 4]], [[0], [1]], [[1, 0]], 0), {}],
93+ [ct.ss, ([], [], [], 3), {}], # static system
9394 [ct.StateSpace, ([[1, 2], [3, 4]], [[0], [1]], [[1, 0]], 0), {}],
9495 [ct.tf, ([1, 2], [3, 4, 5]), {}],
96+ [ct.tf, (2, 3), {}], # static system
9597 [ct.TransferFunction, ([1, 2], [3, 4, 5]), {}],
9698])
9799def test_io_naming(fun, args, kwargs):
@@ -112,7 +114,7 @@ def test_io_naming(fun, args, kwargs):
112114assert sys_g.name == 'sys[0]'
113115assert sys_g.input_labels == [f'u[{i}]' for i in range(sys_g.ninputs)]
114116assert sys_g.output_labels == [f'y[{i}]' for i in range(sys_g.noutputs)]
115-if sys_g.nstates:
117+if sys_g.nstates is not None:
116118assert sys_g.state_labels == [f'x[{i}]' for i in range(sys_g.nstates)]
117119118120#
@@ -128,7 +130,7 @@ def test_io_naming(fun, args, kwargs):
128130sys_r.set_outputs(output_labels)
129131assert sys_r.output_labels == output_labels
130132131-if sys_g.nstates:
133+if sys_g.nstates is not None:
132134state_labels = [f'x{i}' for i in range(sys_g.nstates)]
133135sys_r.set_states(state_labels)
134136assert sys_r.state_labels == state_labels
@@ -143,7 +145,7 @@ def test_io_naming(fun, args, kwargs):
143145sys_k = fun(state_labels, output_labels, input_labels, name='mysys')
144146145147elif sys_g.nstates is None:
146-# Don't pass state labels
148+# Don't pass state labels if TransferFunction
147149sys_k = fun(
148150*args, inputs=input_labels, outputs=output_labels, name='mysys')
149151@@ -155,7 +157,7 @@ def test_io_naming(fun, args, kwargs):
155157assert sys_k.name == 'mysys'
156158assert sys_k.input_labels == input_labels
157159assert sys_k.output_labels == output_labels
158-if sys_g.nstates:
160+if sys_g.nstates is not None:
159161assert sys_k.state_labels == state_labels
160162161163#
@@ -193,6 +195,24 @@ def test_io_naming(fun, args, kwargs):
193195assert sys_tf.input_labels == input_labels
194196assert sys_tf.output_labels == output_labels
195197198+#
199+# Convert the system to a LinearIOSystem and make sure labels transfer
200+#
201+if not isinstance(
202+sys_r, (ct.FrequencyResponseData, ct.NonlinearIOSystem)) and \
203+ct.slycot_check():
204+sys_lio = ct.LinearIOSystem(sys_r)
205+assert sys_lio != sys_r
206+assert sys_lio.input_labels == input_labels
207+assert sys_lio.output_labels == output_labels
208+209+# Reassign system and signal names
210+sys_lio = ct.LinearIOSystem(
211+sys_g, inputs=input_labels, outputs=output_labels, name='new')
212+assert sys_lio.name == 'new'
213+assert sys_lio.input_labels == input_labels
214+assert sys_lio.output_labels == output_labels
215+196216197217# Internal testing of StateSpace initialization
198218def test_init_namedif():
@@ -221,14 +241,29 @@ def test_init_namedif():
221241222242# Test state space conversion
223243def test_convert_to_statespace():
224-# Set up the initial system
225-sys = ct.tf(ct.rss(2, 1, 1))
244+# Set up the initial systems
245+sys = ct.tf(ct.rss(2, 1, 1), inputs='u', outputs='y', name='sys')
246+sys_static = ct.tf(1, 2, inputs='u', outputs='y', name='sys_static')
247+248+# check that name, inputs, and outputs passed through
249+sys_new = ct.ss(sys)
250+assert sys_new.name == 'sys'
251+assert sys_new.input_labels == ['u']
252+assert sys_new.output_labels == ['y']
253+sys_new = ct.ss(sys_static)
254+assert sys_new.name == 'sys_static'
255+assert sys_new.input_labels == ['u']
256+assert sys_new.output_labels == ['y']
226257227258# Make sure we can rename system name, inputs, outputs
228259sys_new = ct.ss(sys, inputs='u', outputs='y', name='new')
229260assert sys_new.name == 'new'
230261assert sys_new.input_labels == ['u']
231262assert sys_new.output_labels == ['y']
263+sys_new = ct.ss(sys_static, inputs='u', outputs='y', name='new')
264+assert sys_new.name == 'new'
265+assert sys_new.input_labels == ['u']
266+assert sys_new.output_labels == ['y']
232267233268# Try specifying the state names (via low level test)
234269with pytest.warns(UserWarning, match="non-unique state space realization"):