Skip to content

Commit c387c69

Browse files
committed
TRV: removed trailing spaces
1 parent 3bfd2be commit c387c69

File tree

11 files changed

+85
-84
lines changed

11 files changed

+85
-84
lines changed

control/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
bode_dB = False # Bode plot magnitude units
1212
bode_deg = True # Bode Plot phase units
1313
bode_Hz = False # Bode plot frequency units
14-
bode_number_of_samples = None # Bode plot number of samples
14+
bode_number_of_samples = None # Bode plot number of samples
1515
bode_feature_periphery_decade = 1.0 # Bode plot feature periphery in decades
1616

1717
# Set defaults to match MATLAB
@@ -29,7 +29,7 @@ def use_matlab_defaults():
2929
def use_fbs_defaults():
3030
"""
3131
Use `Astrom and Murray <http://fbsbook.org>`_ compatible settings
32-
* Bode plots plot gain in powers of ten, phase in degrees,
32+
* Bode plots plot gain in powers of ten, phase in degrees,
3333
frequency in Hertz
3434
"""
3535
# Bode plot defaults

control/exception.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Author: Richard M. Murray
44
# Date: 31 May 2010
5-
#
5+
#
66
# This file contains definitions of standard exceptions for the control package
77
#
88
# Copyright (c) 2010 by California Institute of Technology
@@ -14,16 +14,16 @@
1414
#
1515
# 1. Redistributions of source code must retain the above copyright
1616
# notice, this list of conditions and the following disclaimer.
17-
#
17+
#
1818
# 2. Redistributions in binary form must reproduce the above copyright
1919
# notice, this list of conditions and the following disclaimer in the
2020
# documentation and/or other materials provided with the distribution.
21-
#
21+
#
2222
# 3. Neither the name of the California Institute of Technology nor
2323
# the names of its contributors may be used to endorse or promote
2424
# products derived from this software without specific prior
2525
# written permission.
26-
#
26+
#
2727
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2828
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2929
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -36,19 +36,19 @@
3636
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3737
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3838
# SUCH DAMAGE.
39-
#
39+
#
4040
# $Id$
4141

42-
class ControlSlycot(Exception):
42+
class ControlSlycot(Exception):
4343
"""Exception for Slycot import. Used when we can't import a function
4444
from the slycot package"""
4545
pass
4646

47-
class ControlDimension(Exception):
47+
class ControlDimension(Exception):
4848
"""Raised when dimensions of system objects are not correct"""
4949
pass
5050

51-
class ControlArgument(Exception):
51+
class ControlArgument(Exception):
5252
"""Raised when arguments to a function are not correct"""
5353
pass
5454

control/freqplot.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
7878
If True, plot phase in degrees (else radians)
7979
Plot : boolean
8080
If True, plot magnitude and phase
81-
omega_limits: tuple, list, ... of two values
81+
omega_limits: tuple, list, ... of two values
8282
Limits of the to generate frequency vector.
8383
If Hz=True the limits are in Hz otherwise in rad/s.
8484
omega_num: int
85-
number of samples
85+
number of samples
8686
*args, **kwargs:
8787
Additional options to matplotlib (color, linestyle, etc)
8888
@@ -120,7 +120,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
120120
# If argument was a singleton, turn it into a list
121121
if (not getattr(syslist, '__iter__', False)):
122122
syslist = (syslist,)
123-
123+
124124
if omega is None:
125125
if omega_limits is None:
126126
# Select a default range if none is provided
@@ -133,7 +133,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
133133
omega = sp.logspace(np.log10(omega_limits[0]), np.log10(omega_limits[1]), num=omega_num, endpoint=True)
134134
else:
135135
omega = sp.logspace(np.log10(omega_limits[0]), np.log10(omega_limits[1]), endpoint=True)
136-
136+
137137
mags, phases, omegas, nyquistfrqs = [], [], [], []
138138
for sys in syslist:
139139
if (sys.inputs > 1 or sys.outputs > 1):
@@ -142,8 +142,8 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
142142
else:
143143
omega_sys = np.array(omega)
144144
if sys.isdtime(True):
145-
nyquistfrq = 2. * np.pi * 1. / sys.dt / 2.
146-
omega_sys = omega_sys[omega_sys < nyquistfrq]
145+
nyquistfrq = 2. * np.pi * 1. / sys.dt / 2.
146+
omega_sys = omega_sys[omega_sys < nyquistfrq]
147147
# TODO: What distance to the Nyquist frequency is appropriate?
148148
else:
149149
nyquistfrq = None
@@ -179,7 +179,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
179179
plt.hold(True);
180180
if nyquistfrq_plot:
181181
ax_mag.axvline(nyquistfrq_plot, color=pltline[0].get_color())
182-
182+
183183
# Add a grid to the plot + labeling
184184
ax_mag.grid(True, which='both')
185185
ax_mag.set_ylabel("Magnitude (dB)" if dB else "Magnitude")
@@ -194,30 +194,31 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
194194
ax_phase.hold(True);
195195
if nyquistfrq_plot:
196196
ax_phase.axvline(nyquistfrq_plot, color=pltline[0].get_color())
197-
197+
198198
# Add a grid to the plot + labeling
199-
ax_phase.set_ylabel("Phase (deg)" if deg else "Phase (rad)")
199+
ax_phase.set_ylabel("Phase (deg)" if deg else "Phase (rad)")
200+
200201
def genZeroCenteredSeries(val_min, val_max, period):
201202
v1 = np.ceil(val_min / period - 0.2)
202203
v2 = np.floor(val_max / period + 0.2)
203-
return np.arange(v1, v2 + 1) * period
204+
return np.arange(v1, v2 + 1) * period
204205
if deg:
205206
ylim = ax_phase.get_ylim()
206-
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], 45.))
207-
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], 15.), minor=True)
207+
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], 45.))
208+
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], 15.), minor=True)
208209
else:
209210
ylim = ax_phase.get_ylim()
210-
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], np.pi / 4.))
211+
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], np.pi / 4.))
211212
ax_phase.set_yticks(genZeroCenteredSeries(ylim[0], ylim[1], np.pi / 12.), minor=True)
212213
ax_phase.grid(True, which='both')
213-
# ax_mag.grid(which='minor', alpha=0.3)
214+
# ax_mag.grid(which='minor', alpha=0.3)
214215
# ax_mag.grid(which='major', alpha=0.9)
215-
# ax_phase.grid(which='minor', alpha=0.3)
216-
# ax_phase.grid(which='major', alpha=0.9)
217-
216+
# ax_phase.grid(which='minor', alpha=0.3)
217+
# ax_phase.grid(which='major', alpha=0.9)
218+
218219
# Label the frequency axis
219-
ax_phase.set_xlabel("Frequency (Hz)" if Hz else "Frequency (rad/sec)")
220-
220+
ax_phase.set_xlabel("Frequency (Hz)" if Hz else "Frequency (rad/sec)")
221+
221222
if len(syslist) == 1:
222223
return mags[0], phases[0], omegas[0]
223224
else:
@@ -314,7 +315,7 @@ def nyquist_plot(syslist, omega=None, Plot=True, color='b',
314315
# instead of 1.0, and this would otherwise be
315316
# truncated to 0.
316317
plt.text(xpt, ypt,
317-
' ' + str(int(np.round(f / 1000 ** pow1000, 0))) +
318+
' ' + str(int(np.round(f / 1000 ** pow1000, 0))) +
318319
' ' + prefix + 'Hz')
319320
return x, y, omega
320321

@@ -394,18 +395,18 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
394395
syslist : list of LTI
395396
List of linear input/output systems (single system is OK)
396397
Hz: boolean
397-
If True, the limits (first and last value) of the frequencies
398-
are set to full decades in Hz so it fits plotting with logarithmic
398+
If True, the limits (first and last value) of the frequencies
399+
are set to full decades in Hz so it fits plotting with logarithmic
399400
scale in Hz otherwise in rad/s. Omega is always returned in rad/sec.
400401
number_of_samples: int
401402
Number of samples to generate
402403
feature_periphery_decade: float
403-
Defines how many decades shall be included in the frequency range on
404-
both sides of features (poles, zeros).
404+
Defines how many decades shall be included in the frequency range on
405+
both sides of features (poles, zeros).
405406
Example: If there is a feature, e.g. a pole, at 1Hz and feature_periphery_decade=1.
406-
then the range of frequencies shall span 0.1 .. 10 Hz.
407+
then the range of frequencies shall span 0.1 .. 10 Hz.
407408
The default value is read from config.bode_feature_periphery_decade.
408-
409+
409410
Returns
410411
-------
411412
omega : array
@@ -425,14 +426,14 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
425426

426427
# Set default values for options
427428
from . import config
428-
if (number_of_samples is None):
429+
if (number_of_samples is None):
429430
number_of_samples = config.bode_number_of_samples
430-
if (feature_periphery_decade is None):
431-
feature_periphery_decade = config.bode_feature_periphery_decade
431+
if (feature_periphery_decade is None):
432+
feature_periphery_decade = config.bode_feature_periphery_decade
432433

433434
# Find the list of all poles and zeros in the systems
434435
features = np.array(())
435-
freq_interesting = []
436+
freq_interesting = []
436437

437438
# detect if single sys passed by checking if it is sequence-like
438439
if (not getattr(syslist, '__iter__', False)):
@@ -443,34 +444,34 @@ def default_frequency_range(syslist, Hz=None, number_of_samples=None, feature_pe
443444
# Add new features to the list
444445
if sys.isctime():
445446
features_ = np.concatenate((np.abs(sys.pole()),
446-
np.abs(sys.zero())))
447+
np.abs(sys.zero())))
447448
# Get rid of poles and zeros at the origin
448449
features_ = features_[features_ != 0.0];
449450
features = np.concatenate((features, features_))
450451
elif sys.isdtime(strict=True):
451452
fn = np.pi * 1. / sys.dt
452-
# TODO: What distance to the Nyquist frequency is appropriate?
453+
# TODO: What distance to the Nyquist frequency is appropriate?
453454
freq_interesting.append(fn * 0.9)
454455

455456
features_ = np.concatenate((sys.pole(),
456-
sys.zero()))
457-
# Get rid of poles and zeros
457+
sys.zero()))
458+
# Get rid of poles and zeros
458459
# * at the origin and real <= 0 & imag==0: log!
459460
# * at 1.: would result in omega=0. (logaritmic plot!)
460461
features_ = features_[(features_.imag != 0.0) | (features_.real > 0.)]
461462
features_ = features_[np.bitwise_not((features_.imag == 0.0) & (np.abs(features_.real - 1.0) < 1.e-10))]
462463
# TODO: improve
463464
features__ = np.abs(np.log(features_) / (1.j * sys.dt))
464-
features = np.concatenate((features, features__))
465+
features = np.concatenate((features, features__))
465466
else:
466467
# TODO
467-
raise NotImplementedError('type of system in not implemented now')
468+
raise NotImplementedError('type of system in not implemented now')
468469
except:
469470
pass
470471

471472

472473
# Make sure there is at least one point in the range
473-
if (features.shape[0] == 0):
474+
if (features.shape[0] == 0):
474475
features = np.array([1.]);
475476

476477
if Hz:

control/margins.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def stability_margins(sysdata, returnall=False, epsw=1e-8):
130130
sys = sysdata
131131
elif getattr(sysdata, '__iter__', False) and len(sysdata) == 3:
132132
mag, phase, omega = sysdata
133-
sys = frdata.FRD(mag * np.exp(1j * phase * np.pi/180),
133+
sys = frdata.FRD(mag * np.exp(1j * phase * np.pi/180),
134134
omega, smooth=True)
135135
else:
136136
sys = xferfcn._convertToTransferFunction(sysdata)
@@ -163,7 +163,7 @@ def stability_margins(sysdata, returnall=False, epsw=1e-8):
163163
# evaluate response at remaining frequencies, to test for phase 180 vs 0
164164
resp_w_180 = np.real(np.polyval(sys.num[0][0], 1.j*w_180) /
165165
np.polyval(sys.den[0][0], 1.j*w_180))
166-
#print ('resp_w_180', resp_w_180)
166+
#print ('resp_w_180', resp_w_180)
167167

168168
# only keep frequencies where the negative real axis is crossed
169169
w_180 = w_180[np.real(resp_w_180) < 0.0]
@@ -192,7 +192,7 @@ def stability_margins(sysdata, returnall=False, epsw=1e-8):
192192
# find the solutions, for positive omega, and only real ones
193193
wstab = np.roots(test_wstab)
194194
#print('wstabr', wstab)
195-
wstab = np.real(wstab[(np.imag(wstab) == 0) *
195+
wstab = np.real(wstab[(np.imag(wstab) == 0) *
196196
(np.real(wstab) >= 0)])
197197
#print('wstab', wstab)
198198

@@ -224,7 +224,7 @@ def dstab(w):
224224
wc = np.array(
225225
[ sp.optimize.brentq(mod, sys.omega[i], sys.omega[i+1])
226226
for i in widx if i+1 < len(sys.omega)])
227-
227+
228228
# find the phase crossings ang(H(jw) == -180
229229
widx = np.where(np.diff(np.sign(arg(sys.omega))))[0]
230230
#print('widx (180)', widx, sys.omega[widx])
@@ -246,17 +246,17 @@ def dstab(w):
246246
for i in widx if i+1 < len(sys.omega) and
247247
np.diff(np.diff(dstab(sys.omega[i-1:i+2])))[0] > 0 ])
248248
#print('wstabf0', wstab)
249-
wstab = wstab[(wstab >= sys.omega[0]) *
249+
wstab = wstab[(wstab >= sys.omega[0]) *
250250
(wstab <= sys.omega[-1])]
251251
#print ('wstabf', wstab)
252-
252+
253253

254254
# margins, as iterables, converted frdata and xferfcn calculations to
255255
# vector for this
256256
GM = 1/np.abs(sys.evalfr(w_180)[0][0])
257257
SM = np.abs(sys.evalfr(wstab)[0][0]+1)
258258
PM = np.angle(sys.evalfr(wc)[0][0], deg=True) + 180
259-
259+
260260
if returnall:
261261
return GM, PM, SM, w_180, wc, wstab
262262
else:
@@ -337,7 +337,7 @@ def margin(*args):
337337
Gain crossover frequency (corresponding to phase margin)
338338
Wcp : float
339339
Phase crossover frequency (corresponding to gain margin) (in rad/sec)
340-
340+
341341
Margins are of SISO open-loop. If more than one crossover frequency is
342342
detected, returns the lowest corresponding margin.
343343

control/tests/bdalg_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def testScalarSS(self):
4040

4141
ans1 = feedback(self.x1, self.sys2)
4242
ans2 = feedback(self.x1, self.sys2, 1.)
43-
43+
4444
np.testing.assert_array_almost_equal(ans1.A, [[-1.5, 4.], [13., 2.]])
4545
np.testing.assert_array_almost_equal(ans1.B, [[2.5], [-10.]])
4646
np.testing.assert_array_almost_equal(ans1.C, [[-2.5, 0.]])
@@ -77,7 +77,7 @@ def testScalarTF(self):
7777

7878
def testSSScalar(self):
7979
"""State space system with scalar feedback block."""
80-
80+
8181
ans1 = feedback(self.sys2, self.x1)
8282
ans2 = feedback(self.sys2, self.x1, 1.)
8383

@@ -98,7 +98,7 @@ def testSSSS1(self):
9898

9999
np.testing.assert_array_almost_equal(ans1.A, [[1., 4., -1., 0.],
100100
[3., 2., 4., 0.], [1., 0., 1., 4.], [-4., 0., 3., 2]])
101-
np.testing.assert_array_almost_equal(ans1.B, [[1.], [-4.], [0.], [0.]])
101+
np.testing.assert_array_almost_equal(ans1.B, [[1.], [-4.], [0.], [0.]])
102102
np.testing.assert_array_almost_equal(ans1.C, [[1., 0., 0., 0.]])
103103
np.testing.assert_array_almost_equal(ans1.D, [[0.]])
104104
np.testing.assert_array_almost_equal(ans2.A, [[1., 4., 1., 0.],
@@ -115,7 +115,7 @@ def testSSSS2(self):
115115
[[-2.]])
116116
sys4 = StateSpace([[-3., -2.], [1., 4.]], [[-2.], [-6.]], [[2., -3.]],
117117
[[3.]])
118-
118+
119119
ans1 = feedback(sys3, sys4)
120120
ans2 = feedback(sys3, sys4, 1.)
121121

@@ -144,7 +144,7 @@ def testSSSS2(self):
144144

145145
def testSSTF(self):
146146
"""State space system with transfer function feedback block."""
147-
147+
148148
# This functionality is not implemented yet.
149149
pass
150150

control/tests/freqresp_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# freqresp_test.py - test frequency response functions
44
# RMM, 30 May 2016 (based on timeresp_test.py)
55
#
6-
# This is a rudimentary set of tests for frequency response functions,
7-
# including bode plots.
6+
# This is a rudimentary set of tests for frequency response functions,
7+
# including bode plots.
88

99
import unittest
1010
import numpy as np
@@ -53,7 +53,7 @@ def test_mimo(self):
5353

5454
#bode(sysMIMO) # - should throw not implemented exception
5555
#bode(tfMIMO) # - should throw not implemented exception
56-
56+
5757
#plt.figure(3)
5858
#plt.semilogx(self.omega,20*np.log10(np.squeeze(frq[0])))
5959

0 commit comments

Comments
 (0)