Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

from __future__ import absolute_import, division, print_function 

import unittest 

 

import numpy as np 

from numpy.testing import assert_allclose 

 

import astshim as ast 

from astshim.test import MappingTestCase 

 

 

class TestMapBox(MappingTestCase): 

 

def test_MapBox(self): 

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

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

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

winmap = ast.WinMap( 

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

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

# MapBox uses the minimum of inbnd_b, inbnd_a for each axis for the lower bound, 

# and the maximum for the upper bound 

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

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

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

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

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

 

lbndin = np.minimum(inbnd_a, inbnd_b) 

ubndin = np.maximum(inbnd_a, inbnd_b) 

predlbndOut = lbndin * zoom + shift 

predubndOut = ubndin * zoom + shift 

assert_allclose(mapbox.lbndOut, predlbndOut) 

assert_allclose(mapbox.ubndOut, predubndOut) 

 

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

# because any X from the input gives the same Y 

for i in range(2): 

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

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

 

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

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

assert_allclose(mapbox2.lbndOut, mapbox.lbndOut) 

assert_allclose(mapbox2.ubndOut, mapbox.ubndOut) 

 

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

for i in range(2): 

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

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

 

 

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

unittest.main()