Package pylal :: Module db_rinca_rings
[hide private]
[frames] | no frames]

Source Code for Module pylal.db_rinca_rings

  1  # Copyright (C) 2009  Kipp Cannon, Chad Hanna 
  2  # 
  3  # This program is free software; you can redistribute it and/or modify it 
  4  # under the terms of the GNU General Public License as published by the 
  5  # Free Software Foundation; either version 2 of the License, or (at your 
  6  # option) any later version. 
  7  # 
  8  # This program is distributed in the hope that it will be useful, but 
  9  # WITHOUT ANY WARRANTY; without even the implied warranty of 
 10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
 11  # Public License for more details. 
 12  # 
 13  # You should have received a copy of the GNU General Public License along 
 14  # with this program; if not, write to the Free Software Foundation, Inc., 
 15  # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 16   
 17   
 18  # 
 19  # ============================================================================= 
 20  # 
 21  #                                   Preamble 
 22  # 
 23  # ============================================================================= 
 24  # 
 25   
 26   
 27  import sys 
 28   
 29   
 30  from glue import iterutils 
 31  from glue import segments 
 32  from glue.ligolw import lsctables 
 33  from glue.ligolw import dbtables 
 34  from glue.ligolw.utils import search_summary as ligolw_search_summary 
 35  from glue.ligolw.utils import segments as ligolw_segments 
 36  from pylal import SnglInspiralUtils 
 37   
 38   
 39  # 
 40  # ============================================================================= 
 41  # 
 42  #                                  Functions 
 43  # 
 44  # ============================================================================= 
 45  # 
 46   
 47   
48 -def get_rinca_rings_by_available_instruments(connection, program_name = "rinca"):
49 """ 50 Return the rinca rings from the database at the given connection. The 51 rings are returned as a glue.segments.segmentlistdict indexed by the 52 set of instruments that were analyzed in that ring. 53 54 Example: 55 56 >>> seglists = get_rinca_rings_by_available_instruments(connection) 57 >>> print(seglists.keys()) 58 [frozenset(['H1', 'L1'])] 59 """ 60 # extract raw rings indexed by available instrument set 61 62 xmldoc = dbtables.get_xml(connection) 63 seglists = segments.segmentlistdict() 64 for row in map(lsctables.SearchSummaryTable.get_table(xmldoc).row_from_cols, connection.cursor().execute(""" 65 SELECT 66 search_summary.* 67 FROM 68 search_summary 69 JOIN process ON ( 70 process.process_id == search_summary.process_id 71 ) 72 WHERE 73 process.program == ? 74 """, (program_name,))): 75 available_instruments = frozenset(row.get_ifos()) 76 try: 77 seglists[available_instruments].append(row.get_out()) 78 except KeyError: 79 seglists[available_instruments] = [row.get_out()] 80 xmldoc.unlink() 81 82 # remove rings that are exact duplicates on the assumption that there are 83 # zero-lag and time-slide rinca jobs represented in the same document 84 85 return segments.segmentlistdict((key, segments.segmentlist(sorted(set(value)))) for key, value in seglists.items())
86 87
88 -def get_rinca_zero_lag_segments(connection, program_name = "rinca"):
89 """ 90 Return the rinca rings from the database at the given connection. The 91 rings are returned as a coalesced glue.segments.segmentlistdict indexed 92 by instrument. 93 94 Example: 95 96 >>> seglists = get_rinca_zero_lag_segments(connection) 97 >>> print(seglists.keys()) 98 ['H1', 'L1'] 99 100 This function is most useful if only zero-lag segments are desired 101 because it allows for more convenient manipulation of the segment lists 102 using the methods in glue.segments. If information about background 103 segments or the original ring boundaries is desired the data returned by 104 get_rinca_rings_by_available_instruments() is required. 105 """ 106 # extract the raw rings indexed by instrument 107 108 xmldoc = dbtables.get_xml(connection) 109 seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, program_name) 110 xmldoc.unlink() 111 112 # remove rings that are exact duplicates on the assumption that there are 113 # zero-lag and time-slide rinca jobs represented in the same document 114 115 seglists = segments.segmentlistdict((key, segments.segmentlist(set(value))) for key, value in seglists.items()) 116 117 # coalesce the remaining segments making sure we don't loose livetime in 118 # the process 119 120 durations_before = abs(seglists) 121 seglists.coalesce() 122 if abs(seglists) != durations_before: 123 raise ValueError, "detected overlapping rinca rings" 124 125 # done 126 127 return seglists
128 129
130 -def get_veto_segments(connection, name):
131 """ 132 Return a coalesced glue.segments.segmentlistdict object containing the 133 segments of the given name extracted from the database at the given 134 connection. 135 """ 136 xmldoc = dbtables.get_xml(connection) 137 seglists = ligolw_segments.segmenttable_get_by_name(xmldoc, name).coalesce() 138 xmldoc.unlink() 139 return seglists
140 141
142 -def get_background_offset_vectors(connection):
143 """ 144 Return a list of the non-zero offset vectors extracted from the database 145 at the given connection. Each offset vector is returned as a dictionary 146 mapping instrument name to offset. 147 """ 148 xmldoc = dbtables.get_xml(connection) 149 offset_vectors = [offsetvector for offsetvector in lsctables.TimeSlideTable.get_table(xmldoc).as_dict().values() if any(offsetvector.values())] 150 xmldoc.unlink() 151 return offset_vectors
152 153
154 -def get_rinca_livetimes(ring_sets, veto_segments, offset_vectors, verbose = False):
155 # FIXME: somebody should document this 156 livetimes = {} 157 for available_instruments, rings in ring_sets.items(): 158 for on_instruments in (combo for m in range(2, len(available_instruments) + 1) for combo in iterutils.choices(sorted(available_instruments), m)): 159 if verbose: 160 print >>sys.stderr, "%s/%s" % (",".join(on_instruments), ",".join(sorted(available_instruments))), 161 on_instruments = frozenset(on_instruments) 162 if on_instruments not in livetimes: 163 livetimes[on_instruments] = [0.0] * len(offset_vectors) 164 for i, livetime in enumerate(SnglInspiralUtils.compute_rinca_livetime(on_instruments, available_instruments - on_instruments, rings, veto_segments, offset_vectors)): 165 livetimes[on_instruments][i] += livetime 166 return livetimes
167