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

# 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__ = ("LsstTS8Translator", ) 

 

import logging 

import re 

 

import astropy.units as u 

from astropy.time import Time 

 

from astro_metadata_translator import cache_translation 

 

from .lsst import LsstBaseTranslator 

 

log = logging.getLogger(__name__) 

 

 

class LsstTS8Translator(LsstBaseTranslator): 

"""Metadata translator for LSST Test Stand 8 data. 

""" 

 

name = "LSST-TS8" 

"""Name of this translation class""" 

 

_const_map = { 

# TS8 is not attached to a telescope so many translations are null. 

"telescope": "LSST", 

"location": None, 

"boresight_rotation_coord": None, 

"boresight_rotation_angle": None, 

"boresight_airmass": None, 

"tracking_radec": None, 

"altaz_begin": None, 

"object": "UNKNOWN", 

"relative_humidity": None, 

"temperature": None, 

"pressure": None, 

} 

 

_trivial_map = { 

"science_program": "RUNNUM", 

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

} 

 

DETECTOR_MAX = 250 

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

detector_exposure_id.""" 

 

cameraPolicyFile = "policy/ts8.yaml" 

 

@classmethod 

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

"""Indicate whether this translation class can translate the 

supplied header. 

 

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

the ``TSTAND`` header. We also look at the file name to see if 

it starts with "ts8-". 

 

Older data has no ``TSTAND`` header so we must use a combination 

of headers. 

 

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. 

""" 

can = cls.can_translate_with_options(header, {"TSTAND": "TS8"}, filename=filename) 

if can: 

return True 

 

if "LSST_NUM" in header and "REBNAME" in header and \ 

"CONTNUM" in header and \ 

header["CONTNUM"] in ("000018910e0c", "000018ee33b7", "000018ee0f35", "000018ee3b40", 

"00001891fcc7", "000018edfd65", "0000123b5ba8", "000018911b05", 

"00001891fa3e", "000018910d7f", "000018ed9f12", "000018edf4a7", 

"000018ee34e6", "000018ef1464", "000018eda120", "000018edf8a2", 

"000018ef3819", "000018ed9486", "000018ee02c8", "000018edfb24", 

"000018ee34c0", "000018edfb51", "0000123b51d1", "0000123b5862", 

"0000123b8ca9", "0000189208fa", "0000189111af", "0000189126e1", 

"000018ee0618", "000018ee3b78", "000018ef1534"): 

return True 

 

return False 

 

@staticmethod 

def compute_exposure_id(dateobs, seqnum=0, controller=None): 

"""Helper method to calculate the TS8 exposure_id. 

 

Parameters 

---------- 

dateobs : `str` 

Date of observation in FITS ISO format. 

seqnum : `int`, unused 

Sequence number. Ignored. 

controller : `str`, unused 

Controller type. Ignored. 

 

Returns 

------- 

exposure_id : `int` 

Exposure ID. 

""" 

# There is worry that seconds are too coarse so use 10th of second 

# and read the first 21 characters. 

exposure_id = re.sub(r"\D", "", dateobs[:21]) 

return int(exposure_id) 

 

@cache_translation 

def to_instrument(self): 

"""Calculate the instrument name. 

 

Returns 

------- 

instrume : `str` 

Name of the test stand. 

""" 

return "LSST-TS8" 

 

@cache_translation 

def to_datetime_begin(self): 

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

self._used_these_cards("MJD-OBS") 

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

 

@cache_translation 

def to_detector_name(self): 

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

serial = self.to_detector_serial() 

detector_info = self.compute_detector_info_from_serial(serial) 

return detector_info[1] 

 

def to_detector_group(self): 

"""Returns the name of the raft. 

 

Extracted from RAFTNAME header. 

 

Raftname should be of the form: 'LCA-11021_RTM-011-Dev' and 

the resulting name will have the form "RTM-NNN". 

 

Returns 

------- 

name : `str` 

Name of raft. 

""" 

raft_name = self._header["RAFTNAME"] 

self._used_these_cards("RAFTNAME") 

match = re.search(r"(RTM-\d\d\d)", raft_name) 

if match: 

return match.group(0) 

raise ValueError(f"RAFTNAME has unexpected form of '{raft_name}'") 

 

@cache_translation 

def to_detector_serial(self): 

"""Returns the serial number of the detector. 

 

Returns 

------- 

serial : `str` 

LSST assigned serial number. 

 

Notes 

----- 

This is the LSST assigned serial number (``LSST_NUM``), and not 

the manufacturer's serial number (``CCD_SERN``). 

""" 

serial = self._header["LSST_NUM"] 

self._used_these_cards("LSST_NUM") 

 

# this seems to be appended more or less at random and should be 

# removed. 

serial = re.sub("-Dev$", "", serial) 

return serial 

 

@cache_translation 

def to_physical_filter(self): 

"""Return the filter name. 

 

Uses the FILTPOS header. 

 

Returns 

------- 

filter : `str` 

The filter name. Returns "NONE" if no filter can be determined. 

 

Notes 

----- 

The calculations here are examples rather than being accurate. 

They need to be fixed once the camera acquisition system does 

this properly. 

""" 

 

try: 

filter_pos = self._header["FILTPOS"] 

self._used_these_cards("FILTPOS") 

except KeyError: 

log.warning("%s: FILTPOS key not found in header (assuming NONE)", 

self.to_observation_id()) 

return "NONE" 

 

try: 

return { 

2: 'g', 

3: 'r', 

4: 'i', 

5: 'z', 

6: 'y', 

}[filter_pos] 

except KeyError: 

log.warning("%s: Unknown filter position (assuming NONE): %d", 

self.to_observation_id(), filter_pos) 

return "NONE" 

 

def to_exposure_id(self): 

"""Generate a unique exposure ID number 

 

Note that SEQNUM is not unique for a given day in TS8 data 

so instead we convert the ISO date of observation directly to an 

integer. 

 

Returns 

------- 

exposure_id : `int` 

Unique exposure number. 

""" 

iso = self._header["DATE-OBS"] 

self._used_these_cards("DATE-OBS") 

 

return self.compute_exposure_id(iso) 

 

# For now assume that visit IDs and exposure IDs are identical 

to_visit_id = to_exposure_id 

 

@cache_translation 

def to_observation_id(self): 

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

filename = self._header["FILENAME"] 

self._used_these_cards("FILENAME") 

return filename[:filename.rfind(".")]