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 SDSS FITS headers""" 

 

__all__ = ("SdssTranslator", ) 

 

import posixpath 

 

from astropy.coordinates import EarthLocation, Angle, AltAz 

import astropy.units as u 

 

from ..translator import cache_translation, CORRECTIONS_RESOURCE_ROOT 

from .fits import FitsTranslator 

from .helpers import tracking_from_degree_headers 

 

 

class SdssTranslator(FitsTranslator): 

"""Metadata translator for SDSS standard headers. 

NB: calibration data is not handled as calibration frames were 

not available to me at time of writing. 

""" 

 

name = "SDSS" 

"""Name of this translation class""" 

 

supported_instrument = "Imager" 

"""Supports the SDSS imager instrument.""" 

 

default_resource_root = posixpath.join(CORRECTIONS_RESOURCE_ROOT, "SDSS") 

"""Default resource path root to use to locate header correction files.""" 

 

# SDSS has has a rotator, but in drift scan mode, the instrument 

# angle on sky is set to +X=East, +Y=North which we define as a 

# 0 degree rotation. 

_const_map = {"boresight_rotation_angle": Angle(0*u.deg), 

"boresight_rotation_coord": "sky", 

"dark_time": 0.0*u.s, # Drift scan implies no dark time 

"instrument": "Imager on SDSS 2.5m", # We only ever ingest data from the imager 

"telescope": "SDSS 2.5m", 

"relative_humidity": None, 

"temperature": None, 

"pressure": None, 

"detector_serial": "UNKNOWN", 

} 

 

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

"object": "OBJECT", 

"physical_filter": "FILTER", 

"exposure_id": "RUN", 

"visit_id": "RUN", 

"science_program": "OBJECT", # This is the closest I can think of to a useful program 

"detector_name": "CCDLOC", # This is a numeric incoding of the "slot", i.e. filter+camcol 

"telescope": ("TELESCOP", dict(default="2.5m")), 

} 

 

# Need a mapping from unique name to index. The order is arbitrary. 

detector_name_id_map = {"g1": 0, "z1": 1, "u1": 2, "i1": 3, "r1": 4, "g2": 5, "z2": 6, "u2": 7, 

"i2": 8, "r2": 9, "g3": 10, "z3": 11, "u3": 12, "i3": 13, "r3": 14, 

"g4": 15, "z4": 16, "u4": 17, "i4": 18, "r4": 19, "g5": 20, "z5": 21, 

"u5": 22, "i5": 23, "r5": 24, "g6": 25, "z6": 26, "u6": 27, "i6": 28, "r6": 29} 

 

@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 (cls.is_keyword_defined(header, "ORIGIN") and cls.is_keyword_defined(header, "CCDMODE") and 

cls.is_keyword_defined(header, "TELESCOP") and "2.5m" in header["TELESCOP"] and 

"SDSS" in header["ORIGIN"] and "DRIFT" in header["CCDMODE"]): 

return True 

return False 

 

@cache_translation 

def to_detector_unique_name(self): 

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

if self.is_key_ok("CAMCOL"): 

return self.to_physical_filter()+str(self._header["CAMCOL"]) 

else: 

raise ValueError("CAMCOL key is not definded") 

 

@cache_translation 

def to_detector_num(self): 

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

return self.detector_name_id_map[self.to_detector_unique_name()] 

 

@cache_translation 

def to_observation_id(self): 

"""Calculate the observation ID. 

 

Returns 

------- 

observation_id : `str` 

A string uniquely describing the observation. 

This incorporates the run, camcol, filter and frame. 

""" 

return " ".join([str(self._header[el]) for el in 

["RUN", "CAMCOL", "FILTER", "FRAME"]]) 

 

@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["TAIHMS"], scale="tai") 

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

return value 

 

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

"""Calculate the observatory location. 

 

Returns 

------- 

location : `astropy.coordinates.EarthLocation` 

An object representing the location of the telescope. 

""" 

 

# Look up the value since files do not have location 

value = EarthLocation.of_site("apo") 

 

return value 

 

@cache_translation 

def to_observation_type(self): 

"""Calculate the observation type. 

 

Returns 

------- 

typ : `str` 

Observation type. Normalized to standard set. 

""" 

obstype_key = "FLAVOR" 

if not self.is_key_ok(obstype_key): 

return "none" 

obstype = self._header[obstype_key].strip().lower() 

self._used_these_cards(obstype_key) 

return obstype 

 

@cache_translation 

def to_tracking_radec(self): 

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

radecsys = ("RADECSYS",) 

radecpairs = (("RA", "DEC"),) 

return tracking_from_degree_headers(self, radecsys, radecpairs, unit=u.deg) 

 

@cache_translation 

def to_altaz_begin(self): 

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

try: 

az = self._header["AZ"] 

alt = self._header["ALT"] 

# It appears SDSS defines azimuth as increasing 

# from South through East. This translates to 

# North through East 

az = (-az + 180.)%360. 

altaz = AltAz(az * u.deg, alt * u.deg, 

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

self._used_these_cards("AZ", "ALT") 

return altaz 

except Exception as e: 

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

return None # Allow Alt/Az not to be set for calibrations 

raise(e) 

 

@cache_translation 

def to_boresight_airmass(self): 

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

altaz = self.to_altaz_begin() 

if altaz is not None: 

return altaz.secz.value # This is an estimate 

 

@cache_translation 

def to_detector_exposure_id(self): 

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

try: 

frame_field_map = dict(r=0, i=2, u=4, z=6, g=8) 

run = self._header["RUN"] 

filt = self._header["FILTER"] 

camcol = self._header["CAMCOL"] 

field = self._header["FRAME"] - frame_field_map[filt] 

self._used_these_cards("RUN", "FILTER", "CAMCOL", "FRAME") 

except Exception as e: 

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

return None 

raise(e) 

filter_id_map = dict(u=0, g=1, r=2, i=3, z=4) 

return ((int(run) * 10 + 

filter_id_map[filt]) * 10 + 

int(camcol)) * 10000 + int(field) 

 

@cache_translation 

def to_detector_group(self): 

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

if self.is_key_ok("CAMCOL"): 

return str(self._header["CAMCOL"]) 

else: 

raise ValueError("CAMCOL key is not definded")