Ejemplo n.º 1
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
Ejemplo n.º 2
0
def lal_resample_01(pipeline, name):

	#
	# This test adds various noise into a stream and uses audioresample to remove it
	#

	rate = 16384		# Hz
	buffer_length = 1.0	# seconds
	test_duration = 2000.0	# seconds
	width = 64		# bits

	#
	# build pipeline
	#

	src = test_common.test_src(pipeline, buffer_length = buffer_length, wave = 5, volume = 1, rate = rate, test_duration = test_duration, width = width, verbose = False)
	tee = pipeparts.mktee(pipeline, src)
	identity = pipeparts.mkgeneric(pipeline, tee, "identity")
	head = pipeparts.mkgeneric(pipeline, tee, "lal_resample", quality = 5)
	head = pipeparts.mkcapsfilter(pipeline, head, "audio/x-raw,format=F64LE,rate=2048")
	head = pipeparts.mkgeneric(pipeline, head, "lal_resample", quality = 5)
	head = pipeparts.mkcapsfilter(pipeline, head, "audio/x-raw,format=F64LE,rate=16384")
	head = calibration_parts.mkinterleave(pipeline, [head, identity])
	#pipeparts.mknxydumpsink(pipeline, head, "resampled_data.txt")
	#head = pipeparts.mkgeneric(pipeline, head, "splitcounter")
	pipeparts.mkgeneric(pipeline, head, "lal_transferfunction", fft_length = rate, fft_overlap = rate / 2, num_ffts = 1000, update_samples = rate * test_duration, filename = "lal_resample_tf.txt")

	#
	# done
	#

	return pipeline
Ejemplo n.º 3
0
def build_pipeline(pipeline,
                   data_source_info,
                   output_path=tempfile.gettempdir(),
                   sample_rate=None,
                   description="TMPFILE_DELETE_ME_%s" % uuid.uuid4().hex,
                   channel_comment=None,
                   frame_duration=1,
                   frames_per_file=1024,
                   verbose=False):
    #
    # get instrument and channel name (requires exactly one
    # instrument+channel)
    #

    channelmux_input_dict = {}

    for instrument, channel_name in data_source_info.channel_dict.items():
        #
        # retrieve h(t)
        #

        src = mkbasicsrc(pipeline,
                         data_source_info,
                         instrument,
                         verbose=verbose)

        #
        # optionally resample
        #

        if sample_rate is not None:
            # make sure we're *down*sampling
            src = pipeparts.mkcapsfilter(
                pipeline, src, "audio/x-raw, rate=[%d,MAX]" % sample_rate)
            src = pipeparts.mkresample(pipeline, src, quality=9)
            src = pipeparts.mkcapsfilter(pipeline, src,
                                         "audio/x-raw, rate=%d" % sample_rate)

        #
        # pack into frame files for output
        #

        src = pipeparts.mkframecppchannelmux(
            pipeline, {"%s:%s" % (instrument, channel_name): src},
            frame_duration=frame_duration,
            frames_per_file=frames_per_file)
        for pad in src.sinkpads:
            if channel_comment is not None:
                pad.set_property("comment", channel_comment)
            pad.set_property("pad-type", "FrProcData")
        pipeparts.mkframecppfilesink(pipeline,
                                     src,
                                     frame_type="%s_%s" %
                                     (instrument, description),
                                     path=output_path)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def complex_test_src(pipeline,
                     buffer_length=1.0,
                     rate=2048,
                     width=64,
                     test_duration=10.0,
                     wave=5,
                     freq=0,
                     is_live=False,
                     verbose=True,
                     src_suffix=""):
    head = pipeparts.mkaudiotestsrc(pipeline,
                                    wave=wave,
                                    freq=freq,
                                    samplesperbuffer=int(buffer_length * rate),
                                    volume=1,
                                    num_buffers=int(test_duration /
                                                    buffer_length),
                                    is_live=is_live)
    head = pipeparts.mkcapsfilter(
        pipeline, head, "audio/x-raw, format=F%d%s, rate=%d, channels=2" %
        (width, BYTE_ORDER, rate))
    head = pipeparts.mktogglecomplex(pipeline, head)
    if verbose:
        head = pipeparts.mkprogressreport(pipeline, head, "src%s" % src_suffix)
    return head
Ejemplo n.º 6
0
def test_src(pipeline,
             buffer_length=1.0,
             rate=2048,
             width=64,
             channels=1,
             test_duration=10.0,
             wave=5,
             freq=0,
             volume=1,
             is_live=False,
             verbose=True,
             src_suffix=""):
    if wave == "ligo":
        head = pipeparts.mkfakeLIGOsrc(pipeline,
                                       instrument="H1",
                                       channel_name="LSC-STRAIN")
    else:
        head = pipeparts.mkaudiotestsrc(
            pipeline,
            wave=wave,
            freq=freq,
            volume=volume,
            samplesperbuffer=int(buffer_length * rate),
            num_buffers=int(test_duration / buffer_length),
            is_live=is_live)
        head = pipeparts.mkcapsfilter(
            pipeline, head,
            "audio/x-raw, format=F%d%s, rate=%d, channels=%d, channel-mask=(bitmask)0x0"
            % (width, BYTE_ORDER, rate, channels))
    if verbose:
        head = pipeparts.mkprogressreport(pipeline, head, "src%s" % src_suffix)
    return head
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
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
def lal_logicalundersample_01(pipeline, name):
    #
    # This is a simple test that the undersample element outputs "1" if a pair of two consecutive inputs are odd and "0" otherwise.
    # Note that the pairing must be such that the two inputs are combined in the logical operation.
    #

    in_rate = 1024  # Hz
    out_rate = 512  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds

    #
    # build pipeline
    #

    src = test_common.int_test_src(pipeline,
                                   buffer_length=buffer_length,
                                   rate=in_rate,
                                   width=32,
                                   test_duration=test_duration)
    #	src = pipeparts.mkaudiotestsrc(pipeline, num_buffers = int(test_duration / buffer_length))
    capsfilter1 = pipeparts.mkcapsfilter(
        pipeline, src, "audio/x-raw, format=S32LE, rate=%d" % int(in_rate))
    tee1 = pipeparts.mktee(pipeline, capsfilter1)
    pipeparts.mknxydumpsink(pipeline, tee1, "%s_in.txt" % name)
    undersample = pipeparts.mkgeneric(pipeline,
                                      tee1,
                                      "lal_logicalundersample",
                                      required_on=1,
                                      required_off=2,
                                      invert_result=True)
    capsfilter2 = pipeparts.mkcapsfilter(
        pipeline, undersample,
        "audio/x-raw, format=S32LE, rate=%d" % int(out_rate))
    #checktimestamps = pipeparts.mkchecktimestamps(pipeline, capsfilter2)
    pipeparts.mknxydumpsink(pipeline, capsfilter2, "%s_out.txt" % name)

    #
    # done
    #

    return pipeline
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
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))
Ejemplo n.º 15
0
def mkcontrolsnksrc(pipeline,
                    rate,
                    verbose=False,
                    suffix=None,
                    control_peak_samples=None):
    """!
	This function implements a portion of a gstreamer graph to provide a
	control signal for deciding when to reconstruct physical SNRS

	@param pipeline A reference to the gstreamer pipeline in which to add this graph
	@param rate An integer representing the target sample rate of the resulting src
	@param verbose Make verbose
	@param suffix Log name for verbosity
	@param control_peak_samples If nonzero, this would do peakfinding on the control signal with the window specified by this parameter.  The peak finding would give a single sample of "on" state at the peak.   This will cause far less CPU to be used if you only want to reconstruct SNR around the peak of the control signal.
	"""
    #
    # start with an adder and caps filter to select a sample rate
    #

    snk = pipeparts.mkadder(pipeline, None)
    src = pipeparts.mkcapsfilter(pipeline, snk, "audio/x-raw, rate=%d" % rate)

    #
    # Add a peak finder on the control signal sample number
    #

    if control_peak_samples > 0:
        src = pipeparts.mkpeak(pipeline, src, control_peak_samples)

    #
    # verbosity and a tee
    #

    logname = suffix and "_%s" % suffix or ""
    if verbose:
        src = pipeparts.mkprogressreport(pipeline, src,
                                         "progress_sumsquares%s" % logname)
    src = pipeparts.mkchecktimestamps(pipeline, src,
                                      "timestamps%s_sumsquares" % logname)
    src = pipeparts.mktee(pipeline, src)

    #
    # return the adder and tee
    #

    return snk, src
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 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
Ejemplo n.º 21
0
def int_test_src(pipeline,
                 buffer_length=1.0,
                 rate=2048,
                 width=64,
                 channels=1,
                 test_duration=10.0,
                 wave=5,
                 freq=0,
                 is_live=False,
                 verbose=True):
    head = pipeparts.mkaudiotestsrc(pipeline,
                                    wave=wave,
                                    freq=freq,
                                    samplesperbuffer=int(buffer_length * rate),
                                    volume=1,
                                    num_buffers=int(test_duration /
                                                    buffer_length),
                                    is_live=is_live)
    head = pipeparts.mkcapsfilter(
        pipeline, head, "audio/x-raw, format=S%d%s, rate=%d, channels=%d" %
        (width, BYTE_ORDER, rate, channels))
    if verbose:
        head = pipeparts.mkprogressreport(pipeline, head, "src")
    return head
Ejemplo n.º 22
0
def remove_lines_with_witnesses_test_01(pipeline, name):
    #
    # This tests generates a fake signal and fake witness channels
    # to test the removal of lines using the witnesses.
    #

    signal_rate = 1024  # Hz
    witness_rate = 1024  # Hz
    width = 64
    buffer_length = 1.0  # seconds
    test_duration = 500.0  # seconds

    compute_rate = 16  # Hz
    f0 = 60
    num_harmonics = 2
    f0_var = 0.02
    filter_latency = 1.0
    use_gate = False

    signal = test_common.test_src(pipeline,
                                  buffer_length=buffer_length,
                                  rate=signal_rate,
                                  width=width,
                                  channels=1,
                                  test_duration=test_duration,
                                  wave=5,
                                  freq=0.1,
                                  volume=1,
                                  src_suffix="signal")

    witness0 = test_common.test_src(pipeline,
                                    buffer_length=buffer_length,
                                    rate=witness_rate,
                                    width=width,
                                    channels=1,
                                    test_duration=test_duration,
                                    wave=5,
                                    freq=0.1,
                                    volume=1,
                                    src_suffix="witness0")
    witness1 = test_common.test_src(pipeline,
                                    buffer_length=buffer_length,
                                    rate=witness_rate,
                                    width=width,
                                    channels=1,
                                    test_duration=test_duration,
                                    wave=5,
                                    freq=0.1,
                                    volume=1,
                                    src_suffix="witness1")

    witnesses = [witness0, witness1]

    noisesub_gate_bit = None
    if use_gate:
        signal = pipeparts.mktee(pipeline, signal)
        noisesub_gate_bit = calibration_parts.mkresample(
            pipeline, noisesub_gate_bit, 0, False, compute_rate)
        noisesub_gate_bit = pipeparts.mkgeneric(pipeline,
                                                noisesub_gate_bit,
                                                "lal_add_constant",
                                                value=3.0)
        noisesub_gate_bit = pipeparts.mkgeneric(pipeline, noisesub_gate_bit,
                                                "lal_typecast")
        noisesub_gate_bit = pipeparts.mkcapsfilter(
            pipeline, noisesub_gate_bit,
            "audio/x-raw, format=U32LE, rate=%d" % compute_rate)

    clean = calibration_parts.remove_harmonics_with_witnesses(
        pipeline,
        signal,
        witnesses,
        f0,
        num_harmonics,
        f0_var,
        filter_latency,
        compute_rate=compute_rate,
        rate_out=signal_rate,
        num_median=2048,
        num_avg=160,
        noisesub_gate_bit=noisesub_gate_bit)
    pipeparts.mknxydumpsink(pipeline, clean, "clean.txt")

    #signal = pipeparts.mktogglecomplex(pipeline, pipeparts.mkmatrixmixer(pipeline, signal, matrix = [[1.0,1.0]]))
    #witness0 = pipeparts.mktogglecomplex(pipeline, pipeparts.mkmatrixmixer(pipeline, witness0, matrix = [[1.0,1.0]]))
    #witness1 = pipeparts.mktogglecomplex(pipeline, pipeparts.mkmatrixmixer(pipeline, witness1, matrix = [[1.0,1.0]]))
    #allchan = [signal, witness0, witness1]
    #allchan = calibration_parts.mkinterleave(pipeline, allchan, complex_data = True)
    #allchan = pipeparts.mktee(pipeline, allchan)
    #pipeparts.mknxydumpsink(pipeline, allchan, "allchan.txt")
    #allchan = calibration_parts.mkdeinterleave(pipeline, allchan, 3, complex_data = True)
    #allchan = calibration_parts.mkadder(pipeline, allchan)
    #pipeparts.mknxydumpsink(pipeline, allchan, "allchan_sum.txt")

    #
    # done
    #

    return pipeline
Ejemplo n.º 23
0
                                          tagInj,
                                          frame_type=options.frame_type,
                                          path=options.output_path)
    else:
        fs = pipeparts.mkframecppfilesink(pipeline,
                                          mux,
                                          frame_type=options.frame_type)
elif options.output_type == "tcp":
    # NB: like the appsrc, the tcp client sink does not use the 'blocksize' property.
    # It is just hanging around because it is inherited
    # gstdataprotocol serializes and sends the caps first. Then serializes and
    # sends the buffers. Less work for us.

    # XXX Sadness. The capsfilter is not "gap-aware". So the gap flag will be unset.
    mux = pipeparts.mkcapsfilter(pipeline,
                                 mux,
                                 caps="application/x-igwd-frame,framed=true")
    tcpclientsink = pipeparts.mkgeneric(pipeline, mux, "tcpclientsink")
    tcpclientsink.set_property("protocol", "GST_TCP_PROTOCOL_GDP")
    tcpclientsink.set_property("port", options.port)
    tcpclientsink.set_property("sync", False)
    # XXX Hack. Attach pad probe to sink pad of tcpclientsink
    tcs_pad = tcpclientsink.get_pad("sink")
    tcs_pad.add_buffer_probe(hc.lateBufferHandler)
else:
    raise ValueError("Invalid output type.")

#
# Start the thing going.
#
Ejemplo n.º 24
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)
Ejemplo n.º 25
0
def lal_dqtukey_01(pipeline, name):

    #
    # This test passes a random series of integers through lal_dqtukey
    #

    rate_in = 4  # Hz
    rate_out = 16384  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 2.0  # seconds
    transition_samples = 997

    #
    # build pipeline
    #

    head = test_common.int_test_src(pipeline,
                                    buffer_length=buffer_length,
                                    rate=rate_in,
                                    width=32,
                                    test_duration=test_duration,
                                    wave=5,
                                    freq=0)
    head = pipeparts.mktee(pipeline, head)
    pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name)
    normal = pipeparts.mkgeneric(pipeline,
                                 head,
                                 "lal_dqtukey",
                                 transition_samples=transition_samples,
                                 required_on=2,
                                 required_off=1,
                                 invert_control=False)
    invert = pipeparts.mkgeneric(pipeline,
                                 head,
                                 "lal_dqtukey",
                                 transition_samples=transition_samples,
                                 required_on=2,
                                 required_off=1,
                                 invert_control=True)
    invwin = pipeparts.mkgeneric(pipeline,
                                 head,
                                 "lal_dqtukey",
                                 transition_samples=transition_samples,
                                 required_on=2,
                                 required_off=1,
                                 invert_control=False,
                                 invert_window=True)
    invboth = pipeparts.mkgeneric(pipeline,
                                  head,
                                  "lal_dqtukey",
                                  transition_samples=transition_samples,
                                  required_on=2,
                                  required_off=1,
                                  invert_control=True,
                                  invert_window=True)
    normal = pipeparts.mkcapsfilter(
        pipeline, normal, "audio/x-raw,rate=%s,format=F64LE" % rate_out)
    invert = pipeparts.mkcapsfilter(
        pipeline, invert, "audio/x-raw,rate=%s,format=F64LE" % rate_out)
    invwin = pipeparts.mkcapsfilter(
        pipeline, invwin, "audio/x-raw,rate=%s,format=F64LE" % rate_out)
    invboth = pipeparts.mkcapsfilter(
        pipeline, invboth, "audio/x-raw,rate=%s,format=F64LE" % rate_out)
    pipeparts.mknxydumpsink(pipeline, normal, "%s_normal_out.txt" % name)
    pipeparts.mknxydumpsink(pipeline, invert, "%s_invert_out.txt" % name)
    pipeparts.mknxydumpsink(pipeline, invwin, "%s_invwin_out.txt" % name)
    pipeparts.mknxydumpsink(pipeline, invboth, "%s_invboth_out.txt" % name)

    #
    # done
    #

    return pipeline
Ejemplo n.º 26
0
def act2darm(pipeline, name):

    # Get actuation injection channels from the raw frames
    act_inj_channels = []
    raw_data = pipeparts.mklalcachesrc(pipeline,
                                       location=options.raw_frame_cache,
                                       cache_dsc_regex=ifo)
    raw_data = pipeparts.mkframecppchanneldemux(
        pipeline,
        raw_data,
        do_file_checksum=False,
        skip_bad_files=True,
        channel_list=list(map("%s:%s".__mod__, channel_list)))
    for i in range(len(act_channels)):
        act_inj_channels.append(
            calibration_parts.hook_up(pipeline, raw_data, act_channels[i], ifo,
                                      1.0))
        act_inj_channels[i] = calibration_parts.caps_and_progress(
            pipeline, act_inj_channels[i],
            "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
            "act_inj_%d" % i)
        act_inj_channels[i] = pipeparts.mktee(pipeline, act_inj_channels[i])

    # Demodulate the actuation injection channels at the lines of interest
    for i in range(0, len(frequencies)):
        demodulated_act = calibration_parts.demodulate(
            pipeline,
            act_inj_channels[i],
            frequencies[i],
            True,
            rate_out,
            filter_time,
            0.5,
            prefactor_real=act_corrections[2 * i],
            prefactor_imag=act_corrections[2 * i + 1])
        demodulated_act_list.append(pipeparts.mktee(pipeline, demodulated_act))

    # Check if we are taking act-to-darm ratios for CALCS data
    for channel, label in zip(calcs_channels, labels[0:len(calcs_channels)]):
        calcs_deltal = calibration_parts.hook_up(pipeline, raw_data, channel,
                                                 ifo, 1.0)
        calcs_deltal = calibration_parts.caps_and_progress(
            pipeline, calcs_deltal,
            "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
            label)
        calcs_deltal = pipeparts.mktee(pipeline, calcs_deltal)
        for i in range(0, len(frequencies)):
            # Demodulate DELTAL_EXTERNAL at each line
            demodulated_calcs_deltal = calibration_parts.demodulate(
                pipeline, calcs_deltal, frequencies[i], True, rate_out,
                filter_time, 0.5)
            # Take ratio \DeltaL(f) / act_injection(f)
            deltaL_over_act = calibration_parts.complex_division(
                pipeline, demodulated_calcs_deltaL, demodulated_act_list[i])
            # Take a running average
            deltaL_over_act = pipeparts.mkgeneric(pipeline,
                                                  deltaL_over_act,
                                                  "lal_smoothkappas",
                                                  array_size=1,
                                                  avg_array_size=int(
                                                      rate_out * average_time))
            # Write to file
            pipeparts.mknxydumpsink(
                pipeline, deltaL_over_act, "%s_%s_over_%s_at_line%d.txt" %
                (ifo, label.replace(' ', '_'), act_channels[i], i + 1))

    # Check if we are taking act-to-darm ratios for gstlal calibrated data
    if options.gstlal_channel_list is not None:
        cache_num = 0
        for cache, channel, label in zip(
                gstlal_frame_cache_list, gstlal_channels,
                labels[len(calcs_channels):len(channel_list)]):
            # Get gstlal channels from the gstlal frames
            hoft_data = pipeparts.mklalcachesrc(pipeline,
                                                location=cache,
                                                cache_dsc_regex=ifo)
            hoft_data = pipeparts.mkframecppchanneldemux(
                pipeline,
                hoft_data,
                do_file_checksum=False,
                skip_bad_files=True,
                channel_list=list(
                    map("%s:%s".__mod__, channel_list +
                        TDCF_channels[cache_num] + DQ_channels)))
            hoft = calibration_parts.hook_up(pipeline,
                                             hoft_data,
                                             channel,
                                             ifo,
                                             1.0,
                                             element_name_suffix="_%d" %
                                             cache_num)
            hoft = calibration_parts.caps_and_progress(
                pipeline, hoft,
                "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
                label)
            deltal = pipeparts.mkaudioamplify(pipeline, hoft, arm_length)
            deltal = pipeparts.mktee(pipeline, deltal)

            # Get a DQ channel
            DQ_channel = "%sCALIB_STATE_VECTOR%s" % (chan_prefixes[cache_num],
                                                     chan_suffixes[cache_num])
            DQ = calibration_parts.hook_up(pipeline,
                                           hoft_data,
                                           DQ_channel,
                                           ifo,
                                           1.0,
                                           element_name_suffix="_%d" %
                                           cache_num)
            DQ = calibration_parts.caps_and_progress(
                pipeline, DQ,
                "audio/x-raw,format=U32LE,channels=1,channel-mask=(bitmask)0x0",
                "DQ_%s" % label)
            DQ = pipeparts.mkgeneric(pipeline,
                                     DQ,
                                     "lal_logicalundersample",
                                     required_on=1,
                                     status_out=1)
            DQ = pipeparts.mkcapsfilter(
                pipeline, DQ,
                "audio/x-raw,format=U32LE,rate=%d,channels=1,channel-mask=(bitmask)0x0"
                % rate_out)
            DQ = pipeparts.mktee(pipeline, DQ)
            for i in range(0, len(frequencies)):
                # Demodulate \DeltaL at each line
                demodulated_deltal = calibration_parts.demodulate(
                    pipeline, deltal, frequencies[i], True, rate_out,
                    filter_time, 0.5)

                # Divide by a TDCF if needed
                if ('tst' in act_line_names[i] or 'esd' in act_line_names[i]
                    ) and (apply_complex_kappatst[cache_num]
                           or apply_kappatst[cache_num]):
                    # Get KAPPA_TST
                    TDCF_real = "%sCALIB_KAPPA_TST_REAL%s" % (
                        chan_prefixes[cache_num], chan_suffixes[cache_num])
                    TDCF_imag = "%sCALIB_KAPPA_TST_IMAGINARY%s" % (
                        chan_prefixes[cache_num], chan_suffixes[cache_num])
                    TDCF_real = calibration_parts.hook_up(
                        pipeline,
                        hoft_data,
                        TDCF_real,
                        ifo,
                        1.0,
                        element_name_suffix="_%d" % cache_num)
                    TDCF_imag = calibration_parts.hook_up(
                        pipeline,
                        hoft_data,
                        TDCF_imag,
                        ifo,
                        1.0,
                        element_name_suffix="_%d" % cache_num)
                    TDCF = calibration_parts.merge_into_complex(
                        pipeline, TDCF_real, TDCF_imag)
                    TDCF = calibration_parts.caps_and_progress(
                        pipeline, TDCF,
                        "audio/x-raw,format=Z128LE,channels=1,channel-mask=(bitmask)0x0",
                        'KAPPA_TST_%s' % label)
                    TDCF = calibration_parts.mkresample(
                        pipeline, TDCF, 3, False, rate_out)
                    if not apply_complex_kappatst[cache_num]:
                        # Only divide by the magnitude
                        TDCF = pipeparts.mkgeneric(pipeline, TDCF, "cabs")
                        TDCF = pipeparts.mktogglecomplex(
                            pipeline,
                            pipeparts.mkmatrixmixer(pipeline,
                                                    TDCF,
                                                    matrix=[[1.0, 0.0]]))
                    demodulated_deltal = calibration_parts.complex_division(
                        pipeline, demodulated_deltal, TDCF)
                elif 'pum' in act_line_names[i] and (
                        apply_complex_kappapum[cache_num]
                        or apply_kappapum[cache_num]):
                    # Get KAPPA_PUM
                    TDCF_real = "%sCALIB_KAPPA_PUM_REAL%s" % (
                        chan_prefixes[cache_num], chan_suffixes[cache_num])
                    TDCF_imag = "%sCALIB_KAPPA_PUM_IMAGINARY%s" % (
                        chan_prefixes[cache_num], chan_suffixes[cache_num])
                    TDCF_real = calibration_parts.hook_up(
                        pipeline,
                        hoft_data,
                        TDCF_real,
                        ifo,
                        1.0,
                        element_name_suffix="_%d" % cache_num)
                    TDCF_imag = calibration_parts.hook_up(
                        pipeline,
                        hoft_data,
                        TDCF_imag,
                        ifo,
                        1.0,
                        element_name_suffix="_%d" % cache_num)
                    TDCF = calibration_parts.merge_into_complex(
                        pipeline, TDCF_real, TDCF_imag)
                    TDCF = calibration_parts.caps_and_progress(
                        pipeline, TDCF,
                        "audio/x-raw,format=Z128LE,channels=1,channel-mask=(bitmask)0x0",
                        'KAPPA_PUM_%s' % label)
                    TDCF = calibration_parts.mkresample(
                        pipeline, TDCF, 3, False, rate_out)
                    if not apply_complex_kappapum[cache_num]:
                        # Only divide by the magnitude
                        TDCF = pipeparts.mkgeneric(pipeline, TDCF, "cabs")
                        TDCF = pipeparts.mktogglecomplex(
                            pipeline,
                            pipeparts.mkmatrixmixer(pipeline,
                                                    TDCF,
                                                    matrix=[[1.0, 0.0]]))
                    demodulated_deltal = calibration_parts.complex_division(
                        pipeline, demodulated_deltal, TDCF)
                elif 'uim' in act_line_names[i] and (
                        apply_complex_kappauim[cache_num]
                        or apply_kappauim[cache_num]):
                    # Get KAPPA_UIM
                    TDCF_real = "%sCALIB_KAPPA_UIM_REAL%s" % (
                        chan_prefixes[cache_num], chan_suffixes[cache_num])
                    TDCF_imag = "%sCALIB_KAPPA_UIM_IMAGINARY%s" % (
                        chan_prefixes[cache_num], chan_suffixes[cache_num])
                    TDCF_real = calibration_parts.hook_up(
                        pipeline,
                        hoft_data,
                        TDCF_real,
                        ifo,
                        1.0,
                        element_name_suffix="_%d" % cache_num)
                    TDCF_imag = calibration_parts.hook_up(
                        pipeline,
                        hoft_data,
                        TDCF_imag,
                        ifo,
                        1.0,
                        element_name_suffix="_%d" % cache_num)
                    TDCF = calibration_parts.merge_into_complex(
                        pipeline, TDCF_real, TDCF_imag)
                    TDCF = calibration_parts.caps_and_progress(
                        pipeline, TDCF,
                        "audio/x-raw,format=Z128LE,channels=1,channel-mask=(bitmask)0x0",
                        'KAPPA_UIM_%s' % label)
                    TDCF = calibration_parts.mkresample(
                        pipeline, TDCF, 3, False, rate_out)
                    if not apply_complex_kappauim[cache_num]:
                        # Only divide by the magnitude
                        TDCF = pipeparts.mkgeneric(pipeline, TDCF, "cabs")
                        TDCF = pipeparts.mktogglecomplex(
                            pipeline,
                            pipeparts.mkmatrixmixer(pipeline,
                                                    TDCF,
                                                    matrix=[[1.0, 0.0]]))
                    demodulated_deltal = calibration_parts.complex_division(
                        pipeline, demodulated_deltal, TDCF)

                # Take ratio \DeltaL(f) / act_injection(f)
                deltaL_over_act = calibration_parts.complex_division(
                    pipeline, demodulated_deltal, demodulated_act_list[i])
                # Take a running average
                deltaL_over_act = pipeparts.mkgeneric(
                    pipeline,
                    deltaL_over_act,
                    "lal_smoothkappas",
                    array_size=1,
                    avg_array_size=int(rate_out * average_time))
                # Find the magnitude
                deltaL_over_act = pipeparts.mktee(pipeline, deltaL_over_act)
                magnitude = pipeparts.mkgeneric(pipeline, deltaL_over_act,
                                                "cabs")
                # Find the phase
                phase = pipeparts.mkgeneric(pipeline, deltaL_over_act, "carg")
                phase = pipeparts.mkaudioamplify(pipeline, phase,
                                                 180.0 / numpy.pi)
                # Interleave
                magnitude_and_phase = calibration_parts.mkinterleave(
                    pipeline, [magnitude, phase])
                # Gate with DQ channel
                magnitude_and_phase = calibration_parts.mkgate(
                    pipeline, magnitude_and_phase, DQ, 1)
                magnitude_and_phase = pipeparts.mkprogressreport(
                    pipeline,
                    magnitude_and_phase,
                    name="progress_sink_%s_%d" % (label, i))
                # Write to file
                pipeparts.mknxydumpsink(
                    pipeline, magnitude_and_phase,
                    "%s_%s_over_%s_at_%0.1fHz_%d.txt" %
                    (ifo, label.replace(' ', '_'), act_channels[i],
                     frequencies[i], options.gps_start_time))
            cache_num = cache_num + 1

    #
    # done
    #

    return pipeline
Ejemplo n.º 27
0
def pcal2darm(pipeline, name):

    # Get pcal from the raw frames
    raw_data = pipeparts.mklalcachesrc(pipeline,
                                       location=options.raw_frame_cache,
                                       cache_dsc_regex=ifo)
    raw_data = pipeparts.mkframecppchanneldemux(
        pipeline,
        raw_data,
        do_file_checksum=False,
        skip_bad_files=True,
        channel_list=list(map("%s:%s".__mod__, channel_list)))
    pcal = calibration_parts.hook_up(pipeline, raw_data,
                                     options.pcal_channel_name, ifo, 1.0)
    pcal = calibration_parts.caps_and_progress(
        pipeline, pcal,
        "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
        "pcal")
    pcal = pipeparts.mktee(pipeline, pcal)

    # Demodulate the pcal channel at the lines of interest
    for i in range(0, len(frequencies)):
        demodulated_pcal = calibration_parts.demodulate(
            pipeline,
            pcal,
            frequencies[i],
            True,
            rate_out,
            filter_time,
            0.5,
            prefactor_real=pcal_corrections[2 * i],
            prefactor_imag=pcal_corrections[2 * i + 1])
        demodulated_pcal_list.append(
            pipeparts.mktee(pipeline, demodulated_pcal))

    # Check if we are taking pcal-to-darm ratios for CALCS data
    for channel, label in zip(calcs_channels, labels[0:len(calcs_channels)]):
        calcs_deltal = calibration_parts.hook_up(pipeline, raw_data, channel,
                                                 ifo, 1.0)
        calcs_deltal = calibration_parts.caps_and_progress(
            pipeline, calcs_deltal,
            "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
            label)
        calcs_deltal = pipeparts.mktee(pipeline, calcs_deltal)
        for i in range(0, len(frequencies)):
            # Demodulate DELTAL_EXTERNAL at each line
            demodulated_calcs_deltal = calibration_parts.demodulate(
                pipeline, calcs_deltal, frequencies[i], True, rate_out,
                filter_time, 0.5)
            # Take ratio \DeltaL(f) / pcal(f)
            deltaL_over_pcal = calibration_parts.complex_division(
                pipeline, demodulated_calcs_deltaL, demodulated_pcal_list[i])
            # Take a running average
            deltaL_over_pcal = pipeparts.mkgeneric(
                pipeline,
                deltaL_over_pcal,
                "lal_smoothkappas",
                array_size=1,
                avg_array_size=int(rate_out * average_time))
            # Write to file
            pipeparts.mknxydumpsink(
                pipeline, deltaL_over_pcal,
                "%s_%s_over_%s_at_line%d.txt" % (ifo, label.replace(
                    ' ', '_'), options.pcal_channel_name, i + 1))

    # Check if we are taking pcal-to-darm ratios for gstlal calibrated data
    if options.gstlal_channel_list is not None:
        cache_num = 0
        for cache, channel, label in zip(
                gstlal_frame_cache_list, gstlal_channels,
                labels[len(calcs_channels):len(channel_list)]):
            # Get gstlal channels from the gstlal frames
            hoft_data = pipeparts.mklalcachesrc(pipeline,
                                                location=cache,
                                                cache_dsc_regex=ifo)
            hoft_data = pipeparts.mkframecppchanneldemux(
                pipeline,
                hoft_data,
                do_file_checksum=False,
                skip_bad_files=True,
                channel_list=list(
                    map("%s:%s".__mod__, channel_list + DQ_channels)))
            hoft = calibration_parts.hook_up(pipeline,
                                             hoft_data,
                                             channel,
                                             ifo,
                                             1.0,
                                             element_name_suffix="_%d" %
                                             cache_num)
            hoft = calibration_parts.caps_and_progress(
                pipeline, hoft,
                "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
                label)
            deltal = pipeparts.mkaudioamplify(pipeline, hoft, arm_length)
            deltal = pipeparts.mktee(pipeline, deltal)

            # Get a DQ channel
            DQ_channel = "%sCALIB_STATE_VECTOR%s" % (chan_prefixes[cache_num],
                                                     chan_suffixes[cache_num])
            DQ = calibration_parts.hook_up(pipeline,
                                           hoft_data,
                                           DQ_channel,
                                           ifo,
                                           1.0,
                                           element_name_suffix="_%d" %
                                           cache_num)
            DQ = calibration_parts.caps_and_progress(
                pipeline, DQ,
                "audio/x-raw,format=U32LE,channels=1,channel-mask=(bitmask)0x0",
                "DQ_%s" % label)
            DQ = pipeparts.mkgeneric(pipeline,
                                     DQ,
                                     "lal_logicalundersample",
                                     required_on=1,
                                     status_out=1)
            DQ = pipeparts.mkcapsfilter(
                pipeline, DQ,
                "audio/x-raw,format=U32LE,rate=%d,channels=1,channel-mask=(bitmask)0x0"
                % rate_out)
            DQ = pipeparts.mkgeneric(
                pipeline,
                DQ,
                "lal_drop",
                drop_samples=int((7.0 + 0.5 * filter_time) * rate_out + 0.5))
            DQ = pipeparts.mktee(pipeline, DQ)

            for i in range(0, len(frequencies)):
                # Demodulate \DeltaL at each line
                demodulated_deltal = calibration_parts.demodulate(
                    pipeline, deltal, frequencies[i], True, rate_out,
                    filter_time, 0.5)
                # Take ratio \DeltaL(f) / pcal(f)
                deltaL_over_pcal = calibration_parts.complex_division(
                    pipeline, demodulated_deltal, demodulated_pcal_list[i])
                # Take a running average
                deltaL_over_pcal = pipeparts.mkgeneric(
                    pipeline,
                    deltaL_over_pcal,
                    "lal_smoothkappas",
                    array_size=1,
                    avg_array_size=int(rate_out * average_time))
                # Find the magnitude
                deltaL_over_pcal = pipeparts.mktee(pipeline, deltaL_over_pcal)
                magnitude = pipeparts.mkgeneric(pipeline, deltaL_over_pcal,
                                                "cabs")
                # Find the phase
                phase = pipeparts.mkgeneric(pipeline, deltaL_over_pcal, "carg")
                phase = pipeparts.mkaudioamplify(pipeline, phase,
                                                 180.0 / numpy.pi)
                # Interleave
                magnitude_and_phase = calibration_parts.mkinterleave(
                    pipeline, [magnitude, phase])
                # Gate with DQ channel
                magnitude_and_phase = calibration_parts.mkgate(
                    pipeline, magnitude_and_phase, DQ, 1)
                magnitude_and_phase = pipeparts.mkprogressreport(
                    pipeline,
                    magnitude_and_phase,
                    name="progress_sink_%s_%d" % (label, i))
                # Write to file
                pipeparts.mknxydumpsink(
                    pipeline, magnitude_and_phase,
                    "%s_%s_over_%s_at_%0.1fHz_%d.txt" %
                    (ifo, label.replace(' ', '_'), options.pcal_channel_name,
                     frequencies[i], options.gps_start_time))
            cache_num = cache_num + 1

    #
    # done
    #

    return pipeline
    path = options.output_path
    if path:
        fs = pipeparts.mkframecppfilesink(pipeline, tagInj, 
            frame_type = options.frame_type, path = options.output_path)
    else:
        fs = pipeparts.mkframecppfilesink(pipeline, mux, 
            frame_type = options.frame_type)
elif options.output_type == "tcp":
    # NB: like the appsrc, the tcp client sink does not use the 'blocksize' property. 
    # It is just hanging around because it is inherited
    # gstdataprotocol serializes and sends the caps first. Then serializes and 
    # sends the buffers. Less work for us.

    # XXX Sadness. The capsfilter is not "gap-aware". So the gap flag will be unset.
    mux = pipeparts.mkcapsfilter(pipeline,mux,caps="application/x-igwd-frame,framed=true")
    tcpclientsink = pipeparts.mkgeneric(pipeline, mux, "tcpclientsink")
    tcpclientsink.set_property("protocol", "GST_TCP_PROTOCOL_GDP")
    tcpclientsink.set_property("port", options.port)
    tcpclientsink.set_property("sync", False)
    # XXX Hack. Attach pad probe to sink pad of tcpclientsink
    tcs_pad = tcpclientsink.get_pad("sink")
    tcs_pad.add_buffer_probe(hc.lateBufferHandler)
else:
    raise ValueError("Invalid output type.")

#
# Start the thing going.
#

pipeline.set_state(gst.STATE_PLAYING)