8000 refactor system classes (frdata, iosys, namedio, statesp, xferfcn) · python-control/python-control@e2f76df · GitHub
[go: up one dir, main page]

Skip to content

Commit e2f76df

Browse files
committed
refactor system classes (frdata, iosys, namedio, statesp, xferfcn)
* LTI is NamedIOSystem instead of StateSpace, TransferFunction, and FRD * implement _process_namedio_keywords and use for system/signal name, dt * move timebase functions from lti to namedio * move statesp/_ss code to iosys/ss and iosys/copy to namedio/copy * clean up duplicate object/sysname warnings * updated unit tests
1 parent 2264c76 commit e2f76df

33 files changed

+1465
-928
lines changed

control/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from .margins import *
5656
from .mateqn import *
5757
from .modelsimp import *
58+
from .namedio import *
5859
from .nichols import *
5960
from .phaseplot import *
6061
from .pzmap import *

control/canonical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RMM, 10 Nov 2012
33

44
from .exception import ControlNotImplemented, ControlSlycot
5-
from .lti import issiso
5+
from .namedio import issiso
66
from .statesp import StateSpace, _convert_to_statespace
77
from .statefbk import ctrb, obsv
88

control/dtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
4848
"""
4949

50-
from .lti import isctime
50+
from .namedio import isctime
5151
from .statesp import StateSpace
5252

5353
__all__ = ['sample_system', 'c2d']

control/frdata.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454

5555
from .lti import LTI, _process_frequency_response
5656
from .exception import pandas_check
57-
from .namedio import _NamedIOSystem
57+
from .namedio import NamedIOSystem, _process_namedio_keywords
5858
from . import config
5959

6060
__all__ = ['FrequencyResponseData', 'FRD', 'frd']
6161

6262

63-
class FrequencyResponseData(LTI, _NamedIOSystem):
63+
class FrequencyResponseData(LTI):
6464
"""FrequencyResponseData(d, w[, smooth])
6565
6666
A class for models defined by frequency response data (FRD).
@@ -117,7 +117,7 @@ class FrequencyResponseData(LTI, _NamedIOSystem):
117117

118118
# Allow NDarray * StateSpace to give StateSpace._rmul_() priority
119119
# https://docs.scipy.org/doc/numpy/reference/arrays.classes.html
120-
__array_priority__ = 11 # override ndarray and matrix types
120+
__array_priority__ = 13 # override ndarray, StateSpace, I/O sys
121121

122122
#
123123
# Class attributes
@@ -157,6 +157,9 @@ def __init__(self, *args, **kwargs):
157157
# TODO: discrete-time FRD systems?
158158
smooth = kwargs.pop('smooth', False)
159159

160+
#
161+
# Process positional arguments
162+
#
160163
if len(args) == 2:
161164
if not isinstance(args[0], FRD) and isinstance(args[0], LTI):
162165
# not an FRD, but still a system, second argument should be
@@ -196,28 +199,28 @@ def __init__(self, *args, **kwargs):
196199
raise ValueError(
197200
"Needs 1 or 2 arguments; received %i." % len(args))
198201

199-
# Set the size of the system
200-
self.noutputs = self.fresp.shape[0]
201-
self.ninputs = self.fresp.shape[1]
202-
203-
# Process signal names
204-
_NamedIOSystem.__init__(
205-
self, name=kwargs.pop('name', None),
206-
inputs=kwargs.pop('inputs', self.ninputs),
207-
outputs=kwargs.pop('outputs', self.noutputs))
208-
202+
#
203+
# Process key word arguments
204+
#
209205
# Keep track of return type
210206
self.return_magphase=kwargs.pop('return_magphase', False)
211207
if self.return_magphase not in (True, False):
212208
raise ValueError("unknown return_magphase value")
213209

210+
# Determine whether to squeeze the output
214211
self.squeeze=kwargs.pop('squeeze', None)
215212
if self.squeeze not in (None, True, False):
216213
raise ValueError("unknown squeeze value")
217214

218-
# Make sure there were no extraneous keywords
219-
if kwargs:
220-
raise TypeError("unrecognized keywords: ", str(kwargs))
215+
# Process namedio keywords
216+
defaults = {
217+
'inputs': self.fresp.shape[1], 'outputs': self.fresp.shape[0]}
218+
name, inputs, outputs, states, dt = _process_namedio_keywords(
219+
kwargs, defaults, end=True)
220+
221+
# Process signal names
222+
NamedIOSystem.__init__(
223+
self, name=name, inputs=inputs, outputs=outputs, dt=dt)
221224

222225
# create interpolation functions
223226
if smooth:
@@ -231,7 +234,6 @@ def __init__(self, *args, **kwargs):
231234
w=1.0/(absolute(self.fresp[i, j, :]) + 0.001), s=0.0)
232235
else:
233236
self.ifunc = None
234-
super().__init__(self.fresp.shape[1], self.fresp.shape[0])
235237

236238
#
237239
# Frequency response properties
@@ -666,8 +668,6 @@ def to_pandas(self):
666668
# FrequenceResponseData and then assigning FRD to point to the same object
667669
# fixes this problem.
668670
#
669-
670-
671671
FRD = FrequencyResponseData
672672

673673

0 commit comments

Comments
 (0)
0