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
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
43
44
45
46
47
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
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
83
84
85 return segments.segmentlistdict((key, segments.segmentlist(sorted(set(value)))) for key, value in seglists.items())
86
87
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
107
108 xmldoc = dbtables.get_xml(connection)
109 seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, program_name)
110 xmldoc.unlink()
111
112
113
114
115 seglists = segments.segmentlistdict((key, segments.segmentlist(set(value))) for key, value in seglists.items())
116
117
118
119
120 durations_before = abs(seglists)
121 seglists.coalesce()
122 if abs(seglists) != durations_before:
123 raise ValueError, "detected overlapping rinca rings"
124
125
126
127 return seglists
128
129
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
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
155
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