Skip to content

Commit dc5482c

Browse files
authored
Merge pull request #142 from mtezzele/codacy
fix codacy issues, erase vtk code for older versions
2 parents 44f9f93 + 944ef06 commit dc5482c

File tree

15 files changed

+175
-140
lines changed

15 files changed

+175
-140
lines changed

pygem/affine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"""
55
import math
66
import sys
7-
import numpy as np
87
from functools import reduce
8+
import numpy as np
99

1010

1111
def angles2matrix(rot_z=0, rot_y=0, rot_x=0):

pygem/freeform.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,19 @@ def perform(self):
150150

151151
# shift_mesh_points needs to be transposed to be summed with mesh_points
152152
# apply inverse transformation to shifted mesh points
153-
new_mesh_points = self._transform_points(np.transpose(shift_mesh_points) +
154-
mesh_points, inverse_transformation) + \
155-
translation
153+
new_mesh_points = self._transform_points(
154+
np.transpose(shift_mesh_points) + mesh_points,
155+
inverse_transformation) + translation
156156

157157
# merge non-shifted mesh points with shifted ones
158158
self.modified_mesh_points = np.copy(self.original_mesh_points)
159-
self.modified_mesh_points[(reference_frame_mesh_points[:,0] >= 0.) &
160-
(reference_frame_mesh_points[:,0] <= 1.) &
161-
(reference_frame_mesh_points[:,1] >= 0.) &
162-
(reference_frame_mesh_points[:,1] <= 1.) &
163-
(reference_frame_mesh_points[:,2] >= 0.) &
164-
(reference_frame_mesh_points[:,2] <= 1.)] \
165-
= new_mesh_points
159+
self.modified_mesh_points[(reference_frame_mesh_points[:, 0] >= 0.)
160+
& (reference_frame_mesh_points[:, 0] <= 1.) &
161+
(reference_frame_mesh_points[:, 1] >= 0.) &
162+
(reference_frame_mesh_points[:, 1] <= 1.) &
163+
(reference_frame_mesh_points[:, 2] >= 0.) &
164+
(reference_frame_mesh_points[:, 2] <=
165+
1.)] = new_mesh_points
166166

167167
@staticmethod
168168
def _transform_points(original_points, transformation):

pygem/idw.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,18 @@
2525
{\\displaystyle\\sum_{j=1}^\\mathcal{N} w(\\mathrm{x},\\mathrm{x}_j)}
2626
u_k
2727
28-
2928
where, in general, :math:`w(\\mathrm{x}, \\mathrm{x}_i)` represents the
3029
weighting function:
3130
3231
.. math::
3332
w(\\mathrm{x}, \\mathrm{x}_i) = \\| \\mathrm{x} - \\mathrm{x}_i \\|^{-p}
34-
33+
3534
being :math:`\\| \\mathrm{x} - \\mathrm{x}_i \\|^{-p} \\ge 0` is the
3635
Euclidean distance between :math:`\\mathrm{x}` and data point
3736
:math:`\\mathrm{x}_i` and :math:`p` is a power parameter, typically equal to
3837
2.
39-
4038
"""
4139
import numpy as np
42-
4340
from scipy.spatial.distance import cdist
4441

4542

@@ -91,7 +88,10 @@ def perform(self):
9188
"""
9289

9390
def distance(u, v):
94-
return np.linalg.norm(u - v, self.parameters.power)
91+
"""
92+
Norm of u - v
93+
"""
94+
return np.linalg.norm(u - v, ord=self.parameters.power)
9595

9696
# Compute displacement of the control points
9797
displ = (self.parameters.deformed_control_points -

pygem/igeshandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Derived module from filehandler.py to handle iges and igs files.
33
"""
4-
54
from OCC.IGESControl import (IGESControl_Reader, IGESControl_Writer,
65
IGESControl_Controller_Init)
76
from OCC.IFSelect import IFSelect_RetDone

pygem/openfhandler.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class OpenFoamHandler(fh.FileHandler):
1111
1212
:cvar string infile: name of the input file to be processed.
1313
:cvar string outfile: name of the output file where to write in.
14-
:cvar list extensions: extensions of the input/output files. It is equal to [''] since
15-
openFOAM files do not have extension.
14+
:cvar list extensions: extensions of the input/output files. It
15+
is equal to [''] since openFOAM files do not have extension.
1616
"""
1717

1818
def __init__(self):
@@ -21,12 +21,13 @@ def __init__(self):
2121

2222
def parse(self, filename):
2323
"""
24-
Method to parse the `filename`. It returns a matrix with all the coordinates.
24+
Method to parse the `filename`. It returns a matrix with all
25+
the coordinates.
2526
2627
:param string filename: name of the input file.
2728
28-
:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
29-
the points of the mesh
29+
:return: mesh_points: it is a `n_points`-by-3 matrix containing
30+
the coordinates of the points of the mesh
3031
:rtype: numpy.ndarray
3132
3233
.. todo::
@@ -58,12 +59,13 @@ def parse(self, filename):
5859

5960
def write(self, mesh_points, filename):
6061
"""
61-
Writes a openFOAM file, called filename, copying all the lines from self.filename but
62-
the coordinates. mesh_points is a matrix that contains the new coordinates to
63-
write in the openFOAM file.
62+
Writes a openFOAM file, called filename, copying all the
63+
lines from self.filename but the coordinates. mesh_points
64+
is a matrix that contains the new coordinates to write in
65+
the openFOAM file.
6466
65-
:param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing
66-
the coordinates of the points of the mesh.
67+
:param numpy.ndarray mesh_points: it is a `n_points`-by-3
68+
matrix containing the coordinates of the points of the mesh.
6769
:param string filename: name of the output file.
6870
6971
.. todo:: DOCS
@@ -82,8 +84,8 @@ def write(self, mesh_points, filename):
8284
for line in input_file:
8385
nrow += 1
8486
if 20 < nrow < 21 + n_points:
85-
output_file.write('(' + str(mesh_points[i][0]) + ' ' + str(mesh_points[i][1]) + \
86-
' ' + str(mesh_points[i][2]) +')')
87+
output_file.write('(' + str(mesh_points[i][0]) + ' ' + str(
88+
mesh_points[i][1]) + ' ' + str(mesh_points[i][2]) + ')')
8789
output_file.write('\n')
8890
i += 1
8991
else:

pygem/params/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
params init
3+
"""
14
from .rbfparams import RBFParameters
25
from .ffdparams import FFDParameters
36
from .idwparams import IDWParameters

pygem/params/ffdparams.py

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
"""
2-
Utilities for reading and writing parameters files to perform the desired
2+
Utilities for reading and writing parameters files to perform FFD
33
geometrical morphing.
44
"""
55
try:
66
import configparser as configparser
77
except ImportError:
88
import ConfigParser as configparser
99
import os
10-
1110
import numpy as np
11+
from OCC.Bnd import Bnd_Box
1212
from OCC.BRepBndLib import brepbndlib_Add
1313
from OCC.BRepMesh import BRepMesh_IncrementalMesh
14-
from OCC.Bnd import Bnd_Box
15-
1614
import vtk
1715
import pygem.affine as at
18-
from math import radians
1916

2017

2118
class FFDParameters(object):
@@ -44,7 +41,7 @@ class FFDParameters(object):
4441
:Example: from file
4542
4643
>>> import pygem.params as ffdp
47-
>>>
44+
>>>
4845
>>> # Reading an existing file
4946
>>> params1 = ffdp.FFDParameters()
5047
>>> params1.read_parameters(
@@ -115,8 +112,8 @@ def rotation_matrix(self):
115112
:rtype: numpy.ndarray
116113
"""
117114
return at.angles2matrix(
118-
radians(self.rot_angle[2]), radians(self.rot_angle[1]),
119-
radians(self.rot_angle[0]))
115+
np.radians(self.rot_angle[2]), np.radians(self.rot_angle[1]),
116+
np.radians(self.rot_angle[0]))
120117

121118
@property
122119
def position_vertices(self):
@@ -213,69 +210,99 @@ def write_parameters(self, filename='parameters.prm'):
213210
output_string += 'n control points z: ' + str(
214211
self.n_control_points[2]) + '\n'
215212

216-
output_string += '\n# box lenght indicates the length of the FFD bounding box along the three canonical directions (x, y, z).\n'
213+
output_string += '\n# box lenght indicates the length of the FFD '
214+
output_string += 'bounding box along the three canonical directions (x, y, z).\n'
215+
217216
output_string += '# It uses the local coordinate system.\n'
218-
output_string += '# For example to create a 2 x 1.5 x 3 meters box use the following: lenght box: 2.0, 1.5, 3.0\n'
217+
output_string += '# For example to create a 2 x 1.5 x 3 meters box '
218+
output_string += 'use the following: lenght box: 2.0, 1.5, 3.0\n'
219+
219220
output_string += 'box lenght x: ' + str(self.lenght_box[0]) + '\n'
220221
output_string += 'box lenght y: ' + str(self.lenght_box[1]) + '\n'
221222
output_string += 'box lenght z: ' + str(self.lenght_box[2]) + '\n'
222223

223-
output_string += '\n# box origin indicates the x, y, and z coordinates of the origin of the FFD bounding box. That is center of\n'
224-
output_string += '# rotation of the bounding box. It corresponds to the point coordinates with position [0][0][0].\n'
224+
output_string += '\n# box origin indicates the x, y, and z coordinates of '
225+
output_string += 'the origin of the FFD bounding box. That is center of\n'
226+
227+
output_string += '# rotation of the bounding box. It corresponds to '
228+
output_string += 'the point coordinates with position [0][0][0].\n'
229+
225230
output_string += '# See section "Parameters weights" for more details.\n'
226-
output_string += '# For example, if the origin is equal to 0., 0., 0., use the following: origin box: 0., 0., 0.\n'
231+
output_string += '# For example, if the origin is equal to 0., 0., 0., use '
232+
output_string += 'the following: origin box: 0., 0., 0.\n'
233+
227234
output_string += 'box origin x: ' + str(self.origin_box[0]) + '\n'
228235
output_string += 'box origin y: ' + str(self.origin_box[1]) + '\n'
229236
output_string += 'box origin z: ' + str(self.origin_box[2]) + '\n'
230237

231-
output_string += '\n# rotation angle indicates the rotation angle around the x, y, and z axis of the FFD bounding box in degrees.\n'
238+
output_string += '\n# rotation angle indicates the rotation angle '
239+
output_string += 'around the x, y, and z axis of the FFD bounding box in degrees.\n'
240+
232241
output_string += '# The rotation is done with respect to the box origin.\n'
233-
output_string += '# For example, to rotate the box by 2 deg along the z direction, use the following: rotation angle: 0., 0., 2.\n'
242+
output_string += '# For example, to rotate the box by 2 deg along the z '
243+
output_string += 'direction, use the following: rotation angle: 0., 0., 2.\n'
244+
234245
output_string += 'rotation angle x: ' + str(self.rot_angle[0]) + '\n'
235246
output_string += 'rotation angle y: ' + str(self.rot_angle[1]) + '\n'
236247
output_string += 'rotation angle z: ' + str(self.rot_angle[2]) + '\n'
237248

238249
output_string += '\n\n[Parameters weights]\n'
239-
output_string += '# This section describes the weights of the FFD control points.\n'
250+
output_string += '# This section describes the weights of the FFD '
251+
output_string += 'control points.\n'
252+
240253
output_string += '# We adopt the following convention:\n'
241-
output_string += '# For example with a 2x2x2 grid of control points we have to fill a 2x2x2 matrix of weights.\n'
242-
output_string += '# If a weight is equal to zero you can discard the line since the default is zero.\n'
254+
output_string += '# For example with a 2x2x2 grid of control points we '
255+
output_string += 'have to fill a 2x2x2 matrix of weights.\n'
256+
257+
output_string += '# If a weight is equal to zero you can discard the line '
258+
output_string += 'since the default is zero.\n'
259+
243260
output_string += '#\n'
244261
output_string += '# | x index | y index | z index | weight |\n'
245262
output_string += '# --------------------------------------\n'
246263
output_string += '# | 0 | 0 | 0 | 1.0 |\n'
247-
output_string += '# | 0 | 1 | 1 | 0.0 | --> you can erase this line without effects\n'
264+
output_string += '# | 0 | 1 | 1 | 0.0 | --> you '
265+
output_string += 'can erase this line without effects\n'
248266
output_string += '# | 0 | 1 | 0 | -2.1 |\n'
249267
output_string += '# | 0 | 0 | 1 | 3.4 |\n'
250268

251-
output_string += '\n# parameter x collects the displacements along x, normalized with the box lenght x.'
269+
output_string += '\n# parameter x collects the displacements along x, '
270+
output_string += 'normalized with the box lenght x.'
271+
252272
output_string += '\nparameter x:'
253273
offset = 1
254274
for i in range(0, self.n_control_points[0]):
255275
for j in range(0, self.n_control_points[1]):
256276
for k in range(0, self.n_control_points[2]):
257-
output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \
258-
' ' + str(self.array_mu_x[i][j][k]) + '\n'
277+
output_string += offset * ' ' + str(i) + ' ' + str(
278+
j) + ' ' + str(k) + ' ' + str(
279+
self.array_mu_x[i][j][k]) + '\n'
259280
offset = 13
260281

261-
output_string += '\n# parameter y collects the displacements along y, normalized with the box lenght y.'
282+
output_string += '\n# parameter y collects the displacements along y, '
283+
output_string += 'normalized with the box lenght y.'
284+
262285
output_string += '\nparameter y:'
263286
offset = 1
264287
for i in range(0, self.n_control_points[0]):
265288
for j in range(0, self.n_control_points[1]):
266289
for k in range(0, self.n_control_points[2]):
267-
output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \
268-
' ' + str(self.array_mu_y[i][j][k]) + '\n'
290+
output_string += offset * ' ' + str(i) + ' ' + str(
291+
j) + ' ' + str(k) + ' ' + str(
292+
self.array_mu_y[i][j][k]) + '\n'
269293
offset = 13
270294

271-
output_string += '\n# parameter z collects the displacements along z, normalized with the box lenght z.'
295+
output_string += '\n# parameter z collects the displacements along z, '
296+
output_string += 'normalized with the box lenght z.'
297+
272298
output_string += '\nparameter z:'
273299
offset = 1
274300
for i in range(0, self.n_control_points[0]):
275301
for j in range(0, self.n_control_points[1]):
276302
for k in range(0, self.n_control_points[2]):
277-
output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \
278-
' ' + str(self.array_mu_z[i][j][k]) + '\n'
303+
output_string += offset * ' ' + str(i) + ' ' + str(
304+
j) + ' ' + str(k) + ' ' + str(
305+
self.array_mu_z[i][j][k]) + '\n'
279306
offset = 13
280307

281308
with open(filename, 'w') as f:

pygem/params/idwparams.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import numpy as np
1+
"""
2+
Utilities for reading and writing parameters files to perform IDW
3+
geometrical morphing.
4+
"""
25
import os
6+
import numpy as np
37
try:
48
import configparser as configparser
59
except ImportError:

0 commit comments

Comments
 (0)