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

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

 

__all__ = ("LsstTS3Translator", ) 

 

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 a single sensor at a time so define a 

# fixed sensor name 

_DETECTOR_NAME = "S00" 

 

 

class LsstTS3Translator(LsstBaseTranslator): 

"""Metadata translator for LSST BNL Test Stand 3 data. 

""" 

 

name = "LSST-TS3" 

"""Name of this translation class""" 

 

_const_map = { 

# TS3 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, # Single sensor 

} 

 

_trivial_map = { 

"detector_serial": "LSST_NUM", 

"physical_filter": "FILTER", 

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

} 

 

DETECTOR_NAME = _DETECTOR_NAME 

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

 

DETECTOR_MAX = 999 

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

detector_exposure_id.""" 

 

cameraPolicyFile = "policy/ts3.yaml" 

 

@classmethod 

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

"""Indicate whether this translation class can translate the 

supplied header. 

 

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

the ``TSTAND`` 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. 

""" 

return cls.can_translate_with_options(header, {"TSTAND": "BNL-TS3-2-Janeway"}, filename=filename) 

 

@staticmethod 

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

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

 

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

 

def to_exposure_id(self): 

"""Generate a unique exposure ID number 

 

Note that SEQNUM is not unique for a given day in TS3 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_science_program(self): 

"""Calculate the science program information. 

 

There is no header recording this in TS3 data so instead return 

the observing day in YYYY-MM-DD format. 

 

Returns 

------- 

run : `str` 

Observing day in YYYY-MM-DD format. 

""" 

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

 

@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(filename)[0] 

 

@cache_translation 

def to_detector_group(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[0]