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 photometry tab for the PESSTO Object tickets* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

11import datetime 

12import re 

13import khufu 

14from marshall_webapp.templates.commonelements.tickets.single_ticket import ticket_building_blocks 

15 

16 

17def photometry_tab( 

18 log, 

19 request, 

20 discoveryDataDictionary, 

21 objectAkas, 

22 atelData, 

23 lightcurveData): 

24 """photometry tab 

25 

26 **Key Arguments** 

27 

28 - ``log`` -- logger 

29 - ``request`` -- the pyramid request 

30 - ``discoveryDataDictionary`` -- the unique discoveryData dictionary of the object in the pessto marshall database (from view_object_contextual_data) 

31 - ``objectAkas`` -- object akas 

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

33 - ``atelData`` -- the atel matches for the objects displayed on the webpage 

34 

35 

36 **Return** 

37 

38 - ``photometry_tab`` -- the lightcurve/photometry tab for a single ticket on the transient listings page 

39 

40 """ 

41 from marshall_webapp.templates.commonelements.tickets import single_ticket 

42 

43 log.debug('starting the ``photometry_tab`` function') 

44 

45 master_lightcurve_block = ticket_building_blocks.master_lightcurve_block.master_lightcurve_block( 

46 log=log, 

47 request=request, 

48 discoveryDataDictionary=discoveryDataDictionary, 

49 lightcurveData=lightcurveData, 

50 objectAkas=objectAkas 

51 ) 

52 

53 master_lightcurve_block = khufu.grid_column( 

54 span=6, # 1-12 

55 offset=0, # 1-12 

56 content=master_lightcurve_block, 

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

58 htmlId=False, 

59 htmlClass=False, 

60 onPhone=True, 

61 onTablet=True, 

62 onDesktop=True 

63 ) 

64 

65 latest_magnitudes_block = ticket_building_blocks.latest_magnitudes_block.latest_magnitudes_block( 

66 log=log, 

67 request=request, 

68 discoveryDataDictionary=discoveryDataDictionary, 

69 lightcurveData=lightcurveData 

70 ) 

71 

72 latest_magnitudes_block = khufu.grid_column( 

73 span=2, # 1-12 

74 offset=0, # 1-12 

75 content=latest_magnitudes_block, 

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

77 htmlId=False, 

78 htmlClass=False, 

79 onPhone=True, 

80 onTablet=True, 

81 onDesktop=True 

82 ) 

83 

84 survey_lightcurves_block = ticket_building_blocks.survey_lightcurves_block.survey_lightcurves_block( 

85 log=log, 

86 request=request, 

87 discoveryDataDictionary=discoveryDataDictionary, 

88 lightcurveData=lightcurveData, 

89 ) 

90 

91 survey_lightcurves_block = khufu.grid_column( 

92 span=2, # 1-12 

93 offset=0, # 1-12 

94 content=survey_lightcurves_block, 

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

96 htmlId=False, 

97 htmlClass="surveyLightcurvesBlock", 

98 onPhone=True, 

99 onTablet=True, 

100 onDesktop=True 

101 ) 

102 

103 photometry_block = """%(master_lightcurve_block)s%(latest_magnitudes_block)s%(survey_lightcurves_block)s""" % locals( 

104 ) 

105 

106 footer = photometry_footer_bar( 

107 log, 

108 request=request, 

109 discoveryDataDictionary=discoveryDataDictionary, 

110 objectAkas=objectAkas, 

111 lightcurveData=lightcurveData) 

112 

113 photometry_tab = single_ticket._ticket_tab_template( 

114 log, 

115 request=request, 

116 tabHeader=False, 

117 blockList=[photometry_block], 

118 tabFooter=footer, 

119 htmlId="photometrytab" 

120 ) 

121 

122 log.debug('completed the ``photometry_tab`` function') 

123 return "%(photometry_tab)s" % locals() 

124 

125 

126def photometry_footer_bar( 

127 log, 

128 request, 

129 discoveryDataDictionary, 

130 objectAkas, 

131 lightcurveData): 

132 """get ticket footer bar 

133 

134 **Key Arguments** 

135 

136 - ``log`` -- logger 

137 - ``discoveryData`` -- the discoveryData for the object 

138 - ``lightcurveData`` -- the lightcurve data for the object 

139 

140 

141 **Return** 

142 

143 - ``photometry_footer_bar`` -- the ticket footer bar for the pesssto object 

144 

145 """ 

146 lsqExists = False 

147 log.debug('starting the ``photometry_footer_bar`` function') 

148 ## VARIABLES ## 

149 transientBucketId = discoveryDataDictionary["transientBucketId"] 

150 name = discoveryDataDictionary["masterName"] 

151 format = ["json", "csv", "plain_table"] 

152 text = ["json", "csv", "plain text"] 

153 

154 linkList = "" 

155 for f, t in zip(format, text): 

156 params = dict(request.params) 

157 params["format"] = f 

158 params["filename"] = "%(name)s_lightcurve" % locals() 

159 href = request.route_path( 

160 'transients_element_lightcurves', elementId=transientBucketId, _query=params) 

161 link = khufu.a( 

162 content=t, 

163 href=href 

164 ) 

165 link = khufu.p( 

166 content=link, 

167 textAlign="center", # [ left | center | right ] 

168 ) 

169 linkList = """%(linkList)s%(link)s""" % locals() 

170 

171 # Override for LSQ lightcurves 

172 href = "" 

173 lightcurveSwitchAttempt = True 

174 transientBucketId = discoveryDataDictionary["transientBucketId"] 

175 for row in lightcurveData: 

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

177 lightcurveSwitchAttempt = False 

178 

179 if lightcurveSwitchAttempt == True: 

180 filePath = request.registry.settings[ 

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

182 if "lsq" in name.lower() and "lsq" in discoveryDataDictionary["survey"]: 

183 lsqname = name 

184 else: 

185 for aka in objectAkas: 

186 if aka["transientBucketId"] == discoveryDataDictionary["transientBucketId"] and "lsq" in aka["name"].lower(): 

187 lsqname = aka["name"] 

188 break 

189 if "lsqname" in locals(): 

190 lsqExists = os.path.exists(filePath) 

191 

192 if lsqExists: 

193 username = request.registry.settings["credentials"]["lsq"]["username"] 

194 password = request.registry.settings["credentials"]["lsq"]["password"] 

195 href = "http://%(username)s:%(password)s@portal.nersc.gov/project/lssn/ms_lcs/%(lsqname)s.extra_out_LSQgr" % locals() 

196 link = khufu.a( 

197 content="lsq plain text", 

198 href=href 

199 ) 

200 link = khufu.p( 

201 content=link, 

202 textAlign="center", # [ left | center | right ] 

203 ) 

204 linkList = """%(linkList)s%(link)s""" % locals() 

205 

206 thisImage = "caches/transients/%(transientBucketId)s/lsq_lightcurve.gif" % locals( 

207 ) 

208 thisImage = request.static_url(f'marshall_webapp:{thisImage}') 

209 filename = "%(name)s_lsq_lightcurve" % locals() 

210 href = request.route_path( 

211 'download', _query={'url': thisImage, "webapp": "marshall_webapp", "filename": filename}) 

212 

213 link = khufu.a( 

214 content="lsq image", 

215 href=href 

216 ) 

217 link = khufu.p( 

218 content=link, 

219 textAlign="center", # [ left | center | right ] 

220 ) 

221 linkList = """%(linkList)s%(link)s""" % locals() 

222 

223 popover = khufu.popover( 

224 tooltip=False, 

225 placement="top", # [ top | bottom | left | right ] 

226 trigger="click hover", # [ False | click | hover | focus | manual ] 

227 title="download lightcurve", 

228 content=linkList, 

229 delay=20 

230 ) 

231 

232 downloadFileButton = khufu.button( 

233 buttonText="""<i class="icon-save"></i>""", 

234 # [ default | primary | info | success | warning | danger | inverse | link ] 

235 buttonStyle='primary', 

236 buttonSize='small', # [ large | default | small | mini ] 

237 popover=popover 

238 ) 

239 

240 footerColumn = khufu.grid_column( 

241 span=2, # 1-12 

242 offset=0, # 1-12 

243 content="%(downloadFileButton)s" % locals( 

244 ) 

245 ) 

246 

247 photometry_footer_bar = khufu.grid_row( 

248 responsive=True, 

249 columns=footerColumn, 

250 htmlId=False, 

251 htmlClass="ticketFooter" 

252 ) 

253 

254 return photometry_footer_bar