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

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

import unittest 

 

import numpy as np 

from numpy.testing import assert_allclose 

 

import astshim as ast 

from astshim.test import MappingTestCase 

 

 

class TestMathMap(MappingTestCase): 

 

def test_MathMapInvertible(self): 

mathmap = ast.MathMap( 

2, 2, 

["r = sqrt(x * x + y * y)", "theta = atan2(y, x)"], 

["x = r * cos(theta)", "y = r * sin(theta)"], 

"SimpIF=1, SimpFI=1, Seed=-57") 

self.assertEqual(mathmap.className, "MathMap") 

self.assertEqual(mathmap.nIn, 2) 

self.assertEqual(mathmap.nOut, 2) 

 

self.checkBasicSimplify(mathmap) 

self.checkCopy(mathmap) 

 

indata = np.array([ 

[1.0, 2.0, 3.0], 

[0.0, 1.0, 2.0], 

]) 

outdata = mathmap.applyForward(indata) 

x = indata[0] 

y = indata[1] 

r = outdata[0] 

theta = outdata[1] 

pred_r = np.sqrt(x * x + y * y) 

pred_theta = np.arctan2(y, x) 

assert_allclose(r, pred_r) 

assert_allclose(theta, pred_theta) 

 

self.checkRoundTrip(mathmap, indata) 

self.checkMappingPersistence(mathmap, indata) 

 

self.assertEqual(mathmap.seed, -57) 

self.assertTrue(mathmap.simpFI) 

self.assertTrue(mathmap.simpIF) 

 

def test_MathMapNonInvertible(self): 

mathmap = ast.MathMap(2, 1, 

["r = sqrt(x * x + y * y)"], 

["x = r", "y = 0"]) 

self.assertEqual(mathmap.className, "MathMap") 

self.assertEqual(mathmap.nIn, 2) 

self.assertEqual(mathmap.nOut, 1) 

 

with self.assertRaises(AssertionError): 

self.checkBasicSimplify(mathmap) 

 

self.assertFalse(mathmap.simpFI) 

self.assertFalse(mathmap.simpIF) 

 

indata = np.array([ 

[1.0, 2.0, 3.0], 

[0.0, 1.0, 2.0], 

]) 

self.checkMappingPersistence(mathmap, indata) 

 

 

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

unittest.main()