gstlal-inspiral  1.9.2
 All Classes Namespaces Files Functions
gstlal_inspiral_pipe
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2011-2014 Chad Hanna
4 # Copyright (C) 2019 Patrick Godwin
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 # Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 
21 ### The offline gstlal inspiral workflow generator; Use to make HTCondor DAGs to run CBC workflows
22 ###
23 ### Usage:
24 ### ------
25 ###
26 ### It is rare that you would invoke this program in a standalone mode. Usually
27 ### the inputs are complicated and best automated via a Makefile, e.g.,
28 ### Makefile.triggers_example
29 ###
30 ### Diagram of the HTCondor workfow produced
31 ### ----------------------------------------
32 ###
33 ### .. graphviz:: ../images/trigger_pipe.dot
34 ###
35 
36 """
37 This program makes a dag to run gstlal_inspiral offline
38 """
39 
40 __author__ = 'Chad Hanna <chad.hanna@ligo.org>, Patrick Godwin <patrick.godwin@ligo.org>'
41 
42 #----------------------------------------------------------
43 ### imports
44 
45 from collections import OrderedDict
46 from optparse import OptionParser
47 import os
48 
49 import numpy
50 
51 from lal.utils import CacheEntry
52 
53 from ligo.lw import ligolw
54 from ligo.lw import lsctables
55 import ligo.lw.utils as ligolw_utils
56 
57 from gstlal import inspiral_pipe
58 from gstlal import dagparts
59 from gstlal import datasource
60 from gstlal import paths as gstlal_config_paths
61 
62 
63 #----------------------------------------------------------
64 ### ligolw initialization
65 
66 class LIGOLWContentHandler(ligolw.LIGOLWContentHandler):
67  pass
68 lsctables.use_in(LIGOLWContentHandler)
69 
70 
71 #----------------------------------------------------------
72 ### command line options
73 
74 def parse_command_line():
75  parser = OptionParser(description = __doc__)
76 
77  # generic data source options
78  datasource.append_options(parser)
79  parser.add_option("--psd-fft-length", metavar = "s", default = 32, type = "int", help = "FFT length, default 32s. Note that 50% will be used for zero-padding.")
80 
81  # reference_psd
82  parser.add_option("--reference-psd", help = "Don't measure PSDs, use this one instead")
83 
84  # Template bank
85  parser.add_option("--template-bank", metavar = "filename", help = "Set the template bank xml file.")
86  parser.add_option("--mass-model", metavar = "filename", help = "Set the name of the mass model. Options are 'narrow-bns', 'broad-bns', 'bbh', 'ligo', 'detected-logm', 'uniform-template', or 'file'")
87  parser.add_option("--mass-model-file", metavar = "filename", help = "Set the name of the mass model file, e.g., mass_model.h5. Required if --mass-model=file")
88 
89  # dtdphi option
90  parser.add_option("--dtdphi-file", metavar = "filename", action = "append", help = "dtdphi snr ratio pdfs to read from (hdf5 format)")
91 
92  # idq option
93  parser.add_option("--idq-file", metavar = "filename", action = "append", help = "idq glitch file (hdf5 format)")
94 
95  # SVD bank construction options
96  parser.add_option("--overlap", metavar = "num", type = "int", action = "append", help = "set the factor that describes the overlap of the sub banks, must be even!")
97  parser.add_option("--autocorrelation-length", metavar = "str", default = '0:1000:351', help = "The chirp mass range and minimum number of samples to use for auto-chisquared. Formatted as min-chirp:max-chirp:AC-length. Samples should be odd. You MUST provide this in a continuous fashion across the entire covered mass space, i.e. 0:15:701,15:1000:351")
98  parser.add_option("--samples-min", type = "int", action = "append", help = "The minimum number of samples to use for time slices default 1024 (can be given multiple times, one for each time --bank-cache is invoked)")
99  parser.add_option("--samples-max-256", type = "int", default = 1024, help = "The maximum number of samples to use for time slices with frequencies above 256Hz, default 1024")
100  parser.add_option("--samples-max-64", type = "int", default = 2048, help = "The maximum number of samples to use for time slices with frequencies above 64Hz, default 2048")
101  parser.add_option("--samples-max", type = "int", default = 4096, help = "The maximum number of samples to use for time slices with frequencies below 64Hz, default 4096")
102  parser.add_option("--bank-cache", metavar = "filenames", action = "append", help = "Set the bank cache files in format H1=H1.cache,H2=H2.cache, etc.. (can be given multiple times)")
103  parser.add_option("--tolerance", metavar = "float", type = "float", default = 0.9999, help = "set the SVD tolerance, default 0.9999")
104  parser.add_option("--flow", metavar = "num", type = "float", action = "append", help = "set the low frequency cutoff. Can be given multiple times.")
105  parser.add_option("--fmax", metavar = "num", type = "float", default = 1600, help = "set the max frequency cutoff, default 1600 (Hz)")
106  parser.add_option("--sample-rate", metavar = "Hz", type = "int", help = "Set the sample rate. If not set, the sample rate will be based on the template frequency. The sample rate must be at least twice the highest frequency in the templates. If provided it must be a power of two")
107  parser.add_option("--identity-transform", action = "store_true", help = "Use identity transform, i.e. no SVD")
108 
109  # trigger generation options
110  parser.add_option("--vetoes", metavar = "filename", help = "Set the veto xml file.")
111  parser.add_option("--time-slide-file", metavar = "filename", help = "Set the time slide table xml file")
112  parser.add_option("--inj-time-slide-file", metavar = "filename", help = "Set the time slide table xml file for injections")
113  parser.add_option("--web-dir", metavar = "directory", help = "Set the web directory like /home/USER/public_html")
114  parser.add_option("--fir-stride", type="int", metavar = "secs", default = 8, help = "Set the duration of the fft output blocks, default 8")
115  parser.add_option("--control-peak-time", type="int", default = 8, metavar = "secs", help = "Set the peak finding time for the control signal, default 8")
116  parser.add_option("--coincidence-threshold", metavar = "value", type = "float", default = 0.005, help = "Set the coincidence window in seconds (default = 0.005). The light-travel time between instruments will be added automatically in the coincidence test.")
117  parser.add_option("--min-instruments", metavar = "count", type = "int", default = 2, help = "Set the minimum number of instruments that must contribute triggers to form a candidate (default = 2).")
118  parser.add_option("--reference-likelihood-file", metavar = "file", help = "Set a reference likelihood file to compute initial likelihood ratios. Required")
119  parser.add_option("--num-banks", metavar = "str", help = "The number of parallel subbanks per gstlal_inspiral job. can be given as a list like 1,2,3,4 then it will split up the bank cache into N groups with M banks each.")
120  parser.add_option("--ht-gate-threshold", type="float", help="set a threshold on whitened h(t) to veto glitches")
121  parser.add_option("--ht-gate-threshold-linear", metavar = "mchirp_min:ht_gate_threshold_min-mchirp_max:ht_gate_threshold_max", type="string", help = "Set the threshold on whitened h(t) to mark samples as gaps (glitch removal) with a linear scale of mchirp")
122  parser.add_option("--blind-injections", metavar = "filename", help = "Set the name of an injection file that will be added to the data without saving the sim_inspiral table or otherwise processing the data differently. Has the effect of having hidden signals in the input data. Separate injection runs using the --injections option will still occur.")
123  parser.add_option("--singles-threshold", default=float("inf"), action = "store", metavar="THRESH", help = "Set the SNR threshold at which to record single-instrument events in the output (default = +inf, i.e. don't retain singles).")
124  parser.add_option("--gzip-test", default=False, action = "store_true", help = "Perform gzip --test on all output files.")
125  parser.add_option("--verbose", action = "store_true", help = "Be verbose")
126  parser.add_option("--disable-calc-inj-snr", default=False, action = "store_true", help = "Disable injection SNR calculation")
127  parser.add_option("--ranking-stat-samples", metavar = "N", default = 2**24, type = "int", help = "Construct ranking statistic histograms by drawing this many samples from the ranking statistic generator (default = 2^24).")
128 
129  # Override the datasource injection option
130  parser.remove_option("--injections")
131  parser.add_option("--injections", action = "append", help = "append injection files to analyze. Must prepend filename with X:Y:, where X and Y are floats, e.g. 1.2:3.1:filename, so that the injections are only searched for in regions of the template bank with X <= chirp mass < Y.")
132 
133  # Data from a zero lag run in the case of an injection-only run.
134  parser.add_option("--injection-only", default=False, action = "store_true", help = "Run an injection only analysis.")
135  parser.add_option("--dist-stats-cache", metavar = "filename", help = "Set the cache file for dist stats (required iff running injection-only analysis)")
136  parser.add_option("--svd-bank-cache", metavar = "filename", help = "Set the cache file for svd banks (required iff running injection-only analysis)")
137  parser.add_option("--psd-cache", metavar = "filename", help = "Set the cache file for psd (required iff running injection-only analysis)")
138  parser.add_option("--non-injection-db", metavar = "filename", help = "Set the non injection data base file (required iff running injection-only analysis)")
139  parser.add_option("--marginalized-likelihood-file", metavar = "filename", help = "Set the marginalized likelihood file (required iff running injection-only analysis)")
140  parser.add_option("--marginalized-likelihood-with-zerolag-file", metavar = "filename", help = "Set the marginalized likelihood with zerolag file (required iff running injection-only analysis)")
141 
142  # Condor commands
143  parser.add_option("--condor-command", action = "append", default = [], metavar = "command=value", help = "set condor commands of the form command=value; can be given multiple times")
144  parser.add_option("--max-inspiral-jobs", type="int", metavar = "jobs", help = "Set the maximum number of gstlal_inspiral jobs to run simultaneously, default no constraint.")
145  parser.add_option("--singularity-image", metavar = "filename", help = "If set, uses the Singularity image provided as the build environment and sets Singularity-specific condor options.")
146 
147  options, filenames = parser.parse_args()
148 
149  if options.template_bank:
150  bank_xmldoc = ligolw_utils.load_filename(options.template_bank, verbose = options.verbose, contenthandler = LIGOLWContentHandler)
151  sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(bank_xmldoc)
152  assert len(sngl_inspiral_table) == len(set([r.template_id for r in sngl_inspiral_table])), "Template bank ids are not unique"
153 
154  if options.mass_model not in ("narrow-bns", "broad-bns", "bbh", "ligo", "detected-logm", "uniform-template", "file"):
155  raise ValueError("--mass-model must be 'narrow-bns', 'broad-bns', 'bbh', 'ligo', 'detected-logm', 'uniform-template', or 'file'")
156  if options.mass_model == "file" and not options.mass_model_file:
157  raise ValueError("--mass-model-file must be provided if --mass-model=file")
158 
159  if not options.dtdphi_file:
160  options.dtdphi_file = [os.path.join(gstlal_config_paths["pkgdatadir"], "inspiral_dtdphi_pdf.h5")] * len(options.overlap)
161 
162  if len(options.dtdphi_file) != len(options.overlap):
163  raise ValueError("You must provide as many dtdphi files as banks")
164 
165  if options.num_banks:
166  options.num_banks = [int(v) for v in options.num_banks.split(",")]
167 
168  if options.sample_rate is not None and (not numpy.log2(options.sample_rate) == int(numpy.log2(options.sample_rate))):
169  raise ValueError("--sample-rate must be a power of two")
170 
171  if not options.samples_min and not options.svd_bank_cache:
172  options.samples_min = [1024]*len(options.bank_cache)
173 
174  if not options.overlap and not options.svd_bank_cache:
175  options.overlap = [0]*len(options.bank_cache)
176 
177  if options.autocorrelation_length:
178  options.autocorrelation_length = [v for v in options.autocorrelation_length.split(",")]
179  if any(int(autocorrelation_length.split(':')[2]) % 2 ==0 for autocorrelation_length in options.autocorrelation_length):
180  raise ValueError("The autocorrelation length must be an odd number of samples.")
181 
182  if not options.svd_bank_cache and any(overlap % 2 for overlap in options.overlap):
183  raise ValueError("overlap must be even")
184 
185  if not options.svd_bank_cache and not (len(options.samples_min) == len(options.bank_cache) == len(options.overlap)):
186  raise ValueError("must provide same number of inputs for --samples-min, --bank-cache, --overlap")
187 
188  missing_injection_options = []
189  for option in ("dist_stats_cache", "svd_bank_cache", "psd_cache", "non_injection_db", "marginalized_likelihood_file", "marginalized_likelihood_with_zerolag_file"):
190  if getattr(options, option) is None:
191  missing_injection_options.append(option)
192  if len(missing_injection_options) > 0 and len(missing_injection_options) < 6:
193  raise ValueError("missing injection-only options %s." % ", ".join([option for option in missing_injection_options]))
194  if len(missing_injection_options) == 0 and options.num_banks:
195  raise ValueError("cant specify --num-banks in injection-only run")
196 
197  fail = ""
198  required_options = []
199  if len(missing_injection_options) == 6:
200  required_options.append("bank_cache")
201 
202  for option in required_options:
203  if getattr(options, option) is None:
204  fail += "must provide option %s\n" % (option)
205  if fail: raise ValueError(fail)
206 
207  #FIXME a hack to find the sql paths
208  share_path = os.path.split(dagparts.which('gstlal_inspiral'))[0].replace('bin', 'share/gstlal')
209  options.cluster_sql_file = os.path.join(share_path, 'simplify_and_cluster.sql')
210  options.snr_cluster_sql_file = os.path.join(share_path, 'snr_simplify_and_cluster.sql')
211  options.injection_snr_cluster_sql_file = os.path.join(share_path, 'inj_snr_simplify_and_cluster.sql')
212  options.injection_sql_file = os.path.join(share_path, 'inj_simplify_and_cluster.sql')
213  options.injection_proc_sql_file = os.path.join(share_path, 'simplify_proc_table_in_inj_file.sql')
214 
215  return options, filenames
216 
217 
218 #----------------------------------------------------------
219 ### DAG utilities
220 
221 def set_up_jobs(options):
222  jobs = {}
223 
224  # default condor options
225  default_condor_opts = OrderedDict()
226  default_condor_opts['want_graceful_removal'] = "True"
227  default_condor_opts['kill_sig'] = "15"
228  default_condor_opts['request_cpus'] = "1"
229  default_condor_opts['+MemoryUsage'] = "( 1000 ) * 2 / 3"
230  default_condor_opts['request_memory'] = "( MemoryUsage ) * 3 / 2"
231  default_condor_opts['periodic_hold'] = "( MemoryUsage >= ( ( RequestMemory ) * 3 / 2 ) )"
232  default_condor_opts['periodic_release'] = "(JobStatus == 5) && ((CurrentTime - EnteredCurrentStatus) > 180) && (HoldReasonCode != 34)"
233 
234  if options.singularity_image:
235  default_condor_opts['+SingularityImage'] = '"{}"'.format(options.singularity_image)
236 
237  # job-specific condor options
238  ref_psd_condor_opts = default_condor_opts.copy()
239  ref_psd_condor_opts['request_cpus'] = "2"
240 
241  calc_rank_pdf_condor_opts = default_condor_opts.copy()
242  calc_rank_pdf_condor_opts['+MemoryUsage'] = "( 3000 ) * 2 / 3"
243  calc_rank_pdf_condor_opts['request_cpus'] = "4"
244 
245  svd_condor_opts = default_condor_opts.copy()
246  svd_condor_opts['+MemoryUsage'] = "( 7000 ) * 2 / 3"
247 
248  inj_snr_condor_opts = default_condor_opts.copy()
249  inj_snr_condor_opts['+MemoryUsage'] = "( 2000 ) * 2 / 3"
250  inj_snr_condor_opts['request_cpus'] = "2"
251 
252  inspiral_1ifo_condor_opts = default_condor_opts.copy()
253  inspiral_1ifo_condor_opts['+MemoryUsage'] = "( 5000 ) * 2 / 3"
254 
255  inspiral_2ifo_condor_opts = default_condor_opts.copy()
256  inspiral_2ifo_condor_opts['+MemoryUsage'] = "( 7000 ) * 2 / 3"
257 
258  inspiral_3ifo_condor_opts = default_condor_opts.copy()
259  inspiral_3ifo_condor_opts['+MemoryUsage'] = "( 9000 ) * 2 / 3"
260  inspiral_3ifo_condor_opts['request_cpus'] = "2"
261 
262  # set condor commands
263  base_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, default_condor_opts)
264  ref_psd_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, ref_psd_condor_opts)
265  calc_rank_pdf_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, calc_rank_pdf_condor_opts)
266  svd_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, svd_condor_opts)
267  inj_snr_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, inj_snr_condor_opts)
268  sh_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, {"want_graceful_removal":"True", "kill_sig":"15"})
269 
270  inspiral_1ifo_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, inspiral_1ifo_condor_opts)
271  inspiral_2ifo_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, inspiral_2ifo_condor_opts)
272  inspiral_3ifo_condor_commands = dagparts.condor_command_dict_from_opts(options.condor_command, inspiral_3ifo_condor_opts)
273 
274  if options.injection_only:
275  jobs['gstlalInspiral1IFO'] = None
276  jobs['gstlalInspiral2IFO'] = None
277  jobs['gstlalInspiral3IFO'] = None
278  jobs['createPriorDistStats'] = None
279  jobs['calcRankPDFs'] = None
280  jobs['calcRankPDFsWithZerolag'] = None
281  jobs['calcLikelihood'] = None
282  jobs['marginalize'] = None
283  jobs['marginalizeWithZerolag'] = None
284 
285  else:
286  jobs['refPSD'] = dagparts.DAGJob("gstlal_reference_psd", condor_commands = ref_psd_condor_commands)
287  jobs['medianPSD'] = dagparts.DAGJob("gstlal_median_of_psds", condor_commands = base_condor_commands)
288  jobs['plotBanks'] = dagparts.DAGJob("gstlal_inspiral_plot_banks", condor_commands = base_condor_commands)
289  jobs['svd'] = dagparts.DAGJob("gstlal_svd_bank", condor_commands = svd_condor_commands)
290  jobs['model'] = dagparts.DAGJob("gstlal_inspiral_mass_model", condor_commands = base_condor_commands)
291  jobs['modelAdd'] = dagparts.DAGJob("gstlal_inspiral_add_mass_models", condor_commands = base_condor_commands)
292  jobs['horizon'] = dagparts.DAGJob("gstlal_plot_psd_horizon", condor_commands = base_condor_commands)
293  jobs['gstlalInspiral1IFO'] = dagparts.DAGJob("gstlal_inspiral", tag_base="gstlal_inspiral_1ifo", condor_commands = inspiral_1ifo_condor_commands)
294  jobs['gstlalInspiral2IFO'] = dagparts.DAGJob("gstlal_inspiral", tag_base="gstlal_inspiral_2ifo", condor_commands = inspiral_2ifo_condor_commands)
295  jobs['gstlalInspiral3IFO'] = dagparts.DAGJob("gstlal_inspiral", tag_base="gstlal_inspiral_3ifo", condor_commands = inspiral_3ifo_condor_commands)
296  jobs['createPriorDistStats'] = dagparts.DAGJob("gstlal_inspiral_create_prior_diststats", condor_commands = base_condor_commands)
297  jobs['calcRankPDFs'] = dagparts.DAGJob("gstlal_inspiral_calc_rank_pdfs", condor_commands = calc_rank_pdf_condor_commands)
298  jobs['calcRankPDFsWithZerolag'] = dagparts.DAGJob("gstlal_inspiral_calc_rank_pdfs", tag_base="gstlal_inspiral_calc_rank_pdfs_with_zerolag", condor_commands=calc_rank_pdf_condor_commands)
299  jobs['calcLikelihood'] = dagparts.DAGJob("gstlal_inspiral_calc_likelihood", condor_commands = base_condor_commands)
300  jobs['marginalize'] = dagparts.DAGJob("gstlal_inspiral_marginalize_likelihood", condor_commands = base_condor_commands)
301  jobs['marginalizeWithZerolag'] = dagparts.DAGJob("gstlal_inspiral_marginalize_likelihood", tag_base="gstlal_inspiral_marginalize_likelihood_with_zerolag", condor_commands=base_condor_commands)
302 
303  # set up rest of jobs
304  jobs['gstlalInspiralInj1IFO'] = dagparts.DAGJob("gstlal_inspiral", tag_base="gstlal_inspiral_inj_1ifo", condor_commands = inspiral_1ifo_condor_commands)
305  jobs['gstlalInspiralInj2IFO'] = dagparts.DAGJob("gstlal_inspiral", tag_base="gstlal_inspiral_inj_2ifo", condor_commands = inspiral_2ifo_condor_commands)
306  jobs['gstlalInspiralInj3IFO'] = dagparts.DAGJob("gstlal_inspiral", tag_base="gstlal_inspiral_inj_3ifo", condor_commands = inspiral_3ifo_condor_commands)
307  jobs['injSplitter'] = dagparts.DAGJob("gstlal_injsplitter", tag_base="gstlal_injsplitter", condor_commands = base_condor_commands)
308  jobs['gstlalInjSnr'] = dagparts.DAGJob("gstlal_inspiral_injection_snr", condor_commands = inj_snr_condor_commands)
309  jobs['ligolwAdd'] = dagparts.DAGJob("ligolw_add", condor_commands = base_condor_commands)
310  jobs['calcLikelihoodInj'] = dagparts.DAGJob("gstlal_inspiral_calc_likelihood", tag_base='gstlal_inspiral_calc_likelihood_inj', condor_commands=base_condor_commands)
311  jobs['ComputeFarFromSnrChisqHistograms'] = dagparts.DAGJob("gstlal_compute_far_from_snr_chisq_histograms", condor_commands = base_condor_commands)
312  jobs['ligolwInspinjFind'] = dagparts.DAGJob("lalapps_inspinjfind", condor_commands = base_condor_commands)
313  jobs['toSqlite'] = dagparts.DAGJob("ligolw_sqlite", tag_base = "ligolw_sqlite_from_xml", condor_commands = base_condor_commands)
314  jobs['toSqliteNoCache'] = dagparts.DAGJob("ligolw_sqlite", tag_base = "ligolw_sqlite_from_xml_final", condor_commands = base_condor_commands)
315  jobs['toXML'] = dagparts.DAGJob("ligolw_sqlite", tag_base = "ligolw_sqlite_to_xml", condor_commands = base_condor_commands)
316  jobs['lalappsRunSqlite'] = dagparts.DAGJob("lalapps_run_sqlite", condor_commands = base_condor_commands)
317  jobs['plotSummary'] = dagparts.DAGJob("gstlal_inspiral_plotsummary", condor_commands = base_condor_commands)
318  jobs['plotSummaryIsolatePrecession'] = dagparts.DAGJob("gstlal_inspiral_plotsummary", tag_base="gstlal_inspiral_plotsummary_isolated_precession", condor_commands=base_condor_commands)
319  jobs['plotSnglInjSummary'] = dagparts.DAGJob("gstlal_inspiral_plotsummary", tag_base = "gstlal_inspiral_plotsummary_inj", condor_commands=base_condor_commands)
320  jobs['plotSnglInjSummaryIsolatePrecession'] = dagparts.DAGJob("gstlal_inspiral_plotsummary", tag_base="gstlal_inspiral_plotsummary_isolated_precession_inj", condor_commands=base_condor_commands)
321  jobs['plotSensitivity'] = dagparts.DAGJob("gstlal_inspiral_plot_sensitivity", condor_commands = base_condor_commands)
322  jobs['summaryPage'] = dagparts.DAGJob("gstlal_inspiral_summary_page", condor_commands = base_condor_commands)
323  jobs['plotBackground'] = dagparts.DAGJob("gstlal_inspiral_plot_background", condor_commands = base_condor_commands)
324  jobs['cp'] = dagparts.DAGJob("cp", tag_base = "cp", condor_commands = sh_condor_commands)
325  jobs['rm'] = dagparts.DAGJob("rm", tag_base = "rm_intermediate_merger_products", condor_commands = sh_condor_commands)
326 
327  return jobs
328 
329 
330 #----------------------------------------------------------
331 ### main
332 
333 if __name__ == '__main__':
334  options, filenames = parse_command_line()
335 
336  if options.bank_cache or options.svd_bank_cache:
337  detectors = datasource.GWDataSourceInfo(options)
338  channel_dict = detectors.channel_dict
339  boundary_seg = detectors.seg
340  else:
341  with open(options.rank_pdf_cache) as f:
342  ce = CacheEntry(f.readline())
343  boundary_seg = ce.segment
344  instruments = ce.observatory
345 
346  # output directories
347  output_dir = "plots"
348  try:
349  os.mkdir("logs")
350  except:
351  pass
352 
353  #
354  # Set up DAG architecture
355  #
356 
357  dag = dagparts.DAG("trigger_pipe")
358  jobs = set_up_jobs(options)
359 
360  if options.max_inspiral_jobs is not None:
361  dag.add_maxjobs_category("INSPIRAL", options.max_inspiral_jobs)
362 
363  # generate xml integrity checker (if requested) and pre-script to back up data
364  inspiral_pipe.set_up_scripts(options)
365 
366  # Get mchirp boundaries of banks, maximum duration of templates, and analysis segments
367  if options.bank_cache or options.psd_cache:
368  if options.bank_cache:
369  template_mchirp_dict, bank_cache, max_time = inspiral_pipe.get_bank_params(options)
370  instrument_set = list(bank_cache.keys())
371 
372  if options.psd_cache:
373  template_mchirp_dict, svd_nodes, max_time = inspiral_pipe.get_svd_bank_params(options.svd_bank_cache)
374  instrument_set = list(svd_nodes.keys())
375 
376  segsdict = inspiral_pipe.analysis_segments(set(instrument_set), detectors.frame_segments, boundary_seg, max_time, options.min_instruments)
377  instruments = "".join(sorted(instrument_set))
378 
379  if options.psd_cache:
380  ### reference psd jobs
381  psd_nodes, ref_psd_parent_nodes = inspiral_pipe.inj_psd_layer(segsdict, options)
382  ref_psd = inspiral_pipe.load_reference_psd(options)
383 
384  elif options.reference_psd:
385  # load reference PSD
386  ref_psd = inspiral_pipe.load_reference_psd(options)
387  ref_psd_parent_nodes = []
388 
389  else:
390  # Compute the PSDs for each segment
391  psd_nodes = inspiral_pipe.ref_psd_layer(dag, jobs, [], segsdict, channel_dict, options)
392 
393  # plot the horizon distance
394  inspiral_pipe.horizon_dist_layer(dag, jobs, psd_nodes, options, boundary_seg, output_dir, instruments)
395 
396  # compute the median PSD
397  median_psd_node = inspiral_pipe.median_psd_layer(dag, jobs, psd_nodes, options, boundary_seg, instruments)
398  ref_psd = median_psd_node.output_files["output-name"]
399  ref_psd_parent_nodes = [median_psd_node]
400 
401  # Calculate Expected SNR jobs
402  if not options.disable_calc_inj_snr:
403  ligolw_add_nodes = inspiral_pipe.expected_snr_layer(dag, jobs, ref_psd_parent_nodes, options, num_split_inj_snr_jobs = 100)
404  else:
405  ligolw_add_nodes = []
406 
407  if options.injection_only:
408  model_node = None
409  model_file = options.mass_model_file
410  svd_dtdphi_map, _ = inspiral_pipe.load_svd_dtdphi_map(options)
411  else:
412  # Compute SVD banks
413  svd_nodes, template_mchirp_dict, svd_dtdphi_map = inspiral_pipe.svd_layer(dag, jobs, ref_psd_parent_nodes, ref_psd, bank_cache, options, boundary_seg, output_dir, template_mchirp_dict)
414 
415  # mass model
416  model_node, model_file = inspiral_pipe.mass_model_layer(dag, jobs, ref_psd_parent_nodes, instruments, options, boundary_seg, ref_psd)
417 
418  # Inspiral jobs by segment
419  inspiral_nodes, lloid_output, lloid_diststats = inspiral_pipe.inspiral_layer(dag, jobs, psd_nodes, svd_nodes, segsdict, options, channel_dict, template_mchirp_dict)
420 
421  # marginalize jobs
422  marg_nodes = inspiral_pipe.marginalize_layer(dag, jobs, svd_nodes, lloid_output, lloid_diststats, options, boundary_seg, instrument_set, model_node, model_file, ref_psd, svd_dtdphi_map, options.idq_file)
423 
424  # calc rank PDF jobs
425  rankpdf_nodes, rankpdf_zerolag_nodes = inspiral_pipe.calc_rank_pdf_layer(dag, jobs, marg_nodes, options, boundary_seg, instrument_set)
426 
427  # final marginalization step
428  final_marg_nodes, margfiles_to_delete = inspiral_pipe.final_marginalize_layer(dag, jobs, rankpdf_nodes, rankpdf_zerolag_nodes, options)
429 
430  # likelihood jobs
431  likelihood_nodes = inspiral_pipe.likelihood_layer(dag, jobs, marg_nodes, lloid_output, lloid_diststats, options, boundary_seg, instrument_set)
432 
433  # Setup clustering and/or merging
434  # after all of the likelihood ranking and preclustering is finished put everything into single databases based on the injection file (or lack thereof)
435  injdbs, noninjdb, final_sqlite_nodes, dbs_to_delete = inspiral_pipe.sql_cluster_and_merge_layer(dag, jobs, likelihood_nodes, ligolw_add_nodes, options, boundary_seg, instruments)
436 
437  # Compute FAR
438  farnode = inspiral_pipe.compute_far_layer(dag, jobs, final_marg_nodes, injdbs, noninjdb, final_sqlite_nodes, options)
439 
440  # make summary plots
441  plotnodes = inspiral_pipe.summary_plot_layer(dag, jobs, farnode, options, injdbs, noninjdb, output_dir)
442 
443  # make a web page
444  inspiral_pipe.summary_page_layer(dag, jobs, plotnodes, options, boundary_seg, injdbs, output_dir)
445 
446  # rm intermediate merger products
447  inspiral_pipe.clean_merger_products_layer(dag, jobs, plotnodes, dbs_to_delete, margfiles_to_delete)
448 
449  #
450  # generate DAG files
451  #
452 
453  dag.write_sub_files()
454  dag.write_dag()
455  dag.write_script()
456  dag.write_cache()