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#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*The HTML template module for the `templates_transients_obs.py` resource* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import str 

10from builtins import object 

11import sys 

12import os 

13import khufu 

14from marshall_webapp.models.transients_obs import models_transients_obs_get 

15 

16 

17class templates_transients_obs(object): 

18 """ 

19 The worker class for the templates_transients_obs module 

20 

21 **Key Arguments** 

22 

23 - ``log`` -- logger 

24 - ``request`` -- the pyramid request 

25 - ``elementId`` -- the specific element requested (or False) 

26 

27 """ 

28 

29 def __init__( 

30 self, 

31 log, 

32 request, 

33 elementId=False 

34 ): 

35 self.log = log 

36 self.request = request 

37 self.elementId = elementId 

38 # xt-self-arg-tmpx 

39 

40 log.debug("instansiating a new 'templates_transients_obs' object") 

41 

42 return None 

43 

44 def get(self): 

45 """get the templates_transients_obs object 

46 

47 **Return** 

48 

49 - ``filename`` 

50 - ``obText`` 

51 

52 """ 

53 self.log.debug('starting the ``get`` method') 

54 

55 # get info needed from database 

56 transients_obs = models_transients_obs_get( 

57 log=self.log, 

58 request=self.request, 

59 elementId=self.elementId 

60 ) 

61 transient_ob_data = transients_obs.get() 

62 

63 # download filename and data for OB 

64 filename, obText = self._generate_ob_text( 

65 transient_ob_data=transient_ob_data 

66 ) 

67 

68 self.log.debug('completed the ``get`` method') 

69 return filename, obText 

70 

71 def _generate_ob_text( 

72 self, 

73 transient_ob_data): 

74 """ generate ob text 

75 

76 **Key Arguments** 

77 

78 - ``transient_ob_data`` 

79 

80 

81 **Return** 

82 

83 - ``downloadFilename`` 

84 - ``obText`` 

85 

86 """ 

87 self.log.debug('starting the ``_generate_ob_text`` method') 

88 

89 od = {} # override dictionary 

90 

91 # UNPACK DICTIONARY VALUES TO LOCAL() 

92 a = {} 

93 for arg, val in list(transient_ob_data.items()): 

94 if arg[0] == "-": 

95 varname = arg.replace("-", "") + "Flag" 

96 else: 

97 varname = arg.replace("<", "").replace(">", "") 

98 a[varname] = val 

99 self.log.debug('%s = %s' % (varname, val,)) 

100 

101 instrument = a["instrument"] 

102 spectrumOrImage = a["spectrumOrImage"] 

103 currentMag = a["currentMag"] 

104 ra = a["ra"] 

105 dec = a["dec"] 

106 objectName = a["objectName"] 

107 objectClass = a["objectClass"] 

108 grism = a["grism"] 

109 badSeeing = a["badSeeing"] 

110 

111 # instrument 

112 if "efos" in instrument: 

113 od["b4_instrument"] = "EFOSC2" 

114 else: 

115 od["b4_instrument"] = "SOFI" 

116 

117 if "spec" in spectrumOrImage: 

118 od["b5_ACQUISITION.TEMPLATE.NAME"] = "EFOSC_img_acq_MoveToSlit" 

119 od["b6_TEMPLATE.NAME"] = "EFOSC_spec_obs_Spectrum" 

120 else: 

121 od["b5_ACQUISITION.TEMPLATE.NAME"] = "EFOSC_img_acq_MoveToPixel" 

122 od["b6_TEMPLATE.NAME"] = "EFOSC_img_obs_Image" 

123 

124 currentMag = float(currentMag) 

125 od["b2_ra"] = ra 

126 od["b2_dec"] = dec 

127 od["b2_TARGET.NAME"] = objectName 

128 od["b2_objectClass"] = objectClass 

129 od["b6_INS.GRIS1.NAME"] = "Gr#%(grism)s" % locals() 

130 

131 filename = """spec_v_""" 

132 # SEEING 

133 if badSeeing is not False: 

134 od["b5_INS.SLIT1.NAME"] = "slit#1.5" 

135 else: 

136 od["b5_INS.SLIT1.NAME"] = "slit#1.0" 

137 od["b6_INS.SLIT1.NAME"] = od["b5_INS.SLIT1.NAME"] 

138 

139 # DEFINE VALUES FROM CURRENT OBJECT MAGNITUDE 

140 if currentMag < 13.0: 

141 # very bright objects (V<13) => t = 40 s (V=12 => S/N~180) 

142 od["b1_userComments"] = "targets: V < 13" 

143 od["b6_DET.WIN1.UIT1"] = 40 

144 od["b5_DET.WIN1.UIT1"] = 1 

145 filename = """%(filename)sbrighter__13_0""" % locals() 

146 

147 elif currentMag < 14.5: 

148 # bright sources (13 < V < 14.5) => t = 120 s (V=14 => S/N~120) 

149 od["b1_userComments"] = "targets: 13 < V < 14.5" 

150 od["b6_DET.WIN1.UIT1"] = 120 

151 od["b5_DET.WIN1.UIT1"] = 3 

152 filename = """%(filename)s13p0_14p5""" % locals() 

153 elif currentMag < 16.0: 

154 # relatively bright sources (14.5 < V < 16) => t = 180 s (V=15.5=> 

155 # S/N~70) 

156 od["b1_userComments"] = "targets: 14.5 < V < 16" 

157 od["b6_DET.WIN1.UIT1"] = 180 

158 od["b5_DET.WIN1.UIT1"] = 5 

159 filename = """%(filename)s14p5_16p0""" % locals() 

160 elif currentMag < 17.5: 

161 # intermediate mag. sources (16 < V < 17.5) => t = 300 s (V=17 => 

162 # S/N~45) 

163 od["b1_userComments"] = "targets: 16 < V < 17.5" 

164 od["b6_DET.WIN1.UIT1"] = 300 

165 od["b5_DET.WIN1.UIT1"] = 10 

166 filename = """%(filename)s16p0_17p5""" % locals() 

167 elif currentMag < 18.5: 

168 # faintish sources (17.5 < V < 18.5) => t = 600 s (V=18 => S/N~35) 

169 od["b1_userComments"] = "targets: 17.5 < V < 18.5" 

170 od["b6_DET.WIN1.UIT1"] = 600 

171 od["b5_DET.WIN1.UIT1"] = 20 

172 filename = """%(filename)s17p5_18p5""" % locals() 

173 elif currentMag < 19.5: 

174 # faint sources (18.5 < V < 19.5) => t = 900 s (V=19 => S/N~25) 

175 od["b1_userComments"] = "targets: 18.5 < V < 19.5" 

176 od["b6_DET.WIN1.UIT1"] = 900 

177 od["b5_DET.WIN1.UIT1"] = 30 

178 filename = """%(filename)s18p5_19p5""" % locals() 

179 elif currentMag < 20.5: 

180 # very faint sources (19.5 < V < 20.5) => t = 1500 s (V=20 => 

181 # S/N~15) 

182 od["b1_userComments"] = "targets: 19.5 < V < 20.5" 

183 od["b6_DET.WIN1.UIT1"] = 1500 

184 od["b5_DET.WIN1.UIT1"] = 40 

185 filename = """%(filename)sfainter_19p5""" % locals() 

186 elif currentMag > 20.5: 

187 obText = "object too faint" 

188 return None, None 

189 else: 

190 obText = "object too faint" 

191 return None, None 

192 

193 filename = """%(filename)s_cls_g%(grism)s_s""" % locals() 

194 if badSeeing is not False: 

195 filename = """%(filename)s1p5""" % locals() 

196 else: 

197 filename = """%(filename)s1""" % locals() 

198 

199 nameForFilename = objectName.replace("-", "") 

200 

201 od["b1_name"] = "class_" + nameForFilename[0:23] 

202 od["b4_OBSERVATION.DESCRIPTION.NAME"] = filename 

203 

204 filename = nameForFilename[0:15] + "_%(filename)s" % locals() 

205 downloadFilename = "%(filename)s.obx" % locals() 

206 

207 # VARIABLES 

208 obText = "" 

209 obDictionary = {} 

210 

211 obDictionary["b1_IMPEX.VERSION"] = "2.0" 

212 obDictionary["b1_type"] = "O" 

213 obDictionary["b1_STTimeIntervals"] = "" 

214 obDictionary["b1_calibrationReq"] = "" 

215 obDictionary["b1_InstrumentComments"] = "" 

216 # 'targets: 17.5 < V < 18.5' 

217 obDictionary["b1_userComments"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

218 obDictionary["b1_userPriority"] = "1" 

219 obDictionary["b1_LineNumber"] = "0" 

220 # of the form Spec_V_18_5__19_5_class_g13_s1 

221 obDictionary["b1_name"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

222 

223 obDictionary["b2_comments"] = "" 

224 # SN | STD 

225 obDictionary["b2_objectClass"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

226 obDictionary["b2_ra"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # sexegesimal 

227 obDictionary["b2_dec"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # sexegesimal 

228 obDictionary["b2_epoch"] = "2000.0" 

229 obDictionary["b2_equinox"] = "2000.0" 

230 obDictionary["b2_propDec"] = "0.000000" 

231 obDictionary["b2_propRA"] = "0.000000" 

232 obDictionary["b2_diffRA"] = "0.000000" 

233 obDictionary["b2_diffDec"] = "0.000000" 

234 obDictionary["b2_LineNumber"] = "0" 

235 # object name 

236 obDictionary["b2_TARGET.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

237 

238 obDictionary["b3_air_mass"] = "5.0" 

239 obDictionary["b3_fractional_lunar_illumination"] = "1.0" 

240 obDictionary["b3_sky_transparency"] = "Variable, thick cirrus" 

241 obDictionary["b3_moon_angular_distance"] = "30" 

242 obDictionary["b3_seeing"] = "1.5" 

243 obDictionary["b3_StrehlRatio"] = "0.0" 

244 obDictionary["b3_CONSTRAINT.SET.NAME"] = "No Name" 

245 

246 obDictionary["b4_longDescription"] = "" 

247 obDictionary["b4_IPVersion"] = "89.01" 

248 obDictionary["b4_instrument"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

249 obDictionary["b4_LineNumber"] = "0" 

250 obDictionary[ 

251 "b4_OBSERVATION.DESCRIPTION.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # same as 'name' in block one (name to be found in the headers of FITS files) 

252 

253 # 'EFOSC_img_acq_MoveToSlit' | ???? 

254 obDictionary[ 

255 "b5_ACQUISITION.TEMPLATE.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # should be moveToSlit (EFOSC_img_acq_MoveToSlit) and photometry movetopixel 

256 obDictionary["b5_DET.READ.SPEED"] = "normal" 

257 obDictionary["b5_DET.WIN1.UIT1"] = "20" 

258 obDictionary["b5_DET.WIN1.BINX"] = "2" 

259 obDictionary["b5_DET.WIN1.BINY"] = "2" 

260 obDictionary["b5_DET.PIXEL.X"] = "1100" 

261 obDictionary["b5_TEL.ROT.OFFANGLE"] = "-9999" 

262 obDictionary["b5_TEL.COMBINED.OFFSET"] = "T" 

263 obDictionary["b5_TEL.FOCUS"] = "F" 

264 obDictionary["b5_TEL.PRESET.NEW"] = "T" 

265 obDictionary["b5_INS.FILT1.NAME"] = "V#641" 

266 # slit#1.0 

267 obDictionary["b5_INS.SLIT1.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxx" 

268 

269 # 'EFOSC_spec_obs_Spectrum' | ??? 

270 obDictionary["b6_TEMPLATE.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxx" 

271 obDictionary["b6_DET.READ.SPEED"] = "normal" 

272 # exposure time 

273 obDictionary["b6_DET.WIN1.UIT1"] = "xxxxxxxxxxxxxxxxxxxxxxxxx" 

274 obDictionary["b6_DET.WIN1.ST"] = "F" 

275 obDictionary["b6_DET.WIN1.STRX"] = "1" 

276 obDictionary["b6_DET.WIN1.STRY"] = "1" 

277 obDictionary["b6_DET.WIN1.NX"] = "2048" 

278 obDictionary["b6_DET.WIN1.NY"] = "2048" 

279 obDictionary["b6_DET.WIN1.BINX"] = "2" 

280 obDictionary["b6_DET.WIN1.BINY"] = "2" 

281 obDictionary["b6_SEQ.NEXPO"] = "1" 

282 obDictionary["b6_INS.FILT1.NAME"] = "Free" 

283 obDictionary[ 

284 "b6_INS.GRIS1.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxxx" # Gr#13 

285 # slit#1.0 

286 obDictionary["b6_INS.SLIT1.NAME"] = "xxxxxxxxxxxxxxxxxxxxxxxxx" 

287 obDictionary["b6_DPR.TYPE"] = "OBJECT" 

288 

289 # override default values with user values 

290 for k, v in list(od.items()): 

291 obDictionary[k] = v 

292 

293 block1 = [ 

294 "b1_IMPEX.VERSION", 

295 "b1_type", 

296 "b1_STTimeIntervals", 

297 "b1_calibrationReq", 

298 "b1_InstrumentComments", 

299 "b1_userComments", 

300 "b1_userPriority", 

301 "b1_LineNumber", 

302 "b1_name", 

303 ] 

304 

305 block2 = [ 

306 "b2_comments", 

307 "b2_objectClass", 

308 "b2_ra", 

309 "b2_dec", 

310 "b2_epoch", 

311 "b2_equinox", 

312 "b2_propDec", 

313 "b2_propRA", 

314 "b2_diffRA", 

315 "b2_diffDec", 

316 "b2_LineNumber", 

317 "b2_TARGET.NAME", 

318 ] 

319 

320 block3 = [ 

321 "b3_air_mass", 

322 "b3_fractional_lunar_illumination", 

323 "b3_sky_transparency", 

324 "b3_moon_angular_distance", 

325 "b3_seeing", 

326 "b3_StrehlRatio", 

327 "b3_CONSTRAINT.SET.NAME", 

328 ] 

329 

330 block4 = [ 

331 "b4_longDescription", 

332 "b4_IPVersion", 

333 "b4_instrument", 

334 "b4_LineNumber", 

335 "b4_OBSERVATION.DESCRIPTION.NAME", 

336 ] 

337 

338 block5 = [ 

339 "b5_ACQUISITION.TEMPLATE.NAME", 

340 "b5_DET.READ.SPEED", 

341 "b5_DET.WIN1.UIT1", 

342 "b5_DET.WIN1.BINX", 

343 "b5_DET.WIN1.BINY", 

344 "b5_DET.PIXEL.X", 

345 "b5_TEL.ROT.OFFANGLE", 

346 "b5_TEL.COMBINED.OFFSET", 

347 "b5_TEL.FOCUS", 

348 "b5_TEL.PRESET.NEW", 

349 "b5_INS.FILT1.NAME", 

350 "b5_INS.SLIT1.NAME", 

351 ] 

352 

353 block6 = [ 

354 "b6_TEMPLATE.NAME", 

355 "b6_DET.READ.SPEED", 

356 "b6_DET.WIN1.UIT1", 

357 "b6_DET.WIN1.ST", 

358 "b6_DET.WIN1.STRX", 

359 "b6_DET.WIN1.STRY", 

360 "b6_DET.WIN1.NX", 

361 "b6_DET.WIN1.NY", 

362 "b6_DET.WIN1.BINX", 

363 "b6_DET.WIN1.BINY", 

364 "b6_SEQ.NEXPO", 

365 "b6_INS.FILT1.NAME", 

366 "b6_INS.GRIS1.NAME", 

367 "b6_INS.SLIT1.NAME", 

368 "b6_DPR.TYPE", 

369 ] 

370 

371 blocks = [block1, block2, block3, block4, block5, block6] 

372 

373 for block in blocks: 

374 for key in block: 

375 printKey = str(key)[3:].ljust(40) 

376 value = obDictionary[key] 

377 value = '"%(value)s"' % locals() 

378 

379 obText = "%(obText)s%(printKey)s%(value)s\n" % locals() 

380 obText = "%(obText)s\n\n" % locals() 

381 

382 self.log.debug('completed the ``_generate_ob_text`` method') 

383 return downloadFilename, obText 

384 

385 # xt-class-method