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

# This file is part of astro_metadata_translator. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

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

# See the LICENSE file at the top-level directory of this distribution 

# 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 SuprimeCam FITS headers""" 

 

__all__ = ("SuprimeCamTranslator", ) 

 

import re 

import logging 

 

import astropy.units as u 

from astropy.coordinates import SkyCoord, Angle 

 

from ..translator import cache_translation 

from .subaru import SubaruTranslator 

from .helpers import altaz_from_degree_headers 

 

log = logging.getLogger(__name__) 

 

 

class SuprimeCamTranslator(SubaruTranslator): 

"""Metadata translator for HSC standard headers. 

""" 

 

name = "SuprimeCam" 

"""Name of this translation class""" 

 

supported_instrument = "SuprimeCam" 

"""Supports the SuprimeCam instrument.""" 

 

_const_map = {"boresight_rotation_coord": "unknown", 

"detector_group": None} 

"""Constant mappings""" 

 

_trivial_map = {"observation_id": "EXP-ID", 

"object": "OBJECT", 

"science_program": "PROP-ID", 

"detector_num": "DET-ID", 

"detector_serial": "DETECTOR", # DETECTOR is the "call name" 

"boresight_airmass": "AIRMASS", 

"relative_humidity": "OUT-HUM", 

"temperature": ("OUT-TMP", dict(unit=u.K)), 

"pressure": ("OUT-PRS", dict(unit=u.hPa)), 

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

"dark_time": ("EXPTIME", dict(unit=u.s)), # Assume same as exposure time 

} 

"""One-to-one mappings""" 

 

# Zero point for SuprimeCam dates: 2004-01-01 

_DAY0 = 53005 

 

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

""" 

if "INSTRUME" in header: 

return header["INSTRUME"] == "SuprimeCam" 

 

for k in ("EXP-ID", "FRAMEID"): 

if cls.is_keyword_defined(header, k): 

if header[k].startswith("SUP"): 

return True 

return False 

 

def _get_adjusted_mjd(self): 

"""Calculate the modified julian date offset from reference day 

 

Returns 

------- 

offset : `int` 

Offset day count from reference day. 

""" 

mjd = self._header["MJD"] 

self._used_these_cards("MJD") 

return int(mjd) - self._DAY0 

 

@cache_translation 

def to_physical_filter(self): 

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

value = self._header["FILTER01"].strip().upper() 

self._used_these_cards("FILTER01") 

return value 

 

@cache_translation 

def to_datetime_begin(self): 

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

# We know it is UTC 

value = self._from_fits_date_string(self._header["DATE-OBS"], 

time_str=self._header["UT"], scale="utc") 

self._used_these_cards("DATE-OBS", "UT") 

return value 

 

@cache_translation 

def to_datetime_end(self): 

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

# We know it is UTC 

value = self._from_fits_date_string(self._header["DATE-OBS"], 

time_str=self._header["UT-END"], scale="utc") 

self._used_these_cards("DATE-OBS", "UT-END") 

return value 

 

@cache_translation 

def to_exposure_id(self): 

"""Calculate unique exposure integer for this observation 

 

Returns 

------- 

visit : `int` 

Integer uniquely identifying this exposure. 

""" 

exp_id = self._header["EXP-ID"].strip() 

m = re.search(r"^SUP[A-Z](\d{7})0$", exp_id) 

if not m: 

raise RuntimeError("Unable to interpret EXP-ID: %s" % exp_id) 

exposure = int(m.group(1)) 

if int(exposure) == 0: 

# Don't believe it 

frame_id = self._header["FRAMEID"].strip() 

m = re.search(r"^SUP[A-Z](\d{7})\d{1}$", frame_id) 

if not m: 

raise RuntimeError("Unable to interpret FRAMEID: %s" % frame_id) 

exposure = int(m.group(1)) 

self._used_these_cards("EXP-ID", "FRAMEID") 

return exposure 

 

@cache_translation 

def to_visit_id(self): 

"""Calculate the unique integer ID for this visit. 

 

Assumed to be identical to the exposure ID in this implementation. 

 

Returns 

------- 

exp : `int` 

Unique visit identifier. 

""" 

if self.to_observation_type() == "science": 

return self.to_exposure_id() 

return None 

 

@cache_translation 

def to_observation_type(self): 

"""Calculate the observation type. 

 

Returns 

------- 

typ : `str` 

Observation type. Normalized to standard set. 

""" 

obstype = self._header["DATA-TYP"].strip().lower() 

self._used_these_cards("DATA-TYP") 

if obstype == "object": 

return "science" 

return obstype 

 

@cache_translation 

def to_tracking_radec(self): 

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

radec = SkyCoord(self._header["RA2000"], self._header["DEC2000"], 

frame="icrs", unit=(u.hourangle, u.deg), 

obstime=self.to_datetime_begin(), location=self.to_location()) 

self._used_these_cards("RA2000", "DEC2000") 

return radec 

 

@cache_translation 

def to_altaz_begin(self): 

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

return altaz_from_degree_headers(self, (("ALTITUDE", "AZIMUTH"),), 

self.to_datetime_begin()) 

 

@cache_translation 

def to_boresight_rotation_angle(self): 

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

angle = Angle(self.quantity_from_card("INR-STR", u.deg)) 

angle = angle.wrap_at("360d") 

return angle 

 

@cache_translation 

def to_detector_exposure_id(self): 

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

return self.to_exposure_id() * 10 + self.to_detector_num() 

 

@cache_translation 

def to_detector_name(self): 

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

# See https://subarutelescope.org/Observing/Instruments/SCam/ccd.html 

num = self.to_detector_num() 

 

names = ( 

"nausicaa", 

"kiki", 

"fio", 

"sophie", 

"sheeta", 

"satsuki", 

"chihiro", 

"clarisse", 

"ponyo", 

"san", 

) 

 

return names[num]