1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24   
 25  import itertools 
 26  from glue import segments 
 27  from glue.ligolw import lsctables 
 28  from glue.ligolw import dbtables 
 29  from glue.ligolw.utils import search_summary as ligolw_search_summary 
 30  from glue.ligolw.utils import segments as ligolw_segments 
 31  from pylal import db_thinca_rings 
 32   
 33   
 35          out = [] 
 36          instruments = tuple(instruments) 
 37          for i in range(1, len(instruments)): 
 38                  X = list(itertools.combinations(instruments, i)) 
 39                  Y = list(itertools.combinations(instruments, len(instruments) - i)) 
 40                  Y.reverse() 
 41                  out.extend(zip(X,Y))  
 42          instruments = list(instruments) 
 43          instruments.sort() 
 44          instruments = tuple(instruments) 
 45          out.append((instruments, ())) 
 46          return out 
  47   
 49           
 50           
 51          seglists = seglists.copy() 
 52          if veto_segments is not None: 
 53                  seglists -= veto_segments 
 54   
 55          background_time_slides = dict((time_slide_id, offsetvector) for time_slide_id, offsetvector in dbtables.TimeSlideTable(connection = connection).as_dict() if any(offsetvector.values())) 
 56          instruments = frozenset(seglists.keys()) 
 57          background_livetime = {} 
 58          for on_inst, off_inst in detector_combos(list(instruments)): 
 59                  on_inst = frozenset(on_inst) 
 60                  off_inst = frozenset(off_inst) 
 61                  key = on_inst 
 62                  old_offsets = seglists.offsets.copy() 
 63                  background_livetime.setdefault(key, {}) 
 64                  for id, time_slide in background_time_slides.items(): 
 65                          seglists.offsets.update(time_slide) 
 66                          segs=seglists.intersection(list(on_inst))-seglists.union(list(off_inst)) 
 67                          if coinc_segments is not None: 
 68                                  segs &= coinc_segments 
 69                          tskey = frozenset(time_slide.items()) 
 70                          background_livetime[key].setdefault(tskey,0) 
 71                          background_livetime[key][tskey] += float(abs(segs)) 
 72                  seglists.offsets.update(old_offsets) 
 73          return background_livetime 
  74   
 89   
 90 -def add_background_livetime(connection, live_time_program, seglists, veto_segments, coinc_segments=None, verbose=False): 
  91          if live_time_program == "thinca": lt = background_livetime_ring_by_slide(connection, live_time_program, seglists, veto_segments, verbose) 
 92          if live_time_program == "gstlal_inspiral": lt = background_livetime_nonring_by_slide(connection, seglists, veto_segments, coinc_segments, verbose) 
 93          if live_time_program == "lalapps_ring": lt = background_livetime_nonring_by_slide(connection, seglists, veto_segments, coinc_segments, verbose) 
 94          out = {} 
 95          for k, v in lt.items(): 
 96                  out.setdefault(k,0) 
 97                  out[k] += sum(v.values()) 
 98          return out 
  99   
101          playground_livetime = {} 
102          nonplayground_livetime = {} 
103          instruments = frozenset(seglists.keys()) 
104          for on_inst, off_inst in detector_combos(list(instruments)): 
105                  on_inst = frozenset(on_inst) 
106                  off_inst = frozenset(off_inst) 
107                  key = lsctables.ifos_from_instrument_set(on_inst) 
108                  selected_segs = seglists.intersection(list(on_inst))-seglists.union(list(off_inst)) 
109                  if playground_segs: 
110                          playground_livetime[on_inst] = float(abs(selected_segs & playground_segs)) 
111                          nonplayground_livetime[on_inst] = float(abs(selected_segs - playground_segs)) 
112                  else: 
113                          playground_livetime[on_inst] = 0 
114                          nonplayground_livetime[on_inst] = float(abs(selected_segs)) 
115   
116          return playground_livetime, nonplayground_livetime 
 117   
118 -def get_veto_segments(connection, program_name, xmldoc=None, veto_segments_name=None): 
 119          veto_segments = segments.segmentlistdict() 
120           
121          if not veto_segments_name: return veto_segments 
122          if program_name == "thinca": veto_segments = db_thinca_rings.get_veto_segments(connection, veto_segments_name) 
123          if program_name == "rinca": veto_segments = ligolw_segments.segmenttable_get_by_name(xmldoc, veto_segments_name).coalesce() 
124          return veto_segments 
 125   
126   
128          seglists = segments.segmentlistdict() 
129          if program_name == "thinca": 
130                  seglists = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name) 
131          if program_name == "gstlal_inspiral" or program_name == "lalapps_ring": 
132                  seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, program_name).coalesce() 
133          return seglists 
 134   
142   
144          lt = {} 
145          if zero_live_time: 
146                  for inst in zero_live_time.keys(): 
147                          lt.setdefault(inst,{}) 
148                          lt[inst][0] = zero_live_time[inst] 
149   
150          for inst, slide in background_by_slide.items(): 
151                  lt.setdefault(inst,{}) 
152                  for offsets, value in slide.items(): 
153                          for ifo, offset in offsets: 
154                                  if ifo == det: 
155                                          lt[inst][offset] = value 
156          return lt 
 157