示例#1
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
示例#2
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
示例#3
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
示例#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 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))
示例#6
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
示例#7
0
def lal_insertgap_test_02(pipeline, name):
    #
    # This tests the element's treatment of complex data streams.
    #

    rate = 1000  # Hz
    width = 32
    buffer_length = 1.0  # seconds
    test_duration = 100.0  # seconds
    gap_frequency = 0.1  # Hz
    gap_threshold = 0.0
    control_dump_filename = "control_insertgap_test_01.dump"
    #bad_data_intervals = numpy.random.random((4,)).astype("float64")
    #bad_data_intervals2 = numpy.random.random((4,)).astype("float64")
    bad_data_intervals = [-1e35, -1.0, -0.5, 1e35]
    bad_data_intervals2 = [-1e35, 0.5, 1.0, 1e35]

    head = test_common.gapped_test_src(
        pipeline,
        buffer_length=buffer_length,
        rate=rate,
        width=width,
        channels=2,
        test_duration=test_duration,
        wave=0,
        freq=1,
        volume=1,
        gap_frequency=gap_frequency,
        gap_threshold=gap_threshold,
        control_dump_filename=control_dump_filename)
    head = pipeparts.mktogglecomplex(pipeline, head)
    #head = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, width = width, channels = 1, test_duration = test_duration, wave = 5, freq = 0, volume = 1)
    head = pipeparts.mkgeneric(pipeline,
                               head,
                               "lal_insertgap",
                               bad_data_intervals=bad_data_intervals,
                               insert_gap=True,
                               fill_discont=True,
                               replace_value=3.0)
    head = pipeparts.mktee(pipeline, head)
    pipeparts.mknxydumpsink(pipeline, head, "%s_in.dump" % name)
    head = pipeparts.mkgeneric(pipeline,
                               head,
                               "lal_insertgap",
                               bad_data_intervals=bad_data_intervals2,
                               insert_gap=True,
                               remove_gap=True,
                               fill_discont=True,
                               replace_value=7.0)
    pipeparts.mknxydumpsink(pipeline, head, "%s_out.dump" % name)

    #
    # done
    #

    return pipeline
示例#8
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
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_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
示例#11
0
def single_pole_filter_test(pipeline, name, line_sep=0.5):

    rate = 16384  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 1000  # seconds
    fcc_rate = 16  # Hz
    gain = 1.1
    fcc = 430  # Hz
    update_time = 20  # seconds

    #
    # build pipeline
    #

    # Make a source of fake data to act as input values for a gain and a zero
    gain_fcc_data = test_common.test_src(pipeline,
                                         rate=fcc_rate,
                                         test_duration=test_duration,
                                         wave=5,
                                         src_suffix="_gain_fcc_data")
    # Take to the power of 0 to make it a stream of ones
    gain_fcc_data = calibration_parts.mkpow(pipeline,
                                            gain_fcc_data,
                                            exponent=0.0)
    # Make a copy which we can use to make both the gain and the fcc data
    gain_fcc_data = pipeparts.mktee(pipeline, gain_fcc_data)
    # Make the gain data by multiplying ones by the gain
    gain_data = pipeparts.mkaudioamplify(pipeline, gain_fcc_data, gain)
    # Make the fcc data by multiplying ones by fcc
    fcc_data = pipeparts.mkaudioamplify(pipeline, gain_fcc_data, fcc)
    # Now, this needs to be used in the element lal_adaptivefirfilt to turn it into a FIR filter.
    # lal_adaptivefirfilt takes as inputs (in this order) zeros, poles, a complex factor containing gain and phase.
    # Type "$ gst-inspect-1.0 lal_adaptivefirfilt" for info about the element.
    # Each of the inputs must be a complex data stream, so we first must make these real streams complex
    gain_data = pipeparts.mktogglecomplex(
        pipeline,
        pipeparts.mkmatrixmixer(pipeline, gain_data, matrix=[[1.0, 0.0]]))
    fcc_data = pipeparts.mktogglecomplex(
        pipeline,
        pipeparts.mkmatrixmixer(pipeline, fcc_data, matrix=[[1.0, 0.0]]))
    # Now we must interleave these streams, since lal_adaptivefirfilt takes a single multi-channel stream of interleaved data.
    # The fcc data (the zero frequency) must come first so that it is channel 0; that way lal_adaptivefirfilt recognizes it as such.
    filter_data = calibration_parts.mkinterleave(pipeline,
                                                 [fcc_data, gain_data],
                                                 complex_data=True)
    # Finally, send the interleaved data to lal_adaptivefirfilt, which will make a FIR filter.
    # Note that it needs to know the number of zeros and poles.
    # update_samples tells it how often to send a new filter to the filtering element
    # minimize_filter_length must be True for it to use a 2-tap filter.  Otherwise, it makes a longer FIR filter using and iFFT from a frequency-domain model.
    # This will also write the filter coefficients to file.
    adaptive_invsens_filter = calibration_parts.mkadaptivefirfilt(
        pipeline,
        filter_data,
        update_samples=int(update_time * fcc_rate),
        average_samples=1,
        num_zeros=1,
        num_poles=0,
        filter_sample_rate=rate,
        minimize_filter_length=True,
        filename="%s_FIR_filter.txt" % name)

    # Now make time series source of white noise to be filtered (wave = 5 means white noise)
    in_signal = test_common.test_src(pipeline,
                                     rate=rate,
                                     test_duration=test_duration,
                                     wave=5,
                                     src_suffix="_in_signal")
    # Make a copy of input data so that we can write it to file
    in_signal = pipeparts.mktee(pipeline, in_signal)
    # Write input time series to file
    pipeparts.mknxydumpsink(pipeline, in_signal, "%s_in.txt" % name)
    # Filter the data using lal_tdwhiten, which handles smooth filter updates
    # The property "kernel" is the FIR filter we will update.  To start, give a trivial default value.
    # The "taper_length" is the number of samples over which to handle filter transitions.  It is set to be 1 second.
    out_signal = pipeparts.mkgeneric(pipeline,
                                     in_signal,
                                     "lal_tdwhiten",
                                     kernel=[0, 1],
                                     latency=0,
                                     taper_length=rate)
    # Hook up the adaptive filter from lal_adaptivefirfilt to lal_tdwhiten so that the filter gets updated
    adaptive_invsens_filter.connect("notify::adaptive-filter",
                                    calibration_parts.update_filter,
                                    out_signal, "adaptive_filter", "kernel")
    # Correct the 1/2-sample shift in timestamps by applying a linear-phase FIR filter
    # The last argument here (0.5) is the number of samples worth of timestamp advance to apply to the data.  You might want to try -0.5 as well, since I often get advances and delays mixed up.
    out_signal = calibration_parts.linear_phase_filter(pipeline, out_signal,
                                                       0.5)
    # Make a copy, so that we can write the time series to file and send it to lal_transferfunction
    out_signal = pipeparts.mktee(pipeline, out_signal)
    # Finally, write the output to file
    pipeparts.mknxydumpsink(pipeline, out_signal, "%s_out.txt" % name)

    # Now, take the input and output and compute a transfer function.
    # First, we need to interleave the data for use by lal_transferfunction. The numerator comes first
    tf_input = calibration_parts.mkinterleave(pipeline,
                                              [out_signal, in_signal])
    # Remove some initial samples in case they were filtered by the default dummy filter [0, 1]
    tf_input = calibration_parts.mkinsertgap(
        pipeline, tf_input,
        chop_length=Gst.SECOND * 50)  # Removing 50 s of initial data
    # Send to lal_transferfunction, which will compute the frequency-domain transfer function between the input and output data and write it to file
    calibration_parts.mktransferfunction(
        pipeline,
        tf_input,
        fft_length=16 * rate,
        fft_overlap=8 * rate,
        num_ffts=(test_duration - 50) / 8 - 3,
        use_median=True,
        update_samples=1e15,
        filename="%s_filter_transfer_function.txt" % name)

    # You could, for instance, compare this transfer function to what you expect, i.e., gain * (1 + i f / fcc), and plot the comparison in the frequency-domain.  I'm guessing there will be a fair amount of work involved in getting everything to work and getting the result correct.

    #
    # done
    #

    return pipeline
示例#12
0
def peak_test_01a(pipeline, name, handler):
    #
    # try changing these.  test should still work!
    #

    initial_channels = 2
    rate = 2048  #Hz
    width = 32
    sine_frequency = 1
    gap_frequency = 0.1  # Hz
    gap_threshold = 0.7  # of 1
    buffer_length = 1.0  # seconds
    test_duration = 10.0  # seconds
    peak_window = 2048  # samples
    wave = 0

    #
    # build pipeline
    #

    head = test_common.gapped_test_src(
        pipeline,
        buffer_length=buffer_length,
        rate=rate,
        width=width,
        channels=initial_channels,
        test_duration=test_duration,
        gap_frequency=gap_frequency,
        gap_threshold=gap_threshold,
        control_dump_filename="%s_control.dump" % name)
    head = pipeparts.mktogglecomplex(pipeline, head)
    head = pipeparts.mktaginject(
        pipeline, head, "instrument=H1,channel-name=LSC-STRAIN,units=strain")

    #head = test_common.gapped_complex_test_src(pipeline, buffer_length = buffer_length, rate = in_rate, test_duration = test_duration, wave = wave, freq = sine_frequency, gap_frequency = gap_frequency, gap_threshold = gap_threshold, control_dump_filename = "itac_test_01a_control.dump", tags = "instrument=H1,channel-name=LSC-STRAIN,units=strain")
    #head = tee = pipeparts.mktee(pipeline, head)
    #pipeparts.mktrigger(pipeline, head, peak_window, "test_bank.xml")

    # Does not recieve EOS, hangs
    #pipeparts.mktrigger(pipeline, head, peak_window,autocorrelation_matrix = numpy.ones((1,21), dtype=numpy.complex))

    #head = pipeparts.mkqueue(pipeline, pipeparts.mkitac(pipeline, head, peak_window, "test_bank.xml", autocorrelation_matrix = numpy.array([[0+0.j, 0+0.j, 1+1.j, 0+0.j, 0+0.j]])))
    #head = pipeparts.mkprogressreport(pipeline, head, "test")

    #
    # output the before and after
    #
    #pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head), "%s_out.dump" % name)
    #pipeparts.mkfakesink(pipeline, head)

    #a = pipeparts.mkappsink(pipeline, pipeparts.mkqueue(pipeline, head))

    head = pipeparts.mkgeneric(pipeline, head, "lal_nxydump")

    sink = pipeparts.mkappsink(pipeline, head, max_buffers=1, sync=False)
    sink.connect("new-sample", handler.bufhandler)
    sink.connect("new-preroll", handler.prehandler)

    #outfile = open("itac_test_01a_out.dump", "w")

    #def dump_triggers(elem, output = outfile):
    #	for row in SnglInspiralTable.from_buffer(elem.emit("pull-buffer")):
    #		print >>outfile, row.end_time + row.end_time_ns*1e-9, row.snr, row.chisq, row.chisq_dof

    #a.connect_after("new-buffer", dump_triggers)
    #pipeparts.mknxydumpsink(pipeline, pipeparts.mktogglecomplex(pipeline, pipeparts.mkqueue(pipeline, tee)), "itac_test_01a_in.dump")

    #
    # done
    #

    #if "GST_DEBUG_DUMP_DOT_DIR" in os.environ:
    #	gst.DEBUG_BIN_TO_DOT_FILE(pipeline, gst.DEBUG_GRAPH_SHOW_ALL, "peak_test_01a")

    return pipeline
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
示例#14
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)