diff --git a/docs/source/code.rst b/docs/source/code.rst index d710bd6e..198197d7 100644 --- a/docs/source/code.rst +++ b/docs/source/code.rst @@ -5,9 +5,11 @@ Code Documentation .. toctree:: :maxdepth: 2 - file_handler - ffd_parameters affine_trans + ffd + ffd_parameters + file_handler + .. automodule:: pygem :members: diff --git a/docs/source/ffd.rst b/docs/source/ffd.rst new file mode 100644 index 00000000..0dba69ba --- /dev/null +++ b/docs/source/ffd.rst @@ -0,0 +1,8 @@ +FFD +================= + +.. automodule:: pygem.ffd + +.. autoclass:: FFD + :members: + :private-members: diff --git a/pygem/affine_trans.py b/pygem/affine_trans.py index 3cc0ac6f..b2afb042 100644 --- a/pygem/affine_trans.py +++ b/pygem/affine_trans.py @@ -60,6 +60,7 @@ def affine_points_fit(points_start, points_end): :Example: >>> import pygem.affine_trans as at + >>> # Example of a rotation >>> p_start = np.array([[1,0,0], [0,1,0], [0,0,1], [0,0,0]]) >>> p_end = np.array([[0,1,0], [-1,0,0], [0,0,1], [0,0,0]]) diff --git a/pygem/ffd.py b/pygem/ffd.py index 9ee9ec06..81574e81 100644 --- a/pygem/ffd.py +++ b/pygem/ffd.py @@ -3,7 +3,6 @@ """ import numpy as np from scipy import special -import pygem.ffd_parameters as ffdp import pygem.affine_trans as at @@ -23,60 +22,63 @@ def perform(self): """ (n_rows_mesh, n_cols_mesh) = self.original_mesh_points.shape - ## translation and then affine transformation - translation = np.array([self.parameters.origin_box_x, self.parameters.origin_box_y, self.parameters.origin_box_z]) + # translation and then affine transformation + translation = self.parameters.origin_box fisical_frame = np.array([self.parameters.position_vertex_1 - translation, \ self.parameters.position_vertex_2 - translation, \ self.parameters.position_vertex_3 - translation, \ - [0,0,0]]) - reference_frame = np.array([[1,0,0], [0,1,0], [0,0,1], [0,0,0]]) + [0, 0, 0]]) + reference_frame = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]]) transformation = at.affine_points_fit(fisical_frame, reference_frame) inverse_transformation = at.affine_points_fit(reference_frame, fisical_frame) - - ## + + # initialization (dim_n_mu, dim_m_mu, dim_t_mu) = self.parameters.array_mu_x.shape bernstein_x = np.zeros((n_rows_mesh, dim_n_mu)) bernstein_y = np.zeros((n_rows_mesh, dim_m_mu)) bernstein_z = np.zeros((n_rows_mesh, dim_t_mu)) shift_mesh_points = np.zeros((n_rows_mesh, n_cols_mesh)) - reference_frame_mesh_points = self._transform_points(self.original_mesh_points - translation, transformation) + reference_frame_mesh_points = self._transform_points(self.original_mesh_points - translation, \ + transformation) - for i in range (0, dim_n_mu): - aux1 = np.power((1-reference_frame_mesh_points[:,0]),dim_n_mu-1-i) - aux2 = np.power(reference_frame_mesh_points[:,0],i) - bernstein_x[:,i] = special.binom(dim_n_mu-1,i) * np.multiply(aux1, aux2) + for i in range(0, dim_n_mu): + aux1 = np.power((1-reference_frame_mesh_points[:, 0]), dim_n_mu-1-i) + aux2 = np.power(reference_frame_mesh_points[:, 0], i) + bernstein_x[:, i] = special.binom(dim_n_mu-1, i) * np.multiply(aux1, aux2) - for i in range (0, dim_m_mu): - aux1 = np.power((1-reference_frame_mesh_points[:,1]),dim_m_mu-1-i) - aux2 = np.power(reference_frame_mesh_points[:,1],i) - bernstein_y[:,i] = special.binom(dim_m_mu-1,i) * np.multiply(aux1, aux2) + for i in range(0, dim_m_mu): + aux1 = np.power((1-reference_frame_mesh_points[:, 1]), dim_m_mu-1-i) + aux2 = np.power(reference_frame_mesh_points[:, 1], i) + bernstein_y[:, i] = special.binom(dim_m_mu-1, i) * np.multiply(aux1, aux2) - for i in range (0, dim_t_mu): - aux1 = np.power((1-reference_frame_mesh_points[:,2]),dim_t_mu-1-i) - aux2 = np.power(reference_frame_mesh_points[:,2],i) - bernstein_z[:,i] = special.binom(dim_t_mu-1,i) * np.multiply(aux1, aux2) + for i in range(0, dim_t_mu): + aux1 = np.power((1-reference_frame_mesh_points[:, 2]), dim_t_mu-1-i) + aux2 = np.power(reference_frame_mesh_points[:, 2], i) + bernstein_z[:, i] = special.binom(dim_t_mu-1, i) * np.multiply(aux1, aux2) - for i in range (0, dim_n_mu): - for j in range (0, dim_m_mu): - for k in range (0, dim_t_mu): - aux = np.multiply(bernstein_x[:,i], np.multiply(bernstein_y[:,j], bernstein_z[:,k])) + for i in range(0, dim_n_mu): + for j in range(0, dim_m_mu): + for k in range(0, dim_t_mu): + aux = np.multiply(bernstein_x[:, i], np.multiply(bernstein_y[:, j], bernstein_z[:, k])) aux_x = aux * self.parameters.array_mu_x[i, j, k] aux_y = aux * self.parameters.array_mu_y[i, j, k] aux_z = aux * self.parameters.array_mu_z[i, j, k] - shift_mesh_points[:,0] += aux_x - shift_mesh_points[:,1] += aux_y - shift_mesh_points[:,2] += aux_z + shift_mesh_points[:, 0] += aux_x + shift_mesh_points[:, 1] += aux_y + shift_mesh_points[:, 2] += aux_z # Splitting points inside and outside the lattice: TODO not very efficient - for i in range (0, n_rows_mesh): - if (reference_frame_mesh_points[i,0] < 0) or (reference_frame_mesh_points[i,1] < 0) or (reference_frame_mesh_points[i,2] < 0) or \ - (reference_frame_mesh_points[i,0] > 1) or (reference_frame_mesh_points[i,1] > 1) or (reference_frame_mesh_points[i,2] > 1): - shift_mesh_points[i,:] = 0 + for i in range(0, n_rows_mesh): + if (reference_frame_mesh_points[i, 0] < 0) or (reference_frame_mesh_points[i, 1] < 0) \ + or (reference_frame_mesh_points[i, 2] < 0) or (reference_frame_mesh_points[i, 0] > 1) \ + or (reference_frame_mesh_points[i, 1] > 1) or (reference_frame_mesh_points[i, 2] > 1): + shift_mesh_points[i, :] = 0 - return self._transform_points(shift_mesh_points + reference_frame_mesh_points, inverse_transformation) + translation + return self._transform_points(shift_mesh_points + reference_frame_mesh_points, \ + inverse_transformation) + translation def _transform_points(self, original_points, transformation): @@ -88,6 +90,6 @@ def _transform_points(self, original_points, transformation): for i in range(0, n_rows_mesh): single_point = original_points[i] - modified_points[i,:] = transformation(single_point) + modified_points[i, :] = transformation(single_point) return modified_points diff --git a/pygem/ffd_parameters.py b/pygem/ffd_parameters.py index 2960b0c3..7b902d47 100644 --- a/pygem/ffd_parameters.py +++ b/pygem/ffd_parameters.py @@ -1,5 +1,5 @@ """ -Utilities for reading and writing parameters. +Utilities for reading and writing parameters files to perform the Free Form Deformation (FFD) """ import os import numpy as np @@ -11,23 +11,25 @@ class FFDParameters(object): Class that handle the Free Form Deformation parameters in terms of FFD bounding box and weight of the FFD control points. - :param list n_control_points: number of control points in direction (x, y, z). Default value (1, 1, 1). + :param list n_control_points: number of control points in the x, y, and z direction. + If not provided it is set to [1, 1, 1]. - :cvar float length_box_x: length of the FFD bounding box in the x direction (local coordinate system). - :cvar float length_box_y: length of the FFD bounding box in the y direction (local coordinate system). - :cvar float length_box_z: length of the FFD bounding box in the z direction (local coordinate system). + :cvar float length_box_x: length of the FFD bounding box in the x direction + (local coordinate system). + :cvar float length_box_y: length of the FFD bounding box in the y direction + (local coordinate system). + :cvar float length_box_z: length of the FFD bounding box in the z direction + (local coordinate system). - :cvar float origin_box_x: x coordinate of the origin of the FFD bounding box. - :cvar float origin_box_y: y coordinate of the origin of the FFD bounding box. - :cvar float origin_box_z: z coordinate of the origin of the FFD bounding box. + :cvar numpy.ndarray origin_box: a 3-by-1 vector of float numbers representing the x, y and z + coordinates of the origin of the FFD bounding box. :cvar float rot_angle_x: rotation angle around x axis of the FFD bounding box. :cvar float rot_angle_y: rotation angle around y axis of the FFD bounding box. :cvar float rot_angle_z: rotation angle around z axis of the FFD bounding box. - :cvar int n_control_points_x: number of control points in direction x. - :cvar int n_control_points_y: number of control points in direction y. - :cvar int n_control_points_z: number of control points in direction z. + :cvar list n_control_points: list of 3 int representing the number of control points in the + x, y, and z direction. :cvar numpy.ndarray array_mu_x: weights of control points in direction x. :cvar numpy.ndarray array_mu_y: weights of control points in direction y. @@ -36,9 +38,11 @@ class FFDParameters(object): :cvar numpy.ndarray psi_mapping: map from the pysical domain to the reference domain. :cvar numpy.ndarray inv_psi_mapping: map from the reference domain to the physical domain. - :cvar numpy.ndarray rotation_matrix: rotation matrix (according to rot_angle_x, rot_angle_y, rot_angle_z). + :cvar numpy.ndarray rotation_matrix: rotation matrix (according to rot_angle_x, + rot_angle_y, rot_angle_z). :cvar numpy.ndarray position_vertex_0: position of the first vertex of the FFD bounding box. + It is always equal to the member `origin_box`. :cvar numpy.ndarray position_vertex_1: position of the second vertex of the FFD bounding box. :cvar numpy.ndarray position_vertex_2: position of the third vertex of the FFD bounding box. :cvar numpy.ndarray position_vertex_3: position of the fourth vertex of the FFD bounding box. @@ -46,42 +50,57 @@ class FFDParameters(object): .. note:: Four vertex (non coplanar) are sufficient to uniquely identify a parallelepiped. If the four vertex are coplanar, an assert is thrown when affine_points_fit is used. + + + :Example: + + >>> import pygem.ffd_parameters as ffdp + + >>> # Reading an existing file + >>> params1 = ffdp.FFDParameters() + >>> params1.read_parameters_file(filename='tests/test_datasets/parameters_test_ffd_identity.prm') + + >>> # Creating a defaul paramters file with the right dimensions (if the file does not exists + >>> # it is created with that name). So it is possible to manually edit it and read it again. + >>> params2 = ffdp.FFDParameters(n_control_points=[2, 3, 2]) + >>> params2.read_parameters_file(filename='parameters_test.prm') """ - def __init__(self, n_control_points=[1, 1, 1]): + def __init__(self, n_control_points=None): self.conversion_unit = 1. self.lenght_box_x = 1. self.lenght_box_y = 1. self.lenght_box_z = 1. - self.origin_box_x = 0. - self.origin_box_y = 0. - self.origin_box_z = 0. + self.origin_box = np.array([0., 0., 0.]) self.rot_angle_x = 0. self.rot_angle_y = 0. self.rot_angle_z = 0. - self.n_control_points_x = n_control_points[0] - self.n_control_points_y = n_control_points[1] - self.n_control_points_z = n_control_points[2] + if n_control_points is None: + n_control_points = [1, 1, 1] + self.n_control_points = n_control_points - self.array_mu_x = np.zeros((self.n_control_points_x+1, self.n_control_points_y+1, self.n_control_points_z+1)) - self.array_mu_y = np.zeros((self.n_control_points_x+1, self.n_control_points_y+1, self.n_control_points_z+1)) - self.array_mu_z = np.zeros((self.n_control_points_x+1, self.n_control_points_y+1, self.n_control_points_z+1)) + self.array_mu_x = np.zeros((self.n_control_points[0]+1, self.n_control_points[1]+1, \ + self.n_control_points[2]+1)) + self.array_mu_y = np.zeros((self.n_control_points[0]+1, self.n_control_points[1]+1, \ + self.n_control_points[2]+1)) + self.array_mu_z = np.zeros((self.n_control_points[0]+1, self.n_control_points[1]+1, \ + self.n_control_points[2]+1)) self.psi_mapping = np.diag([1./self.lenght_box_x, 1./self.lenght_box_y, 1./self.lenght_box_z]) self.inv_psi_mapping = np.diag([self.lenght_box_x, self.lenght_box_y, self.lenght_box_z]) self.rotation_matrix = np.eye(3) - self.position_vertex_0 = np.zeros(3) - self.position_vertex_1 = np.zeros(3) - self.position_vertex_2 = np.zeros(3) - self.position_vertex_3 = np.zeros(3) + self.position_vertex_0 = self.origin_box + self.position_vertex_1 = np.array([1., 0., 0.]) + self.position_vertex_2 = np.array([0., 1., 0.]) + self.position_vertex_3 = np.array([0., 0., 1.]) - def read_parameters_file(self, filename='parameters.prm'): + def read_parameters_file(self, filename=None): """ .. todo:: @@ -90,6 +109,9 @@ def read_parameters_file(self, filename='parameters.prm'): if not isinstance(filename, basestring): raise TypeError("filename must be a string") + if filename is None: + filename = 'parameters.prm' + # Checks if the parameters file exists. If not it writes the default class into filename. if not os.path.isfile(filename): self.write_parameters_file(filename) @@ -109,12 +131,12 @@ def read_parameters_file(self, filename='parameters.prm'): self.array_mu_z[int(values[0])][int(values[1])][int(values[2])] = float(values[3]) if line.strip() == 'mu_x:': found_x = True - self.array_mu_x = np.zeros((self.n_control_points_x+1, self.n_control_points_y+1, \ - self.n_control_points_z+1)) - self.array_mu_y = np.zeros((self.n_control_points_x+1, self.n_control_points_y+1, \ - self.n_control_points_z+1)) - self.array_mu_z = np.zeros((self.n_control_points_x+1, self.n_control_points_y+1, \ - self.n_control_points_z+1)) + self.array_mu_x = np.zeros((self.n_control_points[0]+1, self.n_control_points[1]+1, \ + self.n_control_points[2]+1)) + self.array_mu_y = np.zeros((self.n_control_points[0]+1, self.n_control_points[1]+1, \ + self.n_control_points[2]+1)) + self.array_mu_z = np.zeros((self.n_control_points[0]+1, self.n_control_points[1]+1, \ + self.n_control_points[2]+1)) elif line.strip() == 'mu_y:': found_y = True found_x = False @@ -124,11 +146,11 @@ def read_parameters_file(self, filename='parameters.prm'): else: for spl in line.split(): if spl == 'n_control_points_x:': - self.n_control_points_x = int(line.strip(spl)) + self.n_control_points[0] = int(line.strip(spl)) if spl == 'n_control_points_y:': - self.n_control_points_y = int(line.strip(spl)) + self.n_control_points[1] = int(line.strip(spl)) if spl == 'n_control_points_z:': - self.n_control_points_z = int(line.strip(spl)) + self.n_control_points[2] = int(line.strip(spl)) if spl == 'lenght_box_x:': self.lenght_box_x = float(line.strip(spl)) if spl == 'lenght_box_y:': @@ -136,11 +158,11 @@ def read_parameters_file(self, filename='parameters.prm'): if spl == 'lenght_box_z:': self.lenght_box_z = float(line.strip(spl)) if spl == 'origin_box_x:': - self.origin_box_x = float(line.strip(spl)) + self.origin_box[0] = float(line.strip(spl)) if spl == 'origin_box_y:': - self.origin_box_y = float(line.strip(spl)) + self.origin_box[1] = float(line.strip(spl)) if spl == 'origin_box_z:': - self.origin_box_z = float(line.strip(spl)) + self.origin_box[2] = float(line.strip(spl)) if spl == 'rot_angle_x:': self.rot_angle_x = float(line.strip(spl)) if spl == 'rot_angle_y:': @@ -151,7 +173,7 @@ def read_parameters_file(self, filename='parameters.prm'): self.rotation_matrix = at.angles2matrix(self.rot_angle_z*np.pi/180, \ self.rot_angle_y*np.pi/180, self.rot_angle_x*np.pi/180) - self.position_vertex_0 = np.array([self.origin_box_x, self.origin_box_y, self.origin_box_z]) + self.position_vertex_0 = self.origin_box self.position_vertex_1 = self.position_vertex_0 + \ np.dot(self.rotation_matrix, [self.lenght_box_x, 0, 0]) self.position_vertex_2 = self.position_vertex_0 + \ @@ -163,48 +185,51 @@ def read_parameters_file(self, filename='parameters.prm'): self.inv_psi_mapping = np.diag([self.lenght_box_x, self.lenght_box_y, self.lenght_box_z]) - def write_parameters_file(self, filename='parameters.prm'): + def write_parameters_file(self, filename=None): """ - Writes a parameters file called filename and fills it with - the parameters class. + This method writes a parameters file (.prm) called `filename` and fills it with all + the parameters class members. .. todo:: document better """ + if filename is None: + filename = 'parameters.prm' + with open(filename, 'w') as output_file: - output_file.write('\nn_control_points_x: ' + str(self.n_control_points_x) + '\n') - output_file.write('n_control_points_y: ' + str(self.n_control_points_y) + '\n') - output_file.write('n_control_points_z: ' + str(self.n_control_points_z) + '\n') + output_file.write('\nn_control_points_x: ' + str(self.n_control_points[0]) + '\n') + output_file.write('n_control_points_y: ' + str(self.n_control_points[1]) + '\n') + output_file.write('n_control_points_z: ' + str(self.n_control_points[2]) + '\n') output_file.write('\nlenght_box_x: ' + str(self.lenght_box_x) + '\n') output_file.write('lenght_box_y: ' + str(self.lenght_box_y) + '\n') output_file.write('lenght_box_z: ' + str(self.lenght_box_z) + '\n') - output_file.write('\norigin_box_x: ' + str(self.origin_box_x) + '\n') - output_file.write('origin_box_y: ' + str(self.origin_box_y) + '\n') - output_file.write('origin_box_z: ' + str(self.origin_box_z) + '\n') + output_file.write('\norigin_box_x: ' + str(self.origin_box[0]) + '\n') + output_file.write('origin_box_y: ' + str(self.origin_box[1]) + '\n') + output_file.write('origin_box_z: ' + str(self.origin_box[2]) + '\n') output_file.write('\nrot_angle_x: ' + str(self.rot_angle_x) + '\n') output_file.write('rot_angle_y: ' + str(self.rot_angle_y) + '\n') output_file.write('rot_angle_z: ' + str(self.rot_angle_z) + '\n') output_file.write('\nmu_x:\n') - for i in range(0, self.n_control_points_x + 1): - for j in range(0, self.n_control_points_y + 1): - for k in range(0, self.n_control_points_z + 1): + for i in range(0, self.n_control_points[0] + 1): + for j in range(0, self.n_control_points[1] + 1): + for k in range(0, self.n_control_points[2] + 1): output_file.write(str(i) + ' ' + str(j) + ' ' + str(k) + \ ' ' + str(self.array_mu_x[i][j][k]) + '\n') output_file.write('\nmu_y:\n') - for i in range(0, self.n_control_points_x + 1): - for j in range(0, self.n_control_points_y + 1): - for k in range(0, self.n_control_points_z + 1): + for i in range(0, self.n_control_points[0] + 1): + for j in range(0, self.n_control_points[1] + 1): + for k in range(0, self.n_control_points[2] + 1): output_file.write(str(i) + ' ' + str(j) + ' ' + str(k) + \ ' ' + str(self.array_mu_y[i][j][k]) + '\n') output_file.write('\nmu_z:\n') - for i in range(0, self.n_control_points_x + 1): - for j in range(0, self.n_control_points_y + 1): - for k in range(0, self.n_control_points_z + 1): + for i in range(0, self.n_control_points[0] + 1): + for j in range(0, self.n_control_points[1] + 1): + for k in range(0, self.n_control_points[2] + 1): output_file.write(str(i) + ' ' + str(j) + ' ' + str(k) + \ ' ' + str(self.array_mu_z[i][j][k]) + '\n') @@ -217,12 +242,8 @@ def print_info(self): print '(lenght_box_x, lenght_box_y, lenght_box_z) = (' + str(self.lenght_box_x) + \ ', ' + str(self.lenght_box_y) + ', ' + \ str(self.lenght_box_z) + ')' - print '(origin_box_x, origin_box_y, origin_box_z) = (' + str(self.origin_box_x) + \ - ', ' + str(self.origin_box_y) + ', ' + \ - str(self.origin_box_z) + ')' - print '(n_control_points_x, n_control_points_y, n_control_points_z) = (' + \ - str(self.n_control_points_x) + ', ' + str(self.n_control_points_y) + ', ' + \ - str(self.n_control_points_z) + ')' + print 'origin_box = ' + str(self.origin_box) + print 'n_control_points = ' + str(self.n_control_points) print '(rot_angle_x, rot_angle_y, rot_angle_z) = (' + str(self.rot_angle_x) + \ ', ' + str(self.rot_angle_y) + ', ' + \ str(self.rot_angle_z) + ')' diff --git a/tests/test_datasets/parameters_test_ffd_1.prm b/tests/test_datasets/parameters_test_ffd_identity.prm similarity index 100% rename from tests/test_datasets/parameters_test_ffd_1.prm rename to tests/test_datasets/parameters_test_ffd_identity.prm diff --git a/tests/test_datasets/parameters_test_ffd_2.prm b/tests/test_datasets/parameters_test_ffd_sphere.prm similarity index 100% rename from tests/test_datasets/parameters_test_ffd_2.prm rename to tests/test_datasets/parameters_test_ffd_sphere.prm diff --git a/tests/test_ffd.py b/tests/test_ffd.py index eaeddf59..29075c1c 100644 --- a/tests/test_ffd.py +++ b/tests/test_ffd.py @@ -11,9 +11,9 @@ class TestFFD(TestCase): - def test_ffd_1(self): + def test_ffd_identity(self): params = ffdp.FFDParameters() - params.read_parameters_file(filename='tests/test_datasets/parameters_test_ffd_1.prm') + params.read_parameters_file(filename='tests/test_datasets/parameters_test_ffd_identity.prm') mesh_points = np.load('tests/test_datasets/meshpoints_sphere_orig.npy') free_form = ffd.FFD(params, mesh_points) mesh_points_test = free_form.perform() @@ -21,9 +21,9 @@ def test_ffd_1(self): np.testing.assert_array_almost_equal(mesh_points_test, mesh_points) - def test_ffd_2(self): + def test_ffd_sphere_mod(self): params = ffdp.FFDParameters() - params.read_parameters_file(filename='tests/test_datasets/parameters_test_ffd_2.prm') + params.read_parameters_file(filename='tests/test_datasets/parameters_test_ffd_sphere.prm') mesh_points = np.load('tests/test_datasets/meshpoints_sphere_orig.npy') mesh_points_ref = np.load('tests/test_datasets/meshpoints_sphere_mod.npy') free_form = ffd.FFD(params, mesh_points) diff --git a/tests/test_ffd_parameters.py b/tests/test_ffd_parameters.py index d5ccae53..05716949 100644 --- a/tests/test_ffd_parameters.py +++ b/tests/test_ffd_parameters.py @@ -10,19 +10,9 @@ class TestFFDParameters(TestCase): - def test_class_members_default_n_control_points_x(self): + def test_class_members_default_n_control_points(self): params = ffdp.FFDParameters() - assert params.n_control_points_x == 1 - - - def test_class_members_default_n_control_points_y(self): - params = ffdp.FFDParameters() - assert params.n_control_points_y == 1 - - - def test_class_members_default_n_control_points_z(self): - params = ffdp.FFDParameters() - assert params.n_control_points_z == 1 + assert params.n_control_points == [1, 1, 1] def test_class_members_default_conversion_unit(self): @@ -45,19 +35,9 @@ def test_class_members_default_lenght_box_z(self): assert params.lenght_box_z == 1. - def test_class_members_default_origin_box_x(self): + def test_class_members_default_origin_box(self): params = ffdp.FFDParameters() - assert params.origin_box_x == 0. - - - def test_class_members_default_origin_box_y(self): - params = ffdp.FFDParameters() - assert params.origin_box_y == 0. - - - def test_class_members_default_origin_box_z(self): - params = ffdp.FFDParameters() - assert params.origin_box_z == 0. + np.testing.assert_array_almost_equal(params.origin_box, np.zeros(3)) def test_class_members_default_rot_angle_x(self): @@ -112,32 +92,22 @@ def test_class_members_default_position_vertex_0(self): def test_class_members_default_position_vertex_1(self): params = ffdp.FFDParameters() - np.testing.assert_array_almost_equal(params.position_vertex_1, np.zeros(3)) + np.testing.assert_array_almost_equal(params.position_vertex_1, np.array([1., 0., 0.])) def test_class_members_default_position_vertex_2(self): params = ffdp.FFDParameters() - np.testing.assert_array_almost_equal(params.position_vertex_2, np.zeros(3)) + np.testing.assert_array_almost_equal(params.position_vertex_2, np.array([0., 1., 0.])) def test_class_members_default_position_vertex_3(self): params = ffdp.FFDParameters() - np.testing.assert_array_almost_equal(params.position_vertex_3, np.zeros(3)) - - - def test_class_members_generic_n_control_points_x(self): - params = ffdp.FFDParameters([2, 3, 5]) - assert params.n_control_points_x == 2 + np.testing.assert_array_almost_equal(params.position_vertex_3, np.array([0., 0., 1.])) - def test_class_members_generic_n_control_points_y(self): + def test_class_members_generic_n_control_points(self): params = ffdp.FFDParameters([2, 3, 5]) - assert params.n_control_points_y == 3 - - - def test_class_members_generic_n_control_points_z(self): - params = ffdp.FFDParameters([2, 3, 5]) - assert params.n_control_points_z == 5 + assert params.n_control_points == [2, 3, 5] def test_class_members_generic_array_mu_x(self): @@ -161,22 +131,10 @@ def test_read_parameters_file_conversion_unit(self): assert params.conversion_unit == 1. - def test_read_parameters_file_n_control_points_x(self): - params = ffdp.FFDParameters([2, 1, 1]) - params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') - assert params.n_control_points_x == 2 - - - def test_read_parameters_file_n_control_points_y(self): + def test_read_parameters_file_n_control_points(self): params = ffdp.FFDParameters([2, 1, 1]) params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') - assert params.n_control_points_y == 1 - - - def test_read_parameters_file_n_control_points_z(self): - params = ffdp.FFDParameters([2, 1, 1]) - params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') - assert params.n_control_points_z == 1 + assert params.n_control_points == [2, 1, 1] def test_read_parameters_file_lenght_box_x(self): @@ -197,22 +155,11 @@ def test_read_parameters_file_lenght_box_z(self): assert params.lenght_box_z == 90.0 - def test_read_parameters_file_origin_box_x(self): + def test_read_parameters_file_origin_box(self): params = ffdp.FFDParameters([2, 1, 1]) params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') - assert params.origin_box_x == -20.0 - - - def test_read_parameters_file_origin_box_y(self): - params = ffdp.FFDParameters([2, 1, 1]) - params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') - assert params.origin_box_y == -55.0 - - - def test_read_parameters_file_origin_box_z(self): - params = ffdp.FFDParameters([2, 1, 1]) - params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') - assert params.origin_box_z == -45.0 + origin_box_exact = np.array([-20.0, -55.0, -45.0]) + np.testing.assert_array_almost_equal(params.origin_box, origin_box_exact) def test_read_parameters_file_rot_angle_x(self): @@ -276,6 +223,12 @@ def test_read_parameters_file_rotation_matrix(self): np.testing.assert_array_almost_equal(params.rotation_matrix, rotation_matrix_exact) + def test_read_parameters_file_position_vertex_0_origin(self): + params = ffdp.FFDParameters([2, 1, 1]) + params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') + np.testing.assert_array_almost_equal(params.position_vertex_0, params.origin_box) + + def test_read_parameters_file_position_vertex_0(self): params = ffdp.FFDParameters([2, 1, 1]) params.read_parameters_file('tests/test_datasets/parameters_sphere.prm') diff --git a/tests/test_file_handler.py b/tests/test_file_handler.py index 48439e3f..1a942f46 100644 --- a/tests/test_file_handler.py +++ b/tests/test_file_handler.py @@ -10,9 +10,13 @@ class TestFileHandler(TestCase): - def test_base_class_members(self): + def test_base_class_filename(self): file_handler = fh.FileHandler() assert file_handler.filename == None + + + def test_base_class_extension(self): + file_handler = fh.FileHandler() assert file_handler.extension == None