Skip to content

Commit 0530b52

Browse files
committed
change system name when converting ss to tf
1 parent 37243f6 commit 0530b52

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

control/namedio.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ def _copy_names(self, sys, prefix="", suffix="", prefix_suffix_name=None):
119119
self.name = prefix + sys.name + suffix
120120

121121
# Name the inputs, outputs, and states
122-
self.ninputs, self.input_index = \
123-
sys.ninputs, sys.input_index.copy()
124-
self.noutputs, self.output_index = \
125-
sys.noutputs, sys.output_index.copy()
126-
if sys.nstates: # only copy for state space systems
127-
self.nstates, self.state_index = \
128-
sys.nstates, sys.state_index.copy()
122+
self.input_index = sys.input_index.copy()
123+
self.output_index = sys.output_index.copy()
124+
if self.nstates and sys.nstates:
125+
# only copy state names for state space systems
126+
self.state_index = sys.state_index.copy()
129127

130128
def copy(self, name=None, use_prefix_suffix=True):
131129
"""Make a copy of an input/output system

control/tests/xferfcn_test.py

+6
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,12 @@ def test_copy_names(create, args, kwargs, convert):
12621262
if cpy.nstates is not None and sys.nstates is not None:
12631263
assert cpy.state_labels == sys.state_labels
12641264

1265+
# Make sure that names aren't the same if system changed type
1266+
if not isinstance(cpy, create):
1267+
assert cpy.name == sys.name + '$converted'
1268+
else:
1269+
assert cpy.name == sys.name
1270+
12651271
# Relabel inputs and outputs
12661272
cpy = convert(sys, inputs='myin', outputs='myout')
12671273
assert cpy.input_labels == ['myin']

control/xferfcn.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,8 @@ def _add_siso(num1, den1, num2, den2):
14331433
return num, den
14341434

14351435

1436-
def _convert_to_transfer_function(sys, inputs=1, outputs=1):
1436+
def _convert_to_transfer_function(
1437+
sys, inputs=1, outputs=1, use_prefix_suffix=False):
14371438
"""Convert a system to transfer function form (if needed).
14381439
14391440
If sys is already a transfer function, then it is returned. If sys is a
@@ -1509,7 +1510,10 @@ def _convert_to_transfer_function(sys, inputs=1, outputs=1):
15091510
num = squeeze(num) # Convert to 1D array
15101511
den = squeeze(den) # Probably not needed
15111512

1512-
return TransferFunction(num, den, sys.dt)
1513+
newsys = TransferFunction(num, den, sys.dt)
1514+
if use_prefix_suffix:
1515+
newsys._copy_names(sys, prefix_suffix_name='converted')
1516+
return newsys
15131517

15141518
elif isinstance(sys, (int, float, complex, np.number)):
15151519
num = [[[sys] for j in range(inputs)] for i in range(outputs)]
@@ -1809,7 +1813,8 @@ def ss2tf(*args, **kwargs):
18091813
if not kwargs.get('outputs'):
18101814
kwargs['outputs'] = sys.output_labels
18111815
return TransferFunction(
1812-
_convert_to_transfer_function(sys), **kwargs)
1816+
_convert_to_transfer_function(sys, use_prefix_suffix=True),
1817+
**kwargs)
18131818
else:
18141819
raise TypeError(
18151820
"ss2tf(sys): sys must be a StateSpace object. It is %s."

0 commit comments

Comments
 (0)