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

    #
    # This pipeline reads the channels needed for calibration from the raw frames
    # and writes them to smaller frames for faster access.
    #

    head_dict = {}

    # Get the data from the raw frames and pick out the channels we want
    src = pipeparts.mklalcachesrc(pipeline,
                                  location=frame_cache,
                                  cache_dsc_regex=ifo)
    src = pipeparts.mkprogressreport(pipeline, src, "start")
    demux = pipeparts.mkframecppchanneldemux(pipeline,
                                             src,
                                             do_file_checksum=False,
                                             skip_bad_files=True,
                                             channel_list=list(
                                                 map("%s:%s".__mod__,
                                                     ifo_channel_list)))

    # Make a muxer to collect the channels we need
    channelmux_input_dict = {}
    for key, chan in zip(channel_list, channel_list):
        head_dict[key] = calibration_parts.hook_up(pipeline, demux, chan, ifo,
                                                   1.0)
        head_dict[key] = pipeparts.mkprogressreport(pipeline, head_dict[key],
                                                    "before muxer %s" % key)
        channelmux_input_dict["%s:%s" %
                              (ifo, chan)] = calibration_parts.mkqueue(
                                  pipeline, head_dict[key])

    if output_path == 'txt':
        for chan in channel_list:
            pipeparts.mknxydumpsink(
                pipeline, channelmux_input_dict["%s:%s" % (ifo, chan)],
                "%s-%s.txt" % (ifo, chan))
    else:
        mux = pipeparts.mkframecppchannelmux(pipeline,
                                             channelmux_input_dict,
                                             frame_duration=frame_length,
                                             frames_per_file=frames_per_file,
                                             compression_scheme=6,
                                             compression_level=3)
        mux = pipeparts.mkprogressreport(pipeline, mux, "end")
        pipeparts.mkframecppfilesink(pipeline,
                                     mux,
                                     frame_type=frame_type,
                                     path=output_path,
                                     instrument=ifo)

    #
    # done
    #

    return pipeline
Пример #2
0
def test_src(pipeline,
             buffer_length=1.0,
             rate=2048,
             width=64,
             channels=1,
             test_duration=10.0,
             wave=5,
             freq=0,
             volume=1,
             is_live=False,
             verbose=True,
             src_suffix=""):
    if wave == "ligo":
        head = pipeparts.mkfakeLIGOsrc(pipeline,
                                       instrument="H1",
                                       channel_name="LSC-STRAIN")
    else:
        head = pipeparts.mkaudiotestsrc(
            pipeline,
            wave=wave,
            freq=freq,
            volume=volume,
            samplesperbuffer=int(buffer_length * rate),
            num_buffers=int(test_duration / buffer_length),
            is_live=is_live)
        head = pipeparts.mkcapsfilter(
            pipeline, head,
            "audio/x-raw, format=F%d%s, rate=%d, channels=%d, channel-mask=(bitmask)0x0"
            % (width, BYTE_ORDER, rate, channels))
    if verbose:
        head = pipeparts.mkprogressreport(pipeline, head, "src%s" % src_suffix)
    return head
Пример #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 mkLLOIDSnrChisqToTriggers(pipeline,
                              snr,
                              chisq,
                              bank,
                              verbose=False,
                              nxydump_segment=None,
                              logname=""):
    """!
	Build pipeline fragment that converts single detector SNR and Chisq
	into triggers.
	"""
    #
    # trigger generator and progress report
    #

    head = pipeparts.mktriggergen(
        pipeline,
        snr,
        chisq,
        template_bank_filename=bank.template_bank_filename,
        snr_threshold=bank.snr_threshold,
        sigmasq=bank.sigmasq)
    # FIXME:  add ability to choose this
    # "lal_blcbctriggergen", {"bank-filename": bank.template_bank_filename, "snr-thresh": bank.snr_threshold, "sigmasq": bank.sigmasq}
    if verbose:
        head = pipeparts.mkprogressreport(pipeline, head,
                                          "progress_xml_%s" % logname)

    #
    # done
    #

    return head
Пример #5
0
def mkcontrolsnksrc(pipeline,
                    rate,
                    verbose=False,
                    suffix=None,
                    control_peak_samples=None):
    """!
	This function implements a portion of a gstreamer graph to provide a
	control signal for deciding when to reconstruct physical SNRS

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

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

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

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

    #
    # verbosity and a tee
    #

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

    #
    # return the adder and tee
    #

    return snk, src
Пример #6
0
def int_test_src(pipeline,
                 buffer_length=1.0,
                 rate=2048,
                 width=64,
                 channels=1,
                 test_duration=10.0,
                 wave=5,
                 freq=0,
                 is_live=False,
                 verbose=True):
    head = pipeparts.mkaudiotestsrc(pipeline,
                                    wave=wave,
                                    freq=freq,
                                    samplesperbuffer=int(buffer_length * rate),
                                    volume=1,
                                    num_buffers=int(test_duration /
                                                    buffer_length),
                                    is_live=is_live)
    head = pipeparts.mkcapsfilter(
        pipeline, head, "audio/x-raw, format=S%d%s, rate=%d, channels=%d" %
        (width, BYTE_ORDER, rate, channels))
    if verbose:
        head = pipeparts.mkprogressreport(pipeline, head, "src")
    return head
Пример #7
0
def lal_transferfunction_03(pipeline, name):

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

    rate = 16384  # Hz
    buffer_length = 1.0  # seconds
    test_duration = 50.0  # seconds
    width = 64  # bits
    freq = 512  # Hz
    num_witnesses = 2
    witness_factor = 0.5  # Ratio of amplitudes of witness / signal

    #
    # build pipeline
    #

    hoft = test_common.test_src(pipeline,
                                buffer_length=buffer_length,
                                wave=5,
                                volume=1,
                                freq=freq,
                                channels=1,
                                rate=rate,
                                test_duration=test_duration,
                                width=width,
                                verbose=False)
    hoft = pipeparts.mktee(pipeline, hoft)

    noise = []
    for i in range(0, num_witnesses):
        difference = test_common.test_src(pipeline,
                                          buffer_length=buffer_length,
                                          wave=5,
                                          volume=0.001,
                                          channels=1,
                                          rate=rate,
                                          test_duration=test_duration,
                                          width=width,
                                          verbose=False)
        noisy_hoft = calibration_parts.mkadder(
            pipeline,
            calibration_parts.list_srcs(
                pipeline,
                pipeparts.mkaudioamplify(pipeline, hoft, witness_factor),
                difference))
        noisy_hoft = pipeparts.mkprogressreport(pipeline, noisy_hoft,
                                                "noisy_hoft_%d" % i)
        noise.append(noisy_hoft)

    clean_data = calibration_parts.clean_data(pipeline,
                                              hoft,
                                              rate,
                                              noise,
                                              rate,
                                              2 * rate,
                                              rate,
                                              10,
                                              rate * 1000,
                                              rate,
                                              4,
                                              filename="tfs.txt")
    pipeparts.mknxydumpsink(pipeline, hoft, "%s_hoft.txt" % name)
    pipeparts.mknxydumpsink(pipeline, clean_data, "%s_out.txt" % name)

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

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

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

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

    return src
Пример #9
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
Пример #10
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
Пример #11
0
def mkLLOIDmulti(pipeline,
                 detectors,
                 banks,
                 psd,
                 psd_fft_length=32,
                 ht_gate_threshold=float("inf"),
                 veto_segments=None,
                 verbose=False,
                 nxydump_segment=None,
                 chisq_type='autochisq',
                 track_psd=False,
                 fir_stride=16,
                 control_peak_time=2,
                 block_duration=Gst.SECOND,
                 reconstruction_segment_list=None):
    """!
	The multiple instrument, multiple bank LLOID algorithm
	"""

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

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

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

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

    #
    # build gate control branches
    #

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

    #
    # construct trigger generators
    #

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

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

    #
    # done
    #

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