Skip to content

Commit 9d68711

Browse files
committed
[xferfcn.py] Style refactor
- Fix pep8 warnings - convert protected camel case functions to lower case
1 parent 4286329 commit 9d68711

File tree

8 files changed

+203
-207
lines changed

8 files changed

+203
-207
lines changed

control/bdalg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ def feedback(sys1, sys2=1, sign=-1):
239239
# its feedback member function.
240240
if isinstance(sys1, (int, float, complex, np.number)):
241241
if isinstance(sys2, tf.TransferFunction):
242-
sys1 = tf._convertToTransferFunction(sys1)
242+
sys1 = tf._convert_to_transfer_function(sys1)
243243
elif isinstance(sys2, ss.StateSpace):
244244
sys1 = ss._convertToStateSpace(sys1)
245245
elif isinstance(sys2, frd.FRD):
246246
sys1 = ss._convertToFRD(sys1)
247247
else: # sys2 is a scalar.
248-
sys1 = tf._convertToTransferFunction(sys1)
249-
sys2 = tf._convertToTransferFunction(sys2)
248+
sys1 = tf._convert_to_transfer_function(sys1)
249+
sys2 = tf._convert_to_transfer_function(sys2)
250250

251251
return sys1.feedback(sys2, sign)
252252

control/margins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def stability_margins(sysdata, returnall=False, epsw=0.0):
144144
sys = frdata.FRD(mag * np.exp(1j * phase * math.pi/180),
145145
omega, smooth=True)
146146
else:
147-
sys = xferfcn._convertToTransferFunction(sysdata)
147+
sys = xferfcn._convert_to_transfer_function(sysdata)
148148
except Exception as e:
149149
print (e)
150150
raise ValueError("Margin sysdata must be either a linear system or "
@@ -299,7 +299,7 @@ def phase_crossover_frequencies(sys):
299299
"""
300300

301301
# Convert to a transfer function
302-
tf = xferfcn._convertToTransferFunction(sys)
302+
tf = xferfcn._convert_to_transfer_function(sys)
303303

304304
# if not siso, fall back to (0,0) element
305305
#! TODO: should add a check and warning here

control/rlocus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from math import pi
5252
import scipy.signal # signal processing toolbox
5353
import pylab # plotting routines
54-
from .xferfcn import _convertToTransferFunction
54+
from .xferfcn import _convert_to_transfer_function
5555
from .exception import ControlMIMONotImplemented
5656
from functools import partial
5757
from .lti import isdtime
@@ -284,7 +284,7 @@ def _systopoly1d(sys):
284284

285285
else:
286286
# Convert to a transfer function, if needed
287-
sys = _convertToTransferFunction(sys)
287+
sys = _convert_to_transfer_function(sys)
288288

289289
# Make sure we have a SISO system
290290
if (sys.inputs > 1 or sys.outputs > 1):

control/statesp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
from scipy.signal import lti, cont2discrete
6363
from warnings import warn
6464
from .lti import LTI, timebase, timebaseEqual, isdtime
65-
from .xferfcn import _convertToTransferFunction
65+
from .xferfcn import _convert_to_transfer_function
6666
from copy import deepcopy
6767

6868
__all__ = ['StateSpace', 'ss', 'rss', 'drss', 'tf2ss', 'ssdata']

control/tests/timeresp_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# import scipy as sp
1414
from control.timeresp import *
1515
from control.statesp import *
16-
from control.xferfcn import TransferFunction, _convertToTransferFunction
16+
from control.xferfcn import TransferFunction, _convert_to_transfer_function
1717
from control.dtime import c2d
1818
from control.exception import slycot_check
1919

@@ -28,7 +28,7 @@ def setUp(self):
2828

2929
# Create some transfer functions
3030
self.siso_tf1 = TransferFunction([1], [1, 2, 1])
31-
self.siso_tf2 = _convertToTransferFunction(self.siso_ss1)
31+
self.siso_tf2 = _convert_to_transfer_function(self.siso_ss1)
3232

3333
# Create MIMO system, contains ``siso_ss1`` twice
3434
A = np.matrix("1. -2. 0. 0.;"

control/tests/xferfcn_input_test.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from numpy import float, float16, float32, float64, float128
1111
from numpy import all, ndarray, array
1212

13-
from control.xferfcn import _cleanPart
13+
from control.xferfcn import _clean_part
1414

1515
class TestXferFcnInput(unittest.TestCase):
1616
"""These are tests for functionality of cleaning and validating
@@ -20,16 +20,16 @@ class TestXferFcnInput(unittest.TestCase):
2020
def testBadInputType(self):
2121
"""Give the part cleaner invalid input type."""
2222

23-
self.assertRaises(TypeError, _cleanPart, [[0., 1.], [2., 3.]])
23+
self.assertRaises(TypeError, _clean_part, [[0., 1.], [2., 3.]])
2424

2525
def testBadInputType2(self):
2626
"""Give the part cleaner another invalid input type."""
27-
self.assertRaises(TypeError, _cleanPart, [1,"a"])
27+
self.assertRaises(TypeError, _clean_part, [1, "a"])
2828

2929
def testScalar(self):
3030
"""Test single scalar value."""
3131
num = 1
32-
num_ = _cleanPart(num)
32+
num_ = _clean_part(num)
3333

3434
assert isinstance(num_, list)
3535
assert np.all([isinstance(part, list) for part in num_])
@@ -38,7 +38,7 @@ def testScalar(self):
3838
def testListScalar(self):
3939
"""Test single scalar value in list."""
4040
num = [1]
41-
num_ = _cleanPart(num)
41+
num_ = _clean_part(num)
4242

4343
assert isinstance(num_, list)
4444
assert np.all([isinstance(part, list) for part in num_])
@@ -47,7 +47,7 @@ def testListScalar(self):
4747
def testTupleScalar(self):
4848
"""Test single scalar value in tuple."""
4949
num = (1)
50-
num_ = _cleanPart(num)
50+
num_ = _clean_part(num)
5151

5252
assert isinstance(num_, list)
5353
assert np.all([isinstance(part, list) for part in num_])
@@ -56,7 +56,7 @@ def testTupleScalar(self):
5656
def testList(self):
5757
"""Test multiple values in a list."""
5858
num = [1, 2]
59-
num_ = _cleanPart(num)
59+
num_ = _clean_part(num)
6060

6161
assert isinstance(num_, list)
6262
assert np.all([isinstance(part, list) for part in num_])
@@ -65,7 +65,7 @@ def testList(self):
6565
def testTuple(self):
6666
"""Test multiple values in tuple."""
6767
num = (1, 2)
68-
num_ = _cleanPart(num)
68+
num_ = _clean_part(num)
6969

7070
assert isinstance(num_, list)
7171
assert np.all([isinstance(part, list) for part in num_])
@@ -75,7 +75,7 @@ def testAllScalarTypes(self):
7575
"""Test single scalar value for all valid data types."""
7676
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
7777
num = dtype(1)
78-
num_ = _cleanPart(num)
78+
num_ = _clean_part(num)
7979

8080
assert isinstance(num_, list)
8181
assert np.all([isinstance(part, list) for part in num_])
@@ -84,7 +84,7 @@ def testAllScalarTypes(self):
8484
def testNpArray(self):
8585
"""Test multiple values in numpy array."""
8686
num = np.array([1, 2])
87-
num_ = _cleanPart(num)
87+
num_ = _clean_part(num)
8888

8989
assert isinstance(num_, list)
9090
assert np.all([isinstance(part, list) for part in num_])
@@ -94,7 +94,7 @@ def testAllNumpyArrayTypes(self):
9494
"""Test scalar value in numpy array of ndim=0 for all data types."""
9595
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
9696
num = np.array(1, dtype=dtype)
97-
num_ = _cleanPart(num)
97+
num_ = _clean_part(num)
9898

9999
assert isinstance(num_, list)
100100
assert np.all([isinstance(part, list) for part in num_])
@@ -104,7 +104,7 @@ def testAllNumpyArrayTypes2(self):
104104
"""Test numpy array for all types."""
105105
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
106106
num = np.array([1, 2], dtype=dtype)
107-
num_ = _cleanPart(num)
107+
num_ = _clean_part(num)
108108

109109
assert isinstance(num_, list)
110110
assert np.all([isinstance(part, list) for part in num_])
@@ -114,7 +114,7 @@ def testListAllTypes(self):
114114
"""Test list of a single value for all data types."""
115115
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
116116
num = [dtype(1)]
117-
num_ = _cleanPart(num)
117+
num_ = _clean_part(num)
118118
assert isinstance(num_, list)
119119
assert np.all([isinstance(part, list) for part in num_])
120120
np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
@@ -123,7 +123,7 @@ def testListAllTypes2(self):
123123
"""List of list of numbers of all data types."""
124124
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
125125
num = [dtype(1), dtype(2)]
126-
num_ = _cleanPart(num)
126+
num_ = _clean_part(num)
127127
assert isinstance(num_, list)
128128
assert np.all([isinstance(part, list) for part in num_])
129129
np.testing.assert_array_equal(num_[0][0], array([1.0, 2.0], dtype=float))
@@ -132,7 +132,7 @@ def testTupleAllTypes(self):
132132
"""Test tuple of a single value for all data types."""
133133
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
134134
num = (dtype(1),)
135-
num_ = _cleanPart(num)
135+
num_ = _clean_part(num)
136136
assert isinstance(num_, list)
137137
assert np.all([isinstance(part, list) for part in num_])
138138
np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
@@ -141,31 +141,31 @@ def testTupleAllTypes2(self):
141141
"""Test tuple of a single value for all data types."""
142142
for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
143143
num = (dtype(1), dtype(2))
144-
num_ = _cleanPart(num)
144+
num_ = _clean_part(num)
145145
assert isinstance(num_, list)
146146
assert np.all([isinstance(part, list) for part in num_])
147147
np.testing.assert_array_equal(num_[0][0], array([1, 2], dtype=float))
148148

149149
def testListListListInt(self):
150150
""" Test an int in a list of a list of a list."""
151151
num = [[[1]]]
152-
num_ = _cleanPart(num)
152+
num_ = _clean_part(num)
153153
assert isinstance(num_, list)
154154
assert np.all([isinstance(part, list) for part in num_])
155155
np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
156156

157157
def testListListListFloat(self):
158158
""" Test a float in a list of a list of a list."""
159159
num = [[[1.0]]]
160-
num_ = _cleanPart(num)
160+
num_ = _clean_part(num)
161161
assert isinstance(num_, list)
162162
assert np.all([isinstance(part, list) for part in num_])
163163
np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
164164

165165
def testListListListInts(self):
166166
"""Test 2 lists of ints in a list in a list."""
167167
num = [[[1,1],[2,2]]]
168-
num_ = _cleanPart(num)
168+
num_ = _clean_part(num)
169169

170170
assert isinstance(num_, list)
171171
assert np.all([isinstance(part, list) for part in num_])
@@ -175,7 +175,7 @@ def testListListListInts(self):
175175
def testListListListFloats(self):
176176
"""Test 2 lists of ints in a list in a list."""
177177
num = [[[1.0,1.0],[2.0,2.0]]]
178-
num_ = _cleanPart(num)
178+
num_ = _clean_part(num)
179179

180180
assert isinstance(num_, list)
181181
assert np.all([isinstance(part, list) for part in num_])
@@ -186,7 +186,7 @@ def testListListArray(self):
186186
"""List of list of numpy arrays for all valid types."""
187187
for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
188188
num = [[array([1,1], dtype=dtype),array([2,2], dtype=dtype)]]
189-
num_ = _cleanPart(num)
189+
num_ = _clean_part(num)
190190

191191
assert isinstance(num_, list)
192192
assert np.all([isinstance(part, list) for part in num_])
@@ -197,7 +197,7 @@ def testTupleListArray(self):
197197
"""Tuple of list of numpy arrays for all valid types."""
198198
for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
199199
num = ([array([1,1], dtype=dtype),array([2,2], dtype=dtype)],)
200-
num_ = _cleanPart(num)
200+
num_ = _clean_part(num)
201201

202202
assert isinstance(num_, list)
203203
assert np.all([isinstance(part, list) for part in num_])
@@ -208,7 +208,7 @@ def testListTupleArray(self):
208208
"""List of tuple of numpy array for all valid types."""
209209
for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
210210
num = [(array([1,1], dtype=dtype),array([2,2], dtype=dtype))]
211-
num_ = _cleanPart(num)
211+
num_ = _clean_part(num)
212212

213213
assert isinstance(num_, list)
214214
assert np.all([isinstance(part, list) for part in num_])
@@ -220,7 +220,7 @@ def testTupleTuplesArrays(self):
220220
for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
221221
num = ((array([1,1], dtype=dtype),array([2,2], dtype=dtype)),
222222
(array([3,4], dtype=dtype),array([4,4], dtype=dtype)))
223-
num_ = _cleanPart(num)
223+
num_ = _clean_part(num)
224224

225225
assert isinstance(num_, list)
226226
assert np.all([isinstance(part, list) for part in num_])
@@ -232,7 +232,7 @@ def testListTuplesArrays(self):
232232
for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
233233
num = [(array([1,1], dtype=dtype),array([2,2], dtype=dtype)),
234234
(array([3,4], dtype=dtype),array([4,4], dtype=dtype))]
235-
num_ = _cleanPart(num)
235+
num_ = _clean_part(num)
236236

237237
assert isinstance(num_, list)
238238
assert np.all([isinstance(part, list) for part in num_])
@@ -244,7 +244,7 @@ def testListListArrays(self):
244244
for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
245245
num = [[array([1,1], dtype=dtype),array([2,2], dtype=dtype)],
246246
[array([3,3], dtype=dtype),array([4,4], dtype=dtype)]]
247-
num_ = _cleanPart(num)
247+
num_ = _clean_part(num)
248248

249249
assert len(num_) == 2
250250
assert np.all([isinstance(part, list) for part in num_])

control/tests/xferfcn_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import unittest
77
import numpy as np
88
from control.statesp import StateSpace, _convertToStateSpace, rss
9-
from control.xferfcn import TransferFunction, _convertToTransferFunction, ss2tf
9+
from control.xferfcn import TransferFunction, _convert_to_transfer_function, ss2tf
1010
from control.lti import evalfr
1111
from control.exception import slycot_check
1212
# from control.lti import isdtime
@@ -459,7 +459,7 @@ def testConvertToTransferFunction(self):
459459
D = [[1., 0.], [0., 1.], [1., 0.]]
460460
sys = StateSpace(A, B, C, D)
461461

462-
tfsys = _convertToTransferFunction(sys)
462+
tfsys = _convert_to_transfer_function(sys)
463463

464464
num = [[np.array([1., -7., 10.]), np.array([-1., 10.])],
465465
[np.array([2., -8.]), np.array([1., -2., -8.])],
@@ -530,7 +530,7 @@ def testMIMO(self):
530530
H = TransferFunction([[h.num[0][0]], [(h*s).num[0][0]]],
531531
[[h.den[0][0]], [h.den[0][0]]])
532532
sys = _convertToStateSpace(H)
533-
H2 = _convertToTransferFunction(sys)
533+
H2 = _convert_to_transfer_function(sys)
534534
np.testing.assert_array_almost_equal(H.num[0][0], H2.num[0][0])
535535
np.testing.assert_array_almost_equal(H.den[0][0], H2.den[0][0])
536536
np.testing.assert_array_almost_equal(H.num[1][0], H2.num[1][0])

0 commit comments

Comments
 (0)