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

# 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 COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

"""Metadata translation code for CFHT MegaPrime FITS headers""" 

 

__all__ = ("MegaPrimeTranslator", ) 

 

from astropy.coordinates import EarthLocation, Angle 

import astropy.units as u 

 

from ..translator import cache_translation 

from .fits import FitsTranslator 

from .helpers import tracking_from_degree_headers, altaz_from_degree_headers 

 

filters = {'u.MP9301': 'u', 

'u.MP9302': 'u2', 

'g.MP9401': 'g', 

'g.MP9402': 'g2', 

'r.MP9601': 'r', 

'r.MP9602': 'r2', 

'i.MP9701': 'i', 

'i.MP9702': 'i2', 

'i.MP9703': 'i3', 

'z.MP9801': 'z', 

'z.MP9901': 'z2', 

} 

 

 

class MegaPrimeTranslator(FitsTranslator): 

"""Metadata translator for CFHT MegaPrime standard headers. 

""" 

 

name = "MegaPrime" 

"""Name of this translation class""" 

 

supported_instrument = "MegaPrime" 

"""Supports the MegaPrime instrument.""" 

 

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

"boresight_rotation_coord": "unknown", 

"detector_group": None} 

 

_trivial_map = {"physical_filter": "FILTER", 

"dark_time": ("DARKTIME", dict(unit=u.s)), 

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

"observation_id": "OBSID", 

"object": "OBJECT", 

"science_program": "RUNID", 

"exposure_id": "EXPNUM", 

"visit_id": "EXPNUM", 

"detector_serial": "CCDNAME", 

"detector_name": "CCDNICK", 

"relative_humidity": ["RELHUMID", "HUMIDITY"], 

"temperature": (["TEMPERAT", "AIRTEMP"], dict(unit=u.deg_C)), 

"boresight_airmass": ["AIRMASS", "BORE-AIRMASS"]} 

 

@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["UTC-OBS"], scale="utc") 

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

return value 

 

@cache_translation 

def to_datetime_end(self): 

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

# Older files are missing UTCEND 

if "UTCEND" in self._header: 

# We know it is UTC 

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

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

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

else: 

# Take a guess by adding on the exposure time 

value = self.to_datetime_begin() + self.to_exposure_time() 

return value 

 

@cache_translation 

def to_location(self): 

"""Calculate the observatory location. 

 

Returns 

------- 

location : `astropy.coordinates.EarthLocation` 

An object representing the location of the telescope. 

""" 

# Height is not in some MegaPrime files. Use the value from EarthLocation.of_site("CFHT") 

# Some data uses OBS-LONG, OBS-LAT, other data uses LONGITUD and LATITUDE 

for long_key, lat_key in (("LONGITUD", "LATITUDE"), ("OBS-LONG", "OBS-LAT")): 

if long_key in self._header and lat_key in self._header: 

value = EarthLocation.from_geodetic(self._header[long_key], self._header[lat_key], 4215.0) 

self._used_these_cards(long_key, lat_key) 

break 

else: 

value = EarthLocation.of_site("CFHT") 

return value 

 

@cache_translation 

def to_detector_num(self): 

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

try: 

extname = self._header["EXTNAME"] 

num = int(extname[3:]) # chop off "ccd" 

self._used_these_cards("EXTNAME") 

return num 

except (KeyError, ValueError): 

# Dummy value, intended for PHU (need something to get filename) 

return 99 

 

@cache_translation 

def to_observation_type(self): 

"""Calculate the observation type. 

 

Returns 

------- 

typ : `str` 

Observation type. Normalized to standard set. 

""" 

obstype = self._header["OBSTYPE"].strip().lower() 

self._used_these_cards("OBSTYPE") 

if obstype == "object": 

return "science" 

return obstype 

 

@cache_translation 

def to_tracking_radec(self): 

"""Calculate the tracking RA/Dec for this observation. 

 

Currently will be `None` for geocentric apparent coordinates. 

Additionally, can be `None` for non-science observations. 

 

The method supports multiple versions of header defining tracking 

coordinates. 

 

Returns 

------- 

coords : `astropy.coordinates.SkyCoord` 

The tracking coordinates. 

""" 

radecsys = ("RADECSYS", "OBJRADEC", "RADESYS") 

radecpairs = (("RA_DEG", "DEC_DEG"), ("BORE-RA", "BORE-DEC")) 

return tracking_from_degree_headers(self, radecsys, radecpairs) 

 

@cache_translation 

def to_altaz_begin(self): 

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

return altaz_from_degree_headers(self, (("TELALT", "TELAZ"), ("BORE-ALT", "BORE-AZ")), 

self.to_datetime_begin()) 

 

@cache_translation 

def to_detector_exposure_id(self): 

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

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

 

@cache_translation 

def to_pressure(self): 

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

# Can be either AIRPRESS in Pa or PRESSURE in mbar 

for key, unit in (("PRESSURE", u.hPa), ("AIRPRESS", u.Pa)): 

if key in self._header: 

return self.quantity_from_card(key, unit) 

else: 

raise KeyError("Could not find pressure keywords in header")