示例#1
0
def add_to_segment_definer(xmldoc, proc_id, ifo, name, version, comment=''):
    try:
        seg_def_table = lsctables.SegmentDefTable.get_table(xmldoc)
    except:
        seg_def_table = lsctables.New(lsctables.SegmentDefTable, columns = ["process_id", "segment_def_id", "ifos", "name", "version", "comment"])
        xmldoc.childNodes[0].appendChild(seg_def_table)

    seg_def_id                     = seg_def_table.get_next_id()
    segment_definer                = lsctables.SegmentDef()
    segment_definer.process_id     = proc_id
    segment_definer.segment_def_id = seg_def_id
    segment_definer.ifos           = ifo
    segment_definer.name           = name
    segment_definer.version        = version
    segment_definer.comment        = comment

    seg_def_table.append(segment_definer)

    return seg_def_id
示例#2
0
def run_query_types(doc, proc_id, connection, engine, gps_start_time,
                    gps_end_time, included_segments):
    query_segment = glue.segments.segmentlist(
        [glue.segments.segment(gps_start_time, gps_end_time)])

    sql = """SELECT segment_definer.ifos, segment_definer.name,segment_definer.version,
           (CASE WHEN segment_definer.comment IS NULL THEN '-' WHEN segment_definer.comment IS NOT NULL THEN segment_definer.comment END),
           segment_summary.start_time, segment_summary.end_time,
           (CASE WHEN segment_summary.comment IS NULL THEN '-' WHEN segment_summary.comment IS NOT NULL THEN segment_summary.comment END)
    FROM segment_definer, segment_summary
    WHERE segment_definer.segment_def_id = segment_summary.segment_def_id
    AND NOT(%d > segment_summary.end_time OR segment_summary.start_time > %d)
    """ % (gps_start_time, gps_end_time)

    type_clauses = map(seg_spec_to_sql, included_segments.split(','))

    if type_clauses != []:
        sql += " AND (" + "OR ".join(type_clauses) + ")"

    segment_types = {}

    for row in engine.query(sql):
        sd_ifo, sd_name, sd_vers, sd_comment, ss_start, ss_end, ss_comment = row
        key = (sd_ifo, sd_name, sd_vers, sd_comment, ss_comment)
        if key not in segment_types:
            segment_types[key] = glue.segments.segmentlist([])
        segment_types[key] |= glue.segments.segmentlist(
            [glue.segments.segment(ss_start, ss_end)])

    engine.close()

    # Create segment definer and segment_summary tables
    seg_def_table = lsctables.New(lsctables.SegmentDefTable,
                                  columns=[
                                      "process_id", "segment_def_id", "ifos",
                                      "name", "version", "comment"
                                  ])
    doc.childNodes[0].appendChild(seg_def_table)

    seg_sum_table = lsctables.New(lsctables.SegmentSumTable,
                                  columns=[
                                      "process_id", "segment_sum_id",
                                      "start_time", "start_time_ns",
                                      "end_time", "end_time_ns", "comment",
                                      "segment_def_id"
                                  ])

    doc.childNodes[0].appendChild(seg_sum_table)

    for key in segment_types:
        # Make sure the intervals fall within the query window and coalesce
        segment_types[key].coalesce()
        segment_types[key] &= query_segment

        seg_def_id = seg_def_table.get_next_id()
        segment_definer = lsctables.SegmentDef()
        segment_definer.process_id = proc_id
        segment_definer.segment_def_id = seg_def_id
        segment_definer.ifos = key[0]
        segment_definer.name = key[1]
        segment_definer.version = key[2]
        segment_definer.comment = key[3]

        seg_def_table.append(segment_definer)

        # add each segment summary to the segment_summary_table

        for seg in segment_types[key]:
            segment_sum = lsctables.SegmentSum()
            segment_sum.comment = key[4]
            segment_sum.process_id = proc_id
            segment_sum.segment_def_id = seg_def_id
            segment_sum.segment_sum_id = seg_sum_table.get_next_id()
            segment_sum.start_time = seg[0]
            segment_sum.start_time_ns = 0
            segment_sum.end_time = seg[1]
            segment_sum.end_time_ns = 0

            seg_sum_table.append(segment_sum)
示例#3
0
文件: ligolw.py 项目: rpfisher/gwpy
def write_to_xmldoc(flags, xmldoc, process_id=None):
    """Write this `DataQualityFlag` to the given LIGO_LW Document
    """
    if isinstance(flags, DataQualityFlag):
        flags = {flags.name: flags}

    # write SegmentDefTable
    try:
        segdeftab = lsctables.SegmentDefTable.get_table(xmldoc)
    except ValueError:
        segdeftab = lsctables.New(lsctables.SegmentDefTable,
                                  columns=[
                                      'ifos', 'name', 'version', 'comment',
                                      'insertion_time', 'segment_def_id',
                                      'process_id'
                                  ])
        xmldoc.childNodes[-1].appendChild(segdeftab)
    # make SegmentSumTable
    try:
        segsumtab = lsctables.SegmentSumTable.get_table(xmldoc)
    except ValueError:
        segsumtab = lsctables.New(lsctables.SegmentSumTable,
                                  columns=[
                                      'segment_def_id', 'start_time',
                                      'start_time_ns', 'end_time',
                                      'end_time_ns', 'comment',
                                      'segment_sum_id', 'process_id'
                                  ])
        xmldoc.childNodes[-1].appendChild(segsumtab)
    # write SegmentTable
    try:
        segtab = lsctables.SegmentTable.get_table(xmldoc)
    except ValueError:
        segtab = lsctables.New(lsctables.SegmentTable,
                               columns=[
                                   'process_id', 'segment_id',
                                   'segment_def_id', 'start_time',
                                   'start_time_ns', 'end_time', 'end_time_ns'
                               ])
        xmldoc.childNodes[-1].appendChild(segtab)

    # write flags to tables
    for flag in flags.itervalues():
        # segment definer
        segdef = lsctables.SegmentDef()
        segdef.set_ifos([flag.ifo])
        segdef.name = flag.tag
        segdef.version = flag.version
        segdef.comment = flag.description
        segdef.insertion_time = int(
            Time(datetime.datetime.now(), scale='utc').gps)
        segdef.segment_def_id = lsctables.SegmentDefTable.get_next_id()
        segdef.process_id = process_id
        segdeftab.append(segdef)

        # write segment summary (known segments)
        for vseg in flag.known:
            segsum = lsctables.SegmentSum()
            segsum.segment_def_id = segdef.segment_def_id
            segsum.set(map(LIGOTimeGPS, map(float, vseg)))
            segsum.comment = None
            segsum.segment_sum_id = lsctables.SegmentSumTable.get_next_id()
            segsum.process_id = process_id
            segsumtab.append(segsum)

        # write segment table (active segments)
        for aseg in flag.active:
            seg = lsctables.Segment()
            seg.segment_def_id = segdef.segment_def_id
            seg.set(map(LIGOTimeGPS, map(float, aseg)))
            seg.segment_id = lsctables.SegmentTable.get_next_id()
            seg.process_id = process_id
            segtab.append(seg)

    return xmldoc
    faps = fapsD[classifier]
    logger.info('  found %d files' % (len(faps)))

    ### need to load in time-series from frames here!
    chan = idq.channame(ifo, classifier, "%s_fap" % usertag)
    t, ts = idq.combine_gwf(faps, [chan])  ### loads in the data from frames

    logger.info('  found %d continous segments' % (len(t)))

    ### set up segdef row
    fap2segdef_id = {}
    for FAPthr in opts.FAPthr:
        segdef_id = segdef.get_next_id()

        segdef_row = lsctables.SegmentDef()
        segdef_row.process_id = proc_id
        segdef_row.segment_def_id = segdef_id
        segdef_row.ifos = ifo
        segdef_row.name = classifier
        segdef_row.version = 1
        segdef_row.comment = 'FAPthr=%.9e' % FAPthr

        segdef.append(segdef_row)

        fap2segdef_id[FAPthr] = segdef_id

    ### iterate through contiguous segments:
    for T, TS in zip(t, ts):
        if not len(T):
            logger.info('len(T)=0, skipping...')