Skip to content
Snippets Groups Projects
Commit 1e1208cb authored by Brian Moe's avatar Brian Moe
Browse files

Quick attemt at Skyalert submission

parent e23d5c06
No related branches found
No related tags found
No related merge requests found
# Copyright 2010 Roy D. Williams
"""
buildVOEvent: Creates a complex VOEvent with tables
See the VOEvent specification for details
http://www.ivoa.net/Documents/latest/VOEvent.html
"""
from VOEventLib.VOEvent import *
from VOEventLib.Vutil import *
import sys, os
from gracedb.utils import gpsToUtc
def buildVOEvent(gevent):
objid = gevent.graceid()
############ VOEvent header ############################
v = VOEvent.VOEvent(version="2.0")
v.set_ivorn("ivo://ligo.org/gracedb#%s" % objid)
v.set_role("test")
v.set_Description("LIGO / Virgo trigger")
############ Who ############################
w = Who()
a = Author()
a.add_contactName("LIGO Scientific Consortium")
a.add_contactEmail("postmaster@ligo.org")
w.set_Author(a)
v.set_Who(w)
############ What ############################
w = What()
# params related to the event. None are in Groups.
p = Param(name="gracedbid", ucd="meta.id", value="%s"% objid)
p.set_Description(["Identifier assigned by gracedb"])
w.add_Param(p)
p = Param(name="gpstime", ucd="time.epoch", dataType="int", value=str(gevent.gpstime))
p.set_Description(["GPS time of the trigger"])
w.add_Param(p)
p = Param(name="likelihood", ucd="stat.likelihood", dataType="float", value=str(gevent.likelihood))
p.set_Description(["Likelihood"])
w.add_Param(p)
v.set_What(w)
############ Wherewhen ############################
wwd = {'observatory': 'LIGO',
'coord_system': 'UTC-FK5-GEO',
# XXX time format
'time': str(gpsToUtc(gevent.gpstime).isoformat())[:-6], #'1918-11-11T11:11:11',
'timeError': 1.0,
'longitude': 123.45,
'latitude': 67.89,
'positionalError': 180.0,
}
ww = makeWhereWhen(wwd)
if ww: v.set_WhereWhen(ww)
############ Citation ############################
#c = Citations()
#c.add_EventIVORN(EventIVORN(cite="followup", valueOf_="ivo:silly/billy#89474"))
#c.add_EventIVORN(EventIVORN(cite="followup", valueOf_="ivo:silly/billy#89475"))
#v.set_Citations(c)
############ output the event ############################
xml = stringVOEvent(v)
#schemaURL = "http://www.ivoa.net/xml/VOEvent/VOEvent-v2.0.xsd")
return xml
def submitToSkyalert(gevent, validate_only=False):
## Python stub code for validating and authoring VOEvents to Skyalert
import urllib
dict = {}
# the server that will handle the submit request
url = "http://skyalert.org/submit/"
url = "https://betelgeuse.ligo.caltech.edu:8000/submit/"
# choose 'dryrun' for validation and 'author' for authoring
dict['checker'] = 'dryrun'
# for command line, we want plain text output, not HTML
dict['plainResponse'] = 'on'
if not validate_only:
# uncomment these for authoring
dict['checker'] = 'author'
# Skyalert username and password
dict['username'] = 'brian'
dict['password'] = 'man8men.'
# This is the short name for the stream, must match credentials and event!
dict['streamName'] = 'gracedb'
# Should alerts be run once the event is ingested?
dict['doRules'] = 'on'
# open a file for the XML
#dict['xmlText'] = open('sample.xml').read()
dict['xmlText'] = buildVOEvent(gevent)
# Now send it off and print the result
params = urllib.urlencode(dict)
f = urllib.urlopen(url, params)
result = f.read()
return result
......@@ -8,6 +8,9 @@ urlpatterns = patterns('gracedb.gracedb.views',
url (r'^create/$', 'create', name="create"),
url (r'^search/(?P<format>(json|flex))?$', 'search', name="search"),
url (r'^view/(?P<graceid>[\w\d]+)', 'view', name="view"),
url (r'^voevent/(?P<graceid>[\w\d]+)', 'voevent', name="voevent"),
url (r'^skyalert/(?P<graceid>[\w\d]+)', 'skyalert', name="skyalert"),
# (r'^view/(?P<uid>[\w\d]+)', 'view'),
# (r'^edit/(?P<uid>[\w\d]+)', 'edit'),
......
......@@ -19,6 +19,8 @@ import urllib
import os
from buildVOEvent import buildVOEvent, submitToSkyalert
# XXX This should be configurable / moddable or something
MAX_QUERY_RESULTS = 1000
......@@ -31,6 +33,14 @@ def index(request):
{},
context_instance=RequestContext(request))
def voevent(request, graceid):
event = Event.getByGraceid(graceid)
return HttpResponse(buildVOEvent(event), content_type="application/xml")
def skyalert(request, graceid):
event = Event.getByGraceid(graceid)
return HttpResponse(submitToSkyalert(event), content_type="text/plain")
def create(request):
d = _create(request)
if isinstance(d, HttpResponse):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment