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

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

# 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/>. 

 

"""Metadata translation code for DECam FITS headers""" 

 

__all__ = ("DecamTranslator", ) 

 

import re 

 

from astropy.coordinates import EarthLocation, SkyCoord, AltAz, Angle 

import astropy.units as u 

 

from .fits import FitsTranslator 

from .helpers import altitude_from_zenith_distance 

 

 

class DecamTranslator(FitsTranslator): 

"""Metadata translator for DECam standard headers. 

""" 

 

name = "DECam" 

"""Name of this translation class""" 

 

supported_instrument = "DECam" 

"""Supports the DECam instrument.""" 

 

_const_map = {"boresight_rotation_angle": Angle(float("nan")*u.deg), 

"boresight_rotation_coord": "unknown"} 

 

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

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

"boresight_airmass": "AIRMASS", 

"observation_id": "OBSID", 

"object": "OBJECT", 

"science_program": "PROPID", 

"detector_num": "CCDNUM", 

"detector_name": "DETPOS", 

# Ensure that reasonable values are always available 

"relative_humidity": ("HUMIDITY", dict(default=40., minimum=0, maximum=100.)), 

"temperature": ("OUTTEMP", dict(unit=u.deg_C, default=10., minimum=-10., maximum=40.)), 

# Header says torr but seems to be mbar. Use hPa unit 

# which is the SI equivalent of mbar. 

"pressure": ("PRESSURE", dict(unit=u.hPa, 

default=771.611, minimum=700., maximum=850.)), 

"exposure_id": "EXPNUM", 

"visit_id": "EXPNUM"} 

 

def to_datetime_end(self): 

return self._from_fits_date("DTUTC") 

 

def _translate_from_calib_id(self, field): 

"""Fetch the ID from the CALIB_ID header. 

 

Calibration products made with constructCalibs have some metadata 

saved in its FITS header CALIB_ID. 

""" 

data = self._header["CALIB_ID"] 

match = re.search(r".*%s=(\S+)" % field, data) 

self._used_these_cards("CALIB_ID") 

return match.groups()[0] 

 

def to_physical_filter(self): 

"""Calculate physical filter. 

 

Return `None` if the keyword FILTER does not exist in the header, 

which can happen for some valid Community Pipeline products. 

 

Returns 

------- 

filter : `str` 

The full filter name. 

""" 

if "FILTER" in self._header: 

if self.to_observation_type() == "zero": 

return "NONE" 

value = self._header["FILTER"].strip() 

self._used_these_cards("FILTER") 

return value 

elif "CALIB_ID" in self._header: 

return self._translate_from_calib_id("filter") 

else: 

return None 

 

def to_location(self): 

"""Calculate the observatory location. 

 

Returns 

------- 

location : `astropy.coordinates.EarthLocation` 

An object representing the location of the telescope. 

""" 

# OBS-LONG has west-positive sign so must be flipped 

lon = self._header["OBS-LONG"] * -1.0 

value = EarthLocation.from_geodetic(lon, self._header["OBS-LAT"], self._header["OBS-ELEV"]) 

self._used_these_cards("OBS-LONG", "OBS-LAT", "OBS-ELEV") 

return value 

 

def to_observation_type(self): 

"""Calculate the observation type. 

 

Returns 

------- 

typ : `str` 

Observation type. Normalized to standard set. 

""" 

obstype = self._header["OBSTYPE"].strip().lower() 

self._used_these_cards("OBSTYPE") 

if obstype == "object": 

return "science" 

return obstype 

 

def to_tracking_radec(self): 

if "RADESYS" in self._header: 

frame = self._header["RADESYS"].strip().lower() 

if frame == "gappt": 

self._used_these_cards("RADESYS") 

# Moving target 

return None 

else: 

frame = "icrs" 

radec = SkyCoord(self._header["TELRA"], self._header["TELDEC"], 

frame=frame, unit=(u.hourangle, u.deg), 

obstime=self.to_datetime_begin(), location=self.to_location()) 

self._used_these_cards("RADESYS", "TELRA", "TELDEC") 

return radec 

 

def to_altaz_begin(self): 

altaz = AltAz(self._header["AZ"] * u.deg, 

altitude_from_zenith_distance(self._header["ZD"] * u.deg), 

obstime=self.to_datetime_begin(), location=self.to_location()) 

self._used_these_cards("AZ", "ZD") 

return altaz 

 

def to_detector_exposure_id(self): 

return int("{:07d}{:02d}".format(self.to_exposure_id(), self.to_detector_num()))