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

Commit0b5e3fa

Browse files
committed
consolidate system name prefix/suffix updates to namedio.sys
1 parent184d83d commit0b5e3fa

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

‎control/iosys.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,8 @@ def linearize(self, x0, u0, t=0, params=None, eps=1e-6,
591591
DeprecationWarning)
592592

593593
ifcopy_names:
594-
linsys._copy_names(self)
595-
ifnameisNone:
596-
linsys.name= \
597-
config.defaults['namedio.linearized_system_name_prefix']+\
598-
linsys.name+\
599-
config.defaults['namedio.linearized_system_name_suffix']
600-
else:
594+
linsys._copy_names(self,prefix_suffix_name='linearized')
595+
ifnameisnotNone:
601596
linsys.name=name
602597

603598
# re-init to include desired signal names if names were provided

‎control/namedio.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
__all__= ['issiso','timebase','common_timebase','timebaseEqual',
1414
'isdtime','isctime']
15+
1516
# Define module default parameter values
1617
_namedio_defaults= {
1718
'namedio.state_name_delim':'_',
@@ -20,7 +21,9 @@
2021
'namedio.linearized_system_name_prefix':'',
2122
'namedio.linearized_system_name_suffix':'$linearized',
2223
'namedio.sampled_system_name_prefix':'',
23-
'namedio.sampled_system_name_suffix':'$sampled'
24+
'namedio.sampled_system_name_suffix':'$sampled',
25+
'namedio.converted_system_name_prefix':'',
26+
'namedio.converted_system_name_suffix':'$converted',
2427
}
2528

2629

@@ -49,11 +52,15 @@ def __init__(
4952
_idCounter=0# Counter for creating generic system name
5053

5154
# Return system name
52-
def_name_or_default(self,name=None):
55+
def_name_or_default(self,name=None,prefix_suffix_name=None):
5356
ifnameisNone:
5457
name="sys[{}]".format(NamedIOSystem._idCounter)
5558
NamedIOSystem._idCounter+=1
56-
returnname
59+
prefix=""ifprefix_suffix_nameisNoneelseconfig.defaults[
60+
'namedio.'+prefix_suffix_name+'_system_name_prefix']
61+
suffix=""ifprefix_suffix_nameisNoneelseconfig.defaults[
62+
'namedio.'+prefix_suffix_name+'_system_name_suffix']
63+
returnprefix+name+suffix
5764

5865
# Check if system name is generic
5966
def_generic_name_check(self):
@@ -99,16 +106,26 @@ def __str__(self):
99106
def_find_signal(self,name,sigdict):
100107
returnsigdict.get(name,None)
101108

102-
def_copy_names(self,sys):
109+
def_copy_names(self,sys,prefix="",suffix="",prefix_suffix_name=None):
103110
"""copy the signal and system name of sys. Name is given as a keyword
104111
in case a specific name (e.g. append 'linearized') is desired. """
105-
self.name=sys.name
112+
# Figure out the system name and assign it
113+
ifprefix==""andprefix_suffix_nameisnotNone:
114+
prefix=config.defaults[
115+
'namedio.'+prefix_suffix_name+'_system_name_prefix']
116+
ifsuffix==""andprefix_suffix_nameisnotNone:
117+
suffix=config.defaults[
118+
'namedio.'+prefix_suffix_name+'_system_name_suffix']
119+
self.name=prefix+sys.name+suffix
120+
121+
# Name the inputs, outputs, and states
106122
self.ninputs,self.input_index= \
107123
sys.ninputs,sys.input_index.copy()
108124
self.noutputs,self.output_index= \
109125
sys.noutputs,sys.output_index.copy()
110-
self.nstates,self.state_index= \
111-
sys.nstates,sys.state_index.copy()
126+
ifsys.nstates:# only copy for state space systems
127+
self.nstates,self.state_index= \
128+
sys.nstates,sys.state_index.copy()
112129

113130
defcopy(self,name=None,use_prefix_suffix=True):
114131
"""Make a copy of an input/output system
@@ -128,10 +145,8 @@ def copy(self, name=None, use_prefix_suffix=True):
128145
# Update the system name
129146
ifnameisNoneanduse_prefix_suffix:
130147
# Get the default prefix and suffix to use
131-
dup_prefix=config.defaults['namedio.duplicate_system_name_prefix']
132-
dup_suffix=config.defaults['namedio.duplicate_system_name_suffix']
133148
newsys.name=self._name_or_default(
134-
dup_prefix+self.name+dup_suffix)
149+
self.name,prefix_suffix_name='duplicate')
135150
else:
136151
newsys.name=self._name_or_default(name)
137152

‎control/statesp.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,13 +1382,8 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None,
13821382
sysd=StateSpace(Ad,Bd,C,D,Ts)
13831383
# copy over the system name, inputs, outputs, and states
13841384
ifcopy_names:
1385-
sysd._copy_names(self)
1386-
ifnameisNone:
1387-
sysd.name= \
1388-
config.defaults['namedio.sampled_system_name_prefix']+\
1389-
sysd.name+ \
1390-
config.defaults['namedio.sampled_system_name_suffix']
1391-
else:
1385+
sysd._copy_names(self,prefix_suffix_name='sampled')
1386+
ifnameisnotNone:
13921387
sysd.name=name
13931388
# pass desired signal names if names were provided
13941389
returnStateSpace(sysd,**kwargs)

‎control/xferfcn.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,13 +1206,8 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None,
12061206
sysd=TransferFunction(numd[0, :],dend,Ts)
12071207
# copy over the system name, inputs, outputs, and states
12081208
ifcopy_names:
1209-
sysd._copy_names(self)
1210-
ifnameisNone:
1211-
sysd.name= \
1212-
config.defaults['namedio.sampled_system_name_prefix']+\
1213-
sysd.name+ \
1214-
config.defaults['namedio.sampled_system_name_suffix']
1215-
else:
1209+
sysd._copy_names(self,prefix_suffix_name='sampled')
1210+
ifnameisnotNone:
12161211
sysd.name=name
12171212
# pass desired signal names if names were provided
12181213
returnTransferFunction(sysd,name=name,**kwargs)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp