11# namedio.py - internal named I/O object class
22# RMM, 13 Mar 2022
33#
4- # This file implements the _NamedIOSystem and _NamedIOStateSystem classes,
5- # which are used as a parent classes for FrequencyResponseData,
6- # InputOutputSystem, LTI, TimeResponseData, and other similar classes to
7- # allow naming of signals.
4+ # This file implements the _NamedIOSystem class, which is used as a parent
5+ # class for FrequencyResponseData, InputOutputSystem, LTI, TimeResponseData,
6+ # and other similar classes to allow naming of signals.
87
98import numpy as np
109
@@ -19,14 +18,15 @@ def _name_or_default(self, name=None):
1918 return name
2019
2120 def __init__ (
22- self , inputs = None , outputs = None , name = None ):
21+ self , name = None , inputs = None , outputs = None , states = None ):
2322
2423 # system name
2524 self .name = self ._name_or_default (name )
2625
2726 # Parse and store the number of inputs and outputs
2827 self .set_inputs (inputs )
2928 self .set_outputs (outputs )
29+ self .set_states (states )
3030
3131 #
3232 # Class attributes
@@ -38,12 +38,17 @@ def __init__(
3838 #: Number of system inputs.
3939 #:
4040 #: :meta hide-value:
41- ninputs = 0
41+ ninputs = None
4242
4343 #: Number of system outputs.
4444 #:
4545 #: :meta hide-value:
46- noutputs = 0
46+ noutputs = None
47+
48+ #: Number of system states.
49+ #:
50+ #: :meta hide-value:
51+ nstates = None
4752
4853 def __repr__ (self ):
4954 return str (type (self )) + ": " + self .name if self .name is not None \
@@ -58,6 +63,10 @@ def __str__(self):
5863 str += "\n Outputs (%s): " % self .noutputs
5964 for key in self .output_index :
6065 str += key + ", "
66+ if self .nstates is not None :
67+ str += "\n States (%s): " % self .nstates
68+ for key in self .state_index :
69+ str += key + ", "
6170 return str
6271
6372 # Find a signal by name
@@ -122,44 +131,6 @@ def find_output(self, name):
122131 lambda self : list (self .output_index .keys ()), # getter
123132 set_outputs ) # setter
124133
125- def issiso (self ):
126- """Check to see if a system is single input, single output"""
127- return self .ninputs == 1 and self .noutputs == 1
128-
129-
130- class _NamedIOStateSystem (_NamedIOSystem ):
131- def __init__ (
132- self , inputs = None , outputs = None , states = None , name = None ):
133- # Parse and store the system name, inputs, and outputs
134- super ().__init__ (inputs = inputs , outputs = outputs , name = name )
135-
136- # Parse and store the number of states
137- self .set_states (states )
138-
139- #
140- # Class attributes
141- #
142- # These attributes are defined as class attributes so that they are
143- # documented properly. They are "overwritten" in __init__.
144- #
145-
146- #: Number of system states.
147- #:
148- #: :meta hide-value:
149- nstates = 0
150-
151- def __str__ (self ):
152- """String representation of an input/output system"""
153- str = _NamedIOSystem .__str__ (self )
154- str += "\n States (%s): " % self .nstates
155- for key in self .state_index :
156- str += key + ", "
157- return str
158-
159- def _isstatic (self ):
160- """Check to see if a system is a static system (no states)"""
161- return self .nstates == 0
162-
163134 def set_states (self , states , prefix = 'x' ):
164135 """Set the number/names of the system states.
165136
@@ -189,6 +160,14 @@ def find_state(self, name):
189160 lambda self : list (self .state_index .keys ()), # getter
190161 set_states ) # setter
191162
163+ def issiso (self ):
164+ """Check to see if a system is single input, single output"""
165+ return self .ninputs == 1 and self .noutputs == 1
166+
167+ def _isstatic (self ):
168+ """Check to see if a system is a static system (no states)"""
169+ return self .nstates == 0
170+
192171
193172# Utility function to parse a list of signals
194173def _process_signal_list (signals , prefix = 's' ):
0 commit comments