Skip to content

Commit fc7f7f0

Browse files
annaivagnesndem0
authored andcommitted
minor fixes
1 parent 7302612 commit fc7f7f0

File tree

5 files changed

+40
-37
lines changed

5 files changed

+40
-37
lines changed

bladex/blade.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def rotate(self, deg_angle=None, rad_angle=None, axis='x'):
322322
in the 3D Euclidean space about the specified axis, which is
323323
-- by default -- the x axis.
324324
325-
:math: when the axis of rotation is the x-axis `R(\\theta)` is defined
325+
when the axis of rotation is the x-axis :math: `R(\\theta)` is defined
326326
by:
327327
328328
.. math::
@@ -401,12 +401,12 @@ def rotate(self, deg_angle=None, rad_angle=None, axis='x'):
401401
self.blade_coordinates_down[i][2] = new_coord_matrix_down[2]
402402

403403
def scale(self, factor):
404-
'''
404+
"""
405405
Scale the blade coordinates by a specified factor.
406406
407407
:param float factor: scaling factor
408+
"""
408409

409-
'''
410410
scaling_matrix = np.array([factor, 0, 0, 0, factor,
411411
0, 0, 0, factor]).reshape((3, 3))
412412

bladex/customprofile.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import numpy as np
1111
from .profilebase import ProfileBase
12+
from scipy.optimize import newton
1213

1314

1415
class CustomProfile(ProfileBase):
@@ -89,7 +90,7 @@ def _check_parameters(self):
8990
raise ValueError(
9091
'object "thickness_perc" refers to an empty array.')
9192
if self.chord_len is None:
92-
raise ValueError('object "chorf_len" refers to an empty array.')
93+
raise ValueError('object "chord_len" refers to an empty array.')
9394
if self.camber_max is None:
9495
raise ValueError('object "camber_max" refers to an empty array.')
9596
if self.thickness_max is None:
@@ -127,13 +128,13 @@ def _check_parameters(self):
127128
'thickness_perc and chord_perc must have same shape.')
128129

129130
def _compute_orth_camber_coordinates(self):
130-
'''
131+
"""
131132
Compute the coordinates of points on upper and lower profile on the
132133
line orthogonal to the camber line.
133134
134135
:return: x and y coordinates of section points on line orthogonal to
135136
camber line
136-
'''
137+
"""
137138
# Compute the angular coefficient of the camber line
138139
n_pos = self.chord_percentage.shape[0]
139140
m = np.zeros(n_pos)
@@ -157,7 +158,7 @@ def _compute_orth_camber_coordinates(self):
157158
xup_tmp[1], xdown_tmp[1] = xup_tmp[2]-1e-16, xdown_tmp[2]-1e-16
158159
yup_tmp[1], ydown_tmp[1] = yup_tmp[2]-1e-16, ydown_tmp[2]-1e-16
159160

160-
return xup_tmp, xdown_tmp, yup_tmp, ydown_tmp
161+
return [xup_tmp, xdown_tmp, yup_tmp, ydown_tmp]
161162

162163

163164

@@ -169,7 +170,8 @@ def generate_coordinates(self):
169170
and camber.
170171
"""
171172

172-
self.xup_coordinates, self.xdown_coordinates, self.yup_coordinates, self.ydown_coordinates = self._compute_orth_camber_coordinates()
173+
[self.xup_coordinates, self.xdown_coordinates, self.yup_coordinates,
174+
self.ydown_coordinates] = self._compute_orth_camber_coordinates()
173175

174176
self.ydown_coordinates = self.ydown_curve(
175177
self.chord_len*(self.chord_percentage).reshape(-1,1)).reshape(
@@ -186,23 +188,23 @@ def generate_coordinates(self):
186188

187189

188190
def adimensionalize(self):
189-
'''
191+
"""
190192
Rescale coordinates of upper and lower profiles of section such that
191193
coordinates on x axis are between 0 and 1.
192-
'''
194+
"""
193195
factor = abs(self.xup_coordinates[-1]-self.xup_coordinates[0])
194196
self.yup_coordinates *= 1/factor
195197
self.xdown_coordinates *= 1/factor
196198
self.ydown_coordinates *= 1/factor
197199
self.xup_coordinates *= 1/factor
198200

199201
def generate_parameters(self):
200-
'''
202+
"""
201203
Method that generates the parameters of a general airfoil profile
202204
(chord length, chord percentages, camber max, thickness max, camber and
203205
thickness percentages), starting from the upper and lower
204206
coordinates of the section profile.
205-
'''
207+
"""
206208
n_pos = self.xup_coordinates.shape[0]
207209

208210
self.chord_len = abs(np.max(self.xup_coordinates)-
@@ -220,11 +222,12 @@ def generate_parameters(self):
220222
self.chord_percentage[i-1])*self.camber_max/self.chord_len
221223
m_angle = np.arctan(m)
222224

223-
from scipy.optimize import newton
224-
225+
# generating temporary profile coordinates orthogonal to the camber
226+
# line
225227
ind_horizontal_camber = (np.sin(m_angle)==0)
226228
def eq_to_solve(x):
227-
spline_curve = self.ydown_curve(x.reshape(-1,1)).reshape(x.shape[0],)
229+
spline_curve = self.ydown_curve(x.reshape(-1,1)).reshape(
230+
x.shape[0],)
228231
line_orth_camber = (camber[~ind_horizontal_camber] +
229232
np.cos(m_angle[~ind_horizontal_camber])/
230233
np.sin(m_angle[~ind_horizontal_camber])*(self.chord_len*
@@ -235,7 +238,8 @@ def eq_to_solve(x):
235238
xdown_tmp[~ind_horizontal_camber] = newton(eq_to_solve,
236239
xdown_tmp[~ind_horizontal_camber])
237240
xup_tmp = 2*self.chord_len*self.chord_percentage - xdown_tmp
238-
ydown_tmp = self.ydown_curve(xdown_tmp.reshape(-1,1)).reshape(xdown_tmp.shape[0],)
241+
ydown_tmp = self.ydown_curve(xdown_tmp.reshape(-1,1)).reshape(
242+
xdown_tmp.shape[0],)
239243
yup_tmp = 2*self.camber_max*self.camber_percentage - ydown_tmp
240244
if xup_tmp[1]<self.xup_coordinates[0]:
241245
xup_tmp[1], xdown_tmp[1] = xup_tmp[2], xdown_tmp[2]

bladex/profilebase.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import matplotlib.pyplot as plt
77
from .ndinterpolator import reconstruct_f
8+
from scipy.interpolate import RBFInterpolator
89

910

1011
class ProfileBase(object):
@@ -276,7 +277,7 @@ def deform_camber_line(self, percent_change, n_interpolated_points=None):
276277

277278
@property
278279
def yup_curve(self):
279-
'''
280+
"""
280281
Return the spline function corresponding to the upper profile
281282
of the airfoil
282283
@@ -285,15 +286,14 @@ def yup_curve(self):
285286
286287
.. todo::
287288
generalize the interpolation function
288-
'''
289-
from scipy.interpolate import RBFInterpolator
289+
"""
290290
spline = RBFInterpolator(self.xup_coordinates.reshape(-1,1),
291291
self.yup_coordinates.reshape(-1,1))
292292
return spline
293293

294294
@property
295295
def ydown_curve(self):
296-
'''
296+
"""
297297
Return the spline function corresponding to the lower profile
298298
of the airfoil
299299
@@ -302,8 +302,7 @@ def ydown_curve(self):
302302
303303
.. todo::
304304
generalize the interpolation function
305-
'''
306-
from scipy.interpolate import RBFInterpolator
305+
"""
307306
spline = RBFInterpolator(self.xdown_coordinates.reshape(-1,1),
308307
self.ydown_coordinates.reshape(-1,1))
309308
return spline
@@ -537,7 +536,7 @@ def scale(self, factor, translate=True):
537536
538537
:param float factor: the scaling factor
539538
"""
540-
if translate==True:
539+
if translate:
541540
ref_point = self.reference_point
542541
self.translate(-ref_point)
543542
self.xup_coordinates *= factor

bladex/reversepropeller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def optimized_path(coords, start=None):
8484

8585

8686
def point_inside_polygon(x, y, poly, include_edges=True):
87-
'''
87+
"""
8888
Test if point (x,y) is inside polygon poly.
8989
9090
poly is N-vertices polygon defined as
@@ -94,7 +94,7 @@ def point_inside_polygon(x, y, poly, include_edges=True):
9494
Geometrical idea: point is inside polygon if horisontal beam
9595
to the right from point crosses polygon even number of times.
9696
Works fine for non-convex polygons.
97-
'''
97+
"""
9898
n = len(poly)
9999
inside = False
100100

tests/test_ndinterpolator.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,39 @@ def test_wrong_basis(self):
4444
def test_gaussian_evaluation(self):
4545
rbf = nd.RBF(basis='gaussian_spline', radius=1.)
4646
result = rbf.basis(X=1., r=1.)
47-
assert result == 0.36787944117144233
47+
np.testing.assert_almost_equal(result, 0.36787944117144233)
4848

4949
def test_biharmonic_evaluation(self):
5050
rbf = nd.RBF(basis='multi_quadratic_biharmonic_spline', radius=1.)
5151
result = rbf.basis(X=1., r=1.)
52-
assert result == 1.4142135623730951
52+
np.testing.assert_almost_equal(result, 1.4142135623730951)
5353

5454
def test_inv_biharmonic_evaluation(self):
5555
rbf = nd.RBF(basis='inv_multi_quadratic_biharmonic_spline', radius=1.)
5656
result = rbf.basis(X=1., r=1.)
57-
assert result == 0.7071067811865475
57+
np.testing.assert_almost_equal(result, 0.7071067811865475)
5858

5959
def test_thin_plate_evaluation(self):
6060
rbf = nd.RBF(basis='thin_plate_spline', radius=1.)
6161
result = rbf.basis(X=1., r=0.5)
62-
assert result == 2.772588722239781
62+
np.testing.assert_almost_equal(result, 2.772588722239781)
6363

6464
def test_wendland_evaluation(self):
6565
rbf = nd.RBF(basis='beckert_wendland_c2_basis', radius=1.)
6666
result = rbf.basis(X=1., r=2.)
67-
assert result == 0.1875
67+
np.testing.assert_almost_equal(result, 0.1875)
6868

6969
def test_wendland_outside_cutoff(self):
7070
rbf = nd.RBF(basis='beckert_wendland_c2_basis', radius=1.)
7171
result = rbf.basis(X=2., r=1.)
72-
assert result == 0.0
72+
np.testing.assert_almost_equal(result, 0.0)
7373

7474
def test_weight_matrix(self):
7575
x = np.arange(10)
7676
rbf = nd.RBF(basis='beckert_wendland_c2_basis', radius=1.)
7777
weights_matrix = rbf.weights_matrix(X1=x, X2=x)
7878
expected = np.diag(np.ones(10))
79-
np.testing.assert_array_equal(weights_matrix, expected)
79+
np.testing.assert_array_almost_equal(weights_matrix, expected)
8080

8181
def test_reconstruct_f_gaussian(self):
8282
x, y, xx, yy = sample_data()
@@ -91,7 +91,7 @@ def test_reconstruct_f_gaussian(self):
9191
# for argmin(yy) nearest to point y=20.25, where y=x*x
9292
idx = (np.abs(xx - 4.5)).argmin()
9393
idx2 = (np.abs(yy - 20.25)).argmin()
94-
assert idx == idx2
94+
np.testing.assert_array_almost_equal(idx, idx2)
9595

9696
def test_reconstruct_f_biharmonic(self):
9797
x, y, xx, yy = sample_data()
@@ -106,7 +106,7 @@ def test_reconstruct_f_biharmonic(self):
106106
# for argmin(yy) nearest to point y=20.25, where y=x*x
107107
idx = (np.abs(xx - 4.5)).argmin()
108108
idx2 = (np.abs(yy - 20.25)).argmin()
109-
assert idx == idx2
109+
np.testing.assert_array_almost_equal(idx, idx2)
110110

111111
def test_reconstruct_f_inv_biharmonic(self):
112112
x, y, xx, yy = sample_data()
@@ -121,7 +121,7 @@ def test_reconstruct_f_inv_biharmonic(self):
121121
# for argmin(yy) nearest to point y=20.25, where y=x*x
122122
idx = (np.abs(xx - 4.5)).argmin()
123123
idx2 = (np.abs(yy - 20.25)).argmin()
124-
assert idx == idx2
124+
np.testing.assert_array_almost_equal(idx, idx2)
125125

126126
def test_reconstruct_f_plate(self):
127127
x, y, xx, yy = sample_data()
@@ -136,7 +136,7 @@ def test_reconstruct_f_plate(self):
136136
# for argmin(yy) nearest to point y=20.25, where y=x*x
137137
idx = (np.abs(xx - 4.5)).argmin()
138138
idx2 = (np.abs(yy - 20.25)).argmin()
139-
assert idx == idx2
139+
np.testing.assert_array_almost_equal(idx, idx2)
140140

141141
def test_reconstruct_f_wendland(self):
142142
x, y, xx, yy = sample_data()
@@ -151,7 +151,7 @@ def test_reconstruct_f_wendland(self):
151151
# for argmin(yy) nearest to point y=20.25, where y=x*x
152152
idx = (np.abs(xx - 4.5)).argmin()
153153
idx2 = (np.abs(yy - 20.25)).argmin()
154-
assert idx == idx2
154+
np.testing.assert_array_almost_equal(idx, idx2)
155155

156156
def test_reconstruct_f_scalar(self):
157157
x = np.arange(10)

0 commit comments

Comments
 (0)