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 ImSim headers""" 

12 

13__all__ = ("LsstImSimTranslator", ) 

14 

15import logging 

16import astropy.units as u 

17from astropy.coordinates import Angle 

18 

19from astro_metadata_translator import cache_translation 

20from astro_metadata_translator.translators.helpers import tracking_from_degree_headers 

21 

22from .lsstsim import LsstSimTranslator 

23 

24log = logging.getLogger(__name__) 

25 

26 

27class LsstImSimTranslator(LsstSimTranslator): 

28 """Metadata translation class for ImSim headers""" 

29 

30 name = "LSSTCam-imSim" 

31 """Name of this translation class""" 

32 

33 _const_map = { 

34 "instrument": "LSSTCam-imSim", 

35 "boresight_rotation_coord": "sky", 

36 "object": "UNKNOWN", 

37 "pressure": None, 

38 "temperature": None, 

39 "relative_humidity": 40.0, 

40 } 

41 

42 _trivial_map = { 

43 "detector_group": "RAFTNAME", 

44 "detector_name": "SENSNAME", 

45 "observation_id": "OBSID", 

46 "science_program": "RUNNUM", 

47 "exposure_id": "OBSID", 

48 "visit_id": "OBSID", 

49 "dark_time": ("DARKTIME", dict(unit=u.s)), 

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

51 "detector_serial": "LSST_NUM", 

52 } 

53 

54 cameraPolicyFile = "policy/imsim.yaml" 

55 

56 @classmethod 

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

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

59 supplied header. 

60 

61 There is no ``INSTRUME`` header in ImSim data. Instead we use 

62 the ``TESTTYPE`` header. 

63 

64 Parameters 

65 ---------- 

66 header : `dict`-like 

67 Header to convert to standardized form. 

68 filename : `str`, optional 

69 Name of file being translated. 

70 

71 Returns 

72 ------- 

73 can : `bool` 

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

75 otherwise. 

76 """ 

77 return cls.can_translate_with_options(header, {"TESTTYPE": "IMSIM"}, 

78 filename=filename) 

79 

80 @cache_translation 

81 def to_tracking_radec(self): 

82 # Docstring will be inherited. Property defined in properties.py 

83 radecsys = ("RADESYS",) 

84 radecpairs = (("RATEL", "DECTEL"),) 

85 return tracking_from_degree_headers(self, radecsys, radecpairs) 

86 

87 @cache_translation 

88 def to_boresight_airmass(self): 

89 # Docstring will be inherited. Property defined in properties.py 

90 altaz = self.to_altaz_begin() 

91 if altaz is not None: 

92 return altaz.secz.to_value() 

93 return None 

94 

95 @cache_translation 

96 def to_boresight_rotation_angle(self): 

97 angle = Angle(90.*u.deg) - Angle(self.quantity_from_card("ROTANGLE", u.deg)) 

98 angle = angle.wrap_at("360d") 

99 return angle 

100 

101 @cache_translation 

102 def to_physical_filter(self): 

103 # Find throughputs version from imSim header data. For DC2 

104 # data, we used throughputs version 1.4. 

105 throughputs_version = None 

106 for key, value in self._header.items(): 

107 if key.startswith("PKG") and value == "throughputs": 

108 version_key = "VER" + key[len("PKG"):] 

109 throughputs_version = self._header[version_key].strip() 

110 break 

111 if throughputs_version is None: 

112 log.warning("%s: throughputs version not found. Using FILTER keyword value '%s'.", 

113 self.to_observation_id(), self._header["FILTER"]) 

114 return self._header["FILTER"] 

115 return "_".join((self._header["FILTER"], "sim", throughputs_version))