Пример #1
0
def lal_smoothkappas_02(pipeline, name):

	#
	# This is similar to the above test, and makes sure the element treats gaps correctly
	#

	rate = 1000	     # Hz
	width = 64	      # bytes
	wave = 5
	freq = 0.1	      # Hz
	volume = 0.03
	buffer_length = 1.0     # seconds
	test_duration = 10.0    # seconds
	gap_frequency = 0.2     # Hz
	gap_threshold = 0.5     # Hz
	control_dump_filename = "control_smoothkappas_02.dump"

	#
	# build pipeline
	#

	src = test_common.gapped_test_src(pipeline, channels = 2, buffer_length = buffer_length, rate = rate, width = width, test_duration = test_duration, wave = wave, freq = freq, volume = volume, gap_frequency = gap_frequency, gap_threshold = gap_threshold, control_dump_filename = control_dump_filename)
        head = pipeparts.mktogglecomplex(pipeline, src)
        head = pipeparts.mktee(pipeline, head)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head), "%s_in.dump" % name)
        median_avg = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 3, avg_array_size = 2, default_kappa_im = 0, default_kappa_re = 1, track_bad_kappa = False, default_to_median = True)
        kappa_track = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 30, avg_array_size = 160, default_kappa_im = 0, default_kappa_re = 1, track_bad_kappa = True, default_to_median = True)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, median_avg), "%s_median_avg.dump" % name)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, kappa_track), "%s_kappa_track.dump" % name)

	#
	# done
	#

	return pipeline
Пример #2
0
def lal_add_constant_02(pipeline, name):
        
        #
        # This test adds a constant to a stream of double-precision floats
        #

        rate = 1000             # Hz
        buffer_length = 1.0     # seconds
        test_duration = 10.0    # seconds

        #
        # build pipeline
        #

        src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, test_duration = test_duration, width = 64)
        capsfilter1 = pipeparts.mkcapsfilter(pipeline, src, "audio/x-raw, format=F64LE, rate=%d" % int(rate))
        tee1 = pipeparts.mktee(pipeline, capsfilter1)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee1), "%s_in.dump" % name)
        add_constant = pipeparts.mkgeneric(pipeline, tee1, "lal_add_constant", value=3)
        capsfilter2 = pipeparts.mkcapsfilter(pipeline, add_constant, "audio/x-raw, format=F64LE, rate=%d" % int(rate))
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter2), "%s_out.dump" % name)

        #
        # done
        #

        return pipeline
Пример #3
0
def lal_smoothkappas_04(pipeline, name):

	rate = 2000          # Hz
        width = 64            # bytes
        wave = 5
        freq = 0.1            # Hz
        volume = 0.03
        buffer_length = 1.0     # seconds
        test_duration = 10.0    # seconds
        gap_frequency = 0.1     # Hz
        gap_threshold = 0.5     # Hz
        control_dump_filename = "control_smoothkappas_02.dump"

        #
        # build pipeline
        #

        src = test_common.gapped_test_src(pipeline, channels = 1, buffer_length = buffer_length, rate = rate, width = width, test_duration = test_duration, wave = wave, freq = freq, volume = volume, gap_frequency = gap_frequency, gap_threshold = gap_threshold, control_dump_filename = control_dump_filename)
	head = pipeparts.mkmatrixmixer(pipeline, src, matrix = [[1000]])
	head = pipeparts.mkgeneric(pipeline, head, "lal_add_constant", value = 340)
        head = pipeparts.mktee(pipeline, head)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head), "%s_in.dump" % name)
        median_avg = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 3, avg_array_size = 2, default_kappa_im = 0, default_kappa_re = 330, track_bad_kappa = False, default_to_median = True)
        kappa_track = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 2049, avg_array_size = 160, default_kappa_im = 0, default_kappa_re = 330, track_bad_kappa = True, default_to_median = True)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, median_avg), "%s_median_avg.dump" % name)
        pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, kappa_track), "%s_kappa_track.dump" % name)

        #
        # done
        #

	return pipeline
Пример #4
0
def lal_smoothkappas_01(pipeline, name):
	#
	# This test is to check that the inputs are smoothed in a desirable way
	#

	rate = 10		# Hz
	width = 64		# bytes
	wave = 5
	freq = 0.1		# Hz
	volume = 0.9
	buffer_length = 1.0	# seconds
	test_duration = 10.0	# seconds

	#
	# build pipeline
	#

	head = test_common.test_src(pipeline, channels = 2, buffer_length = buffer_length, rate = rate, width = width, test_duration = test_duration, wave = wave, freq = freq, volume = volume)
	head = pipeparts.mktogglecomplex(pipeline, head)
	head = pipeparts.mktee(pipeline, head)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head), "%s_in.dump" % name)
	median = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 3, maximum_offset_re = 0.5, maximum_offset_im = 0.5, default_kappa_im = 0.5, default_kappa_re = 0.5, track_bad_kappa = False, default_to_median = True)
	median_avg = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 3, avg_array_size = 2,  maximum_offset_re = 0.5, maximum_offset_im = 0.5, default_kappa_im = 0.5, default_kappa_re = 0.5, track_bad_kappa = False, default_to_median = True)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, median), "%s_median.dump" % name)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, median_avg), "%s_median_avg.dump" % name)

	#
	# done
	#
	
	return pipeline
Пример #5
0
def mkLLOIDSnrSlicesToTimeSliceChisq(pipeline, branch_heads, bank,
                                     block_duration):
    """!
	Build pipeline fragment that computes the TimeSliceChisq from SnrSlices.
	"""
    #
    # parameters
    #

    rates = sorted(bank.get_rates())

    #
    # compute the chifacs for each rate, store in ascending order in rate
    #

    chifacsdict = dict((rate, []) for rate in rates)
    for bank_fragment in bank.bank_fragments:
        chifacsdict[bank_fragment.rate].append(bank_fragment.chifacs)
    chifacs = []
    for rate, facs in sorted(chifacsdict.items()):
        chifacs.append(facs[0][0::2])
        chifacs[-1] += facs[0][1::2]
        for fac in facs[1:]:
            chifacs[-1] += fac[0::2]
            chifacs[-1] += fac[1::2]
        chifacs[-1] /= 2.

    #
    # create timeslicechisq element and add chifacs as a property
    #

    chisq = Gst.ElementFactory.make("lal_timeslicechisq", None)
    pipeline.add(chisq)

    #
    # link the snrslices to the timeslicechisq element in ascending order in rate
    #

    for rate, snrslice in sorted(branch_heads.items()):
        pipeparts.mkqueue(pipeline,
                          snrslice,
                          max_size_bytes=0,
                          max_size_buffers=0,
                          max_size_time=block_duration).link(chisq)

    #
    # set chifacs-matrix property, needs to be done after snrslices are linked in
    #

    chisq.set_property("chifacs-matrix", chifacs)

    return pipeparts.mkqueue(pipeline,
                             chisq,
                             max_size_bytes=0,
                             max_size_buffers=0,
                             max_size_time=block_duration)
Пример #6
0
def lal_constantupsample_04(pipeline, name):
    #
    # This is a simple test to see that the element treats gaps correctly for complex data
    #

    in_rate = 10  # Hz
    out_rate = 20  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds
    gap_frequency = 0.1  # Hz
    gap_threshold = 0.02  # Hz
    control_dump_filename = "control.dump"

    #
    # build pipeline
    #

    src = test_common.gapped_test_src(
        pipeline,
        buffer_length=buffer_length,
        channels=2,
        rate=in_rate,
        test_duration=test_duration,
        width=64,
        gap_frequency=gap_frequency,
        gap_threshold=gap_threshold,
        control_dump_filename=control_dump_filename)
    test_duration = 10.0  # seconds
    togglecomplex1 = pipeparts.mktogglecomplex(pipeline, src)
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, togglecomplex1,
        "audio/x-raw, format=Z128LE, rate=%d" % int(in_rate))
    tee1 = pipeparts.mktee(pipeline, capsfilter1)
    pipeparts.mknxydumpsink(
        pipeline,
        pipeparts.mkqueue(pipeline, pipeparts.mktogglecomplex(pipeline, tee1)),
        "%s_in.dump" % name)
    upsample = pipeparts.mkgeneric(pipeline, tee1, "lal_constantupsample")
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, upsample,
        "audio/x-raw, format=Z128LE, rate=%d" % int(out_rate))
    #checktimestamps = pipeparts.mkchecktimestamps(pipeline, capsfilter2)
    pipeparts.mknxydumpsink(
        pipeline,
        pipeparts.mkqueue(pipeline,
                          pipeparts.mktogglecomplex(pipeline, capsfilter2)),
        "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
Пример #7
0
def gapped_complex_test_src(pipeline,
                            buffer_length=1.0,
                            rate=2048,
                            width=64,
                            test_duration=10.0,
                            wave=5,
                            freq=0,
                            gap_frequency=None,
                            gap_threshold=None,
                            control_dump_filename=None,
                            tags=None,
                            is_live=False,
                            verbose=True):
    src = complex_test_src(pipeline,
                           buffer_length=buffer_length,
                           rate=rate,
                           width=width,
                           test_duration=test_duration,
                           wave=wave,
                           freq=freq,
                           is_live=is_live,
                           verbose=verbose)
    if tags is not None:
        src = pipeparts.mktaginject(pipeline, src, tags)
    if gap_frequency is None:
        return src
    control = pipeparts.mkcapsfilter(
        pipeline,
        pipeparts.mkaudiotestsrc(pipeline,
                                 wave=0,
                                 freq=gap_frequency,
                                 blocksize=8 * int(buffer_length * rate),
                                 volume=1,
                                 num_buffers=int(test_duration /
                                                 buffer_length)),
        "audio/x-raw, format=F32%s, rate=%d, channels=1" % (BYTE_ORDER, rate))
    if control_dump_filename is not None:
        control = pipeparts.mknxydumpsinktee(
            pipeline, pipeparts.mkqueue(pipeline, control),
            control_dump_filename)
        control = pipeparts.mkqueue(pipeline, control)
    return pipeparts.mktogglecomplex(
        pipeline,
        pipeparts.mkgate(pipeline,
                         pipeparts.mktogglecomplex(pipeline, src),
                         control=control,
                         threshold=gap_threshold))
Пример #8
0
def lal_smoothkappas_03(pipeline, name):

	#
	# This pipeline uses lal_smoothkappas in a similar way that gstlal_compute_strain will
	#

	rate = 2000	     # Hz
	width = 64	      # bytes
	wave = 1		# 0=sine, 1=square
	freq = 0.05	      # Hz
	volume = 0.01
	buffer_length = 1.0     # seconds
	test_duration = 40.0    # seconds
	real_expected = 1
	imag_expected = 0
	N = 2048
	Nav = 160

	src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, width = width, test_duration = test_duration, wave = wave, freq = freq, volume = volume)
	tee = pipeparts.mktee(pipeline, src)
	real = pipeparts.mkgeneric(pipeline, tee, "lal_add_constant", value=1)
	kappas = calibration_parts.merge_into_complex(pipeline, real, tee)
	kappas = pipeparts.mktee(pipeline, kappas)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, kappas), "%s_kappa_in.dump" % name)

	fake_statevector = pipeparts.mkgeneric(pipeline, tee, "pow", exponent=0)
	fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_demodulate", line_frequency=0.5)
	fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_togglecomplex")
	fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_matrixmixer", matrix = [[1],[0]])
	fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_bitvectorgen", threshold=0.1, bit_vector=1)

	fake_coherence = pipeparts.mkgeneric(pipeline, tee, "pow", exponent=0)
	fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_demodulate", line_frequency=0.10)
	fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_togglecomplex")
	fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_matrixmixer", matrix = [[1],[0]])
	fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_bitvectorgen", threshold=0.15, bit_vector=1)

	re, im = calibration_parts.smooth_complex_kappas(pipeline, kappas, fake_statevector, fake_coherence, real_expected, imag_expected, N, Nav)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, re), "%s_re_kappa_out.dump" % name)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, im), "%s_im_kappa_out.dump" % name)

	#
	# done
	#

	return pipeline
def lal_logicalundersample_02(pipeline, name):
    #
    # This is similar to the one above, but here, we wish to see how logicalundersample handles unsigned input data.
    # There is quite possibly a better way to do this...
    #

    in_rate = 1024  # Hz
    out_rate = 512  # Hz
    odd_inputs = 137  # the odd unsigned int's that, when occurring in pairs, should cause an output of "1".
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds

    #
    # build the pipeline
    #

    src = pipeparts.mkaudiotestsrc(pipeline,
                                   num_buffers=int(test_duration /
                                                   buffer_length),
                                   wave=5)
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, src, "audio/x-raw, format=S32LE, rate=%d" % int(in_rate))
    undersample1 = pipeparts.mkgeneric(pipeline,
                                       capsfilter1,
                                       "lal_logicalundersample",
                                       status_out=odd_inputs)
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, undersample1,
        "audio/x-raw, format=U32LE, rate=%d" % int(in_rate))
    tee1 = pipeparts.mktee(pipeline, capsfilter2)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee1),
                            "%s_in.dump" % name)
    undersample2 = pipeparts.mkgeneric(pipeline, tee1,
                                       "lal_logicalundersample")
    capsfilter3 = pipeparts.mkcapsfilter(
        pipeline, undersample2,
        "audio/x-raw, format=U32LE, rate=%d" % int(out_rate))
    #checktimestamps = pipeparts.mkchecktimestamps(pipeline, capsfilter2)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter3),
                            "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
Пример #10
0
 def add_data_sink(self,
                   pipeline,
                   head,
                   name,
                   type,
                   units=EXCESSPOWER_UNIT_SCALE['Hz']):
     mknxyfdsink(pipeline, pipeparts.mkqueue(pipeline, head),
                 self.get_tmp_fd(name, type), self.scan_segment, units)
Пример #11
0
def deinterleave_01(pipeline, name):

    buffer_length = 1.0
    rate = 2048
    width = 64
    channels = 2
    test_duration = 10.0
    freq = 0
    is_live = False

    src = pipeparts.mkaudiotestsrc(pipeline,
                                   wave=5,
                                   freq=freq,
                                   blocksize=8 * int(buffer_length * rate),
                                   volume=1,
                                   num_buffers=int(test_duration /
                                                   buffer_length),
                                   is_live=is_live)
    src = pipeparts.mkcapsfilter(
        pipeline, src,
        "audio/x-raw, format=F%d%s, rate=%d, channels=2, layout=interleaved" %
        (width, BYTE_ORDER, rate))

    elem = pipeparts.mkgeneric(pipeline, src, "deinterleave")
    out1 = pipeparts.mkqueue(pipeline, None)
    out2 = pipeparts.mkqueue(pipeline, None)
    pipeparts.src_deferred_link(elem, "src_0", out1.get_static_pad("sink"))
    pipeparts.src_deferred_link(elem, "src_1", out2.get_static_pad("sink"))
    #out1 = pipeparts.mkaudioconvert(pipeline, out1)
    out1 = pipeparts.mkcapsfilter(
        pipeline, out1,
        "audio/x-raw, format=F%d%s, rate=%d, channels=1, layout=interleaved" %
        (width, BYTE_ORDER, rate))
    #out2 = pipeparts.mkaudioconvert(pipeline, out2)
    out2 = pipeparts.mkcapsfilter(
        pipeline, out2,
        "audio/x-raw, format=F%d%s, rate=%d, channels=1, layout=interleaved" %
        (width, BYTE_ORDER, rate))

    pipeparts.mknxydumpsink(pipeline, out1, "out1.dump")
    pipeparts.mknxydumpsink(pipeline, out2, "out2.dump")
    #pipeparts.mkfakesink(pipeline, out1)
    #pipeparts.mkfakesink(pipeline, out2)

    return pipeline
Пример #12
0
def lal_constantupsample_03(pipeline, name):
    #
    # This is a simple test that the sample rates are adjusted as expected for complex data
    #

    in_rate = 1  # Hz
    out_rate = 10  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds

    #
    # build pipeline
    #

    src = test_common.test_src(pipeline,
                               buffer_length=buffer_length,
                               channels=2,
                               rate=in_rate,
                               test_duration=test_duration,
                               width=64)
    togglecomplex1 = pipeparts.mktogglecomplex(pipeline, src)
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, togglecomplex1,
        "audio/x-raw, format=Z128LE, rate=%d" % int(in_rate))
    tee1 = pipeparts.mktee(pipeline, capsfilter1)
    pipeparts.mknxydumpsink(
        pipeline,
        pipeparts.mkqueue(pipeline, pipeparts.mktogglecomplex(pipeline, tee1)),
        "%s_in.dump" % name)
    upsample = pipeparts.mkgeneric(pipeline, tee1, "lal_constantupsample")
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, upsample,
        "audio/x-raw, format=Z128LE, rate=%d" % int(out_rate))
    #checktimestamps = pipeparts.mkchecktimestamps(pipeline, capsfilter2)
    pipeparts.mknxydumpsink(
        pipeline,
        pipeparts.mkqueue(pipeline,
                          pipeparts.mktogglecomplex(pipeline, capsfilter2)),
        "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
Пример #13
0
def complex_pow_02(pipeline, name):

    buffer_length = 1.0
    rate = 2048
    width = 32
    test_duration = 10.0
    freq = 0
    is_live = False

    src = pipeparts.mkaudiotestsrc(pipeline,
                                   wave=5,
                                   freq=freq,
                                   blocksize=8 * int(buffer_length * rate),
                                   volume=1,
                                   num_buffers=int(test_duration /
                                                   buffer_length),
                                   is_live=is_live)
    src = pipeparts.mkcapsfilter(
        pipeline, src,
        "audio/x-raw, format=F%d%s, rate=%d, channels=1, width=%d, channel-mask=0, endianness=1234"
        % (width, BYTE_ORDER, rate, width))
    tee = pipeparts.mktee(pipeline, src)

    out = pipeparts.mkgeneric(pipeline, None, "interleave")
    pipeparts.mkqueue(pipeline, tee).link(out)
    pipeparts.mkqueue(pipeline, tee).link(out)

    out = pipeparts.mkaudiorate(pipeline, out)
    mix = numpy.random.random((2, 2)).astype("float64")
    out = pipeparts.mkmatrixmixer(pipeline, out, matrix=mix)
    out = pipeparts.mktogglecomplex(pipeline, out)

    outtee = pipeparts.mktee(pipeline, out)
    pipeparts.mknxydumpsink(pipeline, outtee, "before_pow_02.dump")
    out = pipeparts.mkqueue(pipeline, outtee)

    out = pipeparts.mktogglecomplex(pipeline, out)
    out = pipeparts.mkgeneric(pipeline, out, "complex_pow", exponent=2)
    out = pipeparts.mktogglecomplex(pipeline, out)

    pipeparts.mknxydumpsink(pipeline, out, "after_pow_02.dump")

    return pipeline
Пример #14
0
def lal_demodulate_02(pipeline, name):
    #
    # This is similar to the above test, and makes sure the element treats gaps correctly
    #

    rate = 1000  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds
    gap_frequency = 0.1  # Hz
    gap_threshold = 0.2  # Hz
    control_dump_filename = "control_demodulate_02.dump"

    src = test_common.gapped_test_src(
        pipeline,
        buffer_length=buffer_length,
        rate=rate,
        width=64,
        test_duration=test_duration,
        gap_frequency=gap_frequency,
        gap_threshold=gap_threshold,
        control_dump_filename=control_dump_filename)
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, src, "audio/x-raw, format=F64LE, rate=%d" % int(rate))
    tee1 = pipeparts.mktee(pipeline, capsfilter1)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee1),
                            "%s_in.dump" % name)
    demodulate = pipeparts.mkgeneric(pipeline, tee1, "lal_demodulate")
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, demodulate,
        "audio/x-raw, format=Z128LE, rate=%d" % int(rate))
    togglecomplex = pipeparts.mktogglecomplex(pipeline, capsfilter2)
    capsfilter3 = pipeparts.mkcapsfilter(
        pipeline, togglecomplex,
        "audio/x-raw, format=F64LE, rate=%d" % int(rate))
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter3),
                            "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
Пример #15
0
def lal_logical_undersampler_02(pipeline, name):
    #
    # This is a simple test to make sure the element treats gaps correctly
    #

    in_rate = 10  # Hz
    out_rate = 1  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds
    gap_frequency = 0.1  # Hz
    gap_threshold = 0.1  # Hz
    control_dump_filename = "control.dump"

    head = test_common.gapped_test_src_ints(
        pipeline,
        buffer_length=buffer_length,
        rate=in_rate,
        test_duration=test_duration,
        gap_frequency=gap_frequency,
        gap_threshold=gap_threshold,
        control_dump_filename=control_dump_filename)
    head = tee = pipeparts.mktee(pipeline, head)

    head = pipeparts.mkgeneric(pipeline,
                               tee,
                               "lal_logical_undersampler",
                               required_on=0x1,
                               status_out=0x7)
    head = pipeparts.mkcapsfilter(pipeline, head,
                                  "audio/x-raw-int, rate=%d" % int(out_rate))
    head = pipeparts.mkchecktimestamps(pipeline, head)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head),
                            "%s_out.dump" % name)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee),
                            "%s_in.dump" % name)

    #
    # done
    #

    return pipeline
Пример #16
0
def lal_demodulate_01(pipeline, name):
    #
    # This test is to check that the inputs are multiplied by exp(2*pi*i*f*t) using the correct timestamps
    #

    rate = 1000  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds

    #
    # build pipeline
    #

    src = test_common.test_src(pipeline,
                               buffer_length=buffer_length,
                               rate=rate,
                               test_duration=test_duration,
                               width=32)
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, src, "audio/x-raw, format=F32LE, rate=%d" % int(rate))
    tee1 = pipeparts.mktee(pipeline, capsfilter1)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee1),
                            "%s_in.dump" % name)
    demodulate = pipeparts.mkgeneric(pipeline,
                                     tee1,
                                     "lal_demodulate",
                                     line_frequency=100)
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, demodulate, "audio/x-raw, format=Z64LE, rate=%d" % int(rate))
    togglecomplex = pipeparts.mktogglecomplex(pipeline, capsfilter2)
    capsfilter3 = pipeparts.mkcapsfilter(
        pipeline, togglecomplex,
        "audio/x-raw, format=F32LE, rate=%d" % int(rate))
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter3),
                            "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
Пример #17
0
def lal_logical_undersampler_03(pipeline, name):
    #
    # This test reads in a gwf file that has certain bits off to test
    # the logic of the element
    # Note: To run this test you must first make a frame cache, which can be done with the
    # following command:
    # 	ls *.gwf | lalapps_path2cache > frame.cache
    #

    out_rate = 1

    src = pipeparts.mklalcachesrc(pipeline,
                                  location="frame.cache",
                                  cache_dsc_regex="L1")
    demux = pipeparts.mkframecppchanneldemux(pipeline,
                                             src,
                                             do_file_checksum=True,
                                             skip_bad_files=True)
    head = pipeparts.mkqueue(pipeline, None)
    pipeparts.src_deferred_link(demux, "L1:TEST-CHANNEL", head.get_pad("sink"))
    head = tee = pipeparts.mktee(pipeline, head)

    head = pipeparts.mkgeneric(pipeline,
                               tee,
                               "lal_logical_undersampler",
                               required_on=0x1,
                               status_out=0x7)
    head = pipeparts.mkcapsfilter(pipeline, head,
                                  "audio/x-raw-int, rate=%d" % int(out_rate))
    head = pipeparts.mkchecktimestamps(pipeline, head)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head),
                            "%s_out.dump" % name)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee),
                            "%s_in.dump" % name)

    #
    # done
    #

    return pipeline
Пример #18
0
def lal_interleave_01(pipeline, name):

	caps = "audio/x-raw-float, width=64, rate=2048, channels=1"

	#
	# build pipeline
	#

	head = test_common_old.test_src(pipeline)
	headtee = pipeparts.mktee(pipeline, head)

	head1 = pipeparts.mkfirbank(pipeline, headtee, latency=-10, fir_matrix = [[0,1]])
	head1tee = pipeparts.mktee(pipeline, head1)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head1tee), "%s_in_shifted.dump" % name)

	out = pipeparts.mkgeneric(pipeline, None, "lal_interleave", sync = True)
	#out = pipeparts.mkgeneric(pipeline, None, "lal_adder", sync = True)
	pipeparts.mkqueue(pipeline, headtee).link(out)
	pipeparts.mkqueue(pipeline, head1tee).link(out)
	#out = calibration_parts.mkinterleave(pipeline, calibration_parts.list_srcs(pipeline, headtee, head1tee), caps)
	
	pipeparts.mknxydumpsink(pipeline, out, "%s_out.dump" % name)
	pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, headtee), "%s_in_notshifted.dump" % name)

	#
	# done
	#
	
	return pipeline
Пример #19
0
def lal_logical_undersampler_01(pipeline, name):
    #
    # This is a simple test that the sample rates are adjusted as expected
    #

    in_rate = 10  # Hz
    out_rate = 1  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds

    #
    # build pipeline
    #

    head = test_common.test_src_ints(pipeline,
                                     buffer_length=buffer_length,
                                     rate=in_rate,
                                     test_duration=test_duration)
    head = tee = pipeparts.mktee(pipeline, head)

    head = pipeparts.mkgeneric(pipeline,
                               tee,
                               "lal_logical_undersampler",
                               required_on=0x1,
                               status_out=0x7)
    head = pipeparts.mkcapsfilter(pipeline, head,
                                  "audio/x-raw-int, rate=%d" % int(out_rate))
    head = pipeparts.mkchecktimestamps(pipeline, head)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head),
                            "%s_out.dump" % name)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee),
                            "%s_in.dump" % name)

    #
    # done
    #

    return pipeline
def lal_logicalundersample_03(pipeline, name):
    #
    # This tests how lal_logicalundersample handles gaps in the input stream (S32 format in the case)
    #

    in_rate = 8  # Hz
    out_rate = 4  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds
    gap_frequency = 0.1  # Hz
    gap_threshold = 0.5  # Hz
    control_dump_filename = "control.dump"

    src = test_common.gapped_int_test_src(
        pipeline,
        buffer_length=buffer_length,
        rate=in_rate,
        width=32,
        test_duration=test_duration,
        gap_frequency=gap_frequency,
        gap_threshold=gap_threshold,
        control_dump_filename=control_dump_filename)
    tee = pipeparts.mktee(pipeline, src)
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee),
                            "%s_in.dump" % name)
    undersample = pipeparts.mkgeneric(pipeline, tee, "lal_logicalundersample")
    capsfilter = pipeparts.mkcapsfilter(
        pipeline, undersample,
        "audio/x-raw, format=U32LE, rate=%d" % int(out_rate))
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter),
                            "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
Пример #21
0
def lal_multiple_srcs(pipeline, name):

    #
    # This test uses multiple source elements
    #

    rate = 1000  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds

    #
    # build pipeline
    #

    src1 = test_common.test_src(pipeline,
                                buffer_length=buffer_length,
                                rate=rate,
                                test_duration=test_duration,
                                width=32,
                                verbose=False)
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, src1, "audio/x-raw, format=F32LE, rate=%d" % int(rate))
    src2 = test_common.test_src(pipeline,
                                buffer_length=buffer_length,
                                rate=rate,
                                test_duration=test_duration,
                                width=32,
                                verbose=False)
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, src2, "audio/x-raw, format=F32LE, rate=%d" % int(rate))

    combined = calibration_parts.mkadder(
        pipeline,
        calibration_parts.list_srcs(pipeline, capsfilter1, capsfilter2))
    pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, combined),
                            "multiple_srcs_out.dump")

    #
    # done
    #

    return pipeline
Пример #22
0
def mkbasicsrc(pipeline, gw_data_source_info, instrument, verbose=False):
    if gw_data_source_info.data_source == "frames":
        if instrument == "V1":
            #FIXME Hack because virgo often just uses "V" in the file names rather than "V1".  We need to sieve on "V"
            src = pipeparts.mklalcachesrc(
                pipeline,
                blocksize=1048576,
                use_mmap=False,
                location=gw_data_source_info.frame_cache,
                cache_src_regex="V")
        else:
            src = pipeparts.mklalcachesrc(
                pipeline,
                blocksize=1048576,
                use_mmap=False,
                location=gw_data_source_info.frame_cache,
                cache_src_regex=instrument[0],
                cache_dsc_regex=instrument)
        demux = pipeparts.mkframecppchanneldemux(
            pipeline,
            src,
            do_file_checksum=False,
            channel_list=list(
                map("%s:%s".__mod__,
                    gw_data_source_info.channel_dict.items())))
        pipeparts.framecpp_channeldemux_set_units(
            demux, dict.fromkeys(demux.get_property("channel-list"), "strain"))
        # allow frame reading and decoding to occur in a diffrent thread
        src = pipeparts.mkqueue(pipeline,
                                None,
                                max_size_buffers=0,
                                max_size_bytes=0,
                                max_size_time=8 * Gst.SECOND)
        pipeparts.src_deferred_link(
            demux, "%s:%s" %
            (instrument, gw_data_source_info.channel_dict[instrument]),
            src.get_static_pad("sink"))
        # FIXME:  remove this when pipeline can handle disconts
        src = pipeparts.mkaudiorate(pipeline,
                                    src,
                                    skip_to_first=True,
                                    silent=False)
    else:
        raise ValueError("invalid data_source: %s" %
                         gw_data_source_info.data_source)

    # provide an audioconvert element to allow Virgo data (which is single-precision) to be adapted into the pipeline
    src = pipeparts.mkaudioconvert(pipeline, src)

    # progress report
    if verbose:
        src = pipeparts.mkprogressreport(pipeline, src,
                                         "progress_src_%s" % instrument)

    # optional injections
    if gw_data_source_info.injection_filename is not None:
        src = pipeparts.mkinjections(pipeline, src,
                                     gw_data_source_info.injection_filename)
        # let the injection code run in a different thread than the whitener, etc.,
        src = pipeparts.mkqueue(pipeline,
                                src,
                                max_size_bytes=0,
                                max_size_buffers=0,
                                max_size_time=Gst.SECOND * 64)

    return src
Пример #23
0
	def __init__(self):
		super(lal_compute_gamma, self).__init__()
		
		# Make an oscillator at calibration line frequency for computation of gamma factors
		cos = gst.element_factory_make("tee")
		self.add(cos)
		sin = gst.element_factory_make("tee")
		self.add(sin)
		
		self.add_pad(gst.GhostPad("cos", cos.get_pad("sink")))
		self.add_pad(gst.GhostPad("sin", sin.get_pad("sink")))		
		# Tee off sources
		exc = gst.element_factory_make("tee")
		self.add(exc)
		dctrl = gst.element_factory_make("tee")
		self.add(dctrl)
		
		self.add_pad(gst.GhostPad("exc_sink", exc.get_pad("sink")))
		self.add_pad(gst.GhostPad("dctrl_sink", dctrl.get_pad("sink")))

		# EXC branch for gamma
		excR = gst.element_factory_make("lal_multiplier")
		excR.set_property("sync", True)
		self.add(excR)
		pipeparts.mkqueue(self, exc).link(excR)
		pipeparts.mkqueue(self, cos).link(excR)
		excR = pipeparts.mkresample(self, excR, quality=9)
		self.excR_capsfilter = excR = pipeparts.mkgeneric(self, excR, "capsfilter")
		self.excR_firbank = excR = pipeparts.mkfirbank(self, excR)
		excR = pipeparts.mktee(self, excR)

		excI = gst.element_factory_make("lal_multiplier")
		excI.set_property("sync", True)
		self.add(excI)
		pipeparts.mkqueue(self, exc).link(excI)
		pipeparts.mkqueue(self, sin).link(excI)
		excI = pipeparts.mkresample(self, excI, quality=9)
		self.excI_capsfilter = excI = pipeparts.mkgeneric(self, excI, "capsfilter")
		self.excI_firbank = excI = pipeparts.mkfirbank(self, excI)
		excI = pipeparts.mktee(self, excI)

		# DARM_CTRL branch for gamma
		dctrlR = gst.element_factory_make("lal_multiplier")
		dctrlR.set_property("sync", True)
		self.add(dctrlR)
		pipeparts.mkqueue(self, dctrl).link(dctrlR)
		pipeparts.mkqueue(self, cos).link(dctrlR)
		dctrlR = pipeparts.mkresample(self, dctrlR, quality=9)
		self.dctrlR_capsfilter = dctrlR = pipeparts.mkgeneric(self, dctrlR, "capsfilter")
		self.dctrlR_firbank = dctrlR = pipeparts.mkfirbank(self, dctrlR)
		dctrlR = pipeparts.mktee(self, dctrlR)

		dctrlI = gst.element_factory_make("lal_multiplier")
		dctrlI.set_property("sync", True)
		self.add(dctrlI)
		pipeparts.mkqueue(self, dctrl).link(dctrlI)
		pipeparts.mkqueue(self, sin).link(dctrlI)
		dctrlI = pipeparts.mkresample(self, dctrlI, quality=9)
		self.dctrlI_capsfilter = dctrlI = pipeparts.mkgeneric(self, dctrlI, "capsfilter")
		self.dctrlI_firbank = dctrlI = pipeparts.mkfirbank(self, dctrlI)
		dctrlI = pipeparts.mktee(self, dctrlI)

		# Make useful combos of channels for calculating gamma
		dctrl_mod = gst.element_factory_make("lal_adder")
		dctrl_mod.set_property("sync", True)
		self.add(dctrl_mod)
		pipeparts.mkqueue(self, pipeparts.mkpow(self, dctrlR, exponent = 2.0)).link(dctrl_mod)
		pipeparts.mkqueue(self, pipeparts.mkpow(self, dctrlI, exponent = 2.0)).link(dctrl_mod)

		self.dctrl_mod_w_mod = dctrl_mod_w_mod = pipeparts.mkgeneric(self, dctrl_mod, "audioamplify")
		dctrl_mod_w_mod = pipeparts.mktee(self, dctrl_mod_w_mod)
		self.dctrl_mod_w_mod_olgR = dctrl_mod_w_mod_olgR = pipeparts.mkgeneric(self, dctrl_mod_w_mod, "audioamplify")
		self.dctrl_mod_w_mod_olgI = dctrl_mod_w_mod_olgI = pipeparts.mkgeneric(self, dctrl_mod_w_mod, "audioamplify")
		self.dctrl_mod_w_mod_olg_mod = dctrl_mod_w_mod_olg_mod = pipeparts.mkgeneric(self, dctrl_mod_w_mod, "audioamplify")
	
		dctrlR_excI = gst.element_factory_make("lal_multiplier")
		dctrlR_excI.set_property("sync", True)
		self.add(dctrlR_excI)
		pipeparts.mkqueue(self, dctrlR).link(dctrlR_excI)
		pipeparts.mkqueue(self, excI).link(dctrlR_excI)
		dctrlR_excI = pipeparts.mktee(self, dctrlR_excI)

		self.dctrlR_excI_olgI = dctrlR_excI_olgI = pipeparts.mkgeneric(self, dctrlR_excI, "audioamplify")
		dctrlR_excI_olgI = pipeparts.mktee(self, dctrlR_excI_olgI)
		self.dctrlR_excI_olgI_wI = dctrlR_excI_olgI_wI = pipeparts.mkgeneric(self, dctrlR_excI_olgI, "audioamplify")
		self.dctrlR_excI_olgI_wR = dctrlR_excI_olgI_wR = pipeparts.mkgeneric(self, dctrlR_excI_olgI, "audioamplify")

		self.dctrlR_excI_olgR = dctrlR_excI_olgR = pipeparts.mkgeneric(self, dctrlR_excI, "audioamplify")
		dctrlR_excI_olgR = pipeparts.mktee(self, dctrlR_excI_olgR)
		self.dctrlR_excI_olgR_wI = dctrlR_excI_olgR_wI = pipeparts.mkgeneric(self, dctrlR_excI_olgR, "audioamplify")
		self.dctrlR_excI_olgR_wR = dctrlR_excI_olgR_wR = pipeparts.mkgeneric(self, dctrlR_excI_olgR, "audioamplify")

		dctrlI_excR = gst.element_factory_make("lal_multiplier")
		dctrlI_excR.set_property("sync", True)
		self.add(dctrlI_excR)
		pipeparts.mkqueue(self, dctrlI).link(dctrlI_excR)
		pipeparts.mkqueue(self, excR).link(dctrlI_excR)
		dctrlI_excR = pipeparts.mktee(self, dctrlI_excR)

		self.dctrlI_excR_olgI = dctrlI_excR_olgI = pipeparts.mkgeneric(self, dctrlI_excR, "audioamplify")
		dctrlI_excR_olgI = pipeparts.mktee(self, dctrlI_excR_olgI)
		self.dctrlI_excR_olgI_wR = dctrlI_excR_olgI_wR = pipeparts.mkgeneric(self, dctrlI_excR_olgI, "audioamplify")
		self.dctrlI_excR_olgI_wI = dctrlI_excR_olgI_wI = pipeparts.mkgeneric(self, dctrlI_excR_olgI, "audioamplify")

		self.dctrlI_excR_olgR = dctrlI_excR_olgR = pipeparts.mkgeneric(self, dctrlI_excR, "audioamplify")
		dctrlI_excR_olgR = pipeparts.mktee(self, dctrlI_excR_olgR)
		self.dctrlI_excR_olgR_wI = dctrlI_excR_olgR_wI = pipeparts.mkgeneric(self, dctrlI_excR_olgR, "audioamplify")
		self.dctrlI_excR_olgR_wR = dctrlI_excR_olgR_wR = pipeparts.mkgeneric(self, dctrlI_excR_olgR, "audioamplify")

		dctrlI_excI = gst.element_factory_make("lal_multiplier")
		dctrlI_excI.set_property("sync", True)
		self.add(dctrlI_excI)
		pipeparts.mkqueue(self, dctrlI).link(dctrlI_excI)
		pipeparts.mkqueue(self, excI).link(dctrlI_excI)
		dctrlI_excI = pipeparts.mktee(self, dctrlI_excI)

		self.dctrlI_excI_olgR = dctrlI_excI_olgR = pipeparts.mkgeneric(self, dctrlI_excI, "audioamplify")
		dctrlI_excI_olgR = pipeparts.mktee(self, dctrlI_excI_olgR)
		self.dctrlI_excI_olgR_wR = dctrlI_excI_olgR_wR = pipeparts.mkgeneric(self, dctrlI_excI_olgR, "audioamplify")
		self.dctrlI_excI_olgR_wI = dctrlI_excI_olgR_wI = pipeparts.mkgeneric(self, dctrlI_excI_olgR, "audioamplify")

		self.dctrlI_excI_olgI = dctrlI_excI_olgI = pipeparts.mkgeneric(self, dctrlI_excI, "audioamplify")
		dctrlI_excI_olgI = pipeparts.mktee(self, dctrlI_excI_olgI)
		self.dctrlI_excI_olgI_wI = dctrlI_excI_olgI_wI = pipeparts.mkgeneric(self, dctrlI_excI_olgI, "audioamplify")
		self.dctrlI_excI_olgI_wR = dctrlI_excI_olgI_wR = pipeparts.mkgeneric(self, dctrlI_excI_olgI, "audioamplify")

		dctrlR_excR = gst.element_factory_make("lal_multiplier")
		dctrlR_excR.set_property("sync", True)
		self.add(dctrlR_excR)
		pipeparts.mkqueue(self, dctrlR).link(dctrlR_excR)
		pipeparts.mkqueue(self, excR).link(dctrlR_excR)
		dctrlR_excR = pipeparts.mktee(self, dctrlR_excR)

		self.dctrlR_excR_olgR = dctrlR_excR_olgR = pipeparts.mkgeneric(self, dctrlR_excR, "audioamplify")
		dctrlR_excR_olgR = pipeparts.mktee(self, dctrlR_excR_olgR)
		self.dctrlR_excR_olgR_wR = dctrlR_excR_olgR_wR = pipeparts.mkgeneric(self, dctrlR_excR_olgR, "audioamplify")
		self.dctrlR_excR_olgR_wI = dctrlR_excR_olgR_wI = pipeparts.mkgeneric(self, dctrlR_excR_olgR, "audioamplify")

		self.dctrlR_excR_olgI = dctrlR_excR_olgI = pipeparts.mkgeneric(self, dctrlR_excR, "audioamplify")
		dctrlR_excR_olgI = pipeparts.mktee(self, dctrlR_excR_olgI)
		self.dctrlR_excR_olgI_wI = dctrlR_excR_olgI_wI = pipeparts.mkgeneric(self, dctrlR_excR_olgI, "audioamplify")
		self.dctrlR_excR_olgI_wR = dctrlR_excR_olgI_wR = pipeparts.mkgeneric(self, dctrlR_excR_olgI, "audioamplify")

		# Combine all of these branches into real and imaginary gamma
		denom = pipeparts.mktee(self, dctrl_mod_w_mod_olg_mod)

		gammaI_num = gst.element_factory_make("lal_adder")
		gammaI_num.set_property("sync", True)
		self.add(gammaI_num)
		pipeparts.mkqueue(self, dctrl_mod_w_mod_olgI).link(gammaI_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlR_excI_olgI_wI, -1.0)).link(gammaI_num)
		pipeparts.mkqueue(self, dctrlI_excR_olgI_wI).link(gammaI_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlI_excI_olgR_wI, -1.0)).link(gammaI_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlR_excR_olgR_wI, -1.0)).link(gammaI_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlI_excI_olgI_wR, -1.0)).link(gammaI_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlR_excR_olgI_wR, -1.0)).link(gammaI_num)
		pipeparts.mkqueue(self, dctrlR_excI_olgR_wR).link(gammaI_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlI_excR_olgR_wR, -1.0)).link(gammaI_num)

		gammaR_num = gst.element_factory_make("lal_adder")
		gammaR_num.set_property("sync", True)
		self.add(gammaR_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrl_mod_w_mod_olgR, -1.0)).link(gammaR_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlI_excI_olgI_wI, -1.0)).link(gammaR_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlR_excR_olgI_wI, -1.0)).link(gammaR_num)
		pipeparts.mkqueue(self, dctrlR_excI_olgR_wI).link(gammaR_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlI_excR_olgR_wI, -1.0)).link(gammaR_num)
		pipeparts.mkqueue(self, dctrlR_excI_olgI_wR).link(gammaR_num)
		pipeparts.mkqueue(self, pipeparts.mkaudioamplify(self, dctrlI_excR_olgI_wR, -1.0)).link(gammaR_num)
		pipeparts.mkqueue(self, dctrlI_excI_olgR_wR).link(gammaR_num)
		pipeparts.mkqueue(self, dctrlR_excR_olgR_wR).link(gammaR_num)

		gammaR = gst.element_factory_make("lal_multiplier")
		gammaR.set_property("sync", True)
		self.add(gammaR)
		pipeparts.mkqueue(self, gammaR_num).link(gammaR)
		pipeparts.mkqueue(self, pipeparts.mkpow(self, denom, exponent = -1.0)).link(gammaR)

		gammaI = gst.element_factory_make("lal_multiplier")
		gammaI.set_property("sync", True)
		self.add(gammaI)
		pipeparts.mkqueue(self, gammaI_num).link(gammaI)
		pipeparts.mkqueue(self, pipeparts.mkpow(self, denom, exponent = -1.0)).link(gammaI)

		# Set up src pads
		self.add_pad(gst.GhostPad("gammaR", gammaR.get_pad("src")))
		self.add_pad(gst.GhostPad("gammaI", gammaI.get_pad("src")))
Пример #24
0
def mkLLOIDbranch(pipeline,
                  src,
                  bank,
                  bank_fragment,
                  control_input_tpl,
                  gate_attack_length,
                  gate_hold_length,
                  block_duration,
                  nxydump_segment=None,
                  fir_stride=None,
                  control_peak_time=None,
                  reconstruction_segment_list=None):
    """!
	Make a single slice of one branch of the lloid graph, e.g. one instrument and one
	template bank fragment. For details see: http://arxiv.org/abs/1107.2665

	Specifically this implements the filtering of multirate svd basis and
	(conditional) resampling and reconstruction of the physical SNR

	@param pipeline The gstreamer pipeline in which to place this graph
	@param src The source of data for this graph provided by a gstreamer element
	@param bank The template bank class
	@param bank_fragment The specific fragment (time slice) of the template bank in question
	@param (control_snk, control_src) An optional tuple of the sink and source elements for a graph that will construct a control time series for the gate which aggregates the orthogonal snrs from each template slice. This is used to conditionally reconstruct the physical SNR of interesting times
	@param gate_attack_length The attack length in samples for the lal_gate element that controls the reconstruction of physical SNRs
	@param gate_hold_length The hold length in samples for the lal_gate element that controls the reconstruction of physical SNRs
	@param block_duration The characteristic buffer size that is passed around, which is useful for constructing queues.
	@param nxydump_segment Not used
	@param fir_stride The target length of output buffers from lal_firbank in seconds.  Directly effects latency.  Making this short will force time-domain convolution. Otherwise FFT convolution will be done to save CPU cycles, but at higher latency.
	@param control_peak_time The window over which to find peaks in the control signal.  Shorter windows increase computational cost but probably also detection efficiency.
	@param reconstruction_segment_list A segment list object that describes when the control signal should be on.  This can be useful in e.g., only reconstructing physical SNRS around the time of injections, which can save an enormous amount of CPU time.
	"""
    logname = "%s_%.2f.%.2f" % (bank.logname, bank_fragment.start,
                                bank_fragment.end)

    control_snk, control_src = control_input_tpl

    #
    # FIR filter bank.  low frequency branches use time-domain
    # convolution, high-frequency branches use FFT convolution with a
    # block stride given by fir_stride.
    #

    latency = -int(round(bank_fragment.start * bank_fragment.rate))
    block_stride = int(fir_stride * bank_fragment.rate)

    # we figure an fft costs ~5 logN flops where N is duration + block
    # stride.  Time domain costs N * block_stride. So if block stride is
    # less than about 5logN you might as well do time domain filtering
    # FIXME This calculation should probably be made more rigorous
    time_domain = 5 * numpy.log2(
        (bank_fragment.end - bank_fragment.start) * bank_fragment.rate +
        block_stride) > block_stride

    src = pipeparts.mkfirbank(
        pipeline,
        src,
        latency=latency,
        fir_matrix=bank_fragment.orthogonal_template_bank,
        block_stride=block_stride,
        time_domain=time_domain)
    src = pipeparts.mkchecktimestamps(pipeline, src,
                                      "timestamps_%s_after_firbank" % logname)
    # uncomment reblock if you ever use really big ffts and want to cut them down a bit
    #src = pipeparts.mkreblock(pipeline, src, block_duration = control_peak_time * gst.SECOND)
    #src = pipeparts.mkchecktimestamps(pipeline, src, "timestamps_%s_after_firbank_reblock" % logname)
    #src = pipeparts.mktee(pipeline, src)	# comment-out the tee below if this is uncommented
    #pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, src), "orthosnr_%s.dump" % logname, segment = nxydump_segment)

    #pipeparts.mkvideosink(pipeline, pipeparts.mkcapsfilter(pipeline, pipeparts.mkhistogramplot(pipeline, src), "video/x-raw-rgb, width=640, height=480, framerate=1/4"))
    #pipeparts.mkogmvideosink(pipeline, pipeparts.mkcapsfilter(pipeline, pipeparts.mkchannelgram(pipeline, pipeparts.mkqueue(pipeline, src), plot_width = .125), "video/x-raw-rgb, width=640, height=480, framerate=64/1"), "orthosnr_channelgram_%s.ogv" % logname, verbose = True)

    #
    # compute weighted sum-of-squares, feed to sum-of-squares
    # aggregator
    #

    if control_snk is not None and control_src is not None:
        src = pipeparts.mktee(
            pipeline, src)  # comment-out if the tee above is uncommented
        elem = pipeparts.mkqueue(
            pipeline,
            pipeparts.mksumsquares(
                pipeline, src, weights=bank_fragment.sum_of_squares_weights),
            max_size_buffers=0,
            max_size_bytes=0,
            max_size_time=block_duration)
        elem = pipeparts.mkchecktimestamps(
            pipeline, elem, "timestamps_%s_after_sumsquare" % logname)
        elem = pipeparts.mkresample(pipeline, elem, quality=9)
        elem = pipeparts.mkchecktimestamps(
            pipeline, elem,
            "timestamps_%s_after_sumsquare_resampler" % logname)
        elem.link(control_snk)

        #
        # use sum-of-squares aggregate as gate control for
        # orthogonal SNRs
        #
        # FIXME the queuing in this code is broken.  enabling this
        # causes lock-ups.  there is latency in the construction of
        # the composite detection statistic due to the need for
        # resampling and because of the peak finding, therefore the
        # source stream going into the gate needs to be queued
        # until the composite detection statistic can catch up, but
        # we don't know by how much (what we've got here doesn't
        # work).  there should not be a need to buffer the control
        # stream at all, nor is there a need for the queuing to
        # accomodate different latencies for different SNR slices,
        # but we do require that all elements correctly modify
        # segments events to reflect their latency and the actual
        # time stamps of the data stream they will produce.  it
        # might be that not all elements are doing that correctly.
        #
        # FIXME we ignore the bank.gate_threshold parameter and
        # just use 1e-100.  this change was made when peak finding
        # was put into the composite detector

        src = pipeparts.mkgate(
            pipeline,
            pipeparts.mkqueue(
                pipeline,
                src,
                max_size_buffers=0,
                max_size_bytes=0,
                max_size_time=1 * int(
                    (2. * control_peak_time +
                     float(abs(gate_attack_length) + abs(gate_hold_length)) /
                     bank_fragment.rate) * Gst.SECOND)),
            threshold=1e-100,
            attack_length=gate_attack_length,
            hold_length=gate_hold_length,
            control=control_src)
        src = pipeparts.mkchecktimestamps(pipeline, src,
                                          "timestamps_%s_after_gate" % logname)

    #
    # optionally add a segment src and gate to only reconstruct around
    # injections
    #
    # FIXME:  set the names of these gates so their segments can be
    # collected later?  or else propagate this segment list into the
    # output some other way.

    if reconstruction_segment_list is not None:
        src = datasource.mksegmentsrcgate(pipeline,
                                          src,
                                          reconstruction_segment_list,
                                          invert_output=False)

    #
    # reconstruct physical SNRs
    #

    if bank_fragment.mix_matrix is not None:
        src = pipeparts.mkmatrixmixer(pipeline,
                                      src,
                                      matrix=bank_fragment.mix_matrix)
        src = pipeparts.mkchecktimestamps(
            pipeline, src, "timestamps_%s_after_matrixmixer" % logname)

    #
    # done
    #
    # FIXME:  find a way to use less memory without this hack

    del bank_fragment.orthogonal_template_bank
    del bank_fragment.sum_of_squares_weights
    del bank_fragment.mix_matrix

    return src
Пример #25
0
def mkLLOIDhoftToSnrSlices(pipeline,
                           hoftdict,
                           bank,
                           control_snksrc,
                           block_duration,
                           verbose=False,
                           logname="",
                           nxydump_segment=None,
                           fir_stride=None,
                           control_peak_time=None,
                           snrslices=None,
                           reconstruction_segment_list=None):
    """!
	Build the pipeline fragment that creates the SnrSlices associated with
	different sample rates from hoft.

	@param reconstruction_segment_list A segment list object that describes when the control signal should be on.  This can be useful in e.g., only reconstructing physical SNRS around the time of injections, which can save an enormous amount of CPU time.
	"""
    #
    # parameters
    #

    rates = sorted(bank.get_rates())
    output_rate = max(rates)

    # work out the upsample factors for the attack and hold calculations below
    upsample_factor = dict(
        (rate, rates[i + 1] / rate) for i, rate in list(enumerate(rates))[:-1])
    upsample_factor[output_rate] = 0

    autocorrelation_length = bank.autocorrelation_bank.shape[1]
    assert autocorrelation_length % 2 == 1
    autocorrelation_latency = -(autocorrelation_length - 1) / 2

    #
    # loop over template bank slices
    #

    branch_heads = dict((rate, set()) for rate in rates)
    for bank_fragment in bank.bank_fragments:
        # The attack and hold width has three parts
        #
        # 1) The audio resampler filter: 16 comes from the size of
        # the audioresampler filter in samples for the next highest
        # rate at quality 1. Note it must then be converted to the size
        # at the current rate using the upsample_factor dictionary
        # (which is 0 if you are at the max rate).
        #
        # 2) The chisq latency.  You must have at least latency number
        # of points before and after (at the maximum sample rate) to
        # compute the chisq
        #
        # 3) A fudge factor to get the width of the peak.  FIXME this
        # is just set to 1/8th of a second
        peak_half_width = upsample_factor[bank_fragment.rate] * 16 + int(
            math.ceil(-autocorrelation_latency *
                      (float(bank_fragment.rate) / output_rate))) + int(
                          math.ceil(bank_fragment.rate / 8.))
        branch_heads[bank_fragment.rate].add(
            mkLLOIDbranch(
                pipeline,
                # FIXME:  the size isn't ideal:  the correct value
                # depends on how much data is accumulated in the
                # firbank element, and the value here is only
                # approximate and not tied to the fir bank
                # parameters so might not work if those change
                pipeparts.mkqueue(
                    pipeline,
                    hoftdict[bank_fragment.rate],
                    max_size_bytes=0,
                    max_size_buffers=0,
                    max_size_time=int(
                        (1 * fir_stride + int(math.ceil(bank.filter_length))) *
                        Gst.SECOND)),
                bank,
                bank_fragment,
                control_snksrc,
                peak_half_width,
                peak_half_width,
                block_duration,
                nxydump_segment=nxydump_segment,
                fir_stride=fir_stride,
                control_peak_time=control_peak_time,
                reconstruction_segment_list=reconstruction_segment_list))

    #
    # if the calling code has requested copies of the snr
    # slices, sum together the highest sample rate streams and tee
    # them off here.  this needs to be done before constructing the
    # adder network below in order to have access to this snr slice by
    # itself.  if we put this off until later it'll have all the other
    # snrs added into it before we get a chance to tee it off
    #

    if snrslices is not None:
        rate, heads = output_rate, branch_heads[output_rate]
        if len(heads) > 1:
            #
            # this sample rate has more than one snr stream.
            # sum them together in an adder, which becomes the
            # head of the stream at this sample rate
            #

            branch_heads[rate] = pipeparts.mkadder(
                pipeline, (pipeparts.mkqueue(pipeline,
                                             head,
                                             max_size_bytes=0,
                                             max_size_buffers=0,
                                             max_size_time=block_duration)
                           for head in heads))
        else:
            #
            # this sample rate has only one stream.  it's the
            # head of the stream at this sample rate
            #

            branch_heads[rate], = heads
        branch_heads[rate] = pipeparts.mktee(pipeline, branch_heads[rate])
        snrslices[rate] = pipeparts.mktogglecomplex(pipeline,
                                                    branch_heads[rate])

        #
        # the code below expects an interable of elements
        #

        branch_heads[rate] = set([branch_heads[rate]])

    #
    # sum the snr streams
    #

    if True:  # FIXME:  make conditional on time-slice \chi^{2}
        next_rate = dict(zip(rates, rates[1:]))
    else:
        next_rate = dict(
            (rate, output_rate) for rate in rates if rate != output_rate)

    for rate, heads in sorted(branch_heads.items()):
        if len(heads) > 1:
            #
            # this sample rate has more than one snr stream.
            # sum them together in an adder, which becomes the
            # head of the stream at this sample rate
            #

            branch_heads[rate] = pipeparts.mkadder(pipeline, heads)
            branch_heads[rate] = pipeparts.mkchecktimestamps(
                pipeline, branch_heads[rate],
                "timestamps_%s_after_%d_snr_adder" % (logname, rate))
        else:
            #
            # this sample rate has only one stream.  it's the
            # head of the stream at this sample rate
            #

            branch_heads[rate], = heads

        #
        # resample if needed
        #

        if rate in next_rate:
            # NOTE: quality = 1 requires that the template
            # slices are padded such that the Nyquist frequency
            # is 1.5 times the highest frequency of the time
            # slice.  NOTE: the adder (that comes downstream of
            # this) isn't quite smart enough to negotiate a
            # common format among its upstream peers so the
            # capsfilter is still required.
            # NOTE uncomment this line to restore audioresample for
            # upsampling
            #branch_heads[rate] = pipeparts.mkcapsfilter(pipeline, pipeparts.mkresample(pipeline, branch_heads[rate], quality = 1), "audio/x-raw, rate=%d" % next_rate[rate])
            branch_heads[rate] = pipeparts.mkcapsfilter(
                pipeline, pipeparts.mkinterpolator(pipeline,
                                                   branch_heads[rate]),
                "audio/x-raw, rate=%d" % next_rate[rate])
            branch_heads[rate] = pipeparts.mkchecktimestamps(
                pipeline, branch_heads[rate],
                "timestamps_%s_after_%d_to_%d_snr_resampler" %
                (logname, rate, next_rate[rate]))

        #
        # if the calling code has requested copies of the snr
        # slices, tee that off here.  remember that we've already
        # got the highest sample rate slice from above
        #

        if snrslices is not None and rate != output_rate:
            branch_heads[rate] = pipeparts.mktee(pipeline, branch_heads[rate])
            snrslices[rate] = pipeparts.mktogglecomplex(
                pipeline, branch_heads[rate])

        #
        # chain to next adder if this isn't the final answer
        #

        if rate in next_rate:
            branch_heads[next_rate[rate]].add(branch_heads.pop(rate))

    #
    # done
    #

    snr, = branch_heads.values()  # make sure we've summed down to one stream
    return pipeparts.mktogglecomplex(pipeline, snr)
Пример #26
0
def mkLLOIDmulti(pipeline,
                 detectors,
                 banks,
                 psd,
                 psd_fft_length=32,
                 ht_gate_threshold=float("inf"),
                 veto_segments=None,
                 verbose=False,
                 nxydump_segment=None,
                 chisq_type='autochisq',
                 track_psd=False,
                 fir_stride=16,
                 control_peak_time=2,
                 block_duration=Gst.SECOND,
                 reconstruction_segment_list=None):
    """!
	The multiple instrument, multiple bank LLOID algorithm
	"""

    #
    # check for unrecognized chisq_types, non-unique bank IDs
    #

    if chisq_type not in ['autochisq', 'timeslicechisq']:
        raise ValueError(
            "chisq_type must be either 'autochisq' or 'timeslicechisq', given %s"
            % chisq_type)
    if any(
            tuple(iterutils.nonuniq(bank.bank_id for bank in banklist))
            for banklist in banks.values()):
        raise ValueError("bank IDs are not unique: %s" % "; ".join(
            "for %s: %s" %
            (instrument, iterutils.nonuniq(bank.bank_id for bank in banklist))
            for instrument, banklist in banks.items()))

    #
    # construct dictionaries of whitened, conditioned, down-sampled
    # h(t) streams.  NOTE:  we assume all banks for each instrument
    # were generated with the same processed PSD for that instrument
    # and just extract the first without checking that this assumption
    # is correct
    #

    assert psd_fft_length % 4 == 0, "psd_fft_length (= %g) must be multiple of 4" % psd_fft_length
    hoftdicts = {}
    for instrument in detectors.channel_dict:
        src, statevector, dqvector = datasource.mkbasicsrc(
            pipeline, detectors, instrument, verbose)
        hoftdicts[instrument] = multirate_datasource.mkwhitened_multirate_src(
            pipeline,
            src=src,
            rates=set(rate for bank in banks[instrument]
                      for rate in bank.get_rates()),
            instrument=instrument,
            psd=psd[instrument],
            psd_fft_length=psd_fft_length,
            ht_gate_threshold=ht_gate_threshold,
            veto_segments=veto_segments[instrument]
            if veto_segments is not None else None,
            nxydump_segment=nxydump_segment,
            track_psd=track_psd,
            width=32,
            statevector=statevector,
            dqvector=dqvector,
            fir_whiten_reference_psd=banks[instrument][0].processed_psd)

    #
    # build gate control branches
    #

    if control_peak_time > 0:
        control_branch = {}
        for instrument, bank in [(instrument, bank)
                                 for instrument, banklist in banks.items()
                                 for bank in banklist]:
            suffix = "%s%s" % (instrument,
                               (bank.logname and "_%s" % bank.logname or ""))
            if instrument != "H2":
                control_branch[(instrument, bank.bank_id)] = mkcontrolsnksrc(
                    pipeline,
                    max(bank.get_rates()),
                    verbose=verbose,
                    suffix=suffix,
                    control_peak_samples=control_peak_time *
                    max(bank.get_rates()))
                #pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, control_branch[(instrument, bank.bank_id)][1]), "control_%s.dump" % suffix, segment = nxydump_segment)
    else:
        control_branch = None

    #
    # construct trigger generators
    #

    itacac_dict = {}
    for i, (instrument, bank) in enumerate([
        (instrument, bank) for instrument, banklist in banks.items()
            for bank in banklist
    ]):
        suffix = "%s%s" % (instrument,
                           (bank.logname and "_%s" % bank.logname or ""))
        if control_branch is not None:
            if instrument != "H2":
                control_snksrc = control_branch[(instrument, bank.bank_id)]
            else:
                control_snksrc = (None, control_branch[("H1",
                                                        bank.bank_id)][1])
        else:
            control_snksrc = (None, None)
        if chisq_type == 'timeslicechisq':
            snrslices = {}
        else:
            snrslices = None
        snr = mkLLOIDhoftToSnrSlices(
            pipeline,
            hoftdicts[instrument],
            bank,
            control_snksrc,
            block_duration,
            verbose=verbose,
            logname=suffix,
            nxydump_segment=nxydump_segment,
            control_peak_time=control_peak_time,
            fir_stride=fir_stride,
            snrslices=snrslices,
            reconstruction_segment_list=reconstruction_segment_list)
        snr = pipeparts.mkchecktimestamps(pipeline, snr,
                                          "timestamps_%s_snr" % suffix)
        # uncomment this tee if the diagnostic sinks below are
        # needed
        #snr = pipeparts.mktee(pipeline, snr)
        if chisq_type == 'autochisq':
            # 4 is about the lowest we can do stably for
            # coincidence online...
            # FIXME get this to work some day
            #nsamps_window = max(bank.get_rates()) / 4
            nsamps_window = 1 * max(bank.get_rates())
            if bank.bank_id not in itacac_dict:
                itacac_dict[bank.bank_id] = pipeparts.mkgeneric(
                    pipeline, None, "lal_itacac")

            head = itacac_dict[bank.bank_id]
            pad = head.get_request_pad("sink%d" % len(head.sinkpads))
            if instrument == 'H1' or instrument == 'L1':
                for prop, val in [
                    ("n", nsamps_window), ("snr-thresh", LnLRDensity.snr_min),
                    ("bank_filename", bank.template_bank_filename),
                    ("sigmasq", bank.sigmasq),
                    ("autocorrelation_matrix",
                     pipeio.repack_complex_array_to_real(
                         bank.autocorrelation_bank)),
                    ("autocorrelation_mask", bank.autocorrelation_mask)
                ]:
                    pad.set_property(prop, val)
            else:
                for prop, val in [
                    ("n", nsamps_window), ("snr-thresh", LnLRDensity.snr_min),
                    ("bank_filename", bank.template_bank_filename),
                    ("sigmasq", bank.sigmasq),
                    ("autocorrelation_matrix",
                     pipeio.repack_complex_array_to_real(
                         bank.autocorrelation_bank)),
                    ("autocorrelation_mask", bank.autocorrelation_mask)
                ]:
                    pad.set_property(prop, val)
        else:
            raise NotImplementedError(
                "Currently only 'autochisq' is supported")
        # replace this line with the commented-out line below if diagnostic sink is needed
        snr.srcpads[0].link(pad)
        #snr.get_request_pad("src_%d" % len(snr.srcpads)).link(pad)
        # FIXME:  find a way to use less memory without this hack
        del bank.autocorrelation_bank
        #pipeparts.mknxydumpsink(pipeline, pipeparts.mktogglecomplex(pipeline, pipeparts.mkqueue(pipeline, snr)), "snr_%s.dump" % suffix, segment = nxydump_segment)
        #pipeparts.mkogmvideosink(pipeline, pipeparts.mkcapsfilter(pipeline, pipeparts.mkchannelgram(pipeline, pipeparts.mkqueue(pipeline, snr), plot_width = .125), "video/x-raw-rgb, width=640, height=480, framerate=64/1"), "snr_channelgram_%s.ogv" % suffix, audiosrc = pipeparts.mkaudioamplify(pipeline, pipeparts.mkqueue(pipeline, hoftdict[max(bank.get_rates())], max_size_time = 2 * int(math.ceil(bank.filter_length)) * gst.SECOND), 0.125), verbose = True)

    #
    # done
    #

    assert any(itacac_dict.values())
    if verbose:
        for bank_id, head in itacac_dict.items():
            # FIXME Not sure why we need a queue here, but without
            # the queue one injection job in ~5000 hangs
            itacac_dict[bank_id] = pipeparts.mkprogressreport(
                pipeline,
                pipeparts.mkqueue(pipeline,
                                  head,
                                  max_size_buffers=10,
                                  max_size_bytes=0,
                                  max_size_time=0),
                "progress_xml_bank_%s" % bank_id)
    return itacac_dict