gstlal 1.13.0
Loading...
Searching...
No Matches
trigger.py
1"""Module for making trigger elements
2
3"""
4import numpy
5
6from gstlal import pipeio
7from gstlal.pipeparts import pipetools
8
9
10def trigger(pipeline: pipetools.Pipeline, src: pipetools.Element, n: int, autocorrelation_matrix: numpy.ndarray = None, mask_matrix: numpy.ndarray = None,
11 snr_thresh: float = 0, sigmasq: float = None, max_snr: bool = False):
12 """Generic trigger generator, find triggers in snr streams
13
14 Args:
15 pipeline:
16 Gst.Pipeline, the pipeline to which the new element will be added
17 src:
18 Gst.Element, the source element
19 n:
20 int, number of samples over which to identify triggers
21 autocorrelation_matrix:
22 ndarray, Array of complex autocorrelation vectors. Number of vectors (rows) in matrix sets number of channels.
23 All vectors must have the same length.
24 mask_matrix:
25 ndarray, Array of integer autocorrelation mask vectors. Number of vectors (rows) in mask sets number of channels.
26 All vectors must have the same length. The mask values are either 0 or 1 and indicate whether to use the corresponding
27 matrix entry in computing the autocorrelation chi-sq statistic.
28 snr_thresh:
29 float, default 0, SNR Threshold that determines a trigger
30 sigmasq:
31 float, default None
32 max_snr:
33 bool, default False, Set flag to return single loudest trigger from buffer
34
35 References:
36 [1] GstLAL Trigger Implementation: gstlal/gstlal-burst/gst/lal/gstlal_trigger.c
37
38 Returns:
39 Element, the trigger element
40 """
41 properties = {
42 "n": n,
43 "snr_thresh": snr_thresh,
44 "max_snr": max_snr
45 }
46 if autocorrelation_matrix is not None:
47 properties["autocorrelation_matrix"] = pipeio.repack_complex_array_to_real(autocorrelation_matrix)
48 if mask_matrix is not None:
49 properties["autocorrelation_mask"] = mask_matrix
50 if sigmasq is not None:
51 properties["sigmasq"] = sigmasq
52 return pipetools.make_element_with_src(pipeline, src, "lal_trigger", **properties)
53
54
55def burst_trigger_gen(pipeline, src, **properties):
56 """Burst Triggergen, find burst triggers in snr streams
57
58 Args:
59 pipeline:
60 Gst.Pipeline, the pipeline to which the new element will be added
61 src:
62 Gst.Element, the source element
63 **properties:
64
65 References:
66 [1] BurstTriggerGen Implementation: gstlal/gstlal-burst/gst/lal/gstlal_burst_triggergen.c
67
68 Returns:
69 Element, the trigger gen element
70 """
71 return pipetools.make_element_with_src(pipeline, src, "lal_bursttriggergen", **properties)
72
73
74def blcbc_trigger_gen(pipeline: pipetools.Pipeline, snr: pipetools.Element, chisq: pipetools.Element, template_bank_filename: str, snr_threshold: float,
75 sigmasq: pipetools.ValueArray) -> pipetools.Element:
76 """ Produce sngl_inspiral records from SNR and chi squared.
77 A trigger is recorded for every instant at which the absolute value of the SNR
78 is greater than snr-thresh, and also greater than at all of the window seconds
79 of data that come before and after. snr-thresh and window are properties of
80 this element. This element has a bounded latency of ~ window and is suitable
81 for online applications, or applications where precise triggering behavior with
82 small chunks of data is required
83
84 The maximum possible trigger rate is (1/window) Hz per template.
85
86 Args:
87 pipeline:
88 Gst.Pipeline, the pipeline to which the new element will be added
89 snr:
90 Gst.Element, the source element
91 chisq:
92 Element
93 template_bank_filename:
94 str, Path to XML file used to generate the template bank. Setting this property resets sigmasq to a vector of 0s.
95 snr_threshold:
96 float, SNR Threshold that determines a trigger.
97 sigmasq:
98 Vector of \\sigma^{2} factors.
99
100 References:
101 [1] gstlal/gstlal-inspiral/gst/lal/gstlal_blcbc_triggergen.c
102
103 Returns:
104 Element, the blcbc trigger gen
105 """
106 # snr is complex and chisq is real so the correct source and sink
107 # pads will be selected automatically
108 elem = pipetools.make_element_with_src(pipeline, snr, "lal_blcbctriggergen", bank_filename=template_bank_filename, snr_thresh=snr_threshold, sigmasq=sigmasq)
109 chisq.link(elem)
110 return elem
111
112
113def trigger_gen(pipeline: pipetools.Pipeline, snr: pipetools.Element, chisq: pipetools.Element, template_bank_filename: str, snr_threshold: float,
114 sigmasq: pipetools.ValueArray) -> pipetools.Element:
115 """Produce sngl_inspiral records from SNR and chi squared.
116 A trigger is recorded for every instant at which the absolute value of the SNR
117 is greater than snr-thresh, and also greater than at all of the max_gap seconds
118 of data that come before and after. snr-thresh and max_gap are properties of
119 this element
120
121 The maximum possible trigger rate is (1/max_gap) Hz per template.
122
123 Args:
124 pipeline:
125 Gst.Pipeline, the pipeline to which the new element will be added
126 snr:
127 Gst.Element, the source element
128 chisq:
129 Element
130 template_bank_filename:
131 str, Path to XML file used to generate the template bank. Setting this property resets sigmasq to a vector of 0s.
132 snr_threshold:
133 float, SNR Threshold that determines a trigger.
134 sigmasq:
135 Vector of \\sigma^{2} factors.
136
137 References:
138 Implementation: gstlal-inspiral/gst/lal/gstlal_triggergen.c
139
140 Returns:
141 Element
142 """
143 # snr is complex and chisq is real so the correct source and sink
144 # pads will be selected automatically
145 elem = pipetools.make_element_with_src(pipeline, snr, "lal_triggergen", bank_filename=template_bank_filename, snr_thresh=snr_threshold, sigmasq=sigmasq)
146 chisq.link(elem)
147 return elem
148
149
150def itac(pipeline: pipetools.Pipeline, src: pipetools.Element, n: int, bank: str, autocorrelation_matrix: numpy.ndarray = None,
151 mask_matrix: numpy.ndarray = None, snr_thresh=0, sigmasq=None) -> pipetools.Element:
152 """Find inspiral triggers in snr streams
153
154 Args:
155 pipeline:
156 Gst.Pipeline, the pipeline to which the new element will be added
157 src:
158 Gst.Element, the source element
159 n:
160 int, number of samples over which to identify itacs
161 bank:
162 str, Path to XML file used to generate the template bank. Setting this property resets sigmasq to a vector of 0s.
163 autocorrelation_matrix:
164 array, Array of complex autocorrelation vectors. Number of vectors (rows) in matrix sets number of channels. All vectors must have the same length.
165 mask_matrix:
166 array, Array of integer autocorrelation mask vectors. Number of vectors (rows) in mask sets number of channels. All vectors must have the same
167 length. The mask values are either 0 or 1 and indicate whether to use the corresponding matrix entry in computing the autocorrelation chi-sq statistic.
168 snr_thresh:
169 float, SNR Threshold that determines a trigger.
170 sigmasq:
171 array, Vector of \\sigma^{2} factors. The effective distance of a trigger is \\sqrt{sigma^{2}} / SNR.
172
173 References:
174 Implementation: gstlal-inspiral/gst/lal/gstlal_itac.c
175
176 Returns:
177 Element
178 """
179 properties = {
180 "n": n,
181 "bank_filename": bank,
182 "snr_thresh": snr_thresh
183 }
184 if autocorrelation_matrix is not None:
185 properties["autocorrelation_matrix"] = pipeio.repack_complex_array_to_real(autocorrelation_matrix)
186 if mask_matrix is not None:
187 properties["autocorrelation_mask"] = mask_matrix
188 if sigmasq is not None:
189 properties["sigmasq"] = sigmasq
190 return pipetools.make_element_with_src(pipeline, src, "lal_itac", **properties)
191
192
193def itacac(pipeline, srcs, **properties):
194 """Find coincident inspiral triggers in snr streams from multiple detectors
195
196 Args:
197 pipeline:
198 Gst.Pipeline, the pipeline to which the new element will be added
199 srcs:
200 Mapping[str, Gst.Element], maps detector strings to Gst.Elements
201 **properties
202 maps detector strings to pad properties
203
204 References:
205 Implementation: gstlal-inspiral/gst/lal/gstlal_itacac.c
206
207 Returns:
208 Element
209 """
210 elem = pipetools.make_element_with_src(pipeline, None, "lal_itacac")
211
212 for idx, (key, src) in enumerate(srcs.items()):
213 pad = elem.get_request_pad(f"sink{idx:d}")
214 for prop, val in properties[key].items():
215 pad.set_property(prop, pipeio.format_property(val))
216 src.srcpads[0].link(pad)
217
218 return elem
burst_trigger_gen(pipeline, src, **properties)
Definition trigger.py:55
pipetools.Element blcbc_trigger_gen(pipetools.Pipeline pipeline, pipetools.Element snr, pipetools.Element chisq, str template_bank_filename, float snr_threshold, pipetools.ValueArray sigmasq)
Definition trigger.py:75
pipetools.Element trigger_gen(pipetools.Pipeline pipeline, pipetools.Element snr, pipetools.Element chisq, str template_bank_filename, float snr_threshold, pipetools.ValueArray sigmasq)
Definition trigger.py:114
itacac(pipeline, srcs, **properties)
Definition trigger.py:193
pipetools.Element itac(pipetools.Pipeline pipeline, pipetools.Element src, int n, str bank, numpy.ndarray autocorrelation_matrix=None, numpy.ndarray mask_matrix=None, snr_thresh=0, sigmasq=None)
Definition trigger.py:151