Coverage for tests/test_mapBox.py: 24%

31 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 TestMapBox(MappingTestCase): 

11 

12 def test_MapBox(self): 

13 """Test MapBox for the simple case of a shift and zoom""" 

14 shift = np.array([1.5, 0.5]) 

15 zoom = np.array([2.0, 3.0]) 

16 winmap = ast.WinMap( 

17 [0, 0], [1, 1], zoom * [0, 0] + shift, zoom * [1, 1] + shift) 

18 # arbitrary values chosen so that inbnd_a is NOT < inbnd_b for both 

19 # axes because MapBox uses the minimum of inbnd_b, inbnd_a for 

20 # each axis for the lower bound, 

21 # and the maximum for the upper bound. 

22 inbnd_a = np.array([-1.2, 3.3]) 

23 inbnd_b = np.array([2.7, 2.2]) 

24 mapbox = ast.MapBox(winmap, inbnd_a, inbnd_b) 

25 # If maxOutCoord is not specified by the user, it should be set to nout 

26 self.assertEqual(mapbox.maxOutCoord, winmap.nOut) 

27 

28 lbndin = np.minimum(inbnd_a, inbnd_b) 

29 ubndin = np.maximum(inbnd_a, inbnd_b) 

30 predlbndOut = lbndin * zoom + shift 

31 predubndOut = ubndin * zoom + shift 

32 assert_allclose(mapbox.lbndOut, predlbndOut) 

33 assert_allclose(mapbox.ubndOut, predubndOut) 

34 

35 # note that mapbox.xl and xu is only partially predictable 

36 # because any X from the input gives the same Y 

37 for i in range(2): 

38 self.assertAlmostEqual(mapbox.xl[i, i], lbndin[i]) 

39 self.assertAlmostEqual(mapbox.xu[i, i], ubndin[i]) 

40 

41 # confirm that order of inbnd_a, inbnd_b doesn't matter 

42 mapbox2 = ast.MapBox(winmap, inbnd_b, inbnd_a) 

43 assert_allclose(mapbox2.lbndOut, mapbox.lbndOut) 

44 assert_allclose(mapbox2.ubndOut, mapbox.ubndOut) 

45 

46 # the xl and xu need only agree on the diagonal, as above 

47 for i in range(2): 

48 self.assertAlmostEqual(mapbox.xl[i, i], mapbox2.xl[i, i]) 

49 self.assertAlmostEqual(mapbox.xu[i, i], mapbox2.xu[i, i]) 

50 

51 

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

53 unittest.main()