Commit 471d9ad1 authored by Salvatore Vitale's avatar Salvatore Vitale
Browse files

Final touches on LIB postrun info. Updated to use h5

parent 81fcbaeb
......@@ -56,8 +56,13 @@ def cbcBayesGraceDBinfo(gid=None,samples=None,skymap=None,analysis='LALInference
g=ligo.gracedb.rest.GraceDb()
if samples is not None:
samples=os.path.realpath(samples)
if '.hdf' in samples or '.h5' in samples:
peparser = bppu.PEOutputParser('hdf5')
commonResultsObj=peparser.parse(samples)
else:
peparser=bppu.PEOutputParser('common')
commonResultsObj=peparser.parse(open(samples,'r'))
try:
pos = bppu.BurstPosterior(commonResultsObj)
pars=['frequency','quality','hrss']
......@@ -84,12 +89,23 @@ def cbcBayesGraceDBinfo(gid=None,samples=None,skymap=None,analysis='LALInference
outstr+='<tr><td align=left>logBCI</td>'
outstr+='<td align=center>%.2f</td></tr>'%(bci)
bsn=None
if bsnfile is not None and os.path.isfile(bsnfile):
bsn=np.loadtxt(bsnfile)
else: bsn=None
bsn=bsn[0]
else:
try:
import h5py
with h5py.File(samples,'r') as h5grp:
tmp=h5grp['lalinference']['lalinference_nest'].attrs
bsn=tmp['log_bayes_factor']
except Exception,e:
print("Could not obtain BNS\n")
print(e)
if bsn is not None:
outstr+='<tr><td align=left>logBSN</td>'
outstr+='<td align=center>%.2f</td></tr>'%(bsn[0])
outstr+='<td align=center>%.2f</td></tr>'%(bsn)
outstr+='</table>'
if email is not None and bci is not None:
......@@ -132,8 +148,8 @@ def cbcBayesGraceDBinfo(gid=None,samples=None,skymap=None,analysis='LALInference
bsn=np.loadtxt(bsnfile)
else: bsn=None
tag=['sky_loc']
if bci is not None and bsn[0] is not None:
if bsn[0]>5. and bci>2.:
if bci is not None and bsn is not None:
if bsn>5. and bci>2.:
tag.append('lvem')
g.writeLog(gid,message,filename=skymap,tagname=tag)
......@@ -144,10 +160,10 @@ if __name__=='__main__':
from optparse import OptionParser
parser=OptionParser(USAGE)
parser.add_option("-g","--gid", dest="gid",help="GraceDB id", metavar="G123456",default=None)
parser.add_option("-s","--samples",dest="samples",help="posterior_samples.dat",default=None)
parser.add_option("-s","--samples",dest="samples",help="posterior_samples.hdf5/dat",default=None)
parser.add_option("--analysis",help="Prefix to use for the graceDB entries. Should be the name of the analysis (default LALInference)",default='LALInference')
parser.add_option("--bci",dest="bci",help="coherence test file: bci.dat",default=None)
parser.add_option("--bsn",dest="bsn",help="evidence file: bsn.dat",default=None)
parser.add_option("--bsn",dest="bsn",help="evidence file: bsn.dat [Deprecated, now is read from samples.hdf5]",default=None)
parser.add_option("--skymap",dest="skymap",help="FITS file skymap",default=None)
parser.add_option("--message",dest="message",type='str', help="Message to go with skymap uplaod",default=None)
parser.add_option('--email',dest='email',help="Will email when run is done.",default=None)
......
......@@ -1705,6 +1705,8 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
node.add_parent(parent)
infile=parent.get_pos_file()
node.add_file_arg(infile)
node.append_in_files(infile)
node.set_output_path(outdir)
if gzip_output is not None:
node.set_gzip_output(gzip_output)
......@@ -1795,17 +1797,20 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
if respagenode is not None:
samples=respagenode.posfile
hdf5samples=respagenode.get_in_files()[0] # This should only be called by LIB, which only uses one file
else:
# Try to find it
resnodes=filter(lambda x: isinstance(x,ResultsPageNode) ,self.get_nodes())
for rs in resnodes:
if len(rs.ifos)>1:
respagenode=rs
samples=respagenode.posfile
hdf5samples=respagenode.get_in_files()[0] # This should only be called by LIB, which only uses one file
if self.postruninfojob.isdefined is False:
return None
if issky is False:
node=PostRunInfoNode(self.postruninfojob,parent=respagenode,gid=gid,samples=samples)
node=PostRunInfoNode(self.postruninfojob,parent=respagenode,gid=gid,samples=hdf5samples)
if email is not None:
node.set_email(email)
else:
......@@ -2454,6 +2459,7 @@ class ResultsPageNode(pipeline.CondorDAGNode):
self.injfile=None
self.bcifile=None
self.bsnfile=None
self.infiles=[]
def set_gzip_output(self,path):
self.add_file_opt('archive',path,file_is_output_file=True)
......@@ -2508,6 +2514,10 @@ class ResultsPageNode(pipeline.CondorDAGNode):
return
self.add_var_arg('--trig '+coinc)
def append_in_files(self,this_file):
self.infiles.append(this_file)
def add_engine_parent(self,node):
"""
Add a parent node which is one of the engine nodes
......@@ -2515,10 +2525,12 @@ class ResultsPageNode(pipeline.CondorDAGNode):
"""
self.add_parent(node)
self.add_file_arg(node.get_pos_file())
self.infiles.append(node.get_pos_file())
self.append_in_files(node.get_pos_file())
def get_pos_file(self): return self.posfile
def get_in_files(self): return self.infiles
def set_bayes_coherent_incoherent(self,bcifile):
self.add_file_opt('bci',bcifile)
self.bcifile=bcifile
......
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