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

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

# This file is currently part of obs_lsst but is written to allow it 

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

# 

# This product includes software developed by the LSST Project 

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

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

# 

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

# license that can be found in the LICENSE file. 

 

"""Metadata translation code for LSST LATISS headers""" 

 

__all__ = ("LsstLatissTranslator", ) 

 

import logging 

 

import astropy.units as u 

from astropy.time import Time 

from astropy.coordinates import EarthLocation 

 

from astro_metadata_translator import cache_translation 

from astro_metadata_translator.translators.helpers import is_non_science 

from .lsst import LsstBaseTranslator 

 

log = logging.getLogger(__name__) 

 

 

# AuxTel is not the same place as LSST 

# These coordinates read from Apple Maps 

AUXTEL_LOCATION = EarthLocation.from_geodetic(-30.244728, -70.747698, 2663.0) 

 

# Date instrument is taking data at telescope 

# Prior to this date many parameters are automatically nulled out 

# since the headers have not historically been reliable 

TSTART = Time("2019-10-01T00:00", format="isot", scale="utc") 

 

# Define the sensor and group name for AuxTel globally so that it can be used 

# in multiple places. There is no raft but for consistency with other LSST 

# cameras we define one. 

_DETECTOR_GROUP_NAME = "RXX" 

_DETECTOR_NAME = "S00" 

 

 

def is_non_science_or_lab(self): 

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

header. 

 

Raises 

------ 

KeyError 

If this is a science observation and on the mountain. 

""" 

if is_non_science(self): 

return 

if not self._is_on_mountain(): 

return 

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

 

 

class LsstLatissTranslator(LsstBaseTranslator): 

"""Metadata translator for LSST LATISS data from AuxTel. 

 

For lab measurements many values are masked out. 

""" 

 

name = "LSST_LATISS" 

"""Name of this translation class""" 

 

supported_instrument = "LATISS" 

"""Supports the LATISS instrument.""" 

 

_const_map = { 

# LATISS is not yet attached to a telescope so many translations 

# are null. 

"instrument": "LATISS", 

"telescope": "LSSTAuxTel", 

"detector_group": _DETECTOR_GROUP_NAME, 

"detector_num": 0, 

"detector_name": _DETECTOR_NAME, # Single sensor 

"boresight_rotation_coord": "unknown", 

"science_program": "unknown", 

"relative_humidity": None, 

"pressure": None, 

"temperature": None, 

"altaz_begin": None, 

"tracking_radec": None, 

} 

 

_trivial_map = { 

"observation_id": ("OBSID", dict(default=None, checker=is_non_science)), 

"detector_serial": ["LSST_NUM", "DETSER"], 

"boresight_airmass": ("AMSTART", dict(checker=is_non_science_or_lab)), 

"object": ("OBJECT", dict(checker=is_non_science_or_lab, default="UNKNOWN")), 

"boresight_rotation_angle": ("ROTANGLE", dict(checker=is_non_science_or_lab, 

default=float("nan"), unit=u.deg)), 

} 

 

DETECTOR_GROUP_NAME = _DETECTOR_GROUP_NAME 

"""Fixed name of detector group.""" 

 

DETECTOR_NAME = _DETECTOR_NAME 

"""Fixed name of single sensor.""" 

 

DETECTOR_MAX = 0 

"""Maximum number of detectors to use when calculating the 

detector_exposure_id.""" 

 

@classmethod 

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

"""Indicate whether this translation class can translate the 

supplied header. 

 

Parameters 

---------- 

header : `dict`-like 

Header to convert to standardized form. 

filename : `str`, optional 

Name of file being translated. 

 

Returns 

------- 

can : `bool` 

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

otherwise. 

""" 

# INSTRUME keyword might be of two types 

if "INSTRUME" in header: 

instrume = header["INSTRUME"] 

for v in ("LSST_ATISS", "LATISS"): 

if instrume == v: 

return True 

# Calibration files strip important headers at the moment so guess 

if "DETNAME" in header and header["DETNAME"] == "RXX_S00": 

return True 

return False 

 

def _is_on_mountain(self): 

date = self.to_datetime_begin() 

if date > TSTART: 

return True 

return False 

 

@staticmethod 

def compute_detector_exposure_id(exposure_id, detector_num): 

"""Compute the detector exposure ID from detector number and 

exposure ID. 

 

This is a helper method to allow code working outside the translator 

infrastructure to use the same algorithm. 

 

Parameters 

---------- 

exposure_id : `int` 

Unique exposure ID. 

detector_num : `int` 

Detector number. 

 

Returns 

------- 

detector_exposure_id : `int` 

The calculated ID. 

""" 

if detector_num != 0: 

log.warning("Unexpected non-zero detector number for LATISS") 

return exposure_id 

 

@cache_translation 

def to_location(self): 

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

if self._is_on_mountain(): 

return AUXTEL_LOCATION 

return None 

 

@cache_translation 

def to_dark_time(self): 

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

if self.is_key_ok("DARKTIME"): 

return self.quantity_from_card("DARKTIME", u.s) 

 

log.warning("Explicit dark time not found, setting dark time to the exposure time.") 

return self.to_exposure_time() 

 

@cache_translation 

def to_exposure_time(self): 

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

# Some data is missing a value for EXPTIME. 

# Have to be careful we do not have circular logic when trying to 

# guess 

if self.is_key_ok("EXPTIME"): 

return self.quantity_from_card("EXPTIME", u.s) 

 

# A missing or undefined EXPTIME is problematic. Set to -1 

# to indicate that none was found. 

log.warning("Insufficient information to derive exposure time. Setting to -1.0s") 

return -1.0 * u.s 

 

@cache_translation 

def to_observation_type(self): 

"""Determine the observation type. 

 

In the absence of an ``IMGTYPE`` header, assumes lab data is always a 

dark if exposure time is non-zero, else bias. 

 

Returns 

------- 

obstype : `str` 

Observation type. 

""" 

 

# LATISS observation type is documented to appear in OBSTYPE 

# but for historical reasons prefers IMGTYPE. Some data puts 

# it in GROUPID (which is meant to be for something else). 

# Test the keys in order until we find one that contains a 

# defined value. 

obstype_keys = ["OBSTYPE", "IMGTYPE"] 

 

# For now, hope that GROUPID does not contain an obs type value 

# when on the mountain. 

if not self._is_on_mountain(): 

obstype_keys.append("GROUPID") 

 

for k in obstype_keys: 

if self.is_key_ok(k): 

obstype = self._header[k] 

self._used_these_cards(k) 

return obstype.lower() 

 

# In the absence of any observation type information, return 

# unknown unless we think it might be a bias. 

exptime = self.to_exposure_time() 

if exptime == 0.0: 

obstype = "bias" 

else: 

obstype = "unknown" 

log.warning("Unable to determine observation type. Guessing '%s'", obstype) 

return obstype