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 lightcurve block for the object ticket* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

11import re 

12import datetime as datetime 

13from marshall_webapp.templates.commonelements import commonutils as cu 

14import khufu 

15from fundamentals import times 

16 

17 

18def lightcurve_block( 

19 log, 

20 request, 

21 discoveryDataDictionary, 

22 lightcurveData, 

23 objectAkas, 

24 displayTitle=True, 

25 offset=2): 

26 """get ticket lightcurve block 

27 

28 **Key Arguments** 

29 

30 - ``log`` -- logger 

31 - ``request`` -- the pyramid request 

32 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient. 

33 - ``lightcurveData`` -- the lightcurve data for the objects displayed on the webpage 

34 - ``objectAkas`` -- the transient object akas 

35 - ``displayTitle`` -- display the title for this block? 

36 - ``offset`` -- the offset for the block 

37 

38 

39 **Return** 

40 

41 - ``lightcurve_block`` -- the ticket identity block for the pesssto object 

42 

43 """ 

44 log.debug('starting the ``lightcurve_block`` function') 

45 

46 masterName = discoveryDataDictionary["masterName"] 

47 lsqExists = False 

48 atlasExist = False 

49 

50 if displayTitle: 

51 title = cu.block_title( 

52 log, 

53 title="lightcurve" 

54 ) 

55 else: 

56 title = "" 

57 

58 lightCurveImage = "" 

59 dlightCurveImage = "" 

60 

61 if discoveryDataDictionary["master_pessto_lightcurve"]: 

62 dlightCurveImage = 'caches/transients/%s/master_lightcurve.png' % ( 

63 discoveryDataDictionary["transientBucketId"],) 

64 lightCurveImage = request.static_url(f'marshall_webapp:{dlightCurveImage}') 

65 

66 # Override for LSQ lightcurves 

67 lightcurveSwitchAttempt = True 

68 transientBucketId = discoveryDataDictionary["transientBucketId"] 

69 for row in lightcurveData: 

70 if row["transientBucketId"] == discoveryDataDictionary["transientBucketId"] and row["survey"] and "lsq-disc" in row["survey"].lower(): 

71 lightcurveSwitchAttempt = False 

72 

73 if lightcurveSwitchAttempt == True: 

74 filePath = request.registry.settings[ 

75 "cache-directory"] + "/transients/%(transientBucketId)s/lsq_lightcurve.gif" % locals() 

76 lsqExists = os.path.exists(filePath) 

77 

78 if lsqExists: 

79 dlightCurveImage = 'caches/transients/%(transientBucketId)s/lsq_lightcurve.gif' % locals( 

80 ) 

81 lightCurveImage = request.static_url(f'marshall_webapp:{dlightCurveImage}') 

82 

83 # Override for ATLAS lightcurves 

84 if discoveryDataDictionary["atlas_fp_lightcurve"]: 

85 lightCurveImage = 'caches/transients/%s/atlas_fp_lightcurve.png' % ( 

86 discoveryDataDictionary["transientBucketId"],) 

87 lightCurveImage = request.static_url(f'marshall_webapp:{lightCurveImage}') 

88 dlightCurveImage = lightCurveImage 

89 

90 if len(lightCurveImage): 

91 href = request.route_path( 

92 'download', _query={'url': dlightCurveImage, "webapp": "marshall_webapp", "filename": "%(masterName)s_master_lightcurve" % locals()}) 

93 lightCurveImage = khufu.imagingModal( 

94 log=log, 

95 imagePath=lightCurveImage, 

96 display="rounded", # [ rounded | circle | polaroid | False ] 

97 modalHeaderContent="Lightcurve for %(masterName)s" % locals(), 

98 modalFooterContent="", 

99 stampWidth="100%", 

100 modalImageWidth="50%", 

101 downloadLink=href) 

102 lightCurveImage = lightCurveImage.get() 

103 

104 else: 

105 lightCurveImage = khufu.image( 

106 # [ industrial | gray | social ] 

107 src="""holder.js/190x190/auto/industrial/text:master lightcurve not ready""", 

108 display="rounded", # [ rounded | circle | polaroid | False ] 

109 ) 

110 

111 # get current magnitude estimate 

112 currentMagEstimate = discoveryDataDictionary["currentMagnitudeEstimate"] 

113 currentMagEstimateUpdated = discoveryDataDictionary[ 

114 "currentMagnitudeEstimateUpdated"] 

115 

116 now = datetime.datetime.now() 

117 if currentMagEstimate in [9999, -9999]: 

118 for dataPoint in lightcurveData: 

119 if dataPoint["transientBucketId"] == discoveryDataDictionary["transientBucketId"]: 

120 break 

121 if len(lightcurveData) and (now - dataPoint["observationDate"] < datetime.timedelta(days=7)): 

122 currentMagEstimate = dataPoint["magnitude"] 

123 if currentMagEstimateUpdated and currentMagEstimate not in [9999, -9999]: 

124 

125 if now - currentMagEstimateUpdated < datetime.timedelta(days=2): 

126 littleTitle = cu.little_label( 

127 text="current mag estimate:" 

128 ) 

129 # add text color 

130 if currentMagEstimate > 21.: 

131 text = "&nbsp&nbsp> 21.0" 

132 else: 

133 text = "&nbsp&nbsp%(currentMagEstimate)0.2f" % locals() 

134 currentMagEstimate = khufu.coloredText( 

135 text=text, 

136 color="violet", 

137 size=7, # 1-10 

138 pull=False, # "left" | "right" 

139 ) 

140 currentMagEstimateUpdated = khufu.coloredText( 

141 text=currentMagEstimateUpdated, 

142 color="red", 

143 size=False, # 1-10 

144 pull=False, # "left" | "right" 

145 ) 

146 currentMagEstimate = khufu.grid_row( 

147 responsive=True, 

148 columns="%(littleTitle)s %(currentMagEstimate)s" % locals() 

149 ) 

150 else: 

151 currentMagEstimate = "" 

152 

153 else: 

154 currentMagEstimate = "" 

155 

156 # get three latest magnitudes 

157 littleTitle = """<span class="colortext grey littlelabel ">discovery magnitude:</span>""" 

158 ffilter = "" 

159 if discoveryDataDictionary["earliestMagnitudeFilter"]: 

160 ffilter = discoveryDataDictionary["earliestMagnitudeFilter"] 

161 ffilter = """%(ffilter)s-band""" % locals() 

162 elif discoveryDataDictionary["earliestMagnitude"] == None: 

163 ffilter = "waiting on LSQ forced phot." 

164 survey = discoveryDataDictionary["earliestMagnitudeSurvey"] 

165 if not survey: 

166 survey = "" 

167 survey = khufu.coloredText( 

168 text="""%s %s""" % (survey, ffilter, ), 

169 color="orange", 

170 size=3, 

171 pull="left" 

172 ) 

173 earliestMag = discoveryDataDictionary["earliestMagnitude"] 

174 if earliestMag: 

175 earliestMag = khufu.coloredText( 

176 text="""%4.2f""" % (earliestMag,), 

177 color="green", 

178 size=6, 

179 pull="right" 

180 ) 

181 else: 

182 earliestMag = khufu.coloredText( 

183 text="""?""", 

184 color="green", 

185 size=6, 

186 pull="right" 

187 ) 

188 

189 earliestDetection = khufu.coloredText( 

190 text="""%s""" % ( 

191 str(discoveryDataDictionary["earliestDetection"])[0:10],), 

192 color="violet", 

193 pull="left", 

194 size=2 

195 ) 

196 

197 try: 

198 relDate = times.datetime_relative_to_now( 

199 discoveryDataDictionary["earliestDetection"]) 

200 relDate = khufu.coloredText( 

201 text=""" %s""" % (relDate[1:]), 

202 color="magenta", 

203 pull="left", 

204 size=2 

205 ) 

206 except: 

207 relDate = "?" 

208 survey = khufu.grid_row( 

209 responsive=True, 

210 columns=survey 

211 ) 

212 earliestDetection = khufu.grid_row( 

213 responsive=True, 

214 columns="%(earliestDetection)s %(relDate)s" % locals() 

215 ) 

216 info = khufu.grid_column( 

217 span=6, # 1-12 

218 offset=0, # 1-12 

219 content="%(survey)s %(earliestDetection)s" % locals(), 

220 pull="left", # ["right", "left", "center"] 

221 htmlId=False, 

222 htmlClass=False, 

223 onPhone=True, 

224 onTablet=True, 

225 onDesktop=True 

226 ) 

227 earliestMag = khufu.grid_column( 

228 span=3, # 1-12 

229 offset=offset, # 1-12 

230 content=earliestMag, 

231 pull=False, # ["right", "left", "center"] 

232 htmlId=False, 

233 htmlClass=False, 

234 onPhone=True, 

235 onTablet=True, 

236 onDesktop=True 

237 ) 

238 

239 earliestMag = khufu.grid_row( 

240 responsive=True, 

241 columns="%(earliestMag)s %(info)s" % locals(), 

242 htmlId=False, 

243 htmlClass=False, 

244 onPhone=True, 

245 onTablet=True, 

246 onDesktop=True 

247 ) 

248 

249 earliestMag = "%(littleTitle)s<span>%(earliestMag)s</span>" % locals() 

250 

251 # get three latest magnitudes 

252 littleTitle = """<span class="colortext grey littlelabel ">latest magnitude:</span>""" 

253 numOfPointsToDisplay = 1 

254 count = 0 

255 rows = [] 

256 magnitudes = "" 

257 for dataPoint in lightcurveData: 

258 if dataPoint["transientBucketId"] == discoveryDataDictionary["transientBucketId"]: 

259 row = dataPoint 

260 rows.append(row) 

261 count += 1 

262 if count >= numOfPointsToDisplay: 

263 break 

264 

265 for row in rows: 

266 ffilter = "" 

267 if row["filter"]: 

268 ffilter = row["filter"] 

269 ffilter = """%(ffilter)s-band""" % locals() 

270 

271 survey = khufu.coloredText( 

272 text="""%s %s""" % (row["survey"], ffilter, ), 

273 color="orange", 

274 size=3, 

275 pull="left" 

276 ) 

277 

278 relDate = times.datetime_relative_to_now(row["observationDate"]) 

279 dateObs = khufu.coloredText( 

280 text="""%s""" % ( 

281 str(row["observationDate"])[0:10],), 

282 color="violet", 

283 pull="left", 

284 size=2 

285 ) 

286 relDate = khufu.coloredText( 

287 text=""" %s""" % (relDate[1:]), 

288 color="magenta", 

289 pull="left", 

290 size=2 

291 ) 

292 survey = khufu.grid_row( 

293 responsive=True, 

294 columns=survey 

295 ) 

296 dateObs = khufu.grid_row( 

297 responsive=True, 

298 columns="%(dateObs)s %(relDate)s" % locals() 

299 ) 

300 info = khufu.grid_column( 

301 span=6, # 1-12 

302 offset=0, # 1-12 

303 content="%(survey)s %(dateObs)s" % locals(), 

304 pull="left", # ["right", "left", "center"] 

305 htmlId=False, 

306 htmlClass=False, 

307 onPhone=True, 

308 onTablet=True, 

309 onDesktop=True 

310 ) 

311 

312 if row["magnitude"]: 

313 mag = khufu.coloredText( 

314 text="""%4.2f""" % (row["magnitude"],), 

315 color="green", 

316 size=6, 

317 pull="right" 

318 ) 

319 else: 

320 mag = khufu.coloredText( 

321 text="""%s""" % (row["magnitude"],), 

322 color="green", 

323 size=6, 

324 pull="right" 

325 ) 

326 

327 mag = khufu.grid_column( 

328 span=3, # 1-12 

329 offset=offset, # 1-12 

330 content=mag, 

331 pull=False, # ["right", "left", "center"] 

332 htmlId=False, 

333 htmlClass=False, 

334 onPhone=True, 

335 onTablet=True, 

336 onDesktop=True 

337 ) 

338 

339 thisMag = khufu.grid_row( 

340 responsive=True, 

341 columns="%(mag)s %(info)s" % locals(), 

342 htmlId=False, 

343 htmlClass=False, 

344 onPhone=True, 

345 onTablet=True, 

346 onDesktop=True 

347 ) 

348 magnitudes = "%(magnitudes)s %(thisMag)s" % locals() 

349 

350 magnitudes = "%(littleTitle)s<span>%(magnitudes)s</span>" % locals() 

351 

352 return "%(title)s %(lightCurveImage)s %(earliestMag)s %(magnitudes)s %(currentMagEstimate)s" % locals()