Skip to content
Snippets Groups Projects
Commit 86bafed4 authored by Branson Stephens's avatar Branson Stephens
Browse files

Mark GRB events with graceid's like Exxxxx. Extract gpstime from VOEvent files.

parent b36b2d3e
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,8 @@ class Event(models.Model):
return "T%04d" % self.id
elif self.analysisType == "HWINJ":
return "H%04d" % self.id
elif self.analysisType == "GRB":
return "E%04d" % self.id
return "G%04d" % self.id
def weburl(self):
......@@ -150,6 +152,8 @@ class Event(models.Model):
return e
if (id[0] == "H") and (e.analysisType == "HWINJ"):
return e
if (id[0] == "E") and (e.analysisType == "GRB"):
return e
if (id[0] == "G"):
return e
raise cls.DoesNotExist()
......
......@@ -114,6 +114,12 @@ tidRange = tid + Suppress("..") + tid
tidQ = Optional(Suppress(Keyword("tid:"))) + (tid^tidRange)
tidQ = tidQ.setParseAction(maybeRange("tid", dbname="id"))
# External trigger event id
eid = Suppress("E")+Word("0123456789")
eidRange = eid + Suppress("..") + eid
eidQ = Optional(Suppress(Keyword("eid:"))) + (eid^eidRange)
eidQ = eidQ.setParseAction(maybeRange("eid", dbname="id"))
# Submitter
submitter = QuotedString('"').setParseAction(lambda toks: Q(submitter__name=toks[0]))
submitterQ = Optional(Suppress(Keyword("submitter:"))) + submitter
......@@ -214,7 +220,7 @@ ifoQ = ifoListQ | nifoQ
###########################
q = (ifoQ | hasfarQ | gidQ | hidQ | tidQ | labelQ | atypeQ | groupQ | gpsQ | createdQ | submitterQ | runQ | attributeQ).setName("query term")
q = (ifoQ | hasfarQ | gidQ | hidQ | tidQ | eidQ | labelQ | atypeQ | groupQ | gpsQ | createdQ | submitterQ | runQ | attributeQ).setName("query term")
#andTheseTags = ["attr"]
andTheseTags = ["nevents"]
......
......@@ -18,6 +18,10 @@ from glue.gracedb.utils import populate_inspiral_tables, \
populate_coinc_tables, \
write_output_files
from VOEventLib.VOEvent import *
from VOEventLib.Vutil import *
from utils import isoToGps
def handle_uploaded_data(event, datafilename,
log_filename='event.log',
coinc_table_filename='coinc.xml'):
......@@ -291,6 +295,13 @@ def handle_uploaded_data(event, datafilename,
f.close()
except:
pass
elif event.analysisType == 'GRB':
# Get the event time from the VOEvent file
try:
event.gpstime = getGpsFromVOEvent(datafilename)
except:
event.gpstime = 0
event.save()
else:
# XXX should we do something here?
pass
......@@ -453,3 +464,8 @@ class CwbData(Translator):
def writeCoincFile(self, path):
pass
def getGpsFromVOEvent(filename):
v = parse(filename)
wwd = getWhereWhen(v)
gpstime = isoToGps(wwd['time'])
return gpstime
......@@ -11,6 +11,7 @@ import pytz
import datetime
import calendar
from time import mktime
gpsEpoch = calendar.timegm((1980, 1, 6, 0, 0, 0, 0, 0, 0))
......@@ -51,4 +52,17 @@ def gpsToUtc(gpsTime):
t = gpsToPosixTime(gpsTime)
return datetime.datetime.fromtimestamp(t, pytz.utc)
def isoToGps(t):
# The input is a string in ISO time format: 2012-10-28T05:04:31.91
# First strip out whitespace, then split off the factional
# second. We'll add that back later.
t=t.strip()
ISOTime = t.split('.')[0]
ISOTime = datetime.datetime.strptime(ISOTime,"%Y-%m-%dT%H:%M:%S")
sec_substr = t.split('.')[1]
if sec_substr:
fracSec = float('0.' + sec_substr)
else:
fracSec = 0
posixTime = mktime(ISOTime.timetuple()) + fracSec
return int(round(posixToGpsTime(posixTime)))
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