Coverage for tests/test_pcdMap.py: 22%

40 statements  

« prev     ^ index     » next       coverage.py v7.2.3, created at 2023-04-19 10:51 +0000

1import unittest 

2 

3import numpy as np 

4from numpy.testing import assert_allclose 

5 

6import astshim as ast 

7from astshim.test import MappingTestCase 

8 

9 

10class TestPcdMap(MappingTestCase): 

11 

12 def test_PcdMap(self): 

13 coeff = 0.002 

14 ctr = [2, 3] 

15 pcdmap = ast.PcdMap(coeff, ctr) 

16 self.assertEqual(pcdmap.className, "PcdMap") 

17 self.assertIsInstance(pcdmap, ast.PcdMap) 

18 self.assertIsInstance(pcdmap, ast.Mapping) 

19 self.assertEqual(pcdmap.nIn, 2) 

20 self.assertEqual(pcdmap.nOut, 2) 

21 self.assertEqual(pcdmap.disco, coeff) 

22 assert_allclose(pcdmap.pcdCen, ctr) 

23 

24 self.checkBasicSimplify(pcdmap) 

25 self.checkCopy(pcdmap) 

26 

27 # the center maps to itself 

28 assert_allclose(pcdmap.applyForward(ctr), ctr) 

29 

30 indata = np.array([ 

31 [0.0, -1.0, 4.2], 

32 [0.0, 7.3, -5.3], 

33 ]) 

34 # inverse uses a fit so don't expect too much 

35 self.checkRoundTrip(pcdmap, indata, atol=1e-4) 

36 self.checkMappingPersistence(pcdmap, indata) 

37 

38 outdata = pcdmap.applyForward(indata) 

39 

40 # the mapping is: 

41 # outrad = inrad*(1 + coeff*inrad^2) 

42 # outdir = indir 

43 # where radius and direction are relative to the center of distortion 

44 inrelctr = (indata.T - ctr).T 

45 inrelctrrad = np.hypot(inrelctr[0], inrelctr[1]) 

46 inrelctrdir = np.arctan2(inrelctr[1], inrelctr[0]) 

47 pred_outrad = inrelctrrad * (1 + coeff * inrelctrrad * inrelctrrad) 

48 pred_outrelctr = np.zeros(indata.shape, dtype=float) 

49 pred_outrelctr[0, :] = pred_outrad * np.cos(inrelctrdir) 

50 pred_outrelctr[1, :] = pred_outrad * np.sin(inrelctrdir) 

51 pred_outdata = pred_outrelctr + np.expand_dims(ctr, 1) 

52 assert_allclose(outdata, pred_outdata) 

53 

54 def test_PcdMapBadConstruction(self): 

55 with self.assertRaises(Exception): 

56 ast.PcdMap(0.5, [1, 2, 3]) 

57 

58 with self.assertRaises(Exception): 

59 ast.PcdMap(0.5, [1]) 

60 

61 

62if __name__ == "__main__": 62 ↛ 63line 62 didn't jump to line 63, because the condition on line 62 was never true

63 unittest.main()