Commit 79dd10ce authored by John Douglas Veitch's avatar John Douglas Veitch

Replace SkyArea with ligo.skymap in postprocessing

parent a68d3365
......@@ -400,8 +400,6 @@ def chooseEngineNode(name):
return LALInferenceBurstNode
if name=='lalinferencemcmc':
return LALInferenceMCMCNode
if name=='lalinferencebambi' or name=='lalinferencebambimpi':
return LALInferenceBAMBINode
if name=='lalinferencedatadump':
return LALInferenceDataDumpNode
if name=='bayeswavepsd':
......@@ -411,7 +409,7 @@ def chooseEngineNode(name):
def get_engine_name(cp):
name=cp.get('analysis','engine')
if name=='random':
engine_list=['lalinferencenest','lalinferencemcmc','lalinferencebambimpi']
engine_list=['lalinferencenest','lalinferencemcmc']
if cp.has_option('input','gid'):
gid=cp.get('input','gid')
engine_number=int(''.join(i for i in gid if i.isdigit())) % 2
......@@ -751,6 +749,8 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
self.coherence_test_job.set_grid_site('local')
self.gracedbjob = GraceDBJob(self.config,os.path.join(self.basepath,'gracedb.sub'),self.logpath,dax=self.is_dax())
self.gracedbjob.set_grid_site('local')
self.mapjob = SkyMapJob(cp, os.path.join(self.basepath,'skymap.sub'), self.logpath)
self.plotmapjob = PlotSkyMapJob(cp, os.path.join(self.basepath,'plotskymap.sub'),self.logpath)
# Process the input to build list of analyses to do
self.events=self.setup_from_inputs()
......@@ -780,7 +780,6 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
# Generate the DAG according to the config given
for event in self.events: self.add_full_analysis(event)
self.add_skyarea_followup()
if self.config.has_option('analysis','upload-to-gracedb'):
if self.config.getboolean('analysis','upload-to-gracedb'):
self.add_gracedb_FITSskymap_upload(self.events[0],engine=self.engine)
......@@ -789,29 +788,13 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
if self.is_dax():
self.set_dax_file(self.dagfilename)
def add_skyarea_followup(self):
# Add skyarea jobs if the executable is given
# Do one for each results page for now
if self.config.has_option('condor','skyarea'):
self.skyareajob=SkyAreaJob(self.config,os.path.join(self.basepath,'skyarea.sub'),self.logpath,dax=self.is_dax())
respagenodes=filter(lambda x: isinstance(x,ResultsPageNode) ,self.get_nodes())
if self.engine=='lalinferenceburst':
prefix='LIB'
else:
prefix='LALInference'
for p in respagenodes:
skyareanode=SkyAreaNode(self.skyareajob,prefix=prefix)
skyareanode.add_resultspage_parent(p)
skyareanode.set_ifos(p.ifos)
self.add_node(skyareanode)
def add_full_analysis(self,event):
if self.engine=='lalinferencenest' or self.engine=='lalinferenceburst':
result=self.add_full_analysis_lalinferencenest(event)
elif self.engine=='lalinferencemcmc':
result=self.add_full_analysis_lalinferencemcmc(event)
elif self.engine=='lalinferencebambi' or self.engine=='lalinferencebambimpi':
result=self.add_full_analysis_lalinferencebambi(event)
else:
raise Exception('Unknown engine {0}'.format(self.engine))
return result
def create_frame_pfn_file(self):
......@@ -1195,6 +1178,14 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
ugid=self.config.get('analysis','ugid')
self.add_gracedb_start_node(ugid,'LIB',[sciseg.get_df_node() for sciseg in enginenodes[0].scisegs.values()])
self.add_gracedb_log_node(respagenode,ugid)
if self.config.has_option('condor','ligo-skymap-plot') and self.config.has_option('condor','ligo-skymap-from-samples'):
if self.engine=='lalinferenceburst': prefix='LIB'
else: prefix='LALInference'
mapnode = SkyMapNode(self.mapjob, posfile = mergenode.get_pos_file(), parent=mergenode,
prefix= prefix, outdir=pagedir)
plotmapnode = PlotSkyMapNode(self.plotmapjob, parent=mapnode, inputfits = mapnode.outfits, output=os.path.join(pagedir,'skymap.png'))
self.add_node(mapnode)
self.add_node(plotmapnode)
return True
def add_full_analysis_lalinferencemcmc(self,event):
......@@ -1258,46 +1249,12 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
if self.config.getboolean('analysis','upload-to-gracedb'):
self.add_gracedb_start_node(event.GID,'LALInference',[sciseg.get_df_node() for sciseg in enginenodes[0].scisegs.values()])
self.add_gracedb_log_node(respagenode,event.GID)
def add_full_analysis_lalinferencebambi(self,event):
"""
Generate an end-to-end analysis of a given event
For LALInferenceBAMBI.
"""
evstring=str(event.event_id)
if event.trig_time is not None:
evstring=str(event.trig_time)+'-'+str(event.event_id)
enginenodes=[]
bwpsdnodes={}
for i in range(Npar):
n,bwpsdnodes=self.add_engine_node(event,bwpsdnodes)
if n is not None:
if i>0:
n.add_var_arg('--dont-dump-extras')
enginenodes.append(n)
if len(enginenodes)==0:
return False
myifos=enginenodes[0].get_ifos()
enginenodes[0].set_psd_files()
enginenodes[0].set_snr_file()
pagedir=os.path.join(self.webdir,evstring,myifos)
mkdirs(pagedir)
respagenode=self.add_results_page_node(outdir=pagedir,ifos=enginenodes[0].ifos)
respagenode.set_psd_files(enginenodes[0].get_psd_files())
respagenode.set_snr_file(enginenodes[0].get_snr_file())
if os.path.exists(self.basepath+'/coinc.xml'):
respagenode.set_coinc_file(self.basepath+'/coinc.xml',self.config.get('input','gid'))
respagenode.set_header_file(enginenodes[0].get_header_file())
if self.config.has_option('input','injection-file') and event.event_id is not None:
respagenode.set_injection(self.config.get('input','injection-file'),event.event_id)
elif self.config.has_option('input','burst-injection-file') and event.event_id is not None:
respagenode.set_injection(self.config.get('input','burst-injection-file'),event.event_id)
map(respagenode.add_engine_parent, enginenodes)
if event.GID is not None:
if self.config.has_option('analysis','upload-to-gracedb'):
if self.config.getboolean('analysis','upload-to-gracedb'):
self.add_gracedb_start_node(event.GID,'LALInference',[sciseg.get_df_node() for sciseg in enginenodes[0].scisegs.values()])
self.add_gracedb_log_node(respagenode,event.GID)
if self.config.has_option('condor','ligo-skymap-plot') and self.config.has_option('condor','ligo-skymap-from-samples'):
mapnode = SkyMapNode(self.mapjob, posfile = mergenode.get_pos_file(), parent=mergenode,
prefix= 'LALInference', outdir=pagedir)
plotmapnode = PlotSkyMapNode(self.plotmapjob, parent=mapnode, inputfits = mapnode.outfits, output=os.path.join(pagedir,'skymap.png'))
self.add_node(mapnode)
self.add_node(plotmapnode)
def add_science_segments(self):
# Query the segment database for science segments and
......@@ -1732,7 +1689,7 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
if self.config.has_option('analysis','add-lvem-tag'):
if self.config.getboolean('analysis','add-lvem-tag'):
tag='sky_loc,lvem'
skynodes=filter(lambda x: isinstance(x,SkyAreaNode) ,self.get_nodes())
skynodes=filter(lambda x: isinstance(x,SkyMapNode) ,self.get_nodes())
nodes=[]
for sk in skynodes:
if len(sk.ifos)>1:
......@@ -1740,7 +1697,7 @@ class LALInferencePipelineDAG(pipeline.CondorDAG):
#for p in sk.__parents:
# if isinstance(p,ResultPageNode):
# resultpagenode=p
node.set_filename(sk.outdir+'/%s.fits.gz'%prefix)
node.set_filename(sk.outfits)
node.set_message('%s FITS sky map'%prefix)
self.add_node(node)
nodes.append(node)
......@@ -1916,10 +1873,7 @@ class EngineJob(SingularityJob,pipeline.AnalysisJob):
if self.engine=='lalinferencemcmc':
exe=cp.get('condor','mpiwrapper')
universe="vanilla"
elif self.engine=='lalinferencebambimpi':
exe=cp.get('condor','mpiwrapper')
universe="vanilla"
elif self.engine=='lalinferencenest' or self.engine=='lalinferenceburst' or self.engine=='lalinferencebambi':
elif self.engine=='lalinferencenest' or self.engine=='lalinferenceburst':
exe=cp.get('condor',self.engine)
if site is not None and site!='local':
universe='vanilla'
......@@ -1971,7 +1925,7 @@ class EngineJob(SingularityJob,pipeline.AnalysisJob):
# Set the options which are always used
self.set_sub_file(os.path.abspath(submitFile))
self.add_condor_cmd('getenv','true')
if self.engine=='lalinferencemcmc' or self.engine=='lalinferencebambimpi':
if self.engine=='lalinferencemcmc':
self.binary=cp.get('condor',self.engine.replace('mpi',''))
self.mpirun=cp.get('condor','mpirun')
if cp.has_section('mpi'):
......@@ -2018,7 +1972,7 @@ class EngineJob(SingularityJob,pipeline.AnalysisJob):
"""
Over-load base class method to choose condor universe properly
"""
if self.engine=='lalinferencenest' or self.engine=='lalinferenceburst' or self.engine=='lalinferencebambi':
if self.engine=='lalinferencenest' or self.engine=='lalinferenceburst':
if site is not None and site!='local':
self.set_universe('vanilla')
else:
......@@ -2321,36 +2275,6 @@ class LALInferenceDataDumpNode(EngineNode):
def set_output_file(self,filename):
pass
class LALInferenceBAMBINode(EngineNode):
def __init__(self,li_job):
super(LALInferenceBAMBINode,self).__init__(li_job)
self.engine='lalinferencebambi'
self.outfilearg='outfile'
if li_job.engine=='lalinferencebambimpi':
self.add_var_opt('mpirun',li_job.mpirun)
self.add_var_opt('np',str(li_job.machine_count))
self.add_var_opt('executable',li_job.binary)
def set_output_file(self,filename):
self.fileroot=filename+'_'
self.posfile=self.fileroot+'post_equal_weights.dat'
self.paramsfile=self.fileroot+'params.txt'
self.Bfilename=self.fileroot+'evidence.dat'
self.headerfile=self.paramsfile
self.add_file_opt(self.outfilearg,self.fileroot,file_is_output_file=True)
self.add_output_file(self.Bfilename)
self.add_output_file(self.posfile)
self.add_output_file(self.headerfile)
def get_B_file(self):
return self.Bfilename
def get_pos_file(self):
return self.posfile
def get_header_file(self):
return self.headerfile
class BayesWavePSDJob(pipeline.CondorDAGJob,pipeline.AnalysisJob):
"""
Class for a BayesWave job
......@@ -2490,6 +2414,7 @@ class ResultsPageNode(pipeline.CondorDAGNode):
"""
self.add_parent(node)
self.add_file_arg(node.get_pos_file())
self.infiles.append(node.get_pos_file())
def get_pos_file(self): return self.posfile
......@@ -2855,74 +2780,123 @@ class BayesLineNode(pipeline.CondorDAGNode):
return
self.__finalized=True
class SkyAreaNode(pipeline.CondorDAGNode):
"""
Node to run sky area code
"""
def __init__(self,skyarea_job,posfile=None,parent=None,prefix=None):
super(SkyAreaNode,self).__init__(skyarea_job)
if parent:
self.add_parent(parent)
if posfile:
self.set_posterior_file(posfile)
self.ifos=None
self.outdir=None
self.prefix=prefix
def set_posterior_file(self,posfile):
self.add_file_opt('samples',posfile,file_is_output_file=False)
self.posfile=posfile
def set_outdir(self,outdir):
self.add_var_opt('outdir',outdir)
self.outdir=outdir
def get_outdir(self):
return self.outdir
def set_fits_name(self):
name='skymap.fits.gz'
if self.prefix is not None:
name=self.prefix+'.fits.gz'
self.add_var_opt('fitsoutname',name)
def set_injection(self,injfile,eventnum):
if injfile is not None:
self.add_file_opt('inj',injfile)
self.add_var_opt('eventnum',str(eventnum))
def set_objid(self,objid):
self.add_var_opt('objid',objid)
def add_resultspage_parent(self,resultspagenode):
self.set_posterior_file(resultspagenode.get_pos_file())
self.set_outdir(resultspagenode.get_output_path())
self.add_parent(resultspagenode)
self.set_fits_name()
self.set_injection(resultspagenode.get_injection(),resultspagenode.get_event_number())
self.set_objid(resultspagenode.get_event_number())
def set_ifos(self,ifos=None):
self.ifos=ifos
class SkyAreaJob(pipeline.CondorDAGJob,pipeline.AnalysisJob):
"""
Class for Sky Area Jobs
"""
def __init__(self,cp,submitFile,logdir,dax=False):
exe=cp.get('condor','skyarea')
pipeline.CondorDAGJob.__init__(self,"vanilla",exe)
pipeline.AnalysisJob.__init__(self,cp,dax=dax)
if cp.has_option('condor','accounting_group'):
self.add_condor_cmd('accounting_group',cp.get('condor','accounting_group'))
if cp.has_option('condor','accounting_group_user'):
self.add_condor_cmd('accounting_group_user',cp.get('condor','accounting_group_user'))
requirements=''
if cp.has_option('condor','queue'):
self.add_condor_cmd('+'+cp.get('condor','queue'),'True')
requirements='(TARGET.'+cp.get('condor','queue')+' =?= True)'
if cp.has_option('condor','Requirements'):
if requirements!='':
requirements=requirements+' && '
requirements=requirements+cp.get('condor','Requirements')
if requirements!='':
self.add_condor_cmd('Requirements',requirements)
self.set_sub_file(submitFile)
self.set_stdout_file(os.path.join(logdir,'skyarea-$(cluster)-$(process).out'))
self.set_stderr_file(os.path.join(logdir,'skyarea-$(cluster)-$(process).err'))
self.add_condor_cmd('getenv','True')
# Add user-specified options from ini file
self.add_ini_opts(cp,'skyarea')
class SkyMapNode(pipeline.CondorDAGNode):
def __init__(self, skymap_job, posfile=None, parent=None, objid=None, prefix=None, outdir=None):
self.prefix=prefix
super(SkyMapNode, self).__init__(skymap_job)
self.objid=None
self.outdir=None
self.finalized=False
if parent:
self.add_parent(parent)
if posfile:
self.set_posfile(posfile)
if objid:
self.set_objid(objid)
if outdir:
self.set_outdir(outdir)
def set_outdir(self, outdir):
self.outdir=outdir
if self.prefix:
name = self.prefix+'.fits.gz'
else:
name = 'skymap.fits.gz'
self.outfits = os.path.join(outdir,name)
def set_posfile(self, posfile):
self.posfile=posfile
def get_outdir(self):
return self.outdir
def set_objid(self,objid):
"""
Object ID for the fits file
"""
self.objid = objid
def finalize(self):
"""
Construct command line
"""
if self.finalized==True: return
self.finalized=True
self.add_input_file(self.posfile)
self.add_file_arg(self.posfile)
self.add_var_opt('fitsoutname',self.outfits)
self.add_file_opt('outdir',self.outdir, file_is_output_file=True)
if self.objid:
self.add_var_opt('objid',self.objid)
super(SkyMapNode,self).finalize()
class SkyMapJob(pipeline.CondorDAGJob,pipeline.AnalysisJob):
"""
Node to run ligo-skymap-from-samples
"""
def __init__(self, cp, submitFile, logdir):
exe=cp.get('condor','ligo-skymap-from-samples')
pipeline.CondorDAGJob.__init__(self,"vanilla",exe)
pipeline.AnalysisJob.__init__(self,cp)
requirements=[]
if cp.has_option('condor','queue'):
self.add_condor_cmd('+'+cp.get('condor','queue'),'True')
requirements.append('(TARGET.'+cp.get('condor','queue')+' =?= True)')
if cp.has_option('condor','Requirements'):
requirements.append(cp.get('condor','Requirements'))
if requirements:
self.add_condor_cmd('Requirements','&&'.join(requirements))
self.set_sub_file(submitFile)
self.set_stdout_file(os.path.join(logdir,'samples2map-$(cluster)-$(process).out'))
self.set_stderr_file(os.path.join(logdir,'samples2map-$(cluster)-$(process).err'))
self.add_condor_cmd('getenv','True')
# Add user-specified options from ini file
self.add_ini_opts(cp,'ligo-skymap-from-samples')
class PlotSkyMapJob(pipeline.CondorDAGJob, pipeline.AnalysisJob):
"""
Job to run ligo-skymap-plot
"""
def __init__(self, cp, submitFile, logdir):
exe=cp.get('condor','ligo-skymap-plot')
pipeline.CondorDAGJob.__init__(self, "vanilla", exe)
pipeline.AnalysisJob.__init__(self, cp)
requirements=[]
if cp.has_option('condor','queue'):
self.add_condor_cmd('+'+cp.get('condor','queue'),'True')
requirements.append('(TARGET.'+cp.get('condor','queue')+' =?= True)')
if cp.has_option('condor','Requirements'):
requirements.append(cp.get('condor','Requirements'))
if requirements:
self.add_condor_cmd('Requirements','&&'.join(requirements))
self.set_sub_file(submitFile)
self.set_stdout_file(os.path.join(logdir,'plotskymap-$(cluster)-$(process).out'))
self.set_stderr_file(os.path.join(logdir,'plotskymap-$(cluster)-$(process).err'))
self.add_condor_cmd('getenv','True')
# Add user-specified options from ini file
self.add_ini_opts(cp,'ligo-skymap-plot')
class PlotSkyMapNode(pipeline.CondorDAGNode):
def __init__(self, plotskymap_job, parent=None, inputfits = None, output=None):
super(PlotSkyMapNode, self).__init__(plotskymap_job)
if parent:
self.add_parent(parent)
if inputfits:
self.set_input_fits(inputfits)
if output:
self.set_output(output)
self.finalized=False
def set_output(self, outfile):
self.outfile=outfile
def set_input_fits(self, fitsfile):
self.fitsfile=fitsfile
def get_output(self):
return self.output
def finalize(self):
"""
Construct command line
"""
if self.finalized==True: return
self.finalized=True
self.add_input_file(self.fitsfile)
self.add_file_arg(self.fitsfile)
self.add_file_opt('output',self.outfile, file_is_output_file=True)
super(PlotSkyMapNode,self).finalize()
......@@ -119,6 +119,7 @@ ignore-science-segments=True
# Can use this option to specify the installation location
# and interpolate the exe paths
lalsuite-install=/home/albert.einstein/opt/lalsuite/
HOME=/home/jveitch/
datafind=%(lalsuite-install)s/bin/gw_data_find
mergeNSscript=%(lalsuite-install)s/bin/lalinference_nest2pos
......@@ -136,10 +137,8 @@ lalinferencedatadump=%(lalsuite-install)s/bin/lalinference_datadump
# Disabled by default, uncomment line below to use it
# bayeswave=%(lalsuite-install)s/bin/bayeswave
# Skyareas code from https://github.com/farr/skyarea
# Comment line below not to use it
skyarea=%(lalsuite-install)s/bin/run_sky_area
ligo-skymap-from-samples=$(HOME)s/bin/ligo-skymap-from-samples
ligo-skymap-plot=$(HOME)s/.local/bin/ligo-skymap-plot
# To have 2D sky PP plot while running the PP pipeline both skyareas above and processareas below must be given
# Comment line below not to use it
processareas=%(lalsuite-install)s/bin/process_areas
......@@ -168,6 +167,9 @@ pos_to_sim_inspiral=%(lalsuite-install)s/bin/cbcBayesPosToSimInspiral
# Queue information if needed to run on specific nodes
#queue=
# Set specific nodes requirements if needed, for instance:
#queue=
# Set specific nodes requirements if needed, for instance:
#Requirements = regexp(“Intel”, TARGET.cpuinfo_model_name)
......@@ -347,9 +349,6 @@ adapt-temps=
margphi=
# Semi-analytically marginalise over time
#margtime=
# Semi-analytically marginalise over time and phase (only for Newtonian amplitude orders)
#margtimephi=
# By default the code use spins if the choosen approximant supports spin. NOTE that this include TaylorF2, which will be run with aligned spins.
# Several options, here below, allows the user to choose a particular setting:
......@@ -464,4 +463,9 @@ maxpts=2000
[singularity]
# When requesting a run via singularity (on the OSG), must specify
# the location of an image
#image=/cvmfs/ligo-containers.opensciencegrid.org/john-veitch/lalinf_docker_test:latest
#image=/cvmfs/ligo-containers.opensciencegrid.org/john-veitch/lalinf_docker_test:latesti
[ligo-skymap-from-samples]
# Optional arguments for ligo-skymap-from-samples, from ligo.skymap module
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