Skip to content

Commit 4692b1e

Browse files
committed
remove unneeded code; clean up TODOs
1 parent 0ef2941 commit 4692b1e

10 files changed

Lines changed: 21 additions & 181 deletions

File tree

control/iosys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def _process_indices(arg, name, labels, length):
698698
if isinstance(arg, int):
699699
# Return the start or end of the list of possible indices
700700
return list(range(arg)) if arg > 0 else list(range(length))[arg:]
701-
701+
702702
elif isinstance(arg, slice):
703703
# Return the indices referenced by the slice
704704
return list(range(length))[arg]

control/statesp.py

Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def __str__(self):
413413
# represent to implement a re-loadable version
414414
def __repr__(self):
415415
"""Print state-space system in loadable form."""
416-
# TODO: add input/output names
416+
# TODO: add input/output names (?)
417417
return "StateSpace({A}, {B}, {C}, {D}{dt})".format(
418418
A=self.A.__repr__(), B=self.B.__repr__(),
419419
C=self.C.__repr__(), D=self.D.__repr__(),
@@ -962,6 +962,7 @@ def zeros(self):
962962
# Feedback around a state space system
963963
def feedback(self, other=1, sign=-1):
964964
"""Feedback interconnection between two LTI systems."""
965+
# Convert the system to state space, if possible
965966
try:
966967
other = _convert_to_statespace(other)
967968
except:
@@ -2293,114 +2294,3 @@ def _rss_generate(
22932294
else:
22942295
ss_args = (A, B, C, D, True)
22952296
return StateSpace(*ss_args, name=name)
2296-
2297-
2298-
def _mimo2siso(sys, input, output, warn_conversion=False):
2299-
# pylint: disable=W0622
2300-
"""
2301-
Convert a MIMO system to a SISO system. (Convert a system with multiple
2302-
inputs and/or outputs, to a system with a single input and output.)
2303-
2304-
The input and output that are used in the SISO system can be selected
2305-
with the parameters ``input`` and ``output``. All other inputs are set
2306-
to 0, all other outputs are ignored.
2307-
2308-
If ``sys`` is already a SISO system, it will be returned unaltered.
2309-
2310-
Parameters
2311-
----------
2312-
sys : StateSpace
2313-
Linear (MIMO) system that should be converted.
2314-
input : int
2315-
Index of the input that will become the SISO system's only input.
2316-
output : int
2317-
Index of the output that will become the SISO system's only output.
2318-
warn_conversion : bool, optional
2319-
If `True`, print a message when sys is a MIMO system,
2320-
warning that a conversion will take place. Default is False.
2321-
2322-
Returns
2323-
sys : StateSpace
2324-
The converted (SISO) system.
2325-
"""
2326-
if not (isinstance(input, int) and isinstance(output, int)):
2327-
raise TypeError("Parameters ``input`` and ``output`` must both "
2328-
"be integer numbers.")
2329-
if not (0 <= input < sys.ninputs):
2330-
raise ValueError("Selected input does not exist. "
2331-
"Selected input: {sel}, "
2332-
"number of system inputs: {ext}."
2333-
.format(sel=input, ext=sys.ninputs))
2334-
if not (0 <= output < sys.noutputs):
2335-
raise ValueError("Selected output does not exist. "
2336-
"Selected output: {sel}, "
2337-
"number of system outputs: {ext}."
2338-
.format(sel=output, ext=sys.noutputs))
2339-
# Convert sys to SISO if necessary
2340-
if sys.ninputs > 1 or sys.noutputs > 1:
2341-
if warn_conversion:
2342-
warn("Converting MIMO system to SISO system. "
2343-
"Only input {i} and output {o} are used."
2344-
.format(i=input, o=output))
2345-
# $X = A*X + B*U
2346-
# Y = C*X + D*U
2347-
new_B = sys.B[:, input]
2348-
new_C = sys.C[output, :]
2349-
new_D = sys.D[output, input]
2350-
sys = StateSpace(
2351-
sys.A, new_B, new_C, new_D, sys.dt,
2352-
name=sys.name,
2353-
inputs=sys.input_labels[input], outputs=sys.output_labels[output])
2354-
2355-
return sys
2356-
2357-
2358-
def _mimo2simo(sys, input, warn_conversion=False):
2359-
# pylint: disable=W0622
2360-
"""
2361-
Convert a MIMO system to a SIMO system. (Convert a system with multiple
2362-
inputs and/or outputs, to a system with a single input but possibly
2363-
multiple outputs.)
2364-
2365-
The input that is used in the SIMO system can be selected with the
2366-
parameter ``input``. All other inputs are set to 0, all other
2367-
outputs are ignored.
2368-
2369-
If ``sys`` is already a SIMO system, it will be returned unaltered.
2370-
2371-
Parameters
2372-
----------
2373-
sys: StateSpace
2374-
Linear (MIMO) system that should be converted.
2375-
input: int
2376-
Index of the input that will become the SIMO system's only input.
2377-
warn_conversion: bool
2378-
If True: print a warning message when sys is a MIMO system.
2379-
Warn that a conversion will take place.
2380-
2381-
Returns
2382-
-------
2383-
sys: StateSpace
2384-
The converted (SIMO) system.
2385-
"""
2386-
if not (isinstance(input, int)):
2387-
raise TypeError("Parameter ``input`` be an integer number.")
2388-
if not (0 <= input < sys.ninputs):
2389-
raise ValueError("Selected input does not exist. "
2390-
"Selected input: {sel}, "
2391-
"number of system inputs: {ext}."
2392-
.format(sel=input, ext=sys.ninputs))
2393-
# Convert sys to SISO if necessary
2394-
if sys.ninputs > 1:
2395-
if warn_conversion:
2396-
warn("Converting MIMO system to SIMO system. "
2397-
"Only input {i} is used." .format(i=input))
2398-
# $X = A*X + B*U
2399-
# Y = C*X + D*U
2400-
new_B = sys.B[:, input:input+1]
2401-
new_D = sys.D[:, input:input+1]
2402-
sys = StateSpace(
2403-
sys.A, new_B, sys.C, new_D, sys.dt, name=sys.name,
2404-
inputs=sys.input_labels[input], outputs=sys.output_labels)
2405-
2406-
return sys

control/tests/convert_test.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import pytest
2020

2121
from control import rss, ss, ss2tf, tf, tf2ss
22-
from control.statesp import _mimo2siso
2322
from control.statefbk import ctrb, obsv
2423
from control.freqplot import bode
2524
from control.exception import slycot_check
@@ -96,7 +95,7 @@ def testConvert(self, fixedseed, states, inputs, outputs):
9695
print("Checking input %d, output %d"
9796
% (inputNum, outputNum))
9897
ssorig_mag, ssorig_phase, ssorig_omega = \
99-
bode(_mimo2siso(ssOriginal, inputNum, outputNum),
98+
bode(ssOriginal[outputNum, inputNum],
10099
deg=False, plot=False)
101100
ssorig_real = ssorig_mag * np.cos(ssorig_phase)
102101
ssorig_imag = ssorig_mag * np.sin(ssorig_phase)
@@ -123,10 +122,8 @@ def testConvert(self, fixedseed, states, inputs, outputs):
123122
# Make sure xform'd SS has same frequency response
124123
#
125124
ssxfrm_mag, ssxfrm_phase, ssxfrm_omega = \
126-
bode(_mimo2siso(ssTransformed,
127-
inputNum, outputNum),
128-
ssorig_omega,
129-
deg=False, plot=False)
125+
bode(ssTransformed[outputNum, inputNum],
126+
ssorig_omega, deg=False, plot=False)
130127
ssxfrm_real = ssxfrm_mag * np.cos(ssxfrm_phase)
131128
ssxfrm_imag = ssxfrm_mag * np.sin(ssxfrm_phase)
132129
np.testing.assert_array_almost_equal(

control/tests/iosys_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def test_static_nonlinearity(self, tsys):
411411
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=2)
412412

413413

414-
@pytest.mark.filterwarnings("ignore:Duplicate name::control.nlsys")
414+
@pytest.mark.filterwarnings("ignore:Duplicate name::control.iosys")
415415
def test_algebraic_loop(self, tsys):
416416
# Create some linear and nonlinear systems to play with
417417
linsys = tsys.siso_linsys
@@ -1368,7 +1368,7 @@ def test_operand_incompatible(self, Pout, Pin, C, op):
13681368
C = ct.rss(2, 3, 2)
13691369
elif isinstance(C, str) and C == 'rss23':
13701370
C = ct.rss(2, 2, 3)
1371-
1371+
13721372
with pytest.raises(ValueError, match="incompatible"):
13731373
PC = op(P, C)
13741374

control/tests/matlab2_test.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import scipy.signal
1616

1717
from control.matlab import ss, step, impulse, initial, lsim, dcgain, ss2tf
18-
from control.statesp import _mimo2siso
1918
from control.timeresp import _check_convert_array
2019
from control.tests.conftest import slycotonly
2120

@@ -362,10 +361,8 @@ def test_convert_MIMO_to_SISO(self, SISO_mats, MIMO_mats):
362361
# t, y = step(sys_siso)
363362
# plot(t, y, label='sys_siso d=0')
364363

365-
sys_siso_00 = _mimo2siso(sys_mimo, input=0, output=0,
366-
warn_conversion=False)
367-
sys_siso_11 = _mimo2siso(sys_mimo, input=1, output=1,
368-
warn_conversion=False)
364+
sys_siso_00 = sys_mimo[0, 0]
365+
sys_siso_11 = sys_mimo[1, 1]
369366
#print("sys_siso_00 ---------------------------------------------")
370367
#print(sys_siso_00)
371368
#print("sys_siso_11 ---------------------------------------------")
@@ -407,10 +404,8 @@ def test_convert_MIMO_to_SISO(self, SISO_mats, MIMO_mats):
407404
sys_mimo = ss(Am, Bm, Cm, Dm)
408405

409406

410-
sys_siso_01 = _mimo2siso(sys_mimo, input=0, output=1,
411-
warn_conversion=False)
412-
sys_siso_10 = _mimo2siso(sys_mimo, input=1, output=0,
413-
warn_conversion=False)
407+
sys_siso_01 = sys_mimo[0, 1]
408+
sys_siso_10 = sys_mimo[1, 0]
414409
# print("sys_siso_01 ---------------------------------------------")
415410
# print(sys_siso_01)
416411
# print("sys_siso_10 ---------------------------------------------")

control/tests/statesp_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
from control.lti import evalfr
2121
from control.statesp import StateSpace, _convert_to_statespace, tf2ss, \
2222
_statesp_defaults, _rss_generate, linfnorm, ss, rss, drss
23-
from control.tests.conftest import slycotonly
2423
from control.xferfcn import TransferFunction, ss2tf
2524

26-
27-
from .conftest import editsdefaults
25+
from .conftest import editsdefaults, slycotonly
2826

2927

3028
class TestStateSpace:

control/timeresp.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
from scipy.linalg import eig, eigvals, matrix_balance, norm
7979
from copy import copy
8080

81-
# TODO: see what is causing MRO issues with .statesp, .xferfcn
8281
from . import config
8382
from .exception import pandas_check
8483
from .iosys import isctime, isdtime
@@ -933,8 +932,7 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
933932
:ref:`package-configuration-parameters`.
934933
935934
"""
936-
from .statesp import StateSpace, _convert_to_statespace, \
937-
_mimo2simo, _mimo2siso
935+
from .statesp import StateSpace, _convert_to_statespace
938936
from .xferfcn import TransferFunction
939937
from .nlsys import NonlinearIOSystem, input_output_response
940938

@@ -1322,8 +1320,8 @@ def step_response(sys, T=None, X0=0, input=None, output=None, T_num=None,
13221320
13231321
"""
13241322
from .lti import LTI
1325-
from .xferfcn import TransferFunction # TODO: move to top?
1326-
from .statesp import _convert_to_statespace # TODO: move to top?
1323+
from .xferfcn import TransferFunction
1324+
from .statesp import _convert_to_statespace
13271325

13281326
# Create the time and input vectors
13291327
if T is None or np.asarray(T).size == 1 and isinstance(sys, LTI):
@@ -1486,7 +1484,6 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None,
14861484
PeakTime: 4.242
14871485
SteadyStateValue: -1.0
14881486
"""
1489-
# TODO: See if there is a better way to do this
14901487
from .statesp import StateSpace
14911488
from .xferfcn import TransferFunction
14921489
from .nlsys import NonlinearIOSystem
@@ -1818,7 +1815,7 @@ def impulse_response(sys, T=None, input=None, output=None, T_num=None,
18181815
>>> T, yout = ct.impulse_response(G)
18191816
18201817
"""
1821-
from .statesp import _convert_to_statespace # TODO: move to top?
1818+
from .statesp import _convert_to_statespace
18221819
from .lti import LTI
18231820

18241821
# Create the time and input vectors
@@ -1941,7 +1938,7 @@ def _ideal_tfinal_and_dt(sys, is_step=True):
19411938
python-control 2020.08.17
19421939
19431940
"""
1944-
from .statesp import _convert_to_statespace # TODO: move to top?
1941+
from .statesp import _convert_to_statespace
19451942

19461943
sqrt_eps = np.sqrt(np.spacing(1.))
19471944
default_tfinal = 5 # Default simulation horizon

control/xferfcn.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def __init__(self, *args, **kwargs):
170170
#
171171
# Process positional arguments
172172
#
173-
# TODO: move to tf()
173+
174174
if len(args) == 2:
175175
# The user provided a numerator and a denominator.
176176
num, den = args
@@ -511,8 +511,7 @@ def _repr_latex_(self, var=None):
511511
mimo = not self.issiso()
512512

513513
if var is None:
514-
# ! TODO: replace with standard calls to lti functions
515-
var = 's' if self.dt is None or self.dt == 0 else 'z'
514+
var = 's' if self.isctime() else 'z'
516515

517516
out = ['$$']
518517

@@ -566,7 +565,6 @@ def __add__(self, other):
566565
from .statesp import StateSpace
567566

568567
# Convert the second argument to a transfer function.
569-
#! TODO: update processing (here and elsewhere)
570568
if isinstance(other, StateSpace):
571569
other = _convert_to_transfer_function(other)
572570
elif isinstance(other, (int, float, complex, np.number, np.ndarray)):
@@ -615,7 +613,7 @@ def __rsub__(self, other):
615613
def __mul__(self, other):
616614
"""Multiply two LTI objects (serial connection)."""
617615
from .statesp import StateSpace
618-
616+
619617
# Convert the second argument to a transfer function.
620618
if isinstance(other, StateSpace):
621619
other = _convert_to_transfer_function(other)

doc/control.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Time domain simulation
7373
phase_plot
7474
step_response
7575
TimeResponseData
76-
7776

7877
Control system analysis
7978
=======================
@@ -98,8 +97,6 @@ Control system analysis
9897
StateSpace.__call__
9998
TransferFunction.__call__
10099

101-
102-
103100
Matrix computations
104101
===================
105102
.. autosummary::

examples/test-response.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)