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 math 

import unittest 

 

import numpy as np 

from numpy.testing import assert_allclose 

 

import astshim as ast 

from astshim.test import MappingTestCase 

 

 

class TestSphMap(MappingTestCase): 

 

def test_SphMapBasics(self): 

sphmap = ast.SphMap() 

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

self.assertEqual(sphmap.nIn, 3) 

self.assertEqual(sphmap.nOut, 2) 

self.assertEqual(sphmap.polarLong, 0) 

self.assertFalse(sphmap.unitRadius) 

 

self.checkCopy(sphmap) 

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

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

# Hence the following test instead of checkBasicSimplify: 

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

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

 

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

indata = np.array([ 

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

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

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

], dtype=float) 

halfpi = math.pi / 2.0 

pred_outdata = np.array([ 

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

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

], dtype=float) 

outdata = sphmap.applyForward(indata) 

assert_allclose(outdata, pred_outdata) 

 

self.checkRoundTrip(sphmap, indata) 

self.checkMappingPersistence(sphmap, indata) 

 

def test_SphMapAttributes(self): 

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

self.assertEqual(sphmap.polarLong, 0.5) 

self.assertTrue(sphmap.unitRadius) 

 

 

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

unittest.main()