From 86bafed4bdf3376c21a1d924a2bf2f546f3b1fed Mon Sep 17 00:00:00 2001 From: Branson Stephens <stephenb@uwm.edu> Date: Tue, 30 Oct 2012 13:13:17 -0500 Subject: [PATCH] Mark GRB events with graceid's like Exxxxx. Extract gpstime from VOEvent files. --- gracedb/models.py | 4 ++++ gracedb/query.py | 8 +++++++- gracedb/translator.py | 16 ++++++++++++++++ utils/__init__.py | 16 +++++++++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/gracedb/models.py b/gracedb/models.py index 746a2365c..9b0842f92 100644 --- a/gracedb/models.py +++ b/gracedb/models.py @@ -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() diff --git a/gracedb/query.py b/gracedb/query.py index 65dfaed11..3da3accbf 100644 --- a/gracedb/query.py +++ b/gracedb/query.py @@ -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"] diff --git a/gracedb/translator.py b/gracedb/translator.py index 6bb058285..b13f6a519 100644 --- a/gracedb/translator.py +++ b/gracedb/translator.py @@ -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 diff --git a/utils/__init__.py b/utils/__init__.py index 19adfb920..e4ac9a306 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -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))) -- GitLab