Skip to content

Commit

Permalink
added new settings to about bode plots
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide-sd committed Feb 7, 2024
1 parent 045af5b commit bdd066a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ v3.0.1
* Fixed bug with ``plot_bode_phase`` when ``phase_units="deg"`` and
``unwrap=True``.

* Added settings for bode plot's ``phase_unit`` and ``freq_unit`` to the
``defaults`` submodule.

* Fixed bug with title of Bode plots.

* Fixed title of ``plot_step_response``.
Expand Down
4 changes: 4 additions & 0 deletions spb/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def _hardcoded_defaults():
# Wheter to use a color map on a 3D surface
"use_cm": False
},
bode={
"phase_unit": "rad",
"freq_unit": "rad/sec"
},

# settings that will be passed to the adaptive library:
# https://github.com/python-adaptive/adaptive/
Expand Down
11 changes: 7 additions & 4 deletions spb/plot_functions/control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from spb.defaults import TWO_D_B
from spb.defaults import TWO_D_B, cfg
from spb.graphics.control import (
_preprocess_system, _pole_zero_helper,
_nichols_helper, _nyquist_helper, _step_response_helper,
Expand Down Expand Up @@ -555,14 +555,15 @@ def plot_ramp_response(

def plot_bode_magnitude(
*systems, initial_exp=-5, final_exp=5,
freq_unit='rad/sec', show_axes=False, **kwargs
freq_unit=None, show_axes=False, **kwargs
):
"""
Returns the Bode magnitude plot of a continuous-time system.
See ``plot_bode`` for all the parameters.
"""
freq_units = ('rad/sec', 'Hz')
freq_unit = cfg["bode"]["freq_unit"] if freq_unit is None else freq_unit
if freq_unit not in freq_units:
raise ValueError('Only "rad/sec" and "Hz" are accepted frequency units.')

Expand All @@ -587,7 +588,7 @@ def plot_bode_magnitude(

def plot_bode_phase(
*systems, initial_exp=-5, final_exp=5,
freq_unit='rad/sec', phase_unit='rad', show_axes=False,
freq_unit=None, phase_unit=None, show_axes=False,
unwrap=True, **kwargs
):
"""
Expand All @@ -597,6 +598,8 @@ def plot_bode_phase(
"""
freq_units = ('rad/sec', 'Hz')
phase_units = ('rad', 'deg')
freq_unit = cfg["bode"]["freq_unit"] if freq_unit is None else freq_unit
phase_unit = cfg["bode"]["phase_unit"] if phase_unit is None else phase_unit
if freq_unit not in freq_units:
raise ValueError(
'Only "rad/sec" and "Hz" are accepted frequency units.'
Expand Down Expand Up @@ -625,7 +628,7 @@ def plot_bode_phase(

def plot_bode(
*systems, initial_exp=-5, final_exp=5,
freq_unit='rad/sec', phase_unit='rad', show_axes=False,
freq_unit=None, phase_unit=None, show_axes=False,
unwrap=True, **kwargs
):
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_cfg_keys():
"adaptive",
"plot_range",
"mayavi",
"bode",
]
for k in must_have_keys:
assert k in cfg.keys()
Expand Down Expand Up @@ -113,6 +114,16 @@ def test_cfg_mayavi_keys():


def test_cfg_interactive_keys():
must_have_keys = ["phase_unit", "freq_unit"]
for k in must_have_keys:
assert k in cfg["bode"].keys()
assert isinstance(cfg["bode"]["phase_unit"], str)
assert isinstance(cfg["bode"]["freq_unit"], str)
assert cfg["bode"]["phase_unit"] == "rad"
assert cfg["bode"]["freq_unit"] == "rad/sec"


def test_cfg_bode_keys():
must_have_keys = ["use_latex", "throttled", "servable", "theme", "module"]
for k in must_have_keys:
assert k in cfg["interactive"].keys()
Expand Down

0 comments on commit bdd066a

Please sign in to comment.