Coverage for tests/test_sphMap.py: 34%

30 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 21:54 -0800

1import math 

2import unittest 

3 

4import numpy as np 

5from numpy.testing import assert_allclose 

6 

7import astshim as ast 

8from astshim.test import MappingTestCase 

9 

10 

11class TestSphMap(MappingTestCase): 

12 

13 def test_SphMapBasics(self): 

14 sphmap = ast.SphMap() 

15 self.assertEqual(sphmap.className, "SphMap") 

16 self.assertEqual(sphmap.nIn, 3) 

17 self.assertEqual(sphmap.nOut, 2) 

18 self.assertEqual(sphmap.polarLong, 0) 

19 self.assertFalse(sphmap.unitRadius) 

20 

21 self.checkCopy(sphmap) 

22 # SphMap followed by an inverse, simplified, is a compound map, 

23 # not a UnitMap, since data only round trips for unit vectors. 

24 # Hence the following test instead of checkBasicSimplify: 

25 simplified = sphmap.then(sphmap.inverted()).simplified() 

26 self.assertTrue(isinstance(simplified, ast.CmpMap)) 

27 

28 # for data to round trip, all inputs must be unit vectors 

29 indata = np.array([ 

30 [1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0 / math.sqrt(3.0)], 

31 [0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 1.0 / math.sqrt(3.0)], 

32 [0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 1.0 / math.sqrt(3.0)], 

33 ], dtype=float) 

34 halfpi = math.pi / 2.0 

35 pred_outdata = np.array([ 

36 [0.0, halfpi, 0.0, math.pi, -halfpi, 0.0, math.pi / 4.0], 

37 [0.0, 0.0, halfpi, 0.0, 0.0, -halfpi, math.atan(1.0 / math.sqrt(2.0))], 

38 ], dtype=float) 

39 outdata = sphmap.applyForward(indata) 

40 assert_allclose(outdata, pred_outdata) 

41 

42 self.checkRoundTrip(sphmap, indata) 

43 self.checkMappingPersistence(sphmap, indata) 

44 

45 def test_SphMapAttributes(self): 

46 sphmap = ast.SphMap("PolarLong=0.5, UnitRadius=1") 

47 self.assertEqual(sphmap.polarLong, 0.5) 

48 self.assertTrue(sphmap.unitRadius) 

49 

50 

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

52 unittest.main()