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

286

# 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 UCDavis Test Stand headers""" 

 

__all__ = ("LsstUCDCamTranslator", ) 

 

import logging 

import re 

import os.path 

 

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__) 

 

# There is only one detector name used 

_DETECTOR_NAME = "S00" 

 

 

class LsstUCDCamTranslator(LsstBaseTranslator): 

"""Metadata translator for LSST UC Davis test camera data. 

 

This instrument is a test system for individual LSST CCDs. 

To fit this instrument into the standard naming convention for LSST 

instruments we use a fixed detector name (S00) and assign a different 

raft name to each detector. The detector number changes for each CCD. 

""" 

 

name = "LSST-UCDCam" 

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

"detector_name": _DETECTOR_NAME, 

} 

 

_trivial_map = { 

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

"detector_serial": "LSST_NUM", 

} 

 

DETECTOR_NAME = _DETECTOR_NAME 

"""Fixed name of single sensor in raft.""" 

 

_detector_map = { 

"E2V-CCD250-112-04": (0, "R00"), 

"ITL-3800C-029": (1, "R01"), 

"ITL-3800C-002": (2, "R02"), 

"E2V-CCD250-112-09": (0, "R03"), 

} 

"""Map detector serial to raft and detector number. Eventually the 

detector number will come out of the policy camera definition.""" 

 

DETECTOR_MAX = 3 

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

""" 

# Check 3 headers that all have to match 

for k, v in (("ORIGIN", "UCDAVIS"), ("INSTRUME", "SAO"), ("TSTAND", "LSST_OPTICAL_SIMULATOR")): 

if k not in header: 

return False 

if header[k] != v: 

return False 

return True 

 

@classmethod 

def compute_detector_num_from_name(cls, detector_group, detector_name): 

"""Helper method to return the detector number from the name. 

 

Parameters 

---------- 

detector_group : `str` 

Detector group name. This is generally the raft name. 

detector_name : `str` 

Detector name. Checked to ensure it is the expected name. 

 

Returns 

------- 

num : `int` 

Detector number. 

 

Raises 

------ 

ValueError 

The supplied name is not known. 

""" 

if detector_name != cls.DETECTOR_NAME: 

raise ValueError(f"Detector {detector_name} is not known to UCDCam") 

for num, group in cls._detector_map.values(): 

if group == detector_group: 

return num 

raise ValueError(f"Detector {detector_group}_{detector_name} is not known to UCDCam") 

 

@classmethod 

def compute_detector_group_from_num(cls, detector_num): 

"""Helper method to return the detector group from the number. 

 

Parameters 

---------- 

detector_num : `int` 

Detector number. 

 

Returns 

------- 

group : `str` 

Detector group. 

 

Raises 

------ 

ValueError 

The supplied number is not known. 

""" 

for num, group in cls._detector_map.values(): 

if num == detector_num: 

return group 

raise ValueError(f"Detector {detector_num} is not known for UCDCam") 

 

@staticmethod 

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

"""Helper method to calculate the 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. 

""" 

# Use 1 second resolution 

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

return int(exposure_id) 

 

@cache_translation 

def to_instrument(self): 

"""Calculate the instrument name. 

 

Returns 

------- 

instrume : `str` 

Name of the test stand. We do not distinguish between ITL and 

E2V. 

""" 

return self.name 

 

@cache_translation 

def to_datetime_begin(self): 

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

self._used_these_cards("MJD") 

mjd = float(self._header["MJD"]) # Header uses a FITS string 

return Time(mjd, scale="utc", format="mjd") 

 

@cache_translation 

def to_detector_num(self): 

"""Determine the number associated with this detector. 

 

Returns 

------- 

num : `int` 

The number of the detector. Each CCD gets a different number. 

""" 

serial = self.to_detector_serial() 

return self._detector_map[serial][0] 

 

@cache_translation 

def to_detector_group(self): 

"""Determine the pseudo raft name associated with this detector. 

 

Returns 

------- 

raft : `str` 

The name of the raft. The raft is derived from the serial number 

of the detector. 

""" 

serial = self.to_detector_serial() 

return self._detector_map[serial][1] 

 

@cache_translation 

def to_physical_filter(self): 

"""Return the filter name. 

 

Uses the FILTER header. 

 

Returns 

------- 

filter : `str` 

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

""" 

 

if "FILTER" in self._header: 

self._used_these_cards("FILTER") 

return self._header["FILTER"].lower() 

else: 

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

self.to_observation_id()) 

return "NONE" 

 

def to_exposure_id(self): 

"""Generate a unique exposure ID number 

 

Note that SEQNUM is not unique for a given day 

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

integer. 

 

Returns 

------- 

exposure_id : `int` 

Unique exposure number. 

""" 

date = self.to_datetime_begin() 

return self.compute_exposure_id(date.isot) 

 

# 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 os.path.splitext(os.path.basename(filename))[0] 

 

@cache_translation 

def to_science_program(self): 

"""Calculate the run number for this observation. 

 

There is no explicit run header, so instead treat each day 

as the run in YYYY-MM-DD format. 

 

Returns 

------- 

run : `str` 

YYYY-MM-DD string corresponding to the date of observation. 

""" 

# Get a copy so that we can edit the default formatting 

date = self.to_datetime_begin().copy() 

date.format = "iso" 

date.out_subfmt = "date" # YYYY-MM-DD format 

return str(date)