3 # Copyright (C) 2009-2011 Kipp Cannon, Chad Hanna, Drew Keppel
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.
20 # may be deprecated soon; do not use at this time
23 # =============================================================================
27 # =============================================================================
32 from optparse
import OptionParser
35 from glue
import segments
36 from glue.ligolw
import ligolw
37 from glue.ligolw
import lsctables
38 from glue.ligolw
import array
39 from glue.ligolw
import param
40 array.use_in(ligolw.LIGOLWContentHandler)
41 param.use_in(ligolw.LIGOLWContentHandler)
42 lsctables.use_in(ligolw.LIGOLWContentHandler)
43 from glue.ligolw
import utils
44 from glue.ligolw.utils
import process as ligolw_process
45 from glue.ligolw.utils
import search_summary as ligolw_search_summary
48 from gstlal
import far
49 from gstlal.inspiral
import gen_likelihood_control_doc
51 ## @file gstlal_inspiral_reset_likelihood
52 # This program resets the trials table and segments from files containing the distribution statistics for gstlal_inspiral jobs; see gstlal_inspiral_reset_likelihood for help and usage
54 ## @package gstlal_inspiral_reset_likelihood
59 # =============================================================================
63 # =============================================================================
67 def parse_command_line():
68 parser = OptionParser()
69 parser.add_option(
"--marginalized-likelihood-file", metavar =
"filename", help =
"Set the name of the xml file containing the marginalized likelihood")
70 parser.add_option(
"--verbose", action =
"store_true", help =
"Be verbose.")
71 options, urls = parser.parse_args()
76 # =============================================================================
80 # =============================================================================
89 options, urls = parse_command_line()
93 # loop over input documents
102 in_xmldoc = utils.load_url(url,
verbose = options.
verbose, contenthandler = ligolw.LIGOLWContentHandler)
103 likelihood_data = far.LocalRankingData.from_xml(in_xmldoc)
104 search_summary_row, = (row for row in lsctables.table.get_table(in_xmldoc, lsctables.SearchSummaryTable.tableName) if row.process_id == likelihood_data.distributions.process_id)
105 ifos = search_summary_row.instruments
106 # reset the clock to None
107 likelihood_data.livetime_seg = segments.segment(None,None)
108 # reset the trials table to 0
109 for k in likelihood_data.trials_table:
110 likelihood_data.trials_table[k].count = 0
111 likelihood_data.trials_table[k].count_below_thresh = 0
113 xmldoc = gen_likelihood_control_doc(likelihood_data, ifos)
115 utils.write_filename(xmldoc, url, gz = url.endswith(
".gz"),
verbose = options.
verbose)
117 # Reset the marginalized likelihood file if it exists too
118 if options.marginalized_likelihood_file is not None:
120 marg, procid = far.RankingData.from_xml(utils.load_filename(options.marginalized_likelihood_file, contenthandler = ligolw.LIGOLWContentHandler,
verbose = options.
verbose))
122 for k in marg.trials_table:
123 marg.trials_table[k].count = 0
124 marg.trials_table[k].count_below_thresh = 0
126 marg.livetime_seg = segments.segment(None,None)
128 xmldoc = ligolw.Document()
129 node = xmldoc.appendChild(ligolw.LIGO_LW())
130 node.appendChild(lsctables.New(lsctables.ProcessTable))
131 node.appendChild(lsctables.New(lsctables.ProcessParamsTable))
132 node.appendChild(lsctables.New(lsctables.SearchSummaryTable))
133 process = ligolw_process.register_to_xmldoc(xmldoc, u
"gstlal_inspiral_reset_likelihood", options.__dict__)
134 search_summary = ligolw_search_summary.append_search_summary(xmldoc, process)
135 search_summary.out_segment = marg.livetime_seg
136 xmldoc.childNodes[-1].appendChild(marg.to_xml(process, search_summary))
137 ligolw_process.set_process_end_time(process)
138 outname = options.marginalized_likelihood_file
139 utils.write_filename(xmldoc, outname, gz = outname.endswith(
".gz"),
verbose = options.
verbose)