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
2 changes: 1 addition & 1 deletion code_formatter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ done
# Find all python files in code directories
python_files=""
for dir in $code_directories; do
python_files="$python_files `ls $dir/*.py`"
python_files="$python_files $(find $dir -name '*.py')"
done
[[ $# != 0 ]] && python_files=$@

Expand Down
17 changes: 9 additions & 8 deletions pygem/params/ffdparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def position_vertices(self):
:rtype: numpy.ndarray
"""
return self.origin_box + np.vstack([
np.zeros((1, 3)),
np.zeros((1, 3)),
self.rotation_matrix.dot(np.diag(self.lenght_box)).T
])

Expand Down Expand Up @@ -330,16 +330,17 @@ def save(self, filename, write_deformed=True):

if write_deformed:
box_points = np.array([
lattice_x_coords.ravel() + self.array_mu_x.ravel() *
self.lenght_box[0],
lattice_y_coords.ravel() + self.array_mu_y.ravel() *
self.lenght_box[1],
lattice_z_coords.ravel() + self.array_mu_z.ravel() *
self.lenght_box[2]
lattice_x_coords.ravel() +
self.array_mu_x.ravel() * self.lenght_box[0],
lattice_y_coords.ravel() +
self.array_mu_y.ravel() * self.lenght_box[1],
lattice_z_coords.ravel() +
self.array_mu_z.ravel() * self.lenght_box[2]
])
else:
box_points = np.array([
lattice_x_coords.ravel(), lattice_y_coords.ravel(),
lattice_x_coords.ravel(),
lattice_y_coords.ravel(),
lattice_z_coords.ravel()
])

Expand Down
32 changes: 10 additions & 22 deletions pygem/params/rbfparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np


class RBFParameters(object):
"""
Class that handles the Radial Basis Functions parameters in terms of RBF
Expand Down Expand Up @@ -41,24 +42,12 @@ def __init__(self):
self.basis = 'gaussian_spline'
self.radius = 0.5
self.power = 2
self.original_control_points = np.array([
[0., 0., 0.],
[0., 0., 1.],
[0., 1., 0.],
[1., 0., 0.],
[0., 1., 1.],
[1., 0., 1.],
[1., 1., 0.],
[1., 1., 1.]])
self.deformed_control_points = np.array([
[0., 0., 0.],
[0., 0., 1.],
[0., 1., 0.],
[1., 0., 0.],
[0., 1., 1.],
[1., 0., 1.],
[1., 1., 0.],
[1., 1., 1.]])
self.original_control_points = np.array(
[[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.],
[0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]])
self.deformed_control_points = np.array(
[[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.],
[0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]])

@property
def n_control_points(self):
Expand Down Expand Up @@ -108,9 +97,9 @@ def read_parameters(self, filename='parameters_rbf.prm'):

if len(lines) != self.n_control_points:
raise TypeError("The number of control points must be equal both in"
"the 'original control points' and in the 'deformed"
"control points' section of the parameters file"
"({0!s})".format(filename))
"the 'original control points' and in the 'deformed"
"control points' section of the parameters file"
"({0!s})".format(filename))

self.deformed_control_points = np.zeros((self.n_control_points, 3))
for line, i in zip(lines, list(range(0, self.n_control_points))):
Expand Down Expand Up @@ -233,4 +222,3 @@ def save(self, filename, write_deformed=True):
else:
writer.SetInputData(data)
writer.Write()

34 changes: 10 additions & 24 deletions tests/test_ffdparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ def test_class_members_default_rotation_matrix(self):

def test_class_members_default_position_vertices(self):
params = FFDParameters()
expected_matrix = np.array([
[0., 0., 0.],
[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]
])
expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
[0., 0., 1.]])
np.testing.assert_array_almost_equal(params.position_vertices,
expected_matrix)

Expand Down Expand Up @@ -177,12 +173,10 @@ def test_read_parameters_position_vertex_0_origin(self):
def test_read_parameters_position_vertex_0(self):
params = FFDParameters(n_control_points=[3, 2, 2])
params.read_parameters('tests/test_datasets/parameters_sphere.prm')
position_vertices = np.array([
[-20.0, -55.0, -45.0],
[24.17322326, -52.02107006, -53.05309404],
[-20., 29.41000412, -13.77579136],
[-2.82719042, -85.65053198, 37.85915459]
])
position_vertices = np.array(
[[-20.0, -55.0, -45.0], [24.17322326, -52.02107006, -53.05309404],
[-20., 29.41000412,
-13.77579136], [-2.82719042, -85.65053198, 37.85915459]])

np.testing.assert_array_almost_equal(params.position_vertices,
position_vertices)
Expand Down Expand Up @@ -260,22 +254,14 @@ def test_build_bounding_box_2(self):
params = FFDParameters()
params.build_bounding_box(cube)

expected_matrix = np.array([
[0., 0., 0.],
[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]
])
expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
[0., 0., 1.]])
np.testing.assert_almost_equal(
params.position_vertices, expected_matrix, decimal=5)

def test_set_position_of_vertices(self):
expected_matrix = np.array([
[0., 0., 0.],
[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]
])
expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
[0., 0., 1.]])
tops = np.array([1., 1., 1.])
params = FFDParameters()
params.origin_box = expected_matrix[0]
Expand Down
12 changes: 3 additions & 9 deletions tests/test_rbfparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@

from pygem import RBFParameters

unit_cube = np.array([
[0., 0., 0.],
[0., 0., 1.],
[0., 1., 0.],
[1., 0., 0.],
[0., 1., 1.],
[1., 0., 1.],
[1., 1., 0.],
[1., 1., 1.]])
unit_cube = np.array([[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.],
[0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]])


class TestRBFParameters(TestCase):
def test_class_members_default_basis(self):
Expand Down