Skip to content

Use slycot's tb05ad for faster and more accurate frequency response e… #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __conda_*.txt
record.txt
build.log
*.egg-info/
.eggs/
.coverage
doc/_build
doc/generated
Expand All @@ -18,3 +19,7 @@ examples/.ipynb_checkpoints/
.project
Untitled*.ipynb
*.idea/

# Files created by or for emacs (RMM, 29 Dec 2017)
*~
TAGS
47 changes: 34 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ cache:
- $HOME/.local

python:
- "2.7"
- "3.3"
- "3.4"
- "3.6"
- "3.5"
- "2.7"

# Test against multiple version of SciPy, with and without slycot
#
# Because there were significant changes in SciPy between v0 and v1, we
# test against both of these using the Travis CI environment capability
#
# We also want to test with and without slycot
env:
- SCIPY=scipy SLYCOT=slycot # default, with slycot
- SCIPY=scipy SLYCOT= # default, w/out slycot
- SCIPY="scipy==0.19.1" SLYCOT= # legacy support, w/out slycot

# install required system libraries
before_install:
# Install gfortran for testing slycot; use apt-get instead of conda in
# order to include the proper CXXABI dependency (updated in GCC 4.9)
# Also need to include liblapack here, to make sure paths are right
- if [[ "$SLYCOT" != "" ]]; then
sudo apt-get update -qq;
sudo apt-get install gfortran liblapack-dev;
fi
# Install display manager to allow testing of plotting functions
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
# use miniconda to install numpy/scipy, to avoid lengthy build from source
Expand All @@ -29,27 +47,30 @@ before_install:
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# conda-build must be installed in the conda root environment
- conda install conda-build
- conda config --add channels python-control
- conda info -a
- conda create -q -n test-environment python="$TRAVIS_PYTHON_VERSION" pip coverage
- source activate test-environment
# coveralls not in conda repos
# Make sure to look in the right place for python libraries (for slycot)
- export LIBRARY_PATH="$HOME/miniconda/envs/test-environment/lib"
# coveralls not in conda repos => install via pip instead
- pip install coveralls

# Install packages
install:
- conda build --python "$TRAVIS_PYTHON_VERSION" conda-recipe
- conda install control --use-local
# Install packages needed by python-control
- conda install $SCIPY matplotlib
# Build slycot from source
# For python 3, need to provide pointer to python library
#! git clone https://github.com/repagh/Slycot.git slycot;
- if [[ "$SLYCOT" != "" ]]; then
git clone https://github.com/python-control/Slycot.git slycot;
cd slycot; python setup.py install; cd ..;
fi

# command to run tests
script:
# Before installing Slycot
- python setup.py test

# Now, get and use Slycot
- conda install slycot
- 'if [ $SLYCOT != "" ]; then python -c "import slycot"; fi'
- coverage run setup.py test

after_success:
Expand Down
5 changes: 5 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package:
name: control
version: {{ GIT_DESCRIBE_TAG }}

source:
git_url: ../

build:
number: {{ GIT_DESCRIBE_NUMBER }}
script:
- cd $RECIPE_DIR/..
- $PYTHON make_version.py
Expand Down
14 changes: 8 additions & 6 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 All @@ -246,7 +247,8 @@ def feedback(sys1, sys2=1, sign=-1):
return sys1.feedback(sys2, sign)

def append(*sys):
'''
'''append(sys1, sys2, ... sysn)

Group models by appending their inputs and outputs

Forms an augmented system model, and appends the inputs and
Expand Down
4 changes: 2 additions & 2 deletions control/ctrlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
# Packages that we need access to
from . import lti
import numpy as np
from numpy import pi
import math

__all__ = ['unwrap', 'issys', 'db2mag', 'mag2db']

# Utility function to unwrap an angle measurement
def unwrap(angle, period=2*pi):
def unwrap(angle, period=2*math.pi):
"""Unwrap a phase angle to give a continuous curve

Parameters
Expand Down
26 changes: 16 additions & 10 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 All @@ -57,7 +58,9 @@
__all__ = ['FRD', 'frd']

class FRD(LTI):
"""A class for models defined by Frequency Response Data (FRD)
"""FRD(d, w)

A class for models defined by frequency response data (FRD)

The FRD class is used to represent systems in frequency response data form.

Expand All @@ -80,7 +83,9 @@ class FRD(LTI):
epsw = 1e-8

def __init__(self, *args, **kwargs):
"""Construct an FRD object
"""FRD(d, w)

Construct an FRD object

The default constructor is FRD(d, w), where w is an iterable of
frequency points, and d is the matching frequency data.
Expand Down Expand Up @@ -219,7 +224,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 +250,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 +277,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 +300,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 +454,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 All @@ -469,8 +474,9 @@ def _convertToFRD(sys, omega, inputs=1, outputs=1):
sys.__class__)

def frd(*args):
"""
Construct a Frequency Response Data model, or convert a system
"""frd(d, w)

Construct a frequency response data model

frd models store the (measured) frequency response of a system.

Expand Down Expand Up @@ -500,6 +506,6 @@ def frd(*args):

See Also
--------
ss, tf
FRD, ss, tf
"""
return FRD(*args)
23 changes: 12 additions & 11 deletions control/freqplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import matplotlib.pyplot as plt
import scipy as sp
import numpy as np
import math
from .ctrlutil import unwrap
from .bdalg import feedback

Expand Down Expand Up @@ -128,7 +129,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
else:
omega_limits = np.array(omega_limits)
if Hz:
omega_limits *= 2.*np.pi
omega_limits *= 2.*math.pi
if omega_num:
omega = sp.logspace(np.log10(omega_limits[0]), np.log10(omega_limits[1]), num=omega_num, endpoint=True)
else:
Expand All @@ -142,7 +143,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
else:
omega_sys = np.array(omega)
if sys.isdtime(True):
nyquistfrq = 2. * np.pi * 1. / sys.dt / 2.
nyquistfrq = 2. * math.pi * 1. / sys.dt / 2.
omega_sys = omega_sys[omega_sys < nyquistfrq]
# TODO: What distance to the Nyquist frequency is appropriate?
else:
Expand All @@ -154,9 +155,9 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
phase = unwrap(phase)
nyquistfrq_plot = None
if Hz:
omega_plot = omega_sys / (2. * np.pi)
omega_plot = omega_sys / (2. * math.pi)
if nyquistfrq:
nyquistfrq_plot = nyquistfrq / (2. * np.pi)
nyquistfrq_plot = nyquistfrq / (2. * math.pi)
else:
omega_plot = omega_sys
if nyquistfrq:
Expand Down Expand Up @@ -187,7 +188,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
# Phase plot
ax_phase = plt.subplot(212, sharex=ax_mag);
if deg:
phase_plot = phase * 180. / np.pi
phase_plot = phase * 180. / math.pi
else:
phase_plot = phase
ax_phase.semilogx(omega_plot, phase_plot, *args, **kwargs)
Expand All @@ -208,8 +209,8 @@ def genZeroCenteredSeries(val_min, val_max, period):
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], 15.), minor=True)
else:
ylim = ax_phase.get_ylim()
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], np.pi / 4.))
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], np.pi / 12.), minor=True)
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], math.pi / 4.))
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], math.pi / 12.), minor=True)
ax_phase.grid(True, which='both')
# ax_mag.grid(which='minor', alpha=0.3)
# ax_mag.grid(which='major', alpha=0.9)
Expand Down Expand Up @@ -449,7 +450,7 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
features_ = features_[features_ != 0.0];
features = np.concatenate((features, features_))
elif sys.isdtime(strict=True):
fn = np.pi * 1. / sys.dt
fn = math.pi * 1. / sys.dt
# TODO: What distance to the Nyquist frequency is appropriate?
freq_interesting.append(fn * 0.9)

Expand All @@ -475,12 +476,12 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
features = np.array([1.]);

if Hz:
features /= 2.*np.pi
features /= 2.*math.pi
features = np.log10(features)
lsp_min = np.floor(np.min(features) - feature_periphery_decade)
lsp_max = np.ceil(np.max(features) + feature_periphery_decade)
lsp_min += np.log10(2.*np.pi)
lsp_max += np.log10(2.*np.pi)
lsp_min += np.log10(2.*math.pi)
lsp_max += np.log10(2.*math.pi)
else:
features = np.log10(features)
lsp_min = np.floor(np.min(features) - feature_periphery_decade)
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
Loading