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 host info block for the object ticket*
6:Author:
7 David Young
8"""
9import sys
10import os
11import re
12import datetime
13import numpy as np
14import khufu
15import collections
16from marshall_webapp.templates.commonelements import commonutils as cu
19def host_info_block(
20 log,
21 request,
22 discoveryDataDictionary,
23 transientCrossmatches):
24 """get ticket host info block
26 **Key Arguments**
28 - ``log`` -- logger
29 - ``request`` -- the pyramid request
30 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient.
31 - ``transientCrossmatches`` -- info from the transient crossmatcher
34 **Return**
36 - ``host_info_block`` -- the ticket identity block for the pesssto object
38 """
39 log.debug('starting the ``host_info_block`` function')
41 title = cu.block_title(
42 log,
43 title="host info"
44 )
46 transientBucketId = discoveryDataDictionary["transientBucketId"]
47 masterName = discoveryDataDictionary["masterName"]
48 sherlockClassification = discoveryDataDictionary["classification"]
49 sherlockAnnotation = discoveryDataDictionary["annotation"]
51 if sherlockAnnotation:
53 sherlockAnnotation = khufu.coloredText(
54 text=" - " + sherlockAnnotation,
55 color="green",
56 size=2,
57 )
59 else:
60 sherlockAnnotation = ""
62 nearestObjectUrl = ""
63 exactLocationUrl = ""
64 ogleStamp = ""
65 ra = discoveryDataDictionary["raDeg"]
66 dec = discoveryDataDictionary["decDeg"]
68 contextMaps = {}
70 contextMaps = collections.OrderedDict(sorted(contextMaps.items()))
72 if discoveryDataDictionary["sdss_coverage"] == 1:
73 nearestObjectUrl = "http://skyserver.sdss3.org/public/en/tools/explore/obj.aspx?ra=%(ra)s&dec=%(dec)s" % locals(
74 )
75 exactLocationUrl = """http://skyserver.sdss3.org/public/en/tools/chart/image.aspx?ra=%(ra)s&dec=%(dec)s&scale=0.25&opt=GS&width=512&height=512""" % locals(
76 )
78 if discoveryDataDictionary["ps1_map"] == 1:
79 downloadContextStamp = "caches/transients/%s/ps1_map_color.jpeg" % (
80 discoveryDataDictionary["transientBucketId"],)
81 contextStamp = request.static_url(f'marshall_webapp:{downloadContextStamp}')
82 contextMaps["PS1"] = contextStamp
83 stampName = "%(masterName)s_ps1_context_image" % locals()
84 if discoveryDataDictionary["sdss_coverage"] == 1:
85 downloadContextStamp = "caches/transients/%s/sdss_stamp.jpeg" % (
86 discoveryDataDictionary["transientBucketId"],)
87 contextStamp = request.static_url(f'marshall_webapp:{downloadContextStamp}')
88 contextMaps["SDSS DR12"] = contextStamp
89 stampName = "%(masterName)s_sdss_context_image" % locals()
90 if discoveryDataDictionary["ogle_color_context_stamp"] == 1:
91 downloadContextStamp = "caches/transients/%(transientBucketId)s/ogle_color_context_stamp.png" % locals(
92 )
93 contextStamp = request.static_url(f'marshall_webapp:{downloadContextStamp}')
94 contextMaps["OGLE"] = contextStamp
95 ogleStamp = "OGLE context stamp"
96 ogleStamp = khufu.coloredText(
97 text="      %(ogleStamp)s" % locals(),
98 color="blue"
99 )
100 stampName = "%(masterName)s_ogle_context_image" % locals()
102 if len(contextMaps) == 0:
103 downloadContextStamp = 'holder.js/500x500/auto/industrial/text:no context stamp'
104 contextStamp = downloadContextStamp
105 contextMaps["PLACEHOLDER"] = contextStamp
106 stampName = False
108 sdssUrl = """http://skyserver.sdss3.org/public/en/tools/chart/image.aspx?ra=%(ra)s&dec=%(dec)s&scale=0.25&opt=GSP&width=512&height=512&query=G""" % locals(
109 )
111 sdssLinkRow = ""
112 if len(nearestObjectUrl):
113 nearestObjectUrl = khufu.a(
114 content='sdss nearest object',
115 href=nearestObjectUrl,
116 openInNewTab=True
117 )
118 nearestObjectUrl = khufu.coloredText(
119 text=nearestObjectUrl,
120 color="cyan",
121 size=False, # 1-10
122 pull=False, # "left" | "right"
123 )
124 exactLocationUrl = khufu.a(
125 content='exact sdss location',
126 href=exactLocationUrl,
127 openInNewTab=True
128 )
129 exactLocationUrl = khufu.coloredText(
130 text=exactLocationUrl,
131 color="blue",
132 size=False, # 1-10
133 pull=False, # "left" | "right"
134 )
135 sdssLinkRow = khufu.grid_row(
136 responsive=True,
137 columns="    %(ogleStamp)s%(exactLocationUrl)s<br>    %(nearestObjectUrl)s" % locals(
138 ),
139 htmlId=False,
140 htmlClass=False,
141 onPhone=True,
142 onTablet=True,
143 onDesktop=True
144 )
146 sdssLink = khufu.a(
147 content='sdss dr12 location',
148 href=sdssUrl,
149 )
151 if len(contextMaps) > 0:
152 for k, v in contextMaps.items():
153 stampName = "%(masterName)s_%(k)s_context_image" % locals()
154 stampName = stampName.lower()
155 contextStamp = v
156 break
157 noModal = False
159 href = request.route_path(
160 'download', _query={'url': downloadContextStamp, "webapp": "marshall_webapp", "filename": stampName})
161 else:
162 href = False
163 contextStamp = contextMaps["PLACEHOLDER"]
164 noModal = True
166 allImage = ""
167 count = 0
168 for k, v in contextMaps.items():
169 count += 1
170 reminderImages = len(contextMaps) % 3
171 if reminderImages == 0:
172 span = 4
173 offset = 0
174 elif count < (len(contextMaps) - reminderImages):
175 span = 4
176 offset = 0
177 elif reminderImages == 2:
178 span = 6
179 offset = 0
180 else:
181 span = 6
182 offset = 3
184 thisImage = khufu.image(
185 src=v, # [ industrial | gray | social ]
186 href=False,
187 display="rounded", # [ rounded | circle | polaroid | False ]
188 pull=False, # [ "left" | "right" | "center" | False ]
189 htmlClass=False,
190 width="90%"
191 )
192 thisImage = khufu.grid_row(
193 responsive=True,
194 columns=thisImage,
195 )
196 # add text color
197 name = khufu.coloredText(
198 text=k,
199 color="blue",
200 size=7, # 1-10
201 pull=False, # "left" | "right",
202 addBackgroundColor=False
203 )
205 name = khufu.grid_row(
206 responsive=True,
207 columns=name,
208 )
209 column = khufu.grid_column(
210 span=span, # 1-12
211 offset=offset, # 1-12
212 content=thisImage + name,
213 pull=False, # ["right", "left", "center"]
214 htmlId=False,
215 htmlClass=False,
216 onPhone=True,
217 onTablet=True,
218 onDesktop=True
219 )
220 allImage += column
222 grid_row = khufu.grid_row(
223 responsive=True,
224 columns=allImage,
225 htmlId=False,
226 htmlClass=False,
227 onPhone=True,
228 onTablet=True,
229 onDesktop=True
230 )
232 randNum = int(np.random.rand() * 10000)
233 modal = khufu.modal(
234 modalHeaderContent="Context Maps for %(masterName)s" % locals(
235 ),
236 modalBodyContent=grid_row,
237 modalFooterContent="",
238 htmlId="hookId%(randNum)s" % locals(),
239 centerContent=True
240 )
241 imageModal = khufu.image(
242 src=contextStamp,
243 href="#hookId%(randNum)s" % locals(),
244 display="rounded", # [ rounded | circle | polaroid | False ]
245 pull=False, # [ "left" | "right" | "center" | False ]
246 htmlClass=False,
247 width="100%",
248 modal=True
249 )
250 if noModal == False:
251 imageModal = imageModal + modal
253 if sherlockClassification:
254 littleTitle = cu.little_label(
255 text="contextual classification:"
256 )
258 sherlockClassification = khufu.coloredText(
259 text=sherlockClassification,
260 color="red",
261 size=4, # 1-10
262 )
264 sherlockClassification = khufu.grid_row(
265 responsive=True,
266 columns="%(littleTitle)s %(sherlockClassification)s %(sherlockAnnotation)s" % locals(
267 ),
268 htmlId=False,
269 htmlClass=False,
270 onPhone=True,
271 onTablet=True,
272 onDesktop=True
273 )
274 else:
275 sherlockClassification = ""
277 return "%(title)s %(imageModal)s %(sdssLinkRow)s %(sherlockClassification)s" % locals()