Commit 0f38f777 authored by Soichiro Morisaki's avatar Soichiro Morisaki
Browse files

lalinferece_pipe: make it possible to specify gracedb url

- modify lalinference_pipe.py and lalinference_pipe_utils.py to enable it.
- add a option, service-url, in [analysis] section in lalinference_pipe_example.ini
parent c33d4c50
......@@ -132,7 +132,7 @@ class Event():
dummyCacheNames=['LALLIGO','LALVirgo','LALAdLIGO','LALAdVirgo']
def readLValert(threshold_snr=None,gid=None,flow=20.0,gracedb="gracedb",basepath="./",downloadpsd=True,roq=False):
def readLValert(threshold_snr=None,gid=None,flow=20.0,gracedb="gracedb",basepath="./",downloadpsd=True,roq=False,service_url=None):
"""
Parse LV alert file, containing coinc, sngl, coinc_event_map.
and create a list of Events as input for pipeline
......@@ -156,7 +156,10 @@ def readLValert(threshold_snr=None,gid=None,flow=20.0,gracedb="gracedb",basepath
cwd=os.getcwd()
os.chdir(basepath)
print("Download %s coinc.xml" % gid)
client = GraceDb()
if service_url is None:
client = GraceDb()
else:
client = GraceDb(service_url=service_url)
xmldoc = ligolw_utils.load_fileobj(client.files(gid, "coinc.xml"), contenthandler = LIGOLWContentHandler)[0]
ligolw_utils.write_filename(xmldoc, "coinc.xml")
coinc_events = lsctables.CoincInspiralTable.get_table(xmldoc)
......@@ -520,7 +523,7 @@ def get_xml_psds(psdxml,ifos,outpath,end_time=None):
out[ifo]=os.path.join(outpath,ifo+'_psd_'+time+'.txt')
return out
def get_trigger_chirpmass(gid=None,gracedb="gracedb"):
def get_trigger_chirpmass(gid=None,gracedb="gracedb",service_url=None):
from glue.ligolw import lsctables
from glue.ligolw import ligolw
from glue.ligolw import utils as ligolw_utils
......@@ -529,7 +532,10 @@ def get_trigger_chirpmass(gid=None,gracedb="gracedb"):
lsctables.use_in(LIGOLWContentHandler)
from ligo.gracedb.rest import GraceDb
cwd=os.getcwd()
client = GraceDb()
if service_url is None:
client = GraceDb()
else:
client = GraceDb(service_url=service_url)
xmldoc = ligolw_utils.load_fileobj(client.files(gid, "coinc.xml"), contenthandler = LIGOLWContentHandler)[0]
ligolw_utils.write_filename(xmldoc, "coinc.xml")
coinc_events = lsctables.CoincInspiralTable.get_table(xmldoc)
......@@ -551,7 +557,7 @@ def get_trigger_chirpmass(gid=None,gracedb="gracedb"):
return mchirp
def get_roq_mchirp_priors(path, roq_paths, roq_params, key, gid=None,sim_inspiral=None):
def get_roq_mchirp_priors(path, roq_paths, roq_params, key, gid=None,sim_inspiral=None, service_url=None):
## XML and GID cannot be given at the same time
## sim_inspiral must already point at the right row
......@@ -577,7 +583,7 @@ def get_roq_mchirp_priors(path, roq_paths, roq_params, key, gid=None,sim_inspira
mc_priors[roq][1]-= (mc_priors[roq][1]- mc_priors[ordered_roq_paths[i+1]][0])/2.
i+=1'''
if gid is not None:
trigger_mchirp = get_trigger_chirpmass(gid)
trigger_mchirp = get_trigger_chirpmass(gid=gid,service_url=service_url)
elif sim_inspiral is not None:
trigger_mchirp = sim_inspiral.mchirp
else:
......@@ -585,7 +591,7 @@ def get_roq_mchirp_priors(path, roq_paths, roq_params, key, gid=None,sim_inspira
return mc_priors, trigger_mchirp
def get_roq_component_mass_priors(path, roq_paths, roq_params, key, gid=None,sim_inspiral=None):
def get_roq_component_mass_priors(path, roq_paths, roq_params, key, gid=None,sim_inspiral=None,service_url=None):
## XML and GID cannot be given at the same time
## sim_inspiral must already point at the right row
......@@ -603,7 +609,7 @@ def get_roq_component_mass_priors(path, roq_paths, roq_params, key, gid=None,sim
m2_priors[roq]=[float(roq_params[roq]['mass2min']),float(roq_params[roq]['mass2max'])]
if gid is not None:
trigger_mchirp = get_trigger_chirpmass(gid)
trigger_mchirp = get_trigger_chirpmass(gid,service_url=service_url)
elif sim_inspiral is not None:
trigger_mchirp = sim_inspiral.mchirp
else:
......@@ -1040,8 +1046,11 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
threshold_snr = None
if not self.config.has_option('engine','distance-max') and self.config.has_option('input','threshold-snr'):
threshold_snr=self.config.getfloat('input','threshold-snr')
service_url = None
if self.config.has_option('analysis','service-url'):
service_url = self.config.get('analysis','service-url')
events = readLValert(gid=gid,flow=flow,gracedb=self.config.get('condor','gracedb'),basepath=self.basepath,downloadpsd=downloadgracedbpsd,
threshold_snr=threshold_snr,roq=self.config.getboolean('analysis','roq'))
threshold_snr=threshold_snr,roq=self.config.getboolean('analysis','roq'),service_url=service_url)
else: gid=None
# pipedown-database
if self.config.has_option('input','gstlal-db'):
......
......@@ -35,6 +35,7 @@ parser.add_option("-g","--gps-time-file",action="store",type="string",default=No
parser.add_option("-t","--single-triggers",action="store",type="string",default=None,help="SnglInspiralTable trigger list",metavar="SNGL_FILE.xml")
parser.add_option("-C","--coinc-triggers",action="store",type="string",default=None,help="CoinInspiralTable trigger list",metavar="COINC_FILE.xml")
parser.add_option("--gid",action="store",type="string",default=None,help="GraceDB ID")
parser.add_option("--service-url",action="store",type="string",default=None,help="GraceDB url from which xml files are downloaded")
parser.add_option("-I","--injections",action="store",type="string",default=None,help="List of injections to perform and analyse",metavar="INJFILE.xml")
parser.add_option("-B","--burst_injections",action="store",type="string",default=None,help="SimBurst table for LIB injections",metavar="INJFILE.xml")
parser.add_option("-P","--pipedown-db",action="store",type="string",default=None,help="Pipedown database to read and analyse",metavar="pipedown.sqlite")
......@@ -177,6 +178,9 @@ if opts.coinc_triggers is not None:
if opts.gid is not None:
cp.set('input','gid',opts.gid)
if opts.service_url is not None:
cp.set('analysis','service-url',opts.service_url)
if opts.pipedown_db is not None:
cp.set('input','pipedown-db',os.path.abspath(opts.pipedown_db))
......@@ -238,15 +242,18 @@ def setup_roq(cp):
gid=None
row=None
service_url = None
if cp.has_option('analysis', 'service-url'):
service_url = cp.get('analysis', 'service-url')
roq_bounds = pipe_utils.Query_ROQ_Bounds_Type(path, roq_paths)
if roq_bounds == 'chirp_mass_q':
print('ROQ has bounds in chirp mass and mass-ratio')
mc_priors, trigger_mchirp = pipe_utils.get_roq_mchirp_priors(path, roq_paths, roq_params, key, gid=gid, sim_inspiral=row)
mc_priors, trigger_mchirp = pipe_utils.get_roq_mchirp_priors(path, roq_paths, roq_params, key, gid=gid, sim_inspiral=row, service_url=service_url)
elif roq_bounds == 'component_mass':
print('ROQ has bounds in component masses')
# get component mass bounds, then compute the chirp mass that can be safely covered
# further below we pass along the component mass bounds to the sampler, not the tighter chirp-mass, q bounds
m1_priors, m2_priors, trigger_mchirp = pipe_utils.get_roq_component_mass_priors(path, roq_paths, roq_params, key, gid=gid, sim_inspiral=row)
m1_priors, m2_priors, trigger_mchirp = pipe_utils.get_roq_component_mass_priors(path, roq_paths, roq_params, key, gid=gid, sim_inspiral=row, service_url=service_url)
mc_priors = {}
for (roq,m1_prior), (roq2,m2_prior) in zip(m1_priors.items(), m2_priors.items()):
mc_priors[roq] = sorted([pipe_utils.mchirp_from_components(m1_prior[1], m2_prior[0]), pipe_utils.mchirp_from_components(m1_prior[0], m2_prior[1])])
......
......@@ -24,6 +24,8 @@ coherence-test=False
upload-to-gracedb=False
# Add the lvem tag to the sky maps and extrinsic triangle plot to share with EM partners
add-lvem-tag=False
# service-url for gracedb, ex. https://gracedb-playground.ligo.org/api/ for O2Replay. Leave commented out for default, https://gracedb.ligo.org/api/.
# service-url=https://gracedb.ligo.org/api/
#chain seed (incremented by one for each parallel chain). If commented the cpu time will be used to initialize the chain.
# randomseed=4321
......
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