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

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

 

def test_PcdMap(self): 

coeff = 0.002 

ctr = [2, 3] 

pcdmap = ast.PcdMap(coeff, ctr) 

self.assertEqual(pcdmap.className, "PcdMap") 

self.assertIsInstance(pcdmap, ast.PcdMap) 

self.assertIsInstance(pcdmap, ast.Mapping) 

self.assertEqual(pcdmap.nIn, 2) 

self.assertEqual(pcdmap.nOut, 2) 

self.assertEqual(pcdmap.disco, coeff) 

assert_allclose(pcdmap.pcdCen, ctr) 

 

self.checkBasicSimplify(pcdmap) 

self.checkCopy(pcdmap) 

 

# the center maps to itself 

assert_allclose(pcdmap.applyForward(ctr), ctr) 

 

indata = np.array([ 

[0.0, -1.0, 4.2], 

[0.0, 7.3, -5.3], 

]) 

# inverse uses a fit so don't expect too much 

self.checkRoundTrip(pcdmap, indata, atol=1e-4) 

self.checkMappingPersistence(pcdmap, indata) 

 

outdata = pcdmap.applyForward(indata) 

 

# the mapping is: 

# outrad = inrad*(1 + coeff*inrad^2) 

# outdir = indir 

# where radius and direction are relative to the center of distortion 

inrelctr = (indata.T - ctr).T 

inrelctrrad = np.hypot(inrelctr[0], inrelctr[1]) 

inrelctrdir = np.arctan2(inrelctr[1], inrelctr[0]) 

pred_outrad = inrelctrrad * (1 + coeff * inrelctrrad * inrelctrrad) 

pred_outrelctr = np.zeros(indata.shape, dtype=float) 

pred_outrelctr[0, :] = pred_outrad * np.cos(inrelctrdir) 

pred_outrelctr[1, :] = pred_outrad * np.sin(inrelctrdir) 

pred_outdata = pred_outrelctr + np.expand_dims(ctr, 1) 

assert_allclose(outdata, pred_outdata) 

 

def test_PcdMapBadConstruction(self): 

with self.assertRaises(Exception): 

ast.PcdMap(0.5, [1, 2, 3]) 

 

with self.assertRaises(Exception): 

ast.PcdMap(0.5, [1]) 

 

 

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

unittest.main()