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

# This file is part of obs_base. 

# 

# 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 

import astropy.units as u 

 

from astro_metadata_translator import FitsTranslator, StubTranslator 

from lsst.daf.base import DateTime 

 

from lsst.obs.base import MakeRawVisitInfoViaObsInfo 

 

 

class NewTranslator(FitsTranslator, StubTranslator): 

_trivial_map = { 

"exposure_time": "EXPTIME", 

"exposure_id": "EXP-ID", 

} 

 

def to_location(self): 

return None 

 

def to_detector_exposure_id(self): 

return self.to_exposure_id() 

 

 

class MakeTestableVisitInfo(MakeRawVisitInfoViaObsInfo): 

metadataTranslator = NewTranslator 

 

 

class TestMakeRawVisitInfoViaObsInfo(unittest.TestCase): 

 

def setUp(self): 

# Reference values 

self.exposure_time = 6.2*u.s 

self.exposure_id = 54321 

self.datetime_begin = Time("2001-01-02T03:04:05.123456789", format="isot", scale="utc") 

self.datetime_begin.precision = 9 

self.datetime_end = Time("2001-01-02T03:04:07.123456789", format="isot", scale="utc") 

self.datetime_end.precision = 9 

 

self.header = { 

"DATE-OBS": self.datetime_begin.isot, 

"DATE-END": self.datetime_end.isot, 

"INSTRUME": "Irrelevant", 

"TELESCOP": "LSST", 

"TIMESYS": "UTC", 

"EXPTIME": self.exposure_time, 

"EXP-ID": self.exposure_id, 

"EXTRA1": "an abitrary key and value", 

"EXTRA2": 5, 

} 

 

def testMakeRawVisitInfoViaObsInfo(self): 

maker = MakeTestableVisitInfo() 

visitInfo = maker(self.header) 

 

self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s")) 

self.assertEqual(visitInfo.getExposureId(), self.exposure_id) 

self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC)) 

self.assertNotIn("EXPTIME", self.header) 

self.assertEqual(len(self.header), 2) 

 

 

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

unittest.main()