Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
43e3779
DEV:
forgi86 Mar 27, 2021
ae7d546
Update control/freqplot.py
forgi86 Mar 28, 2021
36e8b77
Update control/freqplot.py
forgi86 Mar 28, 2021
4e055bb
FIX:
forgi86 Mar 28, 2021
14ef194
Merge remote-tracking branch 'origin/singular-values-plot' into singu…
forgi86 Mar 28, 2021
681edb7
FIX:
forgi86 Mar 28, 2021
8d02fae
FIX:
forgi86 Mar 28, 2021
fe97069
FIX:
forgi86 Mar 28, 2021
762fbd6
FIX: development of parametrized tests for the singular_values_plot f…
forgi86 Mar 31, 2021
3b09ae7
FIX: using option squeeze=False to keep all dimensions from the frequ…
forgi86 Mar 31, 2021
9c68700
FIX:
forgi86 Mar 31, 2021
a392c97
DOC:
forgi86 Mar 31, 2021
caa3e2c
FIX:
forgi86 Mar 31, 2021
0607314
FIX:
forgi86 Mar 31, 2021
65b4e49
TST:
forgi86 Mar 31, 2021
87d48ab
TST:
forgi86 Apr 1, 2021
a289f8c
MAINT: refactoring of the frequency selection logic as a private func…
forgi86 Apr 1, 2021
fbafc6c
FIX: added missing omega vector in test system ss_siso_ct
forgi86 Apr 2, 2021
7f5d66c
TST:
forgi86 Apr 2, 2021
81f9ee7
TST: added a test condition that expects the warning to be issued whe…
forgi86 Apr 2, 2021
7d19b30
MAINT:
forgi86 Apr 3, 2021
34c3826
DOC: updated example for singular_values_plot
forgi86 Apr 7, 2021
48015d5
MAINT: _bode_defaults removed, fields moved in _freqplot_default
forgi86 Apr 7, 2021
38dfeda
MAINT: no warning issued for evaluation above the Nyquist frequency
forgi86 Apr 7, 2021
555902b
MAINT: removing references to singular_values_plot configurations
forgi86 Apr 7, 2021
ec69337
MAINT: removing references to singular_values_plot configurations
forgi86 Apr 7, 2021
288a7ee
MAINT: removing references to bode configurations (use freqplot instead)
forgi86 Apr 7, 2021
8f3f76d
Update control/freqplot.py
forgi86 Apr 7, 2021
fb3d9a0
MAINT: the Hz parameter of bode_plot and singular_values_plot now onl…
forgi86 Apr 18, 2021
37c0962
DOC: bode changed to freqplot in conventions.rst
forgi86 Apr 18, 2021
a486c18
Merge remote-tracking branch 'origin/singular-values-plot' into singu…
forgi86 Apr 18, 2021
9143d75
Merge branch 'master' into singular-values-plot
forgi86 Apr 18, 2021
f5de343
DOC: modified docstring (Examples section) in singular_values_plot to…
forgi86 Apr 23, 2021
9638e92
DOC: modified docstring (Examples section) in singular_values_plot to…
forgi86 Apr 23, 2021
10cde40
DOC: modified docstring (Examples section) in singular_values_plot to…
forgi86 Apr 23, 2021
0ada3f6
DOC: modified imports in docstring (Examples section) in singular_val…
forgi86 Apr 24, 2021
649c394
Merge branch 'master' into pr-593
bnavigator Apr 29, 2021
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
Prev Previous commit
Next Next commit
MAINT: _bode_defaults removed, fields moved in _freqplot_default
TST: tests in config_test modified to interpret omega in Hz if the option Hz is set to True
  • Loading branch information
forgi86 committed Apr 7, 2021
commit 48015d55f6361b3faf0d21e6976d6c2ff227b4a2
8 changes: 4 additions & 4 deletions control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def reset_defaults():
# System level defaults
defaults.update(_control_defaults)

from .freqplot import _bode_defaults, _freqplot_defaults, _nyquist_defaults
defaults.update(_bode_defaults)
from .freqplot import _freqplot_defaults, _nyquist_defaults
defaults.update(_freqplot_defaults)
defaults.update(_nyquist_defaults)

Expand Down Expand Up @@ -133,7 +132,7 @@ def use_matlab_defaults():
* State space class and functions use Numpy matrix objects

"""
set_defaults('bode', dB=True, deg=True, Hz=False, grid=True)
set_defaults('freqplot', dB=True, deg=True, Hz=False, grid=True)
set_defaults('statesp', use_numpy_matrix=True)


Expand All @@ -147,7 +146,7 @@ def use_fbs_defaults():
* Nyquist plots use dashed lines for mirror image of Nyquist curve

"""
set_defaults('bode', dB=False, deg=True, Hz=False, grid=False)
set_defaults('freqplot', dB=False, deg=True, Hz=False, grid=False)
set_defaults('nyquist', mirror_style='--')


Expand Down Expand Up @@ -179,6 +178,7 @@ class and functions. If flat is `False`, then matrices are
stacklevel=2, category=DeprecationWarning)
set_defaults('statesp', use_numpy_matrix=flag)


def use_legacy_defaults(version):
""" Sets the defaults to whatever they were in a given release.

Expand Down
56 changes: 30 additions & 26 deletions control/freqplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
_freqplot_defaults = {
'freqplot.feature_periphery_decades': 1,
'freqplot.number_of_samples': 1000,
'freqplot.dB': False, # Plot gain in dB
'freqplot.deg': True, # Plot phase in degrees
'freqplot.Hz': False, # Plot frequency in Hertz
'freqplot.grid': True, # Turn on grid for gain and phase
'freqplot.wrap_phase': False, # Wrap the phase plot at a given value
}

#
Expand All @@ -76,15 +81,6 @@
# Bode plot
#

# Default values for Bode plot configuration variables
_bode_defaults = {
'bode.dB': False, # Plot gain in dB
'bode.deg': True, # Plot phase in degrees
'bode.Hz': False, # Plot frequency in Hertz
'bode.grid': True, # Turn on grid for gain and phase
'bode.wrap_phase': False, # Wrap the phase plot at a given value
}


def bode_plot(syslist, omega=None,
plot=True, omega_limits=None, omega_num=None,
Expand All @@ -103,10 +99,10 @@ def bode_plot(syslist, omega=None,
If True, plot result in dB. Default is false.
Hz : bool
If True, plot frequency in Hz (omega must be provided in rad/sec).
Default value (False) set by config.defaults['bode.Hz']
Default value (False) set by config.defaults['freqplot.Hz']
deg : bool
If True, plot phase in degrees (else radians). Default value (True)
config.defaults['bode.deg']
config.defaults['freqplot.deg']
plot : bool
If True (default), plot magnitude and phase
omega_limits : array_like of two values
Expand Down Expand Up @@ -184,16 +180,21 @@ def bode_plot(syslist, omega=None,
plot = kwargs.pop('Plot')

# Get values for params (and pop from list to allow keyword use in plot)
dB = config._get_param('bode', 'dB', kwargs, _bode_defaults, pop=True)
deg = config._get_param('bode', 'deg', kwargs, _bode_defaults, pop=True)
Hz = config._get_param('bode', 'Hz', kwargs, _bode_defaults, pop=True)
grid = config._get_param('bode', 'grid', kwargs, _bode_defaults, pop=True)
plot = config._get_param('bode', 'plot', plot, True)
margins = config._get_param('bode', 'margins', margins, False)
dB = config._get_param(
'freqplot', 'dB', kwargs, _freqplot_defaults, pop=True)
deg = config._get_param(
'freqplot', 'deg', kwargs, _freqplot_defaults, pop=True)
Hz = config._get_param(
'freqplot', 'Hz', kwargs, _freqplot_defaults, pop=True)
grid = config._get_param(
'freqplot', 'grid', kwargs, _freqplot_defaults, pop=True)
plot = config._get_param('freqplot', 'plot', plot, True)
margins = config._get_param(
'freqplot', 'margins', margins, False)
wrap_phase = config._get_param(
'bode', 'wrap_phase', kwargs, _bode_defaults, pop=True)
'freqplot', 'wrap_phase', kwargs, _freqplot_defaults, pop=True)
initial_phase = config._get_param(
'bode', 'initial_phase', kwargs, None, pop=True)
'freqplot', 'initial_phase', kwargs, None, pop=True)
omega_num = config._get_param('freqplot', 'number_of_samples', omega_num)
# If argument was a singleton, turn it into a tuple
if not hasattr(syslist, '__iter__'):
Expand Down Expand Up @@ -937,9 +938,12 @@ def gangof4_plot(P, C, omega=None, **kwargs):
"Gang of four is currently only implemented for SISO systems.")

# Get the default parameter values
dB = config._get_param('bode', 'dB', kwargs, _bode_defaults, pop=True)
Hz = config._get_param('bode', 'Hz', kwargs, _bode_defaults, pop=True)
grid = config._get_param('bode', 'grid', kwargs, _bode_defaults, pop=True)
dB = config._get_param(
'freqplot', 'dB', kwargs, _freqplot_defaults, pop=True)
Hz = config._get_param(
'freqplot', 'Hz', kwargs, _freqplot_defaults, pop=True)
grid = config._get_param(
'freqplot', 'grid', kwargs, _freqplot_defaults, pop=True)

# Compute the senstivity functions
L = P * C
Expand Down Expand Up @@ -1094,11 +1098,11 @@ def singular_values_plot(syslist, omega=None,

# Get values for params (and pop from list to allow keyword use in plot)
dB = config._get_param(
'singular_values_plot', 'dB', kwargs, _singular_values_plot_default, pop=True)
'freqplot', 'dB', kwargs, _singular_values_plot_default, pop=True)
Hz = config._get_param(
'singular_values_plot', 'Hz', kwargs, _singular_values_plot_default, pop=True)
'freqplot', 'Hz', kwargs, _singular_values_plot_default, pop=True)
grid = config._get_param(
'singular_values_plot', 'grid', kwargs, _singular_values_plot_default, pop=True)
'freqplot', 'grid', kwargs, _singular_values_plot_default, pop=True)
plot = config._get_param(
'singular_values_plot', 'plot', plot, True)
omega_num = config._get_param('freqplot', 'number_of_samples', omega_num)
Expand Down Expand Up @@ -1262,7 +1266,7 @@ def _determine_omega_vector(syslist, omega_in, omega_limits, omega_num, Hz):
np.log10(omega_limits[1]),
num=omega_num, endpoint=True)
else:
omega_out = np.asarray(omega_in)
omega_out = np.copy(omega_in)
if Hz:
omega_out *= 2. * math.pi
return omega_out, omega_range_given
Expand Down
24 changes: 12 additions & 12 deletions control/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_set_defaults(self):

@mplcleanup
def test_get_param(self):
assert ct.config._get_param('bode', 'dB')\
== ct.config.defaults['bode.dB']
assert ct.config._get_param('bode', 'dB', 1) == 1
assert ct.config._get_param('freqplot', 'dB')\
== ct.config.defaults['freqplot.dB']
assert ct.config._get_param('freqplot', 'dB', 1) == 1
ct.config.defaults['config.test1'] = 1
assert ct.config._get_param('config', 'test1', None) == 1
assert ct.config._get_param('config', 'test1', None, 1) == 1
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_fbs_bode(self):
np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3)

plt.figure()
ct.bode_plot(self.sys, omega, Hz=True)
ct.bode_plot(self.sys, omega/2./pi, Hz=True)
mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
np.testing.assert_almost_equal(mag_x[0], 0.001 / (2*pi), decimal=6)

Expand Down Expand Up @@ -130,7 +130,7 @@ def test_matlab_bode(self):
np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3)

plt.figure()
ct.bode_plot(self.sys, omega, Hz=True)
ct.bode_plot(self.sys, omega/2./pi, Hz=True)
mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
np.testing.assert_almost_equal(mag_x[0], 0.001 / (2*pi), decimal=6)

Expand All @@ -141,9 +141,9 @@ def test_matlab_bode(self):

@mplcleanup
def test_custom_bode_default(self):
ct.config.defaults['bode.dB'] = True
ct.config.defaults['bode.deg'] = True
ct.config.defaults['bode.Hz'] = True
ct.config.defaults['freqplot.dB'] = True
ct.config.defaults['freqplot.deg'] = True
ct.config.defaults['freqplot.Hz'] = True

# Generate a Bode plot
plt.figure()
Expand All @@ -154,7 +154,7 @@ def test_custom_bode_default(self):

# Override defaults
plt.figure()
ct.bode_plot(self.sys, omega, Hz=True, deg=False, dB=True)
ct.bode_plot(self.sys, omega/2./pi, Hz=True, deg=False, dB=True)
mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
phase_x, phase_y = (((plt.gcf().axes[1]).get_lines())[0]).get_data()
np.testing.assert_almost_equal(mag_x[0], 0.001 / (2*pi), decimal=6)
Expand Down Expand Up @@ -200,9 +200,9 @@ def test_bode_feature_periphery_decade(self):
def test_reset_defaults(self):
ct.use_matlab_defaults()
ct.reset_defaults()
assert not ct.config.defaults['bode.dB']
assert ct.config.defaults['bode.deg']
assert not ct.config.defaults['bode.Hz']
assert not ct.config.defaults['freqplot.dB']
assert ct.config.defaults['freqplot.deg']
assert not ct.config.defaults['freqplot.Hz']
assert ct.config.defaults['freqplot.number_of_samples'] == 1000
assert ct.config.defaults['freqplot.feature_periphery_decades'] == 1.0

Expand Down