Ejemplo n.º 1
0
def lal_matrixsolver_01(pipeline, name):

    #
    # Make a bunch of fake data at 16 Hz to pass through the exact kappas function.
    #

    rate_in = 16  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 300.0  # seconds
    channels = 10 * 11  # inputs to lal_matrixsolver

    #
    # build pipeline
    #

    head = test_common.test_src(pipeline,
                                buffer_length=buffer_length,
                                rate=rate_in,
                                width=64,
                                channels=channels,
                                test_duration=test_duration,
                                wave=5,
                                freq=0)
    streams = calibration_parts.mkdeinterleave(pipeline, head, channels)
    head = calibration_parts.mkinterleave(pipeline, streams)
    solutions = pipeparts.mkgeneric(pipeline, head, "lal_matrixsolver")
    solutions = list(calibration_parts.mkdeinterleave(pipeline, solutions, 10))
    for i in range(10):
        pipeparts.mknxydumpsink(pipeline, solutions[i], "solutions_%d.txt" % i)

    #
    # 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 lal_transferfunction_04(pipeline, name):

    #
    # This test produces three-channel data to be read into lal_transferfunction
    #

    rate = 16384  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 500.0  # seconds
    width = 64  # bits
    channels = 1
    freq = 512  # Hz

    #
    # build pipeline
    #

    hoft = test_common.test_src(pipeline,
                                buffer_length=buffer_length,
                                wave=5,
                                volume=1,
                                freq=freq,
                                channels=channels,
                                rate=rate,
                                test_duration=test_duration,
                                width=width,
                                verbose=False)
    hoft = pipeparts.mktee(pipeline, hoft)
    shifted_hoft = pipeparts.mkgeneric(pipeline,
                                       hoft,
                                       "lal_shift",
                                       shift=35024)
    interleaved_data = calibration_parts.mkinterleave(
        pipeline, calibration_parts.list_srcs(pipeline, hoft, shifted_hoft))
    pipeparts.mkgeneric(pipeline,
                        interleaved_data,
                        "lal_transferfunction",
                        fft_length=4 * rate,
                        fft_overlap=2 * rate,
                        num_ffts=64,
                        update_samples=rate * test_duration,
                        make_fir_filters=1,
                        fir_length=rate,
                        update_after_gap=True,
                        filename="lpfilter.txt")

    return pipeline
Ejemplo n.º 4
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(calcs_channels) +
                       len(gstlal_channels)]):
            # 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)))
            hoft = calibration_parts.hook_up(pipeline,
                                             hoft_data,
                                             channel,
                                             ifo,
                                             1.0,
                                             element_name_suffix="_%d" %
                                             cache_num)
            cache_num = cache_num + 1
            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)
            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])
                # 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))

        # Check of we are reading in kappa channels
        if options.kappa_channel_list is not None:
            # Get gstlal channels from the gstlal frames
            kappa_data = pipeparts.mklalcachesrc(
                pipeline,
                location=gstlal_frame_cache_list[0],
                cache_dsc_regex=ifo)
            kappa_data = pipeparts.mkframecppchanneldemux(
                pipeline,
                kappa_data,
                do_file_checksum=False,
                skip_bad_files=True,
                channel_list=list(map("%s:%s".__mod__, channel_list)))
            for i in range(len(kappa_channels) // 2):
                kappa_real = calibration_parts.hook_up(
                    pipeline,
                    kappa_data,
                    kappa_channels[2 * i],
                    ifo,
                    1.0,
                    element_name_suffix="_%d" % (2 * i))
                kappa_imag = calibration_parts.hook_up(
                    pipeline,
                    kappa_data,
                    kappa_channels[2 * i + 1],
                    ifo,
                    1.0,
                    element_name_suffix="_%d" % (2 * i + 1))
                kappa_real = calibration_parts.caps_and_progress(
                    pipeline, kappa_real,
                    "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
                    kappa_channels[2 * i])
                kappa_imag = calibration_parts.caps_and_progress(
                    pipeline, kappa_imag,
                    "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
                    kappa_channels[2 * i + 1])
                kappa = calibration_parts.merge_into_complex(
                    pipeline, kappa_real, kappa_imag)
                phase_angle = pipeparts.mkgeneric(pipeline, kappa, "carg")

                actuation_stage = 'UNKNOWN'
                act_freq = 17.0  # A guess...
                if 'TST' in kappa_channels[2 * i]:
                    actuation_stage = 'T'
                    act_freq = float(filters["ktst_esd_line_freq"])
                elif 'PUM' in kappa_channels[2 * i]:
                    actuation_stage = 'P'
                    act_freq = float(filters["pum_act_line_freq"])
                elif 'UIM' in kappa_channels[2 * i]:
                    actuation_stage = 'U'
                    act_freq = float(filters["uim_act_line_freq"])
                elif 'PU' in kappa_channels[2 * i]:
                    actuation_stage = 'PU'
                    act_freq = float(filters["ka_esd_line_freq"])

                actuation_stages.append(actuation_stage)

                tau = pipeparts.mkaudioamplify(
                    pipeline, phase_angle,
                    1000000.0 / 2.0 / numpy.pi / act_freq)

                pipeparts.mknxydumpsink(
                    pipeline, tau, "%s_%s_%d.txt" %
                    (ifo, actuation_stage, options.gps_start_time))

    #
    # done
    #

    return pipeline
Ejemplo n.º 5
0
def plot_transfer_function(pipeline, name):
    # Get the data from the denominator frames
    denominator = pipeparts.mklalcachesrc(
        pipeline,
        location=options.denominator_frame_cache,
        cache_dsc_regex=ifo)
    denominator = pipeparts.mkframecppchanneldemux(
        pipeline,
        denominator,
        do_file_checksum=False,
        skip_bad_files=True,
        channel_list=list(map("%s:%s".__mod__, channel_list)))
    denominator = calibration_parts.hook_up(pipeline, denominator,
                                            options.denominator_channel_name,
                                            ifo, 1.0)
    denominator = calibration_parts.caps_and_progress(
        pipeline, denominator, "audio/x-raw,format=F64LE", "denominator")
    denominator = calibration_parts.mkresample(pipeline, denominator, 5, False,
                                               int(sample_rate))
    if denominator_correction is not None:
        if numpy.size(filters[denominator_correction]) == 1:
            denominator = pipeparts.mkaudioamplify(
                pipeline, denominator, float(filters[denominator_correction]))
    denominator = pipeparts.mktee(pipeline, denominator)

    # Get the data from the numerator frames
    for i in range(0, len(labels)):
        numerator = pipeparts.mklalcachesrc(
            pipeline,
            location=numerator_frame_cache_list[i],
            cache_dsc_regex=ifo)
        numerator = pipeparts.mkframecppchanneldemux(
            pipeline,
            numerator,
            do_file_checksum=False,
            skip_bad_files=True,
            channel_list=list(map("%s:%s".__mod__, channel_list)))
        numerator = calibration_parts.hook_up(pipeline,
                                              numerator,
                                              numerator_channel_list[i],
                                              ifo,
                                              1.0,
                                              element_name_suffix="%d" % i)
        numerator = calibration_parts.caps_and_progress(
            pipeline, numerator, "audio/x-raw,format=F64LE", labels[i])
        numerator = calibration_parts.mkresample(pipeline, numerator, 5, False,
                                                 int(sample_rate))
        if numerator_correction is not None:
            if numerator_correction[i] is not None:
                if numpy.size(filters[numerator_correction[i]] == 1):
                    numerator = pipeparts.mkaudioamplify(
                        pipeline, numerator,
                        float(filters[numerator_correction[i]]))
        # Interleave the channels to make one stream
        channels = calibration_parts.mkinterleave(pipeline,
                                                  [numerator, denominator])
        # Send the data to lal_transferfunction to compute and write transfer functions
        pipeparts.mkgeneric(pipeline,
                            channels,
                            "lal_transferfunction",
                            fft_length=fft_length,
                            fft_overlap=fft_overlap,
                            num_ffts=num_ffts,
                            fir_length=td_tf_length,
                            use_median=True if options.use_median else False,
                            update_samples=1e15,
                            filename='%s_%s_over_%s_%d-%d.txt' %
                            (ifo, labels[i].replace(' ', '_').replace(
                                '/', 'over'), options.denominator_channel_name,
                             options.gps_start_time, data_duration))

    #
    # done
    #

    return pipeline
Ejemplo n.º 6
0
def demod_ratio(pipeline, name):

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

    # Get numerator data from the raw frames
    if not options.denominator_frame_cache == options.numerator_frame_cache:
        numerator_data = pipeparts.mklalcachesrc(
            pipeline,
            location=options.numerator_frame_cache,
            cache_dsc_regex=ifo)
        numerator_data = pipeparts.mkframecppchanneldemux(
            pipeline,
            numerator_data,
            do_file_checksum=False,
            skip_bad_files=True,
            channel_list=list(map("%s:%s".__mod__, channel_list)))
        numerator = calibration_parts.hook_up(pipeline, numerator_data,
                                              options.numerator_channel_name,
                                              ifo, 1.0)
    else:
        numerator = calibration_parts.hook_up(pipeline, denominator_data,
                                              options.numerator_channel_name,
                                              ifo, 1.0)
    numerator = calibration_parts.caps_and_progress(
        pipeline, numerator,
        "audio/x-raw,format=F64LE,channels=1,channel-mask=(bitmask)0x0",
        "numerator")
    numerator = pipeparts.mktee(pipeline, numerator)

    # Demodulate numerator and denominator at each frequency, take ratios, and write to file
    for i in range(0, len(frequencies)):
        # Demodulate
        demodulated_denominator = calibration_parts.demodulate(
            pipeline, denominator, frequencies[i], True, rate_out, filter_time,
            0.5)
        demodulated_numerator = calibration_parts.demodulate(
            pipeline, numerator, frequencies[i], True, rate_out, filter_time,
            0.5)
        demodulated_numerator = pipeparts.mktee(pipeline,
                                                demodulated_numerator)
        demodulated_denominator = pipeparts.mktee(pipeline,
                                                  demodulated_denominator)
        # Take ratio
        ratio = calibration_parts.complex_division(pipeline,
                                                   demodulated_numerator,
                                                   demodulated_denominator)
        # Average
        ratio = pipeparts.mkgeneric(pipeline,
                                    ratio,
                                    "lal_smoothkappas",
                                    array_size=1,
                                    avg_array_size=int(rate_out *
                                                       average_time),
                                    filter_latency=1.0)
        # Find magnitude and phase
        ratio = pipeparts.mktee(pipeline, ratio)
        magnitude = pipeparts.mkgeneric(pipeline, ratio, "cabs")
        phase = pipeparts.mkgeneric(pipeline, ratio, "carg")
        phase = pipeparts.mkaudioamplify(pipeline, phase, 180.0 / numpy.pi)
        # Interleave
        magnitude_and_phase = calibration_parts.mkinterleave(
            pipeline, [magnitude, phase])
        # Write to file
        pipeparts.mknxydumpsink(
            pipeline, magnitude_and_phase, "%s_%s_over_%s_%0.1fHz.txt" %
            (ifo, options.numerator_channel_name,
             options.denominator_channel_name, frequencies[i]))

    #
    # done
    #

    return pipeline
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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