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""" Site Class 

2 

3 Class defines the attributes of the site unless overridden 

4 ajc@astro 2/23/2010 

5 

6 Restoring this so that the astrometry mixin in Astrometry.py 

7 can inherit the site information 

8 danielsf 1/27/2014 

9 

10""" 

11from builtins import object 

12 

13import numpy as np 

14import warnings 

15 

16__all__ = ["Site"] 

17 

18 

19class LSST_site_parameters(object): 

20 """ 

21 This is a struct containing the LSST site parameters as defined in 

22 

23 https://docushare.lsstcorp.org/docushare/dsweb/ImageStoreViewer/LSE-30 

24 

25 (accessed on 4 January 2016) 

26 

27 This class only exists for initializing Site with LSST parameter values. 

28 Users should not be accessing this class directly. 

29 """ 

30 

31 def __init__(self): 

32 self.longitude = -70.7494 # in degrees 

33 self.latitude = -30.2444 # in degrees 

34 self.height = 2650.0 # in meters 

35 self.temperature = 11.5 # in centigrade 

36 self.pressure = 750.0 # in millibars 

37 self.humidity = 0.4 # scale 0-1 

38 self.lapseRate = 0.0065 # in Kelvin per meter 

39 # the lapse rate was not specified by LSE-30; 

40 # 0.0065 K/m appears to be the "standard" value 

41 # see, for example http://mnras.oxfordjournals.org/content/365/4/1235.full 

42 

43 

44class Site (object): 

45 """ 

46 This class will store site information for use in Catalog objects. 

47 

48 Defaults values are LSST site values taken from the Observatory System Specification 

49 document 

50 

51 https://docushare.lsstcorp.org/docushare/dsweb/ImageStoreViewer/LSE-30 

52 

53 on 4 January 2016 

54 

55 Attributes 

56 ---------- 

57 longitude: in degrees 

58 

59 longitude_rad: longitude in radians 

60 

61 latitude: in degrees 

62 

63 latitude_rad: latitude in radians 

64 

65 height: in meters 

66 

67 temperature: mean temperature in Centigrade 

68 

69 temperature_kelvin: mean temperature in Kelvin 

70 

71 pressure: in millibars 

72 

73 humidity: relative humidity (range 0-1) 

74 

75 lapseRate: change in temperature in Kelvins per meter 

76 

77 name: name of the observatory. If set to 'LSST' any unspecified 

78 values will default to LSST values as defined in 

79 

80 https://docushare.lsstcorp.org/docushare/dsweb/ImageStoreViewer/LSE-30 

81 

82 i.e. 

83 longitude=-70.7494 degrees 

84 latitude=-30.2444 degrees 

85 height=2650.0 meters 

86 temperature=11.5 centigrade 

87 pressure=750.0 millibars 

88 humidity=0.4 

89 lapseRate=0.0065in Kelvin per meter 

90 """ 

91 def __init__(self, 

92 name=None, 

93 longitude=None, 

94 latitude=None, 

95 height=None, 

96 temperature=None, 

97 pressure=None, 

98 humidity=None, 

99 lapseRate=None): 

100 """ 

101 Parameters 

102 ---------- 

103 name: a string denoting the name of the observator. Set to 'LSST' 

104 for other parameters to default to LSST values. 

105 

106 i.e. 

107 longitude=-70.7494 degrees 

108 latitude=-30.2444 degrees 

109 height=2650.0 meters 

110 temperature=11.5 centigrade 

111 pressure=750.0 millibars 

112 humidity=0.4 

113 lapseRate=0.0065 in Kelvin per meter 

114 

115 longitude: in degrees 

116 

117 latitude: in degrees 

118 

119 height: in meters 

120 

121 temperature: in Centigrade 

122 

123 pressure: in millibars 

124 

125 humidity: relative (range 0-1) 

126 

127 lapseRate: in Kelvin per meter 

128 """ 

129 

130 default_params = None 

131 self._name = name 

132 if self._name is 'LSST': 132 ↛ 135line 132 didn't jump to line 135, because the condition on line 132 was never false

133 default_params = LSST_site_parameters() 

134 

135 if default_params is not None: 135 ↛ 157line 135 didn't jump to line 157, because the condition on line 135 was never false

136 if longitude is None: 136 ↛ 139line 136 didn't jump to line 139, because the condition on line 136 was never false

137 longitude = default_params.longitude 

138 

139 if latitude is None: 139 ↛ 142line 139 didn't jump to line 142, because the condition on line 139 was never false

140 latitude = default_params.latitude 

141 

142 if height is None: 142 ↛ 145line 142 didn't jump to line 145, because the condition on line 142 was never false

143 height = default_params.height 

144 

145 if temperature is None: 145 ↛ 148line 145 didn't jump to line 148, because the condition on line 145 was never false

146 temperature = default_params.temperature 

147 

148 if pressure is None: 148 ↛ 151line 148 didn't jump to line 151, because the condition on line 148 was never false

149 pressure = default_params.pressure 

150 

151 if humidity is None: 151 ↛ 154line 151 didn't jump to line 154, because the condition on line 151 was never false

152 humidity = default_params.humidity 

153 

154 if lapseRate is None: 154 ↛ 157line 154 didn't jump to line 157, because the condition on line 154 was never false

155 lapseRate = default_params.lapseRate 

156 

157 if longitude is not None: 157 ↛ 160line 157 didn't jump to line 160, because the condition on line 157 was never false

158 self._longitude_rad = np.radians(longitude) 

159 else: 

160 self._longitude_rad = None 

161 

162 if latitude is not None: 162 ↛ 165line 162 didn't jump to line 165, because the condition on line 162 was never false

163 self._latitude_rad = np.radians(latitude) 

164 else: 

165 self._latitude_rad = None 

166 

167 self._longitude_deg = longitude 

168 self._latitude_deg = latitude 

169 self._height = height 

170 self._pressure = pressure 

171 

172 if temperature is not None: 172 ↛ 175line 172 didn't jump to line 175, because the condition on line 172 was never false

173 self._temperature_kelvin = temperature + 273.15 # in Kelvin 

174 else: 

175 self._temperature_kelvin = None 

176 

177 self._temperature_centigrade = temperature 

178 self._humidity = humidity 

179 self._lapseRate = lapseRate 

180 

181 # Go through all the attributes of this Site. 

182 # Raise a warning if any are None so that the user 

183 # is not surprised when some use of this Site fails 

184 # because something that should have beena a float 

185 # is NoneType 

186 list_of_nones = [] 

187 if self.longitude is None or self.longitude_rad is None: 187 ↛ 188line 187 didn't jump to line 188, because the condition on line 187 was never true

188 if self.longitude_rad is not None: 

189 raise RuntimeError("in Site: longitude is None but longitude_rad is not") 

190 if self.longitude is not None: 

191 raise RuntimeError("in Site: longitude_rad is None but longitude is not") 

192 list_of_nones.append('longitude') 

193 

194 if self.latitude is None or self.latitude_rad is None: 194 ↛ 195line 194 didn't jump to line 195, because the condition on line 194 was never true

195 if self.latitude_rad is not None: 

196 raise RuntimeError("in Site: latitude is None but latitude_rad is not") 

197 if self.latitude is not None: 

198 raise RuntimeError("in Site: latitude_rad is None but latitude is not") 

199 list_of_nones.append('latitude') 

200 

201 if self.temperature is None or self.temperature_kelvin is None: 201 ↛ 202line 201 didn't jump to line 202, because the condition on line 201 was never true

202 if self.temperature is not None: 

203 raise RuntimeError("in Site: temperature_kelvin is None but temperature is not") 

204 if self.temperature_kelvin is not None: 

205 raise RuntimeError("in Site: temperature is None but temperature_kelvin is not") 

206 list_of_nones.append('temperature') 

207 

208 if self.height is None: 208 ↛ 209line 208 didn't jump to line 209, because the condition on line 208 was never true

209 list_of_nones.append('height') 

210 

211 if self.pressure is None: 211 ↛ 212line 211 didn't jump to line 212, because the condition on line 211 was never true

212 list_of_nones.append('pressure') 

213 

214 if self.humidity is None: 214 ↛ 215line 214 didn't jump to line 215, because the condition on line 214 was never true

215 list_of_nones.append('humidity') 

216 

217 if self.lapseRate is None: 217 ↛ 218line 217 didn't jump to line 218, because the condition on line 217 was never true

218 list_of_nones.append('lapseRate') 

219 

220 if len(list_of_nones) != 0: 220 ↛ 221line 220 didn't jump to line 221, because the condition on line 220 was never true

221 msg = "The following attributes of your Site were None:\n" 

222 for name in list_of_nones: 

223 msg += "%s\n" % name 

224 msg += "If you want these to just default to LSST values,\n" 

225 msg += "instantiate your Site with name='LSST'" 

226 warnings.warn(msg) 

227 

228 def __eq__(self, other): 

229 

230 for param in self.__dict__: 

231 if param not in other.__dict__: 

232 return False 

233 if self.__dict__[param] != other.__dict__[param]: 

234 return False 

235 

236 for param in other.__dict__: 

237 if param not in self.__dict__: 

238 return False 

239 

240 return True 

241 

242 def __ne__(self, other): 

243 return not self.__eq__(other) 

244 

245 @property 

246 def name(self): 

247 """ 

248 observatory name 

249 """ 

250 return self._name 

251 

252 @property 

253 def longitude_rad(self): 

254 """ 

255 observatory longitude in radians 

256 """ 

257 return self._longitude_rad 

258 

259 @property 

260 def longitude(self): 

261 """ 

262 observatory longitude in degrees 

263 """ 

264 return self._longitude_deg 

265 

266 @property 

267 def latitude_rad(self): 

268 """ 

269 observatory latitude in radians 

270 """ 

271 return self._latitude_rad 

272 

273 @property 

274 def latitude(self): 

275 """ 

276 observatory latitude in degrees 

277 """ 

278 return self._latitude_deg 

279 

280 @property 

281 def temperature(self): 

282 """ 

283 mean temperature in centigrade 

284 """ 

285 return self._temperature_centigrade 

286 

287 @property 

288 def temperature_kelvin(self): 

289 """ 

290 mean temperature in Kelvin 

291 """ 

292 return self._temperature_kelvin 

293 

294 @property 

295 def height(self): 

296 """ 

297 height in meters 

298 """ 

299 return self._height 

300 

301 @property 

302 def pressure(self): 

303 """ 

304 mean pressure in millibars 

305 """ 

306 return self._pressure 

307 

308 @property 

309 def humidity(self): 

310 """ 

311 mean humidity in the range 0-1 

312 """ 

313 return self._humidity 

314 

315 @property 

316 def lapseRate(self): 

317 """ 

318 temperature lapse rate (in Kelvin per meter) 

319 """ 

320 return self._lapseRate