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 classify object form for the PESSTO Marshall*
6:Author:
7 David Young
8"""
9import sys
10import os
11from datetime import datetime, date, time
12import khufu
15def classify_object_form(
16 log,
17 request,
18 discoveryDataDictionary
19):
20 """classify object form
22 **Key Arguments**
24 - ``log`` -- the logger
25 - ``request`` -- the pyramid request
26 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
29 **Return**
31 - ``classifyObjectForm`` -- the modal form used to classify transients
33 """
34 now = datetime.now()
35 now = now.strftime("%Y-%m-%d")
37 postToScript = request.route_path(
38 'transients_element', elementId=discoveryDataDictionary["transientBucketId"], _query={'method': 'post'})
40 href = request.route_path(
41 'transients_element', elementId=discoveryDataDictionary["transientBucketId"])
43 # MODAL TITLE DEPENDS ON WHETHER THE OBJECT HAS BEEN PREVIOUSLY CLASSIFIED
44 # OR NOT
45 if discoveryDataDictionary["recentClassification"]:
46 title = "Please Update the Classification Details for %(masterName)s" % discoveryDataDictionary
47 else:
48 title = "Please add Classification Details for %(masterName)s" % discoveryDataDictionary
49 thisModal = khufu.modals.modalForm(
50 log=log,
51 title=title,
52 postToScriptUrl=postToScript,
53 reloadToUrl=href,
54 formClassName="classificationForm"
55 )
57 if discoveryDataDictionary["classificationSurvey"]:
58 defaultOption = discoveryDataDictionary["classificationSurvey"]
59 else:
60 defaultOption = False
61 sourceInput = khufu.select(
62 optionList=["atel", "ePESSTO+", "cbat",
63 "private comm.", "GCN", "AstroNote", "ePESSTO", "PESSTO"],
64 multiple=False,
65 span=4,
66 htmlId="clsSource",
67 required=True,
68 defaultOption=defaultOption
69 )
70 thisModal.add_form_object(
71 formObject=sourceInput,
72 label="source"
73 )
75 if discoveryDataDictionary["classificationDate"]:
76 focusedInputText = discoveryDataDictionary[
77 "classificationDate"].strftime("%Y-%m-%d")
78 else:
79 focusedInputText = now
80 obsDateInput = khufu.formInput(
81 # [ text | password | datetime | datetime-local | date | month | time | week | number | float | email | url | search | tel | color ]
82 ttype='text',
83 placeholder='YYYY-MM-DD or mjd',
84 span=4,
85 htmlId="clsObsdate",
86 inlineHelpText="YYYY-MM-DD or mjd",
87 focusedInputText=focusedInputText,
88 required=True,
89 )
90 thisModal.add_form_object(
91 formObject=obsDateInput,
92 label="classification date"
93 )
95 optionList = ["supernova", "agn", "variable star",
96 "galaxy", "cv", "LBV", "imposter", "TDE", "GRB", "kilonova", "light echo", "unknown"]
97 disabled = False
98 if discoveryDataDictionary["recentClassification"]:
99 defaultOption = "supernova"
100 for o in optionList:
101 if o in discoveryDataDictionary["recentClassification"].lower():
102 disabled = True
103 defaultOption = o
104 else:
105 defaultOption = False
107 typeInput = khufu.select(
108 optionList=optionList,
109 multiple=False,
110 span=4,
111 htmlId="clsType",
112 required=True,
113 defaultOption=defaultOption
114 )
115 thisModal.add_form_object(
116 formObject=typeInput,
117 label="object type"
118 )
120 optionList = ["I", "Ia", "Ib", "Ic", "Ibc", "Ibn", "I-CSM", "II",
121 "IIb", "IIL", "IIP", "IIn", "SLSN I", "SLSN Ic", "SLSN II"]
122 if discoveryDataDictionary["recentClassification"] and defaultOption == "supernova":
123 for o in optionList:
124 if o.lower() in discoveryDataDictionary["recentClassification"].lower():
125 defaultOption = o
126 else:
127 defaultOption = False
129 snClassificationInput = khufu.select(
130 optionList=optionList,
131 multiple=False,
132 span=4,
133 htmlId="clsSnClassification",
134 disabled=disabled,
135 defaultOption=defaultOption
136 )
138 if discoveryDataDictionary["recentClassification"] and "-pec" in discoveryDataDictionary["recentClassification"]:
139 checked = True
140 else:
141 checked = False
142 peculiarInput = khufu.checkbox(
143 optionText='peculiar',
144 inline=True,
145 htmlId="clsPeculiar",
146 optionNumber=1,
147 disabled=disabled,
148 checked=checked
149 )
150 thisModal.add_form_object(
151 formObject="""%(snClassificationInput)s   %(peculiarInput)s""" %
152 locals(),
153 label="sn classification"
154 )
156 if discoveryDataDictionary["best_redshift"]:
157 r = discoveryDataDictionary["best_redshift"]
158 elif discoveryDataDictionary["recentClassification"] and discoveryDataDictionary["transientRedshift"]:
159 r = discoveryDataDictionary["transientRedshift"]
160 else:
161 r = False
163 redshiftInput = khufu.formInput(
164 # [ text | password | datetime | datetime-local | date | month | time | week | number | float | email | url | search | tel | color ]
165 ttype='float',
166 placeholder='',
167 span=4,
168 htmlId="clsRedshift",
169 focusedInputText=r
170 )
171 thisModal.add_form_object(
172 formObject=redshiftInput,
173 label="redshift"
174 )
176 checked = True
177 if discoveryDataDictionary["recentClassification"]:
178 checked = False
179 sendToInput1 = khufu.radio(
180 optionText='yes',
181 optionNumber=1,
182 htmlId="clsSendTo",
183 checked=checked
184 )
185 checked = False
186 if discoveryDataDictionary["recentClassification"]:
187 checked = True
188 sendToInput2 = khufu.radio(
189 optionText='no',
190 optionNumber=2,
191 htmlId="clsSendTo",
192 checked=checked
193 )
194 thisModal.add_form_object(
195 formObject="%(sendToInput1)s %(sendToInput2)s" % locals(),
196 label="send to astronote queue"
197 )
199 optionList = ["unknown", "pre-max", "at max", "post-max"]
200 disabled = True
201 if discoveryDataDictionary["classificationWRTMax"]:
202 for o in optionList:
203 if o.lower() in discoveryDataDictionary["classificationWRTMax"].lower():
204 defaultOption = o
205 if "-" in o:
206 disabled = False
207 else:
208 defaultOption = False
210 classificationWRTMaxInput = khufu.select(
211 optionList=["unknown", "pre-max", "at max", "post-max"],
212 multiple=False,
213 span=4,
214 htmlId="clsClassificationWRTMax",
215 defaultOption=defaultOption
216 )
218 thisModal.add_form_object(
219 formObject=classificationWRTMaxInput,
220 label="classifcation phase"
221 )
223 focusedInputText = False
224 if discoveryDataDictionary["classificationPhase"]:
225 focusedInputText = abs(discoveryDataDictionary["classificationPhase"])
227 classificationPhaseInput = khufu.formInput(
228 # [ text | password | datetime | datetime-local | date | month | time | week | number | float | email | url | search | tel | color ]
229 ttype='number',
230 span=7,
231 htmlId="clsClassificationPhase",
232 pull=False,
233 required=False,
234 disabled=disabled,
235 placeholder='unknown',
236 prepend="?",
237 focusedInputText=focusedInputText
238 )
239 thisModal.add_form_object(
240 formObject=classificationPhaseInput,
241 label="days from max"
242 )
244 modalForm, modalTrigger = thisModal.get()
246 if discoveryDataDictionary["classifiedFlag"] == 0:
247 title = "add a spectral classification for this object"
248 else:
249 title = "reclassify this object"
251 popover = khufu.popover(
252 tooltip=True,
253 placement="right",
254 trigger="hover",
255 title=title,
256 content=False,
257 )
259 icon = """<i class="icon-target2"></i> """
260 thisButton = khufu.button(
261 buttonText=icon,
262 # [ default | primary | info | success | warning | danger | inverse | link ]
263 buttonStyle='success',
264 buttonSize='large', # [ large | default | small | mini ]
265 href=modalTrigger,
266 pull=False, # right, left, center
267 dataToggle="modal", # [ modal ]
268 popover=popover
269 )
271 return thisButton, modalForm