Пример #1
0
def return_empty_sngl():
    """
    Function to create a SnglInspiral object where all columns are populated
    but all are set to values that test False (ie. strings to '', floats/ints
    to 0, ...). This avoids errors when you try to create a table containing
    columns you don't care about, but which still need populating. NOTE: This
    will also produce a process_id and event_id with 0 values. For most
    applications these should be set to their correct values.

    Returns
    --------
    lsctables.SnglInspiral
        The "empty" SnglInspiral object.
    """

    sngl = lsctables.SnglInspiral()
    cols = lsctables.SnglInspiralTable.validcolumns
    for entry in cols.keys():
        if cols[entry] in ['real_4', 'real_8']:
            setattr(sngl, entry, 0.)
        elif cols[entry] == 'int_4s':
            setattr(sngl, entry, 0)
        elif cols[entry] == 'lstring':
            setattr(sngl, entry, '')
        elif entry == 'process_id':
            sngl.process_id = ilwd.ilwdchar("process:process_id:0")
        elif entry == 'event_id':
            sngl.event_id = ilwd.ilwdchar("sngl_inspiral:event_id:0")
        else:
            raise ValueError("Column %s not recognized" % (entry))
    return sngl
def detect_sngls(ifos, data, horizons, templates):
    for ifo, x, horizon, zW in zip(ifos, data, horizons, templates):
        # Apply matched filter
        rho = filter.fftfilt(zW, x.data.data)[len(zW)-1:]

        # Find maximum index
        i0 = long(round(-(template_duration + float(x.epoch - end_time)) * sample_rate))
        di = long(round(sample_rate * opts.trigger_window))
        imax = np.argmax(filter.abs2(rho[i0 - di:i0 + di])) + i0 - di

        # If SNR < threshold, then the injection is not found. Skip it.
        if abs(rho[imax]) < opts.snr_threshold:
            continue

        # Interpolate time series
        imax, rhomax = filter.interpolate_max(imax, rho, opts.interp_window, method=opts.interp_method)
        tmax = x.epoch + (imax / sample_rate + template_duration)

        # Add SnglInspiral entry.
        sngl_inspiral = lsctables.SnglInspiral()
        for validcolumn in sngl_inspiral_table.validcolumns.iterkeys():
            setattr(sngl_inspiral, validcolumn, None)
        sngl_inspiral.process_id = process.process_id
        sngl_inspiral.ifo = ifo
        sngl_inspiral.mass1 = mass1
        sngl_inspiral.mass2 = mass2
        sngl_inspiral.mtotal = mass1 + mass2
        sngl_inspiral.mchirp = (mass1 * mass2)**0.6 * sngl_inspiral.mtotal**-0.2
        sngl_inspiral.end_time = tmax.gpsSeconds
        sngl_inspiral.end_time_ns = tmax.gpsNanoSeconds
        sngl_inspiral.snr = abs(rhomax)
        sngl_inspiral.coa_phase = -np.angle(rhomax) # minus sign to match gstlal_inspiral phase convention
        sngl_inspiral.eff_distance = horizon / sngl_inspiral.snr
        yield sngl_inspiral
Пример #3
0
def _empty_row(obj):
    """Create an empty sim_inspiral or sngl_inspiral row where the columns have
    default values of 0.0 for a float, 0 for an int, '' for a string. The ilwd
    columns have a default where the index is 0.
    """

    # check if sim_inspiral or sngl_inspiral
    if obj == lsctables.SimInspiral:
        row = lsctables.SimInspiral()
        cols = lsctables.SimInspiralTable.validcolumns
    else:
        row = lsctables.SnglInspiral()
        cols = lsctables.SnglInspiralTable.validcolumns

    # populate columns with default values
    for entry in cols.keys():
        if cols[entry] in ['real_4', 'real_8']:
            setattr(row, entry, 0.)
        elif cols[entry] == 'int_4s':
            setattr(row, entry, 0)
        elif cols[entry] == 'lstring':
            setattr(row, entry, '')
        elif entry == 'process_id':
            row.process_id = ilwd.ilwdchar("sim_inspiral:process_id:0")
        elif entry == 'simulation_id':
            row.simulation_id = ilwd.ilwdchar("sim_inspiral:simulation_id:0")
        elif entry == 'event_id':
            row.event_id = ilwd.ilwdchar("sngl_inspiral:event_id:0")
        else:
            raise ValueError("Column %s not recognized." % (entry))

    return row
Пример #4
0
for name in param_names:
    col_names.append(name)

print param_names
if options.type == "sngl":
    sngl_inspiral_table = lsctables.New(lsctables.SnglInspiralTable,
                                        columns=col_names)
elif options.type == "sim":
    sngl_inspiral_table = lsctables.New(lsctables.SimInspiralTable,
                                        columns=col_names)

outdoc.childNodes[0].appendChild(sngl_inspiral_table)

for values in params:
    if options.type == "sngl":
        tmplt = lsctables.SnglInspiral()
    elif options.type == "sim":
        tmplt = lsctables.SimInspiral()

    tmplt.process_id = proc_id
    index = 0
    for value in values:
        if value is 'skip':
            continue
        setattr(tmplt, param_names[index], value)
        index += 1
    sngl_inspiral_table.append(tmplt)

# write the xml doc to disk
proctable = table.get_table(outdoc, lsctables.ProcessTable.tableName)
outname = 'table.xml'
    used_W = []

    # Loop over individual detectors and create SnglInspiral entries.
    for ifo, abs_snr, arg_snr, toa, horizon, location, signal_model, W_ in zip(
            opts.detector, abs_snrs, arg_snrs, toas, horizons, locations,
            signal_models, W):

        # If SNR < threshold, then the injection is not found. Skip it.
        if abs_snr >= opts.snr_threshold:
            count_triggers += 1
            net_snr += np.square(abs_snr)
        elif not opts.keep_subthreshold:
            continue

        # Create SnglInspiral entry.
        sngl_inspiral = lsctables.SnglInspiral()
        for validcolumn in sngl_inspiral_table.validcolumns.keys():
            setattr(sngl_inspiral, validcolumn, None)
        sngl_inspiral.process_id = process.process_id
        sngl_inspiral.ifo = ifo
        sngl_inspiral.mass1 = m1
        sngl_inspiral.mass2 = m2
        sngl_inspiral.end_time = (epoch + toa).gpsSeconds
        sngl_inspiral.end_time_ns = (epoch + toa).gpsNanoSeconds
        sngl_inspiral.snr = abs_snr
        sngl_inspiral.coa_phase = np.angle(np.exp(1j * arg_snr))
        sngl_inspiral.eff_distance = horizon / sngl_inspiral.snr
        sngl_inspirals.append(sngl_inspiral)

        used_locations.append(locations)
        used_signal_models.append(signal_model)
Пример #6
0
def new_row(tabletype):
    if tabletype == lsctables.SnglInspiralTable:
        return lsctables.SnglInspiral()
    if tabletype == lsctables.SimInspiralTable:
        return lsctables.SimInspiral()
    raise IOError("Input table type neither Sim or Sngl Inspiral")