gstlal-inspiral  0.4.2
 All Classes Namespaces Files Functions Variables Pages
gstlal_inspiral_recompute_online_far
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2011, 2012 Kipp Cannon, Chad Hanna, Drew Keppel
4 #
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.
9 #
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.
14 #
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.
18 
19 ## @file
20 # This program might be deprecated soon; Do not use for now
21 
22 
23 from optparse import OptionParser
24 import sys
25 try:
26  import sqlite3
27 except ImportError:
28  # pre 2.5.x
29  from pysqlite2 import dbapi2 as sqlite3
30 sqlite3.enable_callback_tracebacks(True)
31 
32 
33 from glue.ligolw import dbtables
34 from glue.ligolw import utils as ligolw_utils
35 from glue.segmentsUtils import vote
36 from gstlal import far
37 
38 
39 def parse_command_line():
40  parser = OptionParser()
41  parser.add_option("--background-bins-file", metavar = "filename", action = "append", help = "Set the name of the xml file containing the snr / chisq background distributions")
42  parser.add_option("--tmp-space", metavar = "dir", help = "Set the name of the tmp space if working with sqlite")
43  parser.add_option("--verbose", "-v", action = "store_true", help = "Be verbose.")
44  parser.add_option("--non-injection-db", metavar = "filename", action = "append", help = "single file for non injections run")
45  options, filenames = parser.parse_args()
46  return options, filenames
47 
48 #
49 # Parse command line
50 #
51 
52 options, filenames = parse_command_line()
53 
54 #
55 # Pull out background and injections distribution and set up the FAR class
56 # FIXME: this needs to be updated. FIXME: this program might now be
57 # identical to gstlal_compute_far_fr... so delete
58 #
59 
60 
61 global_ranking, procid = far.RankingData.from_xml(ligolw_utils.load_filename(options.background_bins_file[0], contenthandler = far.ThincaCoincParams.LIGOLWContentHandler, verbose = options.verbose))
62 
63 global_ranking.compute_joint_cdfs()
64 
65 for ifos in global_ranking.trials_table:
66  global_ranking.scale[ifos] = (global_ranking.trials_table[ifos].count_below_thresh or 1) / global_ranking.trials_table[ifos].thresh / float(abs(global_ranking.livetime_seg)) * global_ranking.trials_table.num_nonzero_count()
67 
68 
69 #
70 # Scale the rate Set the FAP and FAR
71 #
72 
73 
74 for filename in options.non_injection_db:
75  #
76  # get working copy of database
77  #
78 
79  working_filename = dbtables.get_connection_filename(filename, tmp_path = options.tmp_space, verbose = options.verbose)
80  connection = sqlite3.connect(working_filename)
81 
82  #
83  # assign FAPs and FARs
84  #
85 
86  far.assign_faps(connection)
87  far.assign_fars(connection)
88 
89  #
90  # done, restore file to original location
91  #
92 
93  connection.commit()
94  connection.close()
95  dbtables.put_connection_filename(filename, working_filename, verbose = verbose)