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# This file is currently part of obs_lsst but is written to allow it 

2# to be migrated to the astro_metadata_translator package at a later date. 

3# 

4# This product includes software developed by the LSST Project 

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

6# See the LICENSE file in this directory for details of code ownership. 

7# 

8# Use of this source code is governed by a 3-clause BSD-style 

9# license that can be found in the LICENSE file. 

10 

11"""Metadata translation code for the main LSST Camera""" 

12 

13__all__ = ("LsstCamTranslator", ) 

14 

15import logging 

16import astropy.units as u 

17 

18from astro_metadata_translator import cache_translation 

19from astro_metadata_translator.translators.helpers import is_non_science 

20 

21from .lsst import LsstBaseTranslator, SIMONYI_TELESCOPE, FILTER_DELIMITER 

22 

23log = logging.getLogger(__name__) 

24 

25# Normalized name of the LSST Camera 

26LSST_CAM = "LSSTCam" 

27 

28 

29def is_non_science_or_lab(self): 

30 """Pseudo method to determine whether this is a lab or non-science 

31 header. 

32 

33 Raises 

34 ------ 

35 KeyError 

36 If this is a science observation and on the mountain. 

37 """ 

38 if is_non_science(self): 

39 return 

40 if not self._is_on_mountain(): 

41 return 

42 raise KeyError("Required key is missing and this is a mountain science observation") 

43 

44 

45class LsstCamTranslator(LsstBaseTranslator): 

46 """Metadata translation for the main LSST Camera.""" 

47 

48 name = LSST_CAM 

49 """Name of this translation class""" 

50 

51 supported_instrument = LSST_CAM 

52 """Supports the lsstCam instrument.""" 

53 

54 _const_map = { 

55 "instrument": LSST_CAM, 

56 "telescope": SIMONYI_TELESCOPE, 

57 # Migrate these to full translations once test data appears that 

58 # includes them 

59 "boresight_rotation_coord": "unknown", 

60 "boresight_rotation_angle": None, 

61 "boresight_airmass": None, 

62 "tracking_radec": None, 

63 "altaz_begin": None, 

64 "object": "UNKNOWN", 

65 "relative_humidity": None, 

66 "temperature": None, 

67 "pressure": None, 

68 } 

69 

70 _trivial_map = { 

71 "detector_group": "RAFTBAY", 

72 "detector_name": "CCDSLOT", 

73 "observation_id": "OBSID", 

74 "exposure_time": ("EXPTIME", dict(unit=u.s)), 

75 "detector_serial": "LSST_NUM", 

76 "science_program": ("RUNNUM", dict(default="unknown")) 

77 } 

78 

79 # Use Imsim raft definitions until a true lsstCam definition exists 

80 cameraPolicyFile = "policy/lsstCam.yaml" 

81 

82 @classmethod 

83 def can_translate(cls, header, filename=None): 

84 """Indicate whether this translation class can translate the 

85 supplied header. 

86 

87 Parameters 

88 ---------- 

89 header : `dict`-like 

90 Header to convert to standardized form. 

91 filename : `str`, optional 

92 Name of file being translated. 

93 

94 Returns 

95 ------- 

96 can : `bool` 

97 `True` if the header is recognized by this class. `False` 

98 otherwise. 

99 """ 

100 # INSTRUME keyword might be of two types 

101 if "INSTRUME" in header: 

102 instrume = header["INSTRUME"].lower() 

103 if instrume == cls.supported_instrument.lower(): 

104 return True 

105 return False 

106 

107 @cache_translation 

108 def to_physical_filter(self): 

109 """Calculate the physical filter name. 

110 

111 Returns 

112 ------- 

113 filter : `str` 

114 Name of filter. Can be a combination of FILTER and FILTER2 

115 headers joined by a "~" if FILTER2 is set and not empty. 

116 Returns "UNKNOWN" if no filter is declared. 

117 """ 

118 physical_filter = self._determine_primary_filter() 

119 

120 filter2 = None 

121 if self.is_key_ok("FILTER2"): 

122 self._used_these_cards("FILTER2") 

123 filter2 = self._header["FILTER2"] 

124 if self._is_filter_empty(filter2): 

125 filter2 = None 

126 

127 if filter2: 

128 physical_filter = f"{physical_filter}{FILTER_DELIMITER}{filter2}" 

129 

130 return physical_filter