Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lalpulsar_knope.py
Go to the documentation of this file.
1##python
2# -*- coding: utf-8 -*-
3#
4# lalpulsar_knope.py
5#
6# Copyright 2015
7# Matthew Pitkin <matthew.pitkin@ligo.org>,
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22# MA 02110-1301, USA.
23
24## \file
25## \ingroup lalpulsar_bin_HeterodyneSearch
26"""
27The KNOwn Pulsar pipelinE - lalpulsar_knope
28
29DAG generation code for running the known pulsar search pipeline
30"""
31
32from __future__ import print_function, division
33
34from lalpulsar import knope_utils as knope
35import argparse
36from configparser import ConfigParser
37import sys
38import pickle
39
40description = """Setup a Condor DAG file to run the known pulsar search pipeline based on information given in config.ini.
41The user must specify the configuration file for the script to run.
42"""
43
44parser = argparse.ArgumentParser(description=description)
45
46parser.add_argument(
47 "inifile", help="The configuation (.ini) file"
48) # the positional argument for the configuration file
49parser.add_argument(
50 "--condor-submit",
51 action="store_true",
52 default=False,
53 help="Automatically submit the Condor DAG",
54)
55parser.add_argument(
56 "-r",
57 "--run-path",
58 dest="runpath",
59 default=None,
60 help="Set the directory to run the pipeline in (overwrites any value in the config.ini file)",
61)
62parser.add_argument(
63 "-p",
64 "--pulsar",
65 dest="pulsarlist",
66 action="append",
67 default=None,
68 help="A pulsar name to search for rather than all pulsars given in a parameter file directory (this can be specified multiple times to search for more than one pulsar).",
69)
70
71opts = parser.parse_args()
72
73# check that at least the ini file has been given
74inifile = opts.inifile
75
76# parser .ini file
77try:
78 cp = ConfigParser()
79 cp.optionxform = str
80 cp.readfp(open(inifile))
81except:
82 print("Error... problem parsing '%s' configuration file" % inifile, file=sys.stderr)
83 sys.exit(1)
84
85if opts.runpath is not None:
86 cp.set("analysis", "run_dir", opts.runpath)
87
88# Check if we're running in automated mode or not
89try:
90 automated = cp.getboolean("analysis", "autonomous")
91except:
92 automated = False
93
94# Check if configuration file says to submit the DAG
95submitdag = opts.condor_submit
96if not submitdag:
97 try:
98 submitdag = cp.getboolean("analysis", "submit_dag")
99 except:
100 submitdag = False
101
102# Create DAG from ConfigParser object
103dag = knope.knopeDAG(cp, inifile, pulsarlist=opts.pulsarlist)
104if dag.error_code != 0: # check for any errors that occurred
105 if dag.error_code in knope.KNOPE_ERROR.keys():
106 print(knope.KNOPE_ERROR[dag.error_code], file=sys.stderr)
107 else:
108 print("Error... unrecognised error code!", file=sys.stderr)
109
110 # only exit if not in autonomous mode and the error message
111 if not automated or dag.error_code != knope.KNOPE_ERROR_NO_SEGMENTS:
112 sys.exit(dag.error_code)
113
114# write out DAG and submit files (unless in automated mode and no new segment files were found)
115if not automated or dag.error_code != knope.KNOPE_ERROR_NO_SEGMENTS:
116 dag.write_sub_files()
117 dag.write_dag()
118
119 print("Successfully created DAG file: '%s'" % dag.get_dag_file())
120
121 if submitdag:
122 from subprocess import Popen
123
124 x = Popen(["condor_submit_dag", dag.get_dag_file()])
125 x.wait()
126 if x.returncode == 0:
127 print("Submitted DAG file")
128 else:
129 print("Unable to submit DAG file")
130 else:
131 print("Run 'condor_submit_dag %s' to submit DAG file" % dag.get_dag_file())
132
133 # output DAG class to pickle file if given
134 if cp.has_option("analysis", "pickle_file"):
135 try:
136 pfile = cp.get("analysis", "pickle_file")
137 fp = open(pfile, "wb")
138 pickle.dump(dag, fp)
139 fp.close()
140 except:
141 print("Warning... could not output analysis class to pickle file")
142else:
143 print("No new science segments found in current time frame")
144
145sys.exit(0)