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

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

# 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 TestStand 8 headers""" 

 

__all__ = ("LsstAuxTelTranslator", ) 

 

import logging 

 

import astropy.units as u 

from astropy.time import Time 

from astropy.coordinates import EarthLocation 

 

from astro_metadata_translator import cache_translation, StubTranslator 

from astro_metadata_translator.translators.helpers import is_non_science 

 

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-06-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 LsstAuxTelTranslator(StubTranslator): 

"""Metadata translator for LSST AuxTel data. 

 

For lab measurements many values are masked out. 

""" 

 

name = "LSSTAuxTel" 

"""Name of this translation class""" 

 

supported_instrument = "LATISS" 

"""Supports the LATISS instrument.""" 

 

_const_map = { 

# AuxTel 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)), 

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

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

"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.""" 

 

@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 AuxTel") 

return exposure_id 

 

@staticmethod 

def compute_exposure_id(dayobs, seqnum): 

"""Helper method to calculate the AuxTel exposure_id. 

 

Parameters 

---------- 

dayobs : `str` 

Day of observation in either YYYYMMDD or YYYY-MM-DD format. 

seqnum : `int` or `str` 

Sequence number. 

 

Returns 

------- 

exposure_id : `int` 

Exposure ID in form YYYYMMDDnnnnn form. 

""" 

dayobs = dayobs.replace("-", "") 

 

# Form the number as a string zero padding the sequence number 

idstr = f"{dayobs}{seqnum:06d}" 

return int(idstr) 

 

@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_datetime_begin(self): 

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

if "MJD-OBS" in self._header: 

self._used_these_cards("MJD-OBS") 

return Time(self._header["MJD-OBS"], scale="utc", format="mjd") 

if "CALIB_ID" in self._header: 

# Calibration files hide the date information 

calib_id = self._header["CALIB_ID"] 

self._used_these_cards("CALIB_ID") 

parts = calib_id.split() 

for p in parts: 

if p.startswith("calibDate"): 

ymd = p[10:] 

return Time(ymd, scale="utc", format="isot") 

return None 

 

@cache_translation 

def to_datetime_end(self): 

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

return self.to_datetime_begin() + self.to_exposure_time() 

 

@cache_translation 

def to_detector_exposure_id(self): 

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

exposure_id = self.to_exposure_id() 

detector_num = self.to_detector_num() 

return self.compute_detector_exposure_id(exposure_id, detector_num) 

 

@cache_translation 

def to_exposure_id(self): 

"""Generate a unique exposure ID number 

 

This is a combination of DAYOBS and SEQNUM. 

 

Returns 

------- 

exposure_id : `int` 

Unique exposure number. 

""" 

if "CALIB_ID" in self._header: 

self._used_these_cards("CALIB_ID") 

return None 

 

dayobs = self._header["DAYOBS"] 

seqnum = self._header["SEQNUM"] 

self._used_these_cards("DAYOBS", "SEQNUM") 

 

return self.compute_exposure_id(dayobs, seqnum) 

 

# For now "visits" are defined to be identical to exposures. 

to_visit_id = to_exposure_id 

 

@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. 

""" 

if self._is_on_mountain(): 

obstype = self._header["IMGTYPE"] 

self._used_these_cards("IMGTYPE") 

return obstype.lower() 

 

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 

 

@cache_translation 

def to_physical_filter(self): 

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

filters = [] 

for k in ("FILTER1", "FILTER2"): 

if k in self._header: 

filters.append(self._header[k]) 

self._used_these_cards(k) 

 

if filters: 

filterName = "|".join(filters) 

else: 

filterName = "NONE" 

 

return filterName