- Notifications
You must be signed in to change notification settings - Fork441
Fix pzmap grid (matplotlib angle_helper)#456
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
df0051c
update mpl_toolkit function
bnavigatorabc0c3c
fix grid formatter
bnavigatorbdbd198
fix wrong config read on pzmap
bnavigator2ca5220
add pzmap_test
bnavigator5632796
test for correct grid and no plot. fix pzmap config handling
bnavigatorFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
37 changes: 28 additions & 9 deletionscontrol/grid.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletionscontrol/pzmap.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
28 changes: 27 additions & 1 deletioncontrol/tests/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
# contest.py - pytest local plugins and fixtures | ||
import os | ||
import matplotlib as mpl | ||
import pytest | ||
import control | ||
@pytest.fixture(scope="session", autouse=True) | ||
def use_numpy_ndarray(): | ||
"""Switch the config to use ndarray instead of matrix""" | ||
if os.getenv("PYTHON_CONTROL_STATESPACE_ARRAY") == "1": | ||
control.config.defaults['statesp.use_numpy_matrix'] = False | ||
@pytest.fixture(scope="function") | ||
def editsdefaults(): | ||
"""Make sure any changes to the defaults only last during a test""" | ||
restore = control.config.defaults.copy() | ||
yield | ||
control.config.defaults.update(restore) | ||
@pytest.fixture(scope="function") | ||
def mplcleanup(): | ||
"""Workaround for python2 | ||
python 2 does not like to mix the original mpl decorator with pytest | ||
fixtures. So we roll our own. | ||
""" | ||
save = mpl.units.registry.copy() | ||
try: | ||
yield | ||
finally: | ||
mpl.units.registry.clear() | ||
mpl.units.registry.update(save) | ||
mpl.pyplot.close("all") |
89 changes: 89 additions & 0 deletionscontrol/tests/pzmap_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# -*- coding: utf-8 -*- | ||
""" pzmap_test.py - test pzmap() | ||
Created on Thu Aug 20 20:06:21 2020 | ||
@author: bnavigator | ||
""" | ||
import matplotlib | ||
import numpy as np | ||
import pytest | ||
from matplotlib import pyplot as plt | ||
from mpl_toolkits.axisartist import Axes as mpltAxes | ||
from control import TransferFunction, config, pzmap | ||
@pytest.mark.parametrize("kwargs", | ||
[pytest.param(dict(), id="default"), | ||
pytest.param(dict(plot=False), id="plot=False"), | ||
pytest.param(dict(plot=True), id="plot=True"), | ||
pytest.param(dict(grid=True), id="grid=True"), | ||
pytest.param(dict(title="My Title"), id="title")]) | ||
@pytest.mark.parametrize("setdefaults", [False, True], ids=["kw", "config"]) | ||
@pytest.mark.parametrize("dt", [0, 1], ids=["s", "z"]) | ||
def test_pzmap(kwargs, setdefaults, dt, editsdefaults, mplcleanup): | ||
"""Test pzmap""" | ||
# T from from pvtol-nested example | ||
T = TransferFunction([-9.0250000e-01, -4.7200750e+01, -8.6812900e+02, | ||
+5.6261850e+03, +2.1258472e+05, +8.4724600e+05, | ||
+1.0192000e+06, +2.3520000e+05], | ||
[9.02500000e-03, 9.92862812e-01, 4.96974094e+01, | ||
1.35705659e+03, 2.09294163e+04, 1.64898435e+05, | ||
6.54572220e+05, 1.25274600e+06, 1.02420000e+06, | ||
2.35200000e+05], | ||
dt) | ||
Pref = [-23.8877+19.3837j, -23.8877-19.3837j, -23.8349+15.7846j, | ||
-23.8349-15.7846j, -5.2320 +0.4117j, -5.2320 -0.4117j, | ||
-2.2246 +0.0000j, -1.5160 +0.0000j, -0.3627 +0.0000j] | ||
Zref = [-23.8877+19.3837j, -23.8877-19.3837j, +14.3637 +0.0000j, | ||
-14.3637 +0.0000j, -2.2246 +0.0000j, -2.0000 +0.0000j, | ||
-0.3000 +0.0000j] | ||
pzkwargs = kwargs.copy() | ||
if setdefaults: | ||
for k in ['plot', 'grid']: | ||
if k in pzkwargs: | ||
v = pzkwargs.pop(k) | ||
config.set_defaults('pzmap', **{k: v}) | ||
P, Z = pzmap(T, **pzkwargs) | ||
np.testing.assert_allclose(P, Pref, rtol=1e-3) | ||
np.testing.assert_allclose(Z, Zref, rtol=1e-3) | ||
if kwargs.get('plot', True): | ||
ax = plt.gca() | ||
assert ax.get_title() == kwargs.get('title', 'Pole Zero Map') | ||
# FIXME: This won't work when zgrid and sgrid are unified | ||
children = ax.get_children() | ||
has_zgrid = False | ||
for c in children: | ||
if isinstance(c, matplotlib.text.Annotation): | ||
if r'\pi' in c.get_text(): | ||
has_zgrid = True | ||
has_sgrid = isinstance(ax, mpltAxes) | ||
if kwargs.get('grid', False): | ||
assert dt == has_zgrid | ||
assert dt != has_sgrid | ||
else: | ||
assert not has_zgrid | ||
assert not has_sgrid | ||
else: | ||
assert not plt.get_fignums() | ||
def test_pzmap_warns(): | ||
with pytest.warns(FutureWarning): | ||
pzmap(TransferFunction([1], [1, 2]), Plot=True) | ||
def test_pzmap_raises(): | ||
with pytest.raises(TypeError): | ||
# not an LTI system | ||
pzmap(([1], [1,2])) |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.