Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37b06f4
Added notebook for doing development work on IO-Cleanup.
Feb 17, 2017
feb68f5
Added .eggs directory to gitignore.
Feb 17, 2017
5e2d95d
Broke out the numerator/denominator cleanup function into a separate …
Feb 18, 2017
cd7f596
Merge remote-tracking branch 'upstream/master'
Feb 18, 2017
509ff8e
Removed test notebook
Feb 18, 2017
d44489f
Renamed cleanPart to _cleanPart since it is an internal function, as …
Feb 18, 2017
d8d6b02
Fix minreal not returning a discrete TF
rssalessio Mar 26, 2017
585c028
change if to None. add tests
rssalessio Mar 29, 2017
d4fc2d0
BLD: travis update for new/old scipy + improved slycot
murrayrm Dec 23, 2017
11c99ef
Fixes for SciPy 1.0 compatibility
murrayrm Dec 23, 2017
b6e378f
BLD: updated Travis CI script to build slycot from source
murrayrm Dec 24, 2017
087046f
DOC: fix conda-recipe and make_version for conda v3
murrayrm Dec 29, 2017
b19ca11
DOC: update docstrings for system creation (see PR #163)
murrayrm Dec 29, 2017
bde823b
DOC: add more info on class constructors
murrayrm Dec 29, 2017
b881b77
DOC: improved docstrings for fucntions with variable arguments
murrayrm Dec 29, 2017
b1437f0
unit test from kangwonlee commit facfe9c49d79227dd3bdcd22af9d0aa917ac…
murrayrm Dec 29, 2017
10cdb7a
TST: renamed unit test from kangwonlee
murrayrm Dec 29, 2017
af8837e
Merge branch 'InputSanitization' of https://github.com/jed-frey/pytho…
murrayrm Dec 29, 2017
b697a08
Merge branch 'jed-frey-InputSanitization' into sstf_input_sanitization
murrayrm Dec 29, 2017
68b5dd1
address additional comments from roryyorke in PR #135
murrayrm Dec 29, 2017
314c4eb
DOC: fixed typos + address @roryyorke feedback
murrayrm Dec 30, 2017
aa6e0df
replace np.pi with math.pi (avoids Mock() issues) + docstring update …
murrayrm Dec 30, 2017
11a6264
Merge pull request #1 from murrayrm/sstf_input_sanitization
Dec 31, 2017
fbcdc21
Use slycot's tb05ad for faster and more accurate frequency response e…
rabraker Jan 2, 2018
7d8bc65
Merge pull request #169 from murrayrm/fix_travis
murrayrm Jan 2, 2018
9457031
Merge pull request #167 from murrayrm/fix_conda
murrayrm Jan 2, 2018
c4f1c34
Merge pull request #170 from murrayrm/fix_scipy-1.0
murrayrm Jan 2, 2018
bbb902f
Merge branch 'master' into InputSanitization
murrayrm Jan 2, 2018
8c997ff
Merge branch 'master' into InputSanitization
murrayrm Jan 2, 2018
a5094e2
Merge pull request #135 from jed-frey/InputSanitization
murrayrm Jan 2, 2018
6e3c2dd
Merge branch 'master' into statesp_constructor_doc
murrayrm Jan 2, 2018
2635889
Merge branch 'master' into statesp_constructor_doc
murrayrm Jan 2, 2018
f890a88
Merge pull request #171 from murrayrm/statesp_constructor_doc
murrayrm Jan 2, 2018
33bebc1
Merge pull request #140 from rssalessio/master
murrayrm Jan 2, 2018
66c0088
Use slycot's tb05ad for faster and more accurate frequency response e…
rabraker Jan 2, 2018
308d8b5
Merge branch 'freqresp_tb05ad' of github.com:rabraker/python-control …
rabraker Jan 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions control/bdalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"""

import scipy as sp
import numpy as np
from . import xferfcn as tf
from . import statesp as ss
from . import frdata as frd
Expand Down Expand Up @@ -221,18 +222,18 @@ def feedback(sys1, sys2=1, sign=-1):
"""

# Check for correct input types.
if not isinstance(sys1, (int, float, complex, tf.TransferFunction,
ss.StateSpace, frd.FRD)):
if not isinstance(sys1, (int, float, complex, np.number,
tf.TransferFunction, ss.StateSpace, frd.FRD)):
raise TypeError("sys1 must be a TransferFunction, StateSpace " +
"or FRD object, or a scalar.")
if not isinstance(sys2, (int, float, complex, tf.TransferFunction,
ss.StateSpace, frd.FRD)):
if not isinstance(sys2, (int, float, complex, np.number,
tf.TransferFunction, ss.StateSpace, frd.FRD)):
raise TypeError("sys2 must be a TransferFunction, StateSpace " +
"or FRD object, or a scalar.")

# If sys1 is a scalar, convert it to the appropriate LTI type so that we can
# its feedback member function.
if isinstance(sys1, (int, float, complex)):
if isinstance(sys1, (int, float, complex, np.number)):
if isinstance(sys2, tf.TransferFunction):
sys1 = tf._convertToTransferFunction(sys1)
elif isinstance(sys2, ss.StateSpace):
Expand Down
11 changes: 6 additions & 5 deletions control/frdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"""

# External function declarations
import numpy as np
from numpy import angle, array, empty, ones, \
real, imag, matrix, absolute, eye, linalg, where, dot
from scipy.interpolate import splprep, splev
Expand Down Expand Up @@ -219,7 +220,7 @@ def __mul__(self, other):
"""Multiply two LTI objects (serial connection)."""

# Convert the second argument to a transfer function.
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
return FRD(self.fresp * other, self.omega,
smooth=(self.ifunc is not None))
else:
Expand All @@ -245,7 +246,7 @@ def __rmul__(self, other):
"""Right Multiply two LTI objects (serial connection)."""

# Convert the second argument to an frd function.
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
return FRD(self.fresp * other, self.omega,
smooth=(self.ifunc is not None))
else:
Expand All @@ -272,7 +273,7 @@ def __rmul__(self, other):
def __truediv__(self, other):
"""Divide two LTI objects."""

if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
return FRD(self.fresp * (1/other), self.omega,
smooth=(self.ifunc is not None))
else:
Expand All @@ -295,7 +296,7 @@ def __div__(self, other):
# TODO: Division of MIMO transfer function objects is not written yet.
def __rtruediv__(self, other):
"""Right divide two LTI objects."""
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
return FRD(other / self.fresp, self.omega,
smooth=(self.ifunc is not None))
else:
Expand Down Expand Up @@ -449,7 +450,7 @@ def _convertToFRD(sys, omega, inputs=1, outputs=1):

return FRD(fresp, omega, smooth=True)

elif isinstance(sys, (int, float, complex)):
elif isinstance(sys, (int, float, complex, np.number)):
fresp = ones((outputs, inputs, len(omega)), dtype=float)*sys
return FRD(fresp, omega, smooth=True)

Expand Down
9 changes: 5 additions & 4 deletions control/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
timebaseEqual()
"""

import numpy as np
from numpy import absolute, real

__all__ = ['issiso', 'timebase', 'timebaseEqual', 'isdtime', 'isctime',
Expand Down Expand Up @@ -96,7 +97,7 @@ def dcgain(self):

# Test to see if a system is SISO
def issiso(sys, strict=False):
if isinstance(sys, (int, float, complex)) and not strict:
if isinstance(sys, (int, float, complex, np.number)) and not strict:
return True
elif not isinstance(sys, LTI):
raise ValueError("Object is not an LTI system")
Expand All @@ -114,7 +115,7 @@ def timebase(sys, strict=True):
set to False, dt = True will be returned as 1.
"""
# System needs to be either a constant or an LTI system
if isinstance(sys, (int, float, complex)):
if isinstance(sys, (int, float, complex, np.number)):
return None
elif not isinstance(sys, LTI):
raise ValueError("Timebase not defined")
Expand Down Expand Up @@ -162,7 +163,7 @@ def isdtime(sys, strict=False):
"""

# Check to see if this is a constant
if isinstance(sys, (int, float, complex)):
if isinstance(sys, (int, float, complex, np.number)):
# OK as long as strict checking is off
return True if not strict else False

Expand All @@ -187,7 +188,7 @@ def isctime(sys, strict=False):
"""

# Check to see if this is a constant
if isinstance(sys, (int, float, complex)):
if isinstance(sys, (int, float, complex, np.number)):
# OK as long as strict checking is off
return True if not strict else False

Expand Down
14 changes: 7 additions & 7 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from numpy.random import rand, randn
from numpy.linalg import solve, eigvals, matrix_rank
from numpy.linalg.linalg import LinAlgError
import scipy as sp
from scipy.signal import lti, cont2discrete
# from exceptions import Exception
import warnings
Expand Down Expand Up @@ -218,7 +219,7 @@ def __add__(self, other):
"""Add two LTI systems (parallel connection)."""

# Check for a couple of special cases
if (isinstance(other, (int, float, complex))):
if (isinstance(other, (int, float, complex, np.number))):
# Just adding a scalar; put it in the D matrix
A, B, C = self.A, self.B, self.C;
D = self.D + other;
Expand Down Expand Up @@ -275,7 +276,7 @@ def __mul__(self, other):
"""Multiply two LTI objects (serial connection)."""

# Check for a couple of special cases
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
# Just multiplying by a scalar; change the output
A, B = self.A, self.B
C = self.C * other
Expand Down Expand Up @@ -316,7 +317,7 @@ def __rmul__(self, other):
"""Right multiply two LTI objects (serial connection)."""

# Check for a couple of special cases
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
# Just multiplying by a scalar; change the input
A, C = self.A, self.C;
B = self.B * other;
Expand Down Expand Up @@ -699,11 +700,10 @@ def _convertToStateSpace(sys, **kw):
# TODO: do we want to squeeze first and check dimenations?
# I think this will fail if num and den aren't 1-D after
# the squeeze
lti_sys = lti(squeeze(sys.num), squeeze(sys.den))
return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D,
sys.dt)
A, B, C, D = sp.signal.tf2ss(squeeze(sys.num), squeeze(sys.den))
return StateSpace(A, B, C, D, sys.dt)

elif isinstance(sys, (int, float, complex)):
elif isinstance(sys, (int, float, complex, np.number)):
if "inputs" in kw:
inputs = kw["inputs"]
else:
Expand Down
33 changes: 17 additions & 16 deletions control/xferfcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
"""

# External function declarations
import numpy as np
from numpy import angle, any, array, empty, finfo, insert, ndarray, ones, \
polyadd, polymul, polyval, roots, sort, sqrt, zeros, squeeze, exp, pi, \
where, delete, real, poly, poly1d
import numpy as np
import scipy as sp
from scipy.signal import lti, tf2zpk, zpk2tf, cont2discrete
from copy import deepcopy
from warnings import warn
Expand Down Expand Up @@ -126,7 +127,7 @@ def __init__(self, *args):
data = [num, den]
for i in range(len(data)):
# Check for a scalar (including 0d ndarray)
if (isinstance(data[i], (int, float, complex)) or
if (isinstance(data[i], (int, float, complex, np.number)) or
(isinstance(data[i], ndarray) and data[i].ndim == 0)):
# Convert scalar to list of list of array.
if (isinstance(data[i], int)):
Expand All @@ -135,7 +136,7 @@ def __init__(self, *args):
else:
data[i] = [[array([data[i]])]]
elif (isinstance(data[i], (list, tuple, ndarray)) and
isinstance(data[i][0], (int, float, complex))):
isinstance(data[i][0], (int, float, complex, np.number))):
# Convert array to list of list of array.
if (isinstance(data[i][0], int)):
# Convert integers to floats at this point
Expand All @@ -146,7 +147,8 @@ def __init__(self, *args):
elif (isinstance(data[i], list) and
isinstance(data[i][0], list) and
isinstance(data[i][0][0], (list, tuple, ndarray)) and
isinstance(data[i][0][0][0], (int, float, complex))):
isinstance(data[i][0][0][0], (int, float, complex,
np.number))):
# We might already have the right format. Convert the
# coefficient vectors to arrays, if necessary.
for j in range(len(data[i])):
Expand Down Expand Up @@ -363,7 +365,7 @@ def __rsub__(self, other):
def __mul__(self, other):
"""Multiply two LTI objects (serial connection)."""
# Convert the second argument to a transfer function.
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
other = _convertToTransferFunction(other, inputs=self.inputs,
outputs=self.inputs)
else:
Expand Down Expand Up @@ -410,7 +412,7 @@ def __rmul__(self, other):
"""Right multiply two LTI objects (serial connection)."""

# Convert the second argument to a transfer function.
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
other = _convertToTransferFunction(other, inputs=self.inputs,
outputs=self.inputs)
else:
Expand Down Expand Up @@ -458,7 +460,7 @@ def __rmul__(self, other):
def __truediv__(self, other):
"""Divide two LTI objects."""

if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
other = _convertToTransferFunction(
other, inputs=self.inputs,
outputs=self.inputs)
Expand Down Expand Up @@ -492,7 +494,7 @@ def __div__(self, other):
# TODO: Division of MIMO transfer function objects is not written yet.
def __rtruediv__(self, other):
"""Right divide two LTI objects."""
if isinstance(other, (int, float, complex)):
if isinstance(other, (int, float, complex, np.number)):
other = _convertToTransferFunction(
other, inputs=self.inputs,
outputs=self.inputs)
Expand Down Expand Up @@ -1128,22 +1130,21 @@ def _convertToTransferFunction(sys, **kw):
# Each transfer function matrix row
# has a common denominator.
den[i][j] = list(tfout[5][i, :])
# print(num)
# print(den)

except ImportError:
# If slycot is not available, use signal.lti (SISO only)
if (sys.inputs != 1 or sys.outputs != 1):
raise TypeError("No support for MIMO without slycot")

lti_sys = lti(sys.A, sys.B, sys.C, sys.D)
num = squeeze(lti_sys.num)
den = squeeze(lti_sys.den)
# print(num)
# print(den)
# Do the conversion using sp.signal.ss2tf
# Note that this returns a 2D array for the numerator
num, den = sp.signal.ss2tf(sys.A, sys.B, sys.C, sys.D)
num = squeeze(num) # Convert to 1D array
den = squeeze(den) # Probably not needed

return TransferFunction(num, den, sys.dt)

elif isinstance(sys, (int, float, complex)):
elif isinstance(sys, (int, float, complex, np.number)):
if "inputs" in kw:
inputs = kw["inputs"]
else:
Expand Down