Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit37243f6

Browse files
committed
change system name when converting tf to ss
1 parent0b5e3fa commit37243f6

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

‎control/iosys.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,9 @@ def ss(*args, **kwargs):
23952395
"non-unique state space realization")
23962396

23972397
# Create a state space system from an LTI system
2398-
sys=LinearIOSystem(_convert_to_statespace(sys),**kwargs)
2398+
sys=LinearIOSystem(
2399+
_convert_to_statespace(sys,use_prefix_suffix=True),**kwargs)
2400+
23992401
else:
24002402
raiseTypeError("ss(sys): sys must be a StateSpace or "
24012403
"TransferFunction object. It is %s."%type(sys))

‎control/statesp.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ def output(self, t, x, u=None, params=None):
15191519

15201520

15211521
# TODO: add discrete time check
1522-
def_convert_to_statespace(sys):
1522+
def_convert_to_statespace(sys,use_prefix_suffix=False):
15231523
"""Convert a system to state space form (if needed).
15241524
15251525
If sys is already a state space, then it is returned. If sys is a
@@ -1556,11 +1556,10 @@ def _convert_to_statespace(sys):
15561556
denorder,den,num,tol=0)
15571557

15581558
states=ssout[0]
1559-
returnStateSpace(
1559+
newsys=StateSpace(
15601560
ssout[1][:states, :states],ssout[2][:states, :sys.ninputs],
1561-
ssout[3][:sys.noutputs, :states],ssout[4],sys.dt,
1562-
inputs=sys.input_labels,outputs=sys.output_labels,
1563-
name=sys.name)
1561+
ssout[3][:sys.noutputs, :states],ssout[4],sys.dt)
1562+
15641563
exceptImportError:
15651564
# No Slycot. Scipy tf->ss can't handle MIMO, but static
15661565
# MIMO is an easy special case we can check for here
@@ -1585,9 +1584,13 @@ def _convert_to_statespace(sys):
15851584
# the squeeze
15861585
A,B,C,D= \
15871586
sp.signal.tf2ss(squeeze(sys.num),squeeze(sys.den))
1588-
returnStateSpace(
1589-
A,B,C,D,sys.dt,inputs=sys.input_labels,
1590-
outputs=sys.output_labels,name=sys.name)
1587+
newsys=StateSpace(A,B,C,D,sys.dt)
1588+
1589+
# Copy over the signal (and system) names
1590+
newsys._copy_names(
1591+
sys,
1592+
prefix_suffix_name='converted'ifuse_prefix_suffixelseNone)
1593+
returnnewsys
15911594

15921595
elifisinstance(sys,FrequencyResponseData):
15931596
raiseTypeError("Can't convert FRD to StateSpace system.")
@@ -1600,7 +1603,6 @@ def _convert_to_statespace(sys):
16001603
exceptException:
16011604
raiseTypeError("Can't convert given type to StateSpace system.")
16021605

1603-
16041606
# TODO: add discrete time option
16051607
def_rss_generate(
16061608
states,inputs,outputs,cdtype,strictly_proper=False,name=None):
@@ -1914,7 +1916,8 @@ def tf2ss(*args, **kwargs):
19141916
ifnotisinstance(sys,TransferFunction):
19151917
raiseTypeError("tf2ss(sys): sys must be a TransferFunction "
19161918
"object.")
1917-
returnStateSpace(_convert_to_statespace(sys),**kwargs)
1919+
returnStateSpace(_convert_to_statespace(sys,use_prefix_suffix=True),
1920+
**kwargs)
19181921
else:
19191922
raiseValueError("Needs 1 or 2 arguments; received %i."%len(args))
19201923

‎control/tests/namedio_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def test_io_naming(fun, args, kwargs):
169169
assertsys_ss!=sys_r
170170
assertsys_ss.input_labels==input_labels
171171
assertsys_ss.output_labels==output_labels
172+
ifnotisinstance(sys_r,ct.StateSpace):
173+
# System should get unique name
174+
assertsys_ss.name!=sys_r.name
172175

173176
# Reassign system and signal names
174177
sys_ss=ct.ss(
@@ -247,11 +250,11 @@ def test_convert_to_statespace():
247250

248251
# check that name, inputs, and outputs passed through
249252
sys_new=ct.ss(sys)
250-
assertsys_new.name=='sys'
253+
assertsys_new.name=='sys$converted'
251254
assertsys_new.input_labels== ['u']
252255
assertsys_new.output_labels== ['y']
253256
sys_new=ct.ss(sys_static)
254-
assertsys_new.name=='sys_static'
257+
assertsys_new.name=='sys_static$converted'
255258
assertsys_new.input_labels== ['u']
256259
assertsys_new.output_labels== ['y']
257260

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp