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

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

# This file is part of astro_metadata_translator. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

import unittest 

from astropy.time import Time 

 

from astro_metadata_translator import FitsTranslator, StubTranslator, ObservationInfo 

 

 

class InstrumentTestTranslator(FitsTranslator, StubTranslator): 

"""Simple FITS-like translator to test the infrastructure""" 

 

# Needs a name to be registered 

name = "TestTranslator" 

 

# Indicate the instrument this class understands 

supported_instrument = "SCUBA_test" 

 

# Some new mappings, including an override 

_trivial_map = {"foobar": "BAZ", 

"telescope": "TELCODE", 

"observation_id": "OBSID"} 

 

_const_map = {"format": "HDF5"} 

 

 

class TranslatorTestCase(unittest.TestCase): 

 

def setUp(self): 

# Known simple header 

self.header = {"TELESCOP": "JCMT", 

"TELCODE": "LSST", 

"INSTRUME": "SCUBA_test", 

"DATE-OBS": "2000-01-01T01:00:01.500", 

"DATE-END": "2000-01-01T02:00:01.500", 

"OBSGEO-X": "-5464588.84421314", 

"OBSGEO-Y": "-2493000.19137644", 

"OBSGEO-Z": "2150653.35350771", 

"OBSID": "20000101_00002", 

"BAZ": "bar"} 

 

def test_manual_translation(self): 

 

header = self.header 

translator = FitsTranslator(header) 

 

# Treat the header as standard FITS 

self.assertFalse(FitsTranslator.can_translate(header)) 

self.assertEqual(translator.to_telescope(), "JCMT") 

self.assertEqual(translator.to_instrument(), "SCUBA_test") 

self.assertEqual(translator.to_datetime_begin(), 

Time(header["DATE-OBS"], format="isot")) 

 

# Use the special test translator instead 

translator = InstrumentTestTranslator(header) 

self.assertTrue(InstrumentTestTranslator.can_translate(header)) 

self.assertEqual(translator.to_telescope(), "LSST") 

self.assertEqual(translator.to_instrument(), "SCUBA_test") 

self.assertEqual(translator.to_format(), "HDF5") 

self.assertEqual(translator.to_foobar(), "bar") 

 

def test_translator(self): 

header = self.header 

 

# Specify a translation class 

with self.assertWarns(UserWarning): 

# Since the translator is incomplete it should issue warnings 

v1 = ObservationInfo(header, translator_class=InstrumentTestTranslator) 

self.assertEqual(v1.instrument, "SCUBA_test") 

self.assertEqual(v1.telescope, "LSST") 

 

# Now automated class 

with self.assertWarns(UserWarning): 

# Since the translator is incomplete it should issue warnings 

v1 = ObservationInfo(header) 

self.assertEqual(v1.instrument, "SCUBA_test") 

self.assertEqual(v1.telescope, "LSST") 

 

location = v1.location.to_geodetic() 

self.assertAlmostEqual(location.height.to("m").to_value(), 4123.0, places=1) 

 

# Check that headers have been removed 

new_hdr = v1.stripped_header() 

self.assertNotIn("INSTRUME", new_hdr) 

self.assertNotIn("OBSGEO-X", new_hdr) 

self.assertIn("TELESCOP", new_hdr) 

 

# Check the list of cards that were used 

used = v1.cards_used 

self.assertIn("INSTRUME", used) 

self.assertIn("OBSGEO-Y", used) 

self.assertNotIn("TELESCOP", used) 

 

 

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

unittest.main()