Skip to content

Commit e62dd44

Browse files
committed
python-occ 0.17 compatibility, formatter, documentation and minor fixes (#97)
1 parent f6cfc71 commit e62dd44

32 files changed

+1580
-1398
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Please see the table below for instructions on how to satisfy the requirements.
3535

3636
| Package | Version | Comment |
3737
|---------|----------|----------------------------------------------------------------------------|
38-
| OCC | >= 0.16 | See pythonocc.org or github.com.tpaviot/pythonocc-core for instructions or `conda install -c https://conda.anaconda.org/dlr-sc pythonocc-core` |
38+
| OCC | == 0.17 | See pythonocc.org or github.com.tpaviot/pythonocc-core for instructions or `conda install -c https://conda.anaconda.org/dlr-sc pythonocc-core` |
3939
| vtk | >= 5.0 | Simplest solution is `conda install vtk` |
4040

4141

@@ -133,7 +133,8 @@ just a few small guidelines you need to follow.
133133
commits related to that bug or feature.
134134

135135
3. To ensure properly formatted code, please make sure to use a tab of 4
136-
spaces to indent the code. You should also run [pylint][] over your code.
136+
spaces to indent the code. The easy way is to run on your bash the provided
137+
script: ./code_formatter.sh. You should also run [pylint][] over your code.
137138
It's not strictly necessary that your code be completely "lint-free",
138139
but this will help you find common style issues.
139140

code_formatter.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
#######################################
4+
5+
required_command="yapf unexpand"
6+
code_directories="pygem tests"
7+
8+
#######################################
9+
10+
usage() {
11+
echo
12+
echo -e "\tUsage: $0 [files]"
13+
echo
14+
echo -e "\tIf not files are specified, script formats all ".py" files"
15+
echo -e "\tin code directories ($code_directories); otherwise, formats"
16+
echo -e "\tall given files"
17+
echo
18+
echo -e "\tRequired command: $required_command"
19+
echo
20+
exit 0
21+
}
22+
23+
24+
[[ $1 == "-h" ]] && usage
25+
26+
# Test for required program
27+
for comm in $required_command; do
28+
command -v $comm >/dev/null 2>&1 || {
29+
echo "I require $comm but it's not installed. Aborting." >&2;
30+
exit 1
31+
}
32+
done
33+
34+
# Find all python files in code directories
35+
python_files=""
36+
for dir in $code_directories; do
37+
python_files="$python_files `ls $dir/*.py`"
38+
done
39+
[[ $# != 0 ]] && python_files=$@
40+
41+
# The files unvhandler.py and params.py can not be formatted because there are
42+
# strings with spaces inside that otherwise would be converted in tabs.
43+
python_files_true=""
44+
for file in $python_files; do
45+
if [ $file != "pygem/unvhandler.py" ] && [ $file != "pygem/params.py" ]; then
46+
python_files_true="$python_files_true $file"
47+
fi
48+
done
49+
50+
# Here the important part:
51+
# - first, yapf format the files; it works very well just setting few option
52+
# by command line, but at the moment it has bugs for tabs, so uses spaces.
53+
# - second, convert 4 spaces to tab character
54+
# - third, you can look a very pretty code
55+
for file in $python_files_true; do
56+
echo "Making beatiful $file..."
57+
[[ ! -f $file ]] && echo "$file does not exist; $0 -h for more info" && exit
58+
59+
yapf --style='{
60+
based_on_style: pep8,
61+
indent_width: 4,
62+
dedent_closing_brackets = true,
63+
coalesce_brackets = true,
64+
column_limit = 80
65+
}' -i $file
66+
unexpand -t 4 $file > tmp.py
67+
mv tmp.py $file
68+
done

docs/source/code.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Code Documentation
2-
==================
2+
=======================
33

44

55
.. toctree::

docs/source/index.rst

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,29 @@ PyGeM is a python library using Free Form Deformation and Radial Basis Functions
2121
By now, it has been used with meshes with up to 14 milions of cells. Try with more and more complicated input files!
2222

2323

24-
Guide
25-
^^^^^
24+
Installation
25+
^^^^^^^^^^^^
26+
27+
To install the pygem package, open the terminal/command line and clone the repository with the command
28+
::
29+
30+
git clone https://github.com/mathLab/PyGeM
31+
32+
For a complete list of dependencies to be installed via conda please refer to the official `repository <https://github.com/mathLab/PyGeM>`_.
33+
After installing the dependencies you can navigate into the ``PyGeM`` folder (where the ``setup.py`` file is located) and run the command
34+
::
35+
36+
python setup.py install
37+
38+
You should now be able to import the pygem library in Python scripts and interpreters with the command ``import pygem``.
39+
40+
41+
42+
Developer's Guide
43+
^^^^^^^^^^^^^^^^^^^^^^^
2644

2745
.. toctree::
28-
:maxdepth: 3
46+
:maxdepth: 1
2947

3048
code
3149
contact
@@ -38,10 +56,10 @@ Tutorials
3856

3957
We made some tutorial examples:
4058

41-
- `Tutorial 1 <tutorial1stl.html>`_ shows how to deal with stl files and FFD
42-
- `Turorial 2 <tutorial2iges.html>`_ shows how to deal with iges files and FFD
43-
- `Turorial 3 <tutorial3unv.html>`_ shows how to deal with unv files and how to set the desired continuity to the geometry using FFD
44-
- `Turorial 4 <tutorial4rbf.html>`_ shows how to perform RBF interpolation
59+
- `Tutorial 1 <tutorial1stl.html>`_ shows how to deal with stl files and FFD.
60+
- `Turorial 2 <tutorial2iges.html>`_ shows how to deal with iges files and FFD.
61+
- `Turorial 3 <tutorial3unv.html>`_ shows how to deal with unv files and how to set the desired continuity to the geometry using FFD.
62+
- `Turorial 4 <tutorial4rbf.html>`_ shows how to perform RBF interpolation.
4563

4664

4765

pygem/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
2-
__all__ = ['affine', 'filehandler', 'freeform', 'radial', 'openfhandler', 'params', 'stlhandler', 'unvhandler', 'vtkhandler', 'igeshandler', 'utils', 'gui']
1+
__all__ = [
2+
'affine', 'filehandler', 'freeform', 'radial', 'openfhandler', 'params',
3+
'stlhandler', 'unvhandler', 'vtkhandler', 'igeshandler', 'utils', 'gui'
4+
]
35

46
from . import affine
57
from . import freeform

pygem/affine.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,21 @@ def angles2matrix(rot_z=0, rot_y=0, rot_x=0):
4040
if rot_z:
4141
cos = math.cos(rot_z)
4242
sin = math.sin(rot_z)
43-
rot_matrix.append(np.array([cos, -sin, 0, sin, cos, 0, 0, 0, 1]).reshape((3, 3)))
43+
rot_matrix.append(
44+
np.array([cos, -sin, 0, sin, cos, 0, 0, 0, 1]).reshape((3, 3))
45+
)
4446
if rot_y:
4547
cos = math.cos(rot_y)
4648
sin = math.sin(rot_y)
47-
rot_matrix.append(np.array([cos, 0, sin, 0, 1, 0, -sin, 0, cos]).reshape((3, 3)))
49+
rot_matrix.append(
50+
np.array([cos, 0, sin, 0, 1, 0, -sin, 0, cos]).reshape((3, 3))
51+
)
4852
if rot_x:
4953
cos = math.cos(rot_x)
5054
sin = math.sin(rot_x)
51-
rot_matrix.append(np.array([1, 0, 0, 0, cos, -sin, 0, sin, cos]).reshape((3, 3)))
55+
rot_matrix.append(
56+
np.array([1, 0, 0, 0, cos, -sin, 0, sin, cos]).reshape((3, 3))
57+
)
5258
if rot_matrix:
5359
return reduce(np.dot, rot_matrix[::-1])
5460
return np.eye(3)
@@ -96,7 +102,9 @@ def to_reduced_row_echelon_form(matrix):
96102
for i in range(row_count):
97103
if i != r:
98104
lv = matrix[i][lead]
99-
matrix[i] = [iv - lv*rv for rv, iv in zip(matrix[r], matrix[i])]
105+
matrix[i] = [
106+
iv - lv * rv for rv, iv in zip(matrix[r], matrix[i])
107+
]
100108
lead += 1
101109
return matrix
102110

@@ -130,34 +138,36 @@ def affine_points_fit(points_start, points_end):
130138

131139
dim = len(points_start[0])
132140
if len(points_start) < dim:
133-
raise RuntimeError("Too few starting points => under-determined system.")
141+
raise RuntimeError(
142+
"Too few starting points => under-determined system."
143+
)
134144

135145
# Fill an an empty (dim+1) x (dim) matrix
136-
c = [[0.0 for a in range(dim)] for i in range(dim+1)]
146+
c = [[0.0 for a in range(dim)] for i in range(dim + 1)]
137147
for j in range(dim):
138-
for k in range(dim+1):
148+
for k in range(dim + 1):
139149
for i, pnts_i in enumerate(points_start):
140150
qt = list(pnts_i) + [1]
141151
c[k][j] += qt[k] * points_end[i][j]
142152

143153
# Fill an an empty (dim+1) x (dim+1) matrix
144-
Q = [[0.0 for a in range(dim)] + [0] for i in range(dim+1)]
154+
Q = [[0.0 for a in range(dim)] + [0] for i in range(dim + 1)]
145155
for qi in points_start:
146156
qt = list(qi) + [1]
147-
for i in range(dim+1):
148-
for j in range(dim+1):
157+
for i in range(dim + 1):
158+
for j in range(dim + 1):
149159
Q[i][j] += qt[i] * qt[j]
150160

151-
152161
# Augement Q with c and get the reduced row echelon form of the result
153-
affine_matrix = [Q[i] + c[i] for i in range(dim+1)]
162+
affine_matrix = [Q[i] + c[i] for i in range(dim + 1)]
154163

155-
if np.linalg.cond(affine_matrix) < 1/sys.float_info.epsilon:
164+
if np.linalg.cond(affine_matrix) < 1 / sys.float_info.epsilon:
156165
rref_aff_matrix = to_reduced_row_echelon_form(affine_matrix)
157166
rref_aff_matrix = np.array(rref_aff_matrix)
158167
else:
159-
raise RuntimeError("Error: singular matrix. Points are probably coplanar.")
160-
168+
raise RuntimeError(
169+
"Error: singular matrix. Points are probably coplanar."
170+
)
161171

162172
def transform_vector(source):
163173
"""
@@ -171,9 +181,9 @@ def transform_vector(source):
171181
destination = np.zeros(dim)
172182
for i in range(dim):
173183
for j in range(dim):
174-
destination[j] += source[i] * rref_aff_matrix[i][j+dim+1]
184+
destination[j] += source[i] * rref_aff_matrix[i][j + dim + 1]
175185
# Add the last line of the rref
176-
destination[i] += rref_aff_matrix[dim][i+dim+1]
186+
destination[i] += rref_aff_matrix[dim][i + dim + 1]
177187
return destination
178188

179189
return transform_vector

pygem/filehandler.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import os
55

6+
67
class FileHandler(object):
78
"""
89
A base class for file handling.
@@ -12,21 +13,20 @@ class FileHandler(object):
1213
:cvar string extension: extension of the input/output files. It is specific for each
1314
subclass.
1415
"""
16+
1517
def __init__(self):
1618
self.infile = None
1719
self.outfile = None
1820
self.extension = None
1921

20-
2122
def parse(self, *args):
2223
"""
2324
Abstract method to parse a specific file.
2425
2526
Not implemented, it has to be implemented in subclasses.
2627
"""
2728
raise NotImplementedError("Subclass must implement abstract method " \
28-
+ self.__class__.__name__ + ".parse")
29-
29+
+ self.__class__.__name__ + ".parse")
3030

3131
def write(self, *args):
3232
"""
@@ -35,8 +35,7 @@ def write(self, *args):
3535
Not implemented, it has to be implemented in subclasses.
3636
"""
3737
raise NotImplementedError("Subclass must implement abstract method " \
38-
+ self.__class__.__name__ + ".write")
39-
38+
+ self.__class__.__name__ + ".write")
4039

4140
def _check_extension(self, filename):
4241
"""
@@ -47,9 +46,10 @@ def _check_extension(self, filename):
4746
"""
4847
__, file_ext = os.path.splitext(filename)
4948
if not file_ext in self.extension:
50-
raise ValueError('The input file does not have the proper extension. \
51-
It is {0!s}, instead of {1!s}.'.format(file_ext, self.extension))
52-
49+
raise ValueError(
50+
'The input file does not have the proper extension. \
51+
It is {0!s}, instead of {1!s}.'.format(file_ext, self.extension)
52+
)
5353

5454
@staticmethod
5555
def _check_filename_type(filename):
@@ -59,8 +59,9 @@ def _check_filename_type(filename):
5959
:param string filename: file to check.
6060
"""
6161
if not isinstance(filename, basestring):
62-
raise TypeError('The given filename ({0!s}) must be a string'.format(filename))
63-
62+
raise TypeError(
63+
'The given filename ({0!s}) must be a string'.format(filename)
64+
)
6465

6566
@staticmethod
6667
def _check_infile_instantiation(infile):
@@ -72,4 +73,6 @@ def _check_infile_instantiation(infile):
7273
:param string infile: file to check.
7374
"""
7475
if not infile:
75-
raise RuntimeError("You can not write a file without having parsed one.")
76+
raise RuntimeError(
77+
"You can not write a file without having parsed one."
78+
)

0 commit comments

Comments
 (0)