35 gobject.threads_init()
40 from gstlal
import bottle
41 from gstlal
import pipeparts
42 from gstlal
import reference_psd
43 from gstlal
import datasource
141 def mkwhitened_multirate_src(pipeline, src, rates, instrument, psd = None, psd_fft_length = 8, ht_gate_threshold = float(
"inf"), veto_segments =
None, seekevent =
None, nxydump_segment =
None, track_psd =
False, block_duration = 1 * gst.SECOND, zero_pad = 0, width = 64, unit_normalize =
True):
143 Build pipeline stage to whiten and downsample h(t).
145 - pipeline: the gstreamer pipeline to add this to
146 - src: the gstreamer element that will be providing data to this
147 - rates: a list of the requested sample rates, e.g., [512,1024].
148 - instrument: the instrument to process
149 - psd: a psd frequency series
150 - psd_fft_length: length of fft used for whitening
151 - ht_gate_threshold: gate h(t) if it crosses this value
152 - veto_segments: segments to mark as gaps after whitening
153 - track_psd: decide whether to dynamically track the spectrum or use the fixed spectrum provided
154 - width: type convert to either 32 or 64 bit float
172 head = pipeparts.mkcapsfilter(pipeline, src,
"audio/x-raw-float, rate=[%d,MAX]" % max(rates))
173 head = pipeparts.mkcapsfilter(pipeline, pipeparts.mkresample(pipeline, head, quality = quality),
"audio/x-raw-float, rate=%d" % max(rates))
174 head = pipeparts.mknofakedisconts(pipeline, head)
175 head = pipeparts.mkchecktimestamps(pipeline, head,
"%s_timestamps_%d_hoft" % (instrument, max(rates)))
187 head = pipeparts.mkreblock(pipeline, head, block_duration = block_duration)
193 head = whiten = pipeparts.mkwhiten(pipeline, head, fft_length = psd_fft_length, zero_pad = zero_pad, average_samples = 64, median_samples = 7, expand_gaps =
True, name =
"lal_whiten_%s" % instrument)
194 head = pipeparts.mkaudioconvert(pipeline, head)
195 head = pipeparts.mkcapsfilter(pipeline, head,
"audio/x-raw-float, width=%d, rate=%d, channels=1" % (width, max(rates)))
199 whiten.set_property(
"psd-mode", 0)
203 whiten.set_property(
"psd-mode", 0)
206 whiten.set_property(
"psd-mode", 1)
215 def psd_resolution_changed(elem, pspec, psd):
217 delta_f = elem.get_property(
"delta-f")
218 n = int(round(elem.get_property(
"f-nyquist") / delta_f) + 1)
220 psd = reference_psd.interpolate_psd(psd, delta_f)
221 elem.set_property(
"mean-psd", psd.data[:n])
223 whiten.connect_after(
"notify::f-nyquist", psd_resolution_changed, psd)
224 whiten.connect_after(
"notify::delta-f", psd_resolution_changed, psd)
225 head = pipeparts.mkchecktimestamps(pipeline, head,
"%s_timestamps_%d_whitehoft" % (instrument, max(rates)))
231 if veto_segments
is not None:
232 head = datasource.mksegmentsrcgate(pipeline, head, veto_segments, seekevent=seekevent, invert_output=
True)
242 ht_gate_window = max(max(rates) // 4, 1)
243 head = datasource.mkhtgate(pipeline, head, threshold = ht_gate_threshold
if ht_gate_threshold
is not None else float(
"+inf"), hold_length = ht_gate_window, attack_length = ht_gate_window, name =
"%s_ht_gate" % instrument)
245 head.set_property(
"emit-signals",
True)
251 head = {max(rates): pipeparts.mktee(pipeline, head)}
278 for rate
in sorted(set(rates))[:-1]:
283 head[rate] = pipeparts.mkaudioamplify(pipeline, head[max(rates)], 1. / math.sqrt(pipeparts.audioresample_variance_gain(quality, max(rates), rate)))
285 head[rate] = head[max(rates)]
286 head[rate] = pipeparts.mkcapsfilter(pipeline, pipeparts.mkresample(pipeline, head[rate], quality = quality), caps =
"audio/x-raw-float, rate=%d" % rate)
287 head[rate] = pipeparts.mknofakedisconts(pipeline, head[rate])
288 head[rate] = pipeparts.mkchecktimestamps(pipeline, head[rate],
"%s_timestamps_%d_whitehoft" % (instrument, rate))
290 head[rate] = pipeparts.mktee(pipeline, head[rate])