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

69

70

71

import unittest 

 

import numpy as np 

from numpy.testing import assert_allclose 

 

import astshim as ast 

from astshim.test import MappingTestCase 

 

SecPerDay = 3600 * 24 

 

 

class TestTimeMap(MappingTestCase): 

 

def test_TimeMapDefault(self): 

"""Test a TimeMap with no conversions added 

""" 

timemap = ast.TimeMap() 

self.assertEqual(timemap.className, "TimeMap") 

self.assertEqual(timemap.nIn, 1) 

self.assertEqual(timemap.nOut, 1) 

 

self.checkCopy(timemap) 

self.checkBasicSimplify(timemap) 

 

indata = np.array([0.0, 1.0], dtype=float) 

outdata = timemap.applyForward(indata) 

assert_allclose(outdata, indata) 

 

self.checkRoundTrip(timemap, indata) 

self.checkMappingPersistence(timemap, indata) 

 

def test_TimeMapAddUTTOUTC(self): 

timemap = ast.TimeMap() 

dut1 = 0.35 

timemap.add("UTTOUTC", [dut1]) 

indata = np.array([512345.0, 512346.0], dtype=float) 

outdata = timemap.applyForward(indata) 

pred_outdata = (indata.T - dut1 / SecPerDay).T 

assert_allclose(outdata, pred_outdata, atol=1e-15, rtol=0) 

 

self.checkRoundTrip(timemap, indata) 

self.checkMappingPersistence(timemap, indata) 

 

def test_TimeMapAddInvalid(self): 

timemap = ast.TimeMap() 

 

with self.assertRaises(Exception): 

timemap.add("BEPTOMJD", [560]) # too few arguments 

with self.assertRaises(Exception): 

timemap.add("BEPTOMJD", [560, 720, 33]) # too many arguments 

timemap.add("BEPTOMJD", [560, 720]) # just right 

 

with self.assertRaises(Exception): 

timemap.add("UTCTOTAI", [560]) # just right 

with self.assertRaises(Exception): 

timemap.add("UTCTOTAI", [560, 720, 23]) # too many arguments 

timemap.add("UTCTOTAI", [560, 720]) # too many arguments 

 

with self.assertRaises(Exception): 

timemap.add("TTTOTDB", [560, 720, 33, 53]) # too few arguments 

with self.assertRaises(Exception): 

# too many arguments 

timemap.add("TTTOTDB", [560, 720, 33, 53, 23, 10, 20]) 

timemap.add("TTTOTDB", [560, 720, 33, 53, 10]) # just right 

 

with self.assertRaises(Exception): 

timemap.timeadd("UNRECOGNIZED", [1]) 

 

 

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

unittest.main()