11from hexrd .distortion .dexela_2923 import Dexela_2923 , _find_quadrant
2+ from hexrd .distortion .dexela_2923_quad import Dexela_2923_quad
23from hexrd import constants
34import numpy as np
45
56
6- def test_distortion ():
7+ def test_dexela_2923_distortion ():
78 pts = np .random .randn (16 , 2 )
89 qi = _find_quadrant (pts )
910
@@ -25,3 +26,40 @@ def test_distortion():
2526 raise RuntimeError ("distortion apply failed!" )
2627 if not np .all (abs (result_inv + ptile ) <= constants .ten_epsf ):
2728 raise RuntimeError ("distortion apply_inverse failed!" )
29+
30+
31+ def test_dexela_2923_quad_distortion ():
32+ pts = np .random .randn (16 , 2 )
33+ qi = _find_quadrant (pts )
34+
35+ # test trivial
36+ params = np .zeros (10 )
37+ dc = Dexela_2923 (params )
38+ if not np .all (dc .apply (pts ) - pts == 0.0 ):
39+ raise RuntimeError ("distortion apply failed!" )
40+ if not np .all (dc .apply_inverse (pts ) - pts == 0.0 ):
41+ raise RuntimeError ("distortion apply_inverse failed!" )
42+
43+ # test non-trivial
44+
45+ # this is the original test submited in
46+ # https://github.com/HEXRD/hexrd/issues/749
47+ # but it does not currently work. First, params needs to be of size 6, but
48+ # this break vstack command bellow. Not sure how to adapt it.
49+ # params = np.random.randn(10)
50+ # dc = Dexela_2923_quad(params)
51+ # ptile = np.vstack([params.reshape(4, 2)[j - 1, :] for j in qi])
52+ # result = dc.apply(pts) - pts
53+ # result_inv = dc.apply_inverse(pts) - pts
54+ # if not np.all(abs(result - ptile) <= constants.epsf):
55+ # raise RuntimeError("distortion apply failed!")
56+ # if not np.all(abs(result_inv + ptile) <= constants.epsf):
57+ # raise RuntimeError("distortion apply_inverse failed!")
58+ # return True
59+
60+ # we simply test that apply and reverse cancel each other
61+ params = np .random .randn (6 )
62+ dc = Dexela_2923_quad (params )
63+ result = dc .apply_inverse (dc .apply (pts ))
64+ if not np .all (abs (result - pts ) <= 100 * constants .epsf ):
65+ raise RuntimeError ("distortion apply_inverse(apply) failed!" )
0 commit comments