Commit e33cdec7 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by Alexander Pace
Browse files

extracting and exposing single IFO times for CWB events

parent b635856a
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('gracedb', '0014_add_many_MOU_EMGroups'),
]
operations = [
migrations.AddField(
model_name='multiburstevent',
name='single_ifo_times',
field=models.CharField(default=b'', max_length=255),
),
]
......@@ -823,6 +823,7 @@ class MultiBurstEvent(Event):
ligo_axis_dec = models.FloatField(null=True)
ligo_angle = models.FloatField(null=True)
ligo_angle_sig = models.FloatField(null=True)
single_ifo_times = models.CharField(max_length=255, default="")
class LalInferenceBurstEvent(Event):
bci = models.FloatField(null=True)
......
......@@ -515,12 +515,16 @@ class CwbData(Translator):
# MultiBurst table attributes
data = self.getData()
event.ifo = data.get('ifo')
event.ifos = data.get('ifo')
event.start_time = data.get('start_time')
event.start_time_ns = data.get('start_time_ns')
event.duration = data.get('duration')
event.central_freq = data.get('central_freq')
event.bandwidth = data.get('bandwidth')
# Single IFO times are cast as a comma-separated string,
# in same order as the 'ifos' field.
event.single_ifo_times = data.get('single_ifo_times')
try:
event.snr = sqrt(data.get('likelihood'))
except:
......@@ -565,7 +569,6 @@ class CwbData(Translator):
rawdata[key] = val.split()
datafile.seek(0)
# scan down for FAR
next_line_is_far = False
for line in datafile:
......@@ -590,9 +593,16 @@ class CwbData(Translator):
data['likelihood'] = rawdata.get('likelihood',[None])[0]
data['far'] = rawdata.get('far',[None])[0]
# Get ifos and corresponding GPS times.
ifos = rawdata.get('ifo',[])
single_ifo_times = rawdata.get('time',[])
# Sort both by ifo.
single_ifo_times = [x for (y,x) in sorted(zip(ifos,single_ifo_times),
key=lambda pair: pair[0])]
ifos.sort()
data['instruments'] = ','.join(ifos)
data['single_ifo_times'] = ','.join(single_ifo_times)
# MultiBurst table attributes
start = rawdata.get('start',[None])[0]
......
......@@ -259,6 +259,7 @@ def eventToDict(event, columns=None, request=None):
# MultiBurstEvent
rv['extra_attributes']['MultiBurst'] = {
"ifos" : event.ifos,
"single_ifo_times": event.single_ifo_times,
"start_time" : event.start_time,
"start_time_ns" : event.start_time_ns,
"duration" : event.duration,
......@@ -303,6 +304,8 @@ def eventToDict(event, columns=None, request=None):
if si_set.count():
rv['extra_attributes']['SingleInspiral'] = [ singleInspiralToDict(si) for si in si_set ]
elif (request and request.user) and (is_external(request.user)):
# adding extra attributes for external users.
# CBC events
try:
rv['extra_attributes'] = {}
# Only expose SingleInspiral times and ifos for external users.
......@@ -315,6 +318,14 @@ def eventToDict(event, columns=None, request=None):
rv['extra_attributes']['SingleInspiral'].append({ k: si[k] for k in ext_keys })
except:
pass
# MultiBurst events
try:
rv['extra_attributes']['MultiBurst'] = {
"ifos" : event.ifos,
"single_ifo_times": event.single_ifo_times,
}
except:
pass
rv['links'] = {
"neighbors" : reverse("neighbors", args=[graceid], request=request),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment