3 # Copyright (C) 2011-2012 Shaun Hooper, Chad Hanna
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 ## @file gstlal_inspiral_iir_bank_pipe
20 # A program to make an HTCondor DAG to create banks of IIR filters for an online CBC analysis
22 # ### Command line interface
23 # + `--flow` [Hz] (float): Set the template low-frequency cut-off (default = 40.0).
24 # + `--sampleRate` [Hz] (float): Set the sample rate of the IIR template bank (optional).
25 # + `--padding` [pad] (float): Fractional amount to pad time slices (default = 1.1).
26 # + `--epsilon` [pad] (float): Second order correction factor (default = 0.02).
27 # + `--reference-psd` [file]: Set the name of the reference psd file, required.
28 # + `--bank-cache` [file]: Set the name of the bank cache, required.
29 # + `--output-name`: Set the base name of the output, required.
30 # + `--instrument`: Set the name of the instrument, required.
31 # + `--verbose`: Be verbose.
32 # + `--downsample`: Choose if you want to downsample IIR bank (recommended).
35 This program makes a dag to generate iir banks
38 __author__ =
'Chad Hanna <channa@caltech.edu>, Shaun Hooper <shaun.hooper@uwa.edu.au>'
40 ##############################################################################
41 # import standard modules and append the lalapps prefix to the python path
42 import sys, os, copy, math
43 import subprocess, socket, tempfile
45 ##############################################################################
46 # import the modules we need to build the pipeline
47 from glue
import iterutils
50 from glue.ligolw
import lsctables
51 from glue
import segments
52 from optparse
import OptionParser
55 which = subprocess.Popen([
'which',prog], stdout=subprocess.PIPE)
56 out = which.stdout.read().strip()
58 print >>sys.stderr,
"ERROR: could not find %s in your path, have you built the proper software and source the proper env. scripts?" % (prog,prog)
63 host = socket.getfqdn()
64 #FIXME add more hosts as you need them
65 if
'caltech.edu' in host: return
'/usr1/' + os.environ[
'USER']
66 if
'phys.uwm.edu' in host: return
'/localscratch/' + os.environ[
'USER']
67 if
'aei.uni-hannover.de' in host: return
'/local/user/' + os.environ[
'USER']
68 if
'phy.syr.edu' in host: return
'/usr1/' + os.environ[
'USER']
73 def __init__(self, name, logpath =
log_path()):
75 tempfile.tempdir = logpath
76 tempfile.template = self.basename +
'.dag.log.'
77 logfile = tempfile.mktemp()
78 fh = open( logfile,
"w" )
81 self.set_dag_file(self.basename)
84 self.output_cache = []
86 def add_node(
self, node):
89 node.add_macro(
"macroid", self.node_id)
92 def write_cache(self):
93 out = self.basename +
".cache"
95 for c in self.output_cache:
101 A gstlal_iir_bank job
103 def __init__(self, executable=
which(
'gstlal_iir_bank'), tag_base=
'gstlal_iir_bank'):
106 self.__prog__ =
'gstlal_iir_bank'
107 self.__executable = executable
108 self.__universe =
'vanilla'
110 self.add_condor_cmd(
'getenv',
'True')
111 self.add_condor_cmd(
'requirements',
'Memory > 1999') #FIXME is this enough?
112 self.tag_base = tag_base
113 self.add_condor_cmd(
'environment',
"KMP_LIBRARY=serial;MKL_SERIAL=yes")
114 self.set_sub_file(tag_base+
'.sub')
115 self.set_stdout_file(
'logs/'+tag_base+
'-$(macroid)-$(process).out')
116 self.set_stderr_file(
'logs/'+tag_base+
'-$(macroid)-$(process).err')
122 def __init__(self, job, dag, template_bank, ifo, flow, reference_psd, sampleRate, padding, downsample, epsilon=0.02, p_node=[]):
125 self.add_var_opt(
"template-bank", template_bank)
126 self.add_var_opt(
"instrument", ifo)
127 self.add_var_opt(
"flow", flow)
128 self.add_var_opt(
"reference-psd", reference_psd)
129 self.add_var_opt(
"sampleRate",sampleRate)
130 self.add_var_opt(
"padding",padding)
131 if downsample: self.add_var_opt(
"downsample",
"")
132 self.add_var_opt(
"epsilon", epsilon)
133 iir_bank_name_path = os.path.split(template_bank)
134 iir_bank_name = iir_bank_name_path[0] +
"/iir_" + iir_bank_name_path[1]
135 self.add_var_opt(
"output", iir_bank_name)
136 dag.output_cache.append(lal.CacheEntry(ifo,
"-", segments.segment(0, 999999999),
"file://localhost%s" % (iir_bank_name,)))
141 def parse_command_line():
142 parser = OptionParser()
143 parser.add_option(
"--flow", metavar =
"Hz", type =
"float", default = 40.0, help =
"Set the template low-frequency cut-off (default = 40.0).")
144 parser.add_option(
"--sampleRate", metavar =
"Hz", type =
"float", help =
"Set the sample rate of the IIR template bank (optional).")
145 parser.add_option(
"--padding", metavar =
"pad", type =
"float", default = 1.1, help =
"Fractional amount to pad time slices.")
146 parser.add_option(
"--epsilon", metavar =
"pad", type =
"float", default = 0.02, help =
"Second order correction factor.")
147 parser.add_option(
"--reference-psd", metavar =
"file", help =
"Set the name of the reference psd file, required")
148 parser.add_option(
"--bank-cache", metavar =
"file", help =
"Set the name of the bank cache, required")
149 parser.add_option(
"--output-name", help =
"set the base name of the output, required")
150 parser.add_option(
"--instrument", help =
"set the name of the instrument, required")
151 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
152 parser.add_option(
"--downsample", action =
"store_true", help =
"Choose if you want to downsample IIR bank (recommended)")
153 options, filenames = parser.parse_args()
155 return options, filenames
157 options, filenames = parse_command_line()
159 # get input arguments
160 ifo = options.instrument
161 ref_psd = options.reference_psd
162 input_cache = options.bank_cache
163 psdname = ref_psd.split(
'.')[0]
165 try: os.mkdir(
"logs")
167 dag = bank_DAG(options.output_name)
169 iirJob = gstlal_iir_bank_job(tag_base=psdname +
"_gstlal_iir_bank")
173 for f in [lal.CacheEntry(line).path
for line in open(input_cache)]:
175 iirNode[f] = gstlal_iir_bank_node(iirJob, dag, f, ifo, options.flow, ref_psd, options.sampleRate, options.padding, options.downsample, options.epsilon)
177 dag.write_sub_files()