LALPulsar  6.1.0.1-fe68b98
lalpulsar_run_crosscorr_v2.py
Go to the documentation of this file.
1 # script to call lalpulsar_crosscorr_v2 (for use with e.g. condor)
2 
3 # Copyright (C) 2014 John Whelan
4 
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 
15 # You should have received a copy of the GNU General Public License
16 # along with with program; see the file COPYING. If not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA 02110-1301 USA
19 
20 from __future__ import division
21 from argparse import ArgumentParser
22 from subprocess import check_call
23 from configparser import SafeConfigParser
24 from time import sleep
25 
26 ap = ArgumentParser()
27 ap.add_argument(
28  "--configFile",
29  action="store",
30  required=True,
31  help="Configuration file containing arguments",
32 )
33 ap.add_argument(
34  "--numJobs",
35  action="store",
36  type=int,
37  required=True,
38  help="Number of jobs into which run is split",
39 )
40 ap.add_argument(
41  "--jobNum", action="store", type=int, required=True, help="Number of this job"
42 )
43 
44 args = ap.parse_args()
45 
46 cp = SafeConfigParser()
47 cp.optionxform = str
48 cp.read(args.configFile)
49 
50 fMin = cp.getfloat("param-space", "f_min")
51 fMax = cp.getfloat("param-space", "f_max")
52 fFullBand = fMax - fMin
53 fBand = fFullBand / args.numJobs
54 fStart = fMin + args.jobNum * fBand
55 
56 toplistPattern = cp.get("filename-patterns", "toplist_name")
57 toplistName = toplistPattern % (args.jobNum, args.numJobs)
58 
59 logfilePattern = cp.get("filename-patterns", "logfile_name")
60 logfileName = logfilePattern % (args.jobNum, args.numJobs)
61 
62 
63 # Pass along the arguments from the ini file
64 program_args = ["--%s=%s" % a for a in cp.items("raw-program-arguments")]
65 
66 # Add calculated frequency band
67 program_args += ["--fStart=%.11f" % fStart]
68 program_args += ["--fBand=%.11f" % fBand]
69 program_args += ["--toplistFilename=%s" % toplistName]
70 program_args += ["--logFilename=%s" % logfileName]
71 
72 # check if latticeFilename is in the ini file
73 if cp.has_section("program") and cp.has_option("filename-patterns", "latticefile_name"):
74  # print("has latticefile")
75  latticefilePattern = cp.get("filename-patterns", "latticefile_name")
76  latticefileName = latticefilePattern % (args.jobNum, args.numJobs)
77  program_args += ["--LatticeOutputFilename=%s" % latticefileName]
78 
79 if cp.has_section("raw-program-arguments") and cp.has_option(
80  "raw-program-arguments", "latticeType"
81 ):
82  if (
83  cp.get("raw-program-arguments", "latticeType") == "byHand"
84  or cp.get("raw-program-arguments", "latticeType") == "byhand"
85  or cp.get("raw-program-arguments", "latticeType") == "byhand"
86  ):
87  print("no lattice")
88  else:
89  print("has lattice--uselattice")
90  program_args += ["--useLattice"]
91  # latticeType = cp.get('raw-program-arguments','latticeType')
92  # program_args += ['--latticeType=%s' % latticeType]
93 
94 
95 if cp.has_section("raw-program-arguments") and cp.has_option(
96  "raw-program-arguments", "useShearedPeriod"
97 ):
98  print("has --useShearedPeriod")
99  program_args += ["--useShearedPeriod"]
100 
101 # Variable delay to stagger start times of lalpulsar_crosscorr_v2 code
102 if cp.has_section("program") and cp.has_option("program", "delay_secs"):
103  sleep(args.jobNum * cp.getfloat("program", "delay_secs"))
104 
105 # Check if program was specified
106 if cp.has_section("program") and cp.has_option("program", "executable"):
107  program = cp.get("program", "executable")
108 else:
109  program = "lalpulsar_crosscorr_v2"
110 
111 print(program, program_args)
112 check_call(([program] + program_args))