Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Commit

Permalink
fixed bug in hmatrix z vector calculation, added unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
ferchault committed Jun 8, 2015
1 parent 268107c commit 9f21946
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/euston/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def abc_to_hmatrix(a, b, c, alpha, beta, gamma, degrees=True):
a = np.array((a, 0, 0))
b = b*np.array((math.cos(gamma), math.sin(gamma),0))
bracket = (math.cos(alpha)-math.cos(beta)*math.cos(gamma))/math.sin(gamma)
c = c*np.array((math.cos(beta), bracket, math.sin(beta)**2-bracket**2))
c = c*np.array((math.cos(beta), bracket, math.sqrt(math.sin(beta)**2-bracket**2)))

result[:, 0] = a
result[:, 1] = b
Expand Down
19 changes: 9 additions & 10 deletions tests/data/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ def test_anglebetween(self):
self.assertEqual(0, np.rad2deg(geo._angle_between(a, a)))
self.assertEqual(180, np.rad2deg(geo._angle_between(a, -a)))

#def test_hmatabc(self):
# """Tests whether alternating conversions are stable."""
# def _docheck(self, test):
# abc = np.array(test)
# result = geo.hmatrix_to_abc(geo.abc_to_hmatrix(*abc, degrees=True), degrees=True)
# print np.array(test)-result
# self.assertTrue(np.allclose(np.array(test), result))
def test_hmatabc(self):
"""Tests whether alternating conversions are stable."""
def _docheck(self, test):
abc = np.array(test)
result = geo.hmatrix_to_abc(geo.abc_to_hmatrix(*abc, degrees=True), degrees=True)
self.assertTrue(np.allclose(np.array(test), result))

# _docheck(self, [1.1, 2.2, 3.3, 90,90,120])
# _docheck(self, [1.1, 2.2, 3.3, 90,90,90])
_docheck(self, [1.1, 2.2, 3.3, 90,90,120])
_docheck(self, [1.1, 2.2, 3.3, 90,90,90])
# triclinic: Chalcanthite
# _docheck(self, [6.12, 10.72, 5.96, 82.4,107.3,102.6])
_docheck(self, [6.11, 10.673, 5.95, 97.58, 107.17, 77.55])

0 comments on commit 9f21946

Please sign in to comment.