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

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

 

__all__ = ("MegaPrimeTranslator", ) 

 

import re 

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

"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 self.is_key_ok("UTCEND"): 

# 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 self.are_keys_ok([long_key, lat_key]): 

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

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

if self.is_key_ok("EXTNAME"): 

name = self._header["EXTNAME"] 

# Only valid name has form "ccdNN" 

if re.match(r"ccd\d+$", name): 

self._used_these_cards("EXTNAME") 

return name 

 

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

return "ccd99" 

 

@cache_translation 

def to_detector_num(self): 

name = self.to_detector_name() 

return int(name[3:]) 

 

@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 self.is_key_ok(key): 

return self.quantity_from_card(key, unit) 

else: 

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