Commit 42d9f672 authored by John Douglas Veitch's avatar John Douglas Veitch

Add option to read GSTLAL databases

Original: 1dd89d5263ef92079dff5032e6c732a0cd00dcbe
parent 941336a4
......@@ -85,6 +85,7 @@ analyse-all-time=False
#sngl-inspiral-file=
#coinc-inspiral-file=
#pipedown-db=
#gstlal-db=
# If this option is set "true" and a pipedown database is used as input, the pipeline will analyse the time slide events
timeslides=false
......
......@@ -161,6 +161,49 @@ def open_pipedown_database(database_filename,tmp_space):
dbtables.DBTable_set_connection(connection)
return (connection,working_filename)
def get_zerolag_lloid(database_connection, dumpfile=None, gpsstart=None, gpsend=None, max_cfar=-1, min_cfar=-1):
"""
Returns a list of Event objects
from pipedown data base. Can dump some stats to dumpfile if given,
and filter by gpsstart and gpsend to reduce the nunmber or specify
max_cfar to select by combined FAR
"""
output={}
if gpsstart is not None: gpsstart=float(gpsstart)
if gpsend is not None: gpsend=float(gpsend)
# Get coincs
get_coincs = "SELECT sngl_inspiral.end_time+sngl_inspiral.end_time_ns*1e-9,sngl_inspiral.ifo,coinc_event.coinc_event_id,sngl_inspiral.snr,sngl_inspiral.chisq,coinc_inspiral.combined_far \
FROM sngl_inspiral join coinc_event_map on (coinc_event_map.table_name=='sngl_inspiral' and coinc_event_map.event_id ==\
sngl_inspiral.event_id) join coinc_event on (coinc_event.coinc_event_id==coinc_event_map.coinc_event_id) \
join coinc_inspiral on (coinc_event.coinc_event_id==coinc_inspiral.coinc_event_id) \
WHERE coinc_event.time_slide_id=='time_slide:time_slide_id:1'\
"
if gpsstart is not None:
get_coincs=get_coincs+' and coinc_inspiral.end_time+coinc_inspiral.end_time_ns*1.0e-9 > %f'%(gpsstart)
if gpsend is not None:
get_coincs=get_coincs+' and coinc_inspiral.end_time+coinc_inspiral.end_time_ns*1.0e-9 < %f'%(gpsend)
if max_cfar !=-1:
get_coincs=get_coincs+' and coinc_inspiral.combined_far < %f'%(max_cfar)
if min_cfar != -1:
get_coincs=get_coincs+' and coinc_inspiral.combined_far > %f'%(min_cfar)
db_out=database_connection.cursor().execute(get_coincs)
extra={}
for (sngl_time, ifo, coinc_id, snr, chisq, cfar) in db_out:
coinc_id=int(coinc_id.split(":")[-1])
if not coinc_id in output.keys():
output[coinc_id]=Event(trig_time=sngl_time,timeslide_dict={},event_id=int(coinc_id))
extra[coinc_id]={}
output[coinc_id].timeslides[ifo]=0
output[coinc_id].ifos.append(ifo)
extra[coinc_id][ifo]={'snr':snr,'chisq':chisq,'cfar':cfar}
if dumpfile is not None:
fh=open(dumpfile,'w')
for co in output.keys():
for ifo in output[co].ifos:
fh.write('%s %s %s %s %s %s %s\n'%(str(co),ifo,str(output[co].trig_time),str(output[co].timeslides[ifo]),str(extra[co][ifo]['snr']),str(extra[co][ifo]['chisq']),str(extra[co][ifo]['cfar'])))
fh.close()
return output.values()
def get_zerolag_pipedown(database_connection, dumpfile=None, gpsstart=None, gpsend=None, max_cfar=-1, min_cfar=-1):
"""
......@@ -619,7 +662,7 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
gpsstart=self.config.getfloat('input','gps-start-time')
if self.config.has_option('input','gps-end-time'):
gpsend=self.config.getfloat('input','gps-end-time')
inputnames=['gps-time-file','injection-file','sngl-inspiral-file','coinc-inspiral-file','pipedown-db','gid']
inputnames=['gps-time-file','injection-file','sngl-inspiral-file','coinc-inspiral-file','pipedown-db','gid','gstlal-db']
ReadInputFromList=sum([ 1 if self.config.has_option('input',name) else 0 for name in inputnames])
if ReadInputFromList!=1 and (gpsstart is None or gpsend is None):
return []
......@@ -698,10 +741,17 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
if self.config.getboolean('input','ignore-gracedb-psd'):
downloadgracedbpsd=False
events = readLValert(gid=gid,flow=flow,gracedb=self.config.get('condor','gracedb'),savepsdpath=self.basepath,downloadpsd=downloadgracedbpsd)
# pipedown-database
else: gid=None
if self.config.has_option('input','pipedown-db'):
db_connection = open_pipedown_database(self.config.get('input','pipedown-db'),None)[0]
# pipedown-database
if self.config.has_option('input','gstlal-db'):
queryfunc=get_zerolag_lloid
dbname=self.config.get('input','gstlal-db')
elif self.config.has_option('input','pipedown-db'):
queryfunc=get_zerolag_pipedown
dbname=self.config.get('input','pipedown-db')
else: dbname=None
if dbname:
db_connection = open_pipedown_database(dbname,None)[0]
# Timeslides
if self.config.has_option('input','time-slide-dump'):
timeslidedump=self.config.get('input','time-slide-dump')
......@@ -718,7 +768,7 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
if self.config.get('input','timeslides').lower()=='true':
events=get_timeslides_pipedown(db_connection, gpsstart=gpsstart, gpsend=gpsend,dumpfile=timeslidedump,max_cfar=maxcfar)
else:
events=get_zerolag_pipedown(db_connection, gpsstart=gpsstart, gpsend=gpsend, dumpfile=timeslidedump,max_cfar=maxcfar,min_cfar=mincfar)
events=queryfunc(db_connection, gpsstart=gpsstart, gpsend=gpsend, dumpfile=timeslidedump,max_cfar=maxcfar,min_cfar=mincfar)
if(selected_events is not None):
used_events=[]
for i in selected_events:
......
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