Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pygem/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
__all__ = ["affine_trans", "ffd_parameters", "file_handler", "free_form"]

__all__ = ['affine', 'params', 'filehandler', 'freeform']

from . import affine
from . import params
from . import filehandler
from . import freeform
4 changes: 2 additions & 2 deletions pygem/affine_trans.py → pygem/affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def angles2matrix(rot_z=0, rot_y=0, rot_x=0):

:Example:

>>> import pygem.affine_trans as at
>>> import pygem.affine as at
>>> import numpy as np

>>> # Example of a rotation around x, y, z axis
Expand Down Expand Up @@ -118,7 +118,7 @@ def affine_points_fit(points_start, points_end):

:Example:

>>> import pygem.affine_trans as at
>>> import pygem.affine as at

>>> # Example of a rotation (affine transformation)
>>> p_start = np.array([[1,0,0], [0,1,0], [0,0,1], [0,0,0]])
Expand Down
30 changes: 14 additions & 16 deletions pygem/file_handler.py → pygem/filehandler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Utilities for reading and writing different CAD files.
"""
import os
import numpy as np
from mpl_toolkits import mplot3d
from matplotlib import pyplot
Expand Down Expand Up @@ -52,7 +53,7 @@ class UnvHandler(FileHandler):
"""
def __init__(self):
super(UnvHandler, self).__init__()
self.extension = 'unv'
self.extension = '.unv'


def parse(self, filename):
Expand Down Expand Up @@ -155,7 +156,7 @@ class VtkHandler(FileHandler):
"""
def __init__(self):
super(VtkHandler, self).__init__()
self.extension = 'vtk'
self.extension = '.vtk'


def parse(self, filename):
Expand Down Expand Up @@ -215,22 +216,22 @@ def write(self, mesh_points, filename):
reader.ReadAllScalarsOn()
reader.Update()
data = reader.GetOutput()

points = vtk.vtkPoints()

for i in range(data.GetNumberOfPoints()):
points.InsertNextPoint(mesh_points[i,:])
points.InsertNextPoint(mesh_points[i, :])

data.SetPoints(points)

writer = vtk.vtkDataSetWriter()
writer.SetFileName(self.outfile)

if vtk.VTK_MAJOR_VERSION <= 5:
writer.SetInput(data)
else:
writer.SetInputData(data)

writer.Write()


Expand All @@ -242,7 +243,7 @@ class StlHandler(FileHandler):
"""
def __init__(self):
super(StlHandler, self).__init__()
self.extension = 'stl'
self.extension = '.stl'


def parse(self, filename):
Expand Down Expand Up @@ -423,13 +424,10 @@ def _check_extension(filename, extension):
:param string filename: file to check.
:param string extension: file extension to check.
"""
file_ext = filename.split('.')[-1].lower()
# to manage the case of open foam (no extension) the following check is needed
if file_ext == filename.lower():
pass
elif not file_ext == extension:
__, file_ext = os.path.splitext(filename)
if not file_ext == extension:
raise ValueError('The input file does not have the proper extension. \
It should be %s.' % extension)
It is %s, instead of %s.' % (file_ext, extension))


def _check_filename_type(filename):
Expand Down
6 changes: 3 additions & 3 deletions pygem/free_form.py → pygem/freeform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import numpy as np
from scipy import special
import pygem.affine_trans as at
import pygem.affine as at


class FFD(object):
Expand All @@ -21,8 +21,8 @@ class FFD(object):

:Example:

>>> import pygem.free_form as ffd
>>> import pygem.ffd_parameters as ffdp
>>> import pygem.freeform as ffd
>>> import pygem.params as ffdp
>>> import numpy as np

>>> ffd_parameters = ffdp.FFDParameters()
Expand Down
4 changes: 2 additions & 2 deletions pygem/ffd_parameters.py → pygem/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import os
import numpy as np
import pygem.affine_trans as at
import pygem.affine as at


class FFDParameters(object):
Expand Down Expand Up @@ -49,7 +49,7 @@ class FFDParameters(object):

:Example:

>>> import pygem.ffd_parameters as ffdp
>>> import pygem.params as ffdp

>>> # Reading an existing file
>>> params1 = ffdp.FFDParameters()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_affine_trans.py → tests/test_affine.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

from unittest import TestCase
import unittest
import pygem.affine_trans as at
import pygem.affine as at
import numpy as np


class TestAffineTrans(TestCase):
class TestAffine(TestCase):


def test_angles2matrix_rot_default(self):
Expand Down
32 changes: 22 additions & 10 deletions tests/test_file_handler.py → tests/test_filehandler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

from unittest import TestCase
import unittest
import pygem.file_handler as fh
import pygem.filehandler as fh
import numpy as np
import filecmp
import os


class TestFileHandler(TestCase):
class TestFilehandler(TestCase):


def test_base_class_infile(self):
Expand Down Expand Up @@ -38,7 +38,10 @@ def test_base_class_write(self):
file_handler.write(mesh_points, 'output')


# UNV tests

class TestUnvHandler(TestCase):


def test_unv_instantiation(self):
unv_handler = fh.UnvHandler()

Expand All @@ -55,7 +58,7 @@ def test_unv_default_outfile_member(self):

def test_unv_default_extension_member(self):
unv_handler = fh.UnvHandler()
assert unv_handler.extension == 'unv'
assert unv_handler.extension == '.unv'


def test_unv_parse_failing_filename_type(self):
Expand Down Expand Up @@ -159,8 +162,11 @@ def test_unv_write_comparison(self):
self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
os.remove(outfilename)


# VTK tests


class TestVtkHandler(TestCase):


def test_vtk_instantiation(self):
vtk_handler = fh.VtkHandler()

Expand All @@ -177,7 +183,7 @@ def test_vtk_default_outfile_member(self):

def test_vtk_default_extension_member(self):
vtk_handler = fh.VtkHandler()
assert vtk_handler.extension == 'vtk'
assert vtk_handler.extension == '.vtk'


def test_vtk_parse_failing_filename_type(self):
Expand Down Expand Up @@ -286,7 +292,10 @@ def test_vtk_write_comparison(self):
os.remove(outfilename)


# STL tests

class TestStlHandler(TestCase):


def test_stl_instantiation(self):
stl_handler = fh.StlHandler()

Expand All @@ -303,7 +312,7 @@ def test_stl_default_outfile_member(self):

def test_stl_default_extension_member(self):
stl_handler = fh.StlHandler()
assert stl_handler.extension == 'stl'
assert stl_handler.extension == '.stl'


def test_stl_parse_failing_filename_type(self):
Expand Down Expand Up @@ -427,7 +436,10 @@ def test_stl_plot_failing_outfile_type(self):
stl_handler.plot(plot_file=3)


# openFOAM tests

class TestOpenFoamHandler(TestCase):


def test_open_foam_instantiation(self):
open_foam_handler = fh.OpenFoamHandler()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_free_form.py → tests/test_freeform.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

from unittest import TestCase
import unittest
import pygem.free_form as ffd
import pygem.ffd_parameters as ffdp
import pygem.freeform as ffd
import pygem.params as ffdp
import numpy as np



class TestFFD(TestCase):
class TestFreeform(TestCase):


def test_ffd_parameters_member(self):
Expand Down
39 changes: 39 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

from unittest import TestCase
import unittest
import pkgutil
from os import walk
from os import path


class TestPackage(TestCase):


def test_modules_name(self):
import pygem
package = pygem
mod = ['__init__.py']
for __, modname, __ in pkgutil.iter_modules(package.__path__):
mod.append(modname + '.py')

f_aux = []
for (__, __, filenames) in walk('pygem'):
f_aux.extend(filenames)

f = []
for i in f_aux:
__, file_ext = path.splitext(i)
if file_ext == '.py':
f.append(i)

self.assertItemsEqual(mod, f)


def test_import_pg_1(self):
import pygem as pg
params = pg.params.FFDParameters()


def test_import_pg_2(self):
import pygem as pg
mat = pg.affine.angles2matrix(2)
2 changes: 1 addition & 1 deletion tests/test_ffd_parameters.py → tests/test_params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from unittest import TestCase
import unittest
import pygem.ffd_parameters as ffdp
import pygem.params as ffdp
import numpy as np
import filecmp
import os
Expand Down