Skip to content

Commit dda3149

Browse files
committed
small fixes based on @sawyerbfuller, @bnavigator comments
1 parent 5736a6b commit dda3149

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

control/freqplot.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,7 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
688688
'nyquist', 'indent_direction', kwargs, _nyquist_defaults, pop=True)
689689

690690
# If argument was a singleton, turn it into a list
691-
isscalar = not hasattr(syslist, '__iter__')
692-
if isscalar:
691+
if not hasattr(syslist, '__iter__'):
693692
syslist = (syslist,)
694693

695694
# Decide whether to go above Nyquist frequency
@@ -844,11 +843,12 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
844843
ax.set_ylabel("Imaginary axis")
845844
ax.grid(color="lightgray")
846845

846+
# "Squeeze" the results
847+
if len(syslist) == 1:
848+
counts, contours = counts[0], contours[0]
849+
847850
# Return counts and (optionally) the contour we used
848-
if return_contour:
849-
return (counts[0], contours[0]) if isscalar else (counts, contours)
850-
else:
851-
return counts[0] if isscalar else counts
851+
return (counts, contours) if return_contour else counts
852852

853853

854854
# Internal function to add arrows to a curve
@@ -1101,7 +1101,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
11011101
freq_interesting = []
11021102

11031103
# detect if single sys passed by checking if it is sequence-like
1104-
if not getattr(syslist, '__iter__', False):
1104+
if not hasattr(syslist, '__iter__'):
11051105
syslist = (syslist,)
11061106

11071107
for sys in syslist:

control/matlab/wrappers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def bode(*args, **kwargs):
5959
from ..freqplot import bode_plot
6060

6161
# If first argument is a list, assume python-control calling format
62-
if (getattr(args[0], '__iter__', False)):
62+
if hasattr(args[0], '__iter__'):
6363
return bode_plot(*args, **kwargs)
6464

6565
# Parse input arguments
@@ -97,7 +97,7 @@ def nyquist(*args, **kwargs):
9797
from ..freqplot import nyquist_plot
9898

9999
# If first argument is a list, assume python-control calling format
100-
if (getattr(args[0], '__iter__', False)):
100+
if hasattr(args[0], '__iter__'):
101101
return nyquist_plot(*args, **kwargs)
102102

103103
# Parse arguments

control/tests/nyquist_test.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# In interactive mode, turn on ipython interactive graphics
1818
plt.ion()
1919

20+
2021
# Utility function for counting unstable poles of open loop (P in FBS)
2122
def _P(sys, indent='right'):
2223
if indent == 'right':
@@ -29,19 +30,14 @@ def _P(sys, indent='right'):
2930
else:
3031
raise TypeError("unknown indent value")
3132

33+
3234
# Utility function for counting unstable poles of closed loop (Z in FBS)
3335
def _Z(sys):
3436
return (sys.feedback().pole().real >= 0).sum()
3537

36-
# Decorator to close figures when done with test (to avoid matplotlib warning)
37-
@pytest.fixture(scope="function")
38-
def figure_cleanup():
39-
plt.close('all')
40-
yield
41-
plt.close('all')
4238

4339
# Basic tests
44-
@pytest.mark.usefixtures("figure_cleanup")
40+
@pytest.mark.usefixtures("mplcleanup")
4541
def test_nyquist_basic():
4642
# Simple Nyquist plot
4743
sys = ct.rss(5, 1, 1)
@@ -116,7 +112,7 @@ def test_nyquist_basic():
116112

117113

118114
# Some FBS examples, for comparison
119-
@pytest.mark.usefixtures("figure_cleanup")
115+
@pytest.mark.usefixtures("mplcleanup")
120116
def test_nyquist_fbs_examples():
121117
s = ct.tf('s')
122118

@@ -158,7 +154,7 @@ def test_nyquist_fbs_examples():
158154
1, 2, 3, 4, # specified number of arrows
159155
[0.1, 0.5, 0.9], # specify arc lengths
160156
])
161-
@pytest.mark.usefixtures("figure_cleanup")
157+
@pytest.mark.usefixtures("mplcleanup")
162158
def test_nyquist_arrows(arrows):
163159
sys = ct.tf([1.4], [1, 2, 1]) * ct.tf(*ct.pade(1, 4))
164160
plt.figure();
@@ -167,7 +163,7 @@ def test_nyquist_arrows(arrows):
167163
assert _Z(sys) == count + _P(sys)
168164

169165

170-
@pytest.mark.usefixtures("figure_cleanup")
166+
@pytest.mark.usefixtures("mplcleanup")
171167
def test_nyquist_encirclements():
172168
# Example 14.14: effect of friction in a cart-pendulum system
173169
s = ct.tf('s')
@@ -192,7 +188,7 @@ def test_nyquist_encirclements():
192188
assert _Z(sys) == count + _P(sys)
193189

194190

195-
@pytest.mark.usefixtures("figure_cleanup")
191+
@pytest.mark.usefixtures("mplcleanup")
196192
def test_nyquist_indent():
197193
# FBS Figure 10.10
198194
s = ct.tf('s')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy