コード例 #1
0
def add_to_segment_summary(xmldoc, proc_id, seg_def_id, sgmtlist, comment=''):
    try:
        seg_sum_table = lsctables.SegmentSumTable.get_table(xmldoc)
    except:
        seg_sum_table = lsctables.New(lsctables.SegmentSumTable,
                                      columns=[
                                          "process_id", "segment_def_id",
                                          "segment_sum_id", "start_time",
                                          "start_time_ns", "end_time",
                                          "end_time_ns", "comment"
                                      ])
        xmldoc.childNodes[0].appendChild(seg_sum_table)

    for seg in sgmtlist:
        segment_sum = lsctables.SegmentSum()
        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
        segment_sum.comment = comment

        seg_sum_table.append(segment_sum)
コード例 #2
0
ファイル: clientutils.py プロジェクト: reedessick/dqsegdb
def add_to_segment_summary_ns(xmldoc,
                              proc_id,
                              seg_def_id,
                              sgmtlist,
                              comment=''):
    try:
        seg_sum_table = table.get_table(xmldoc,
                                        lsctables.SegmentSumTable.tableName)
    except:
        seg_sum_table = lsctables.New(lsctables.SegmentSumTable,
                                      columns=[
                                          "process_id", "segment_def_id",
                                          "segment_sum_id", "start_time",
                                          "start_time_ns", "end_time",
                                          "end_time_ns", "comment"
                                      ])
        xmldoc.childNodes[0].appendChild(seg_sum_table)

    for seg in sgmtlist:
        segment_sum = lsctables.SegmentSum()
        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()
        seconds, nanoseconds = output_microseconds(seg[0])
        segment_sum.start_time = seconds
        segment_sum.start_time_ns = nanoseconds
        seconds, nanoseconds = output_microseconds(seg[1])
        segment_sum.end_time = seconds
        segment_sum.end_time_ns = nanoseconds
        #segment_sum.start_time     = seg[0]
        #segment_sum.start_time_ns  = 0
        #segment_sum.end_time       = seg[1]
        #segment_sum.end_time_ns    = 0
        segment_sum.comment = comment

        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
コード例 #4
0
ファイル: clientutils.py プロジェクト: reedessick/dqsegdb
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)
        end = min(scisegs[-1][-1], T[-1] + dT + opts.t_lag)

        start_time = int(start)
        start_time_ns = (start - start_time) * 1e9
        end_time = int(end)
        end_time_ns = (end - end_time) * 1e9

        dur = end_time - start_time

        ### iterate through FAPthr
        for FAPthr in opts.FAPthr:
            print "    FAPthr : %.6e" % (FAPthr)

            segdef_id = fap2segdef_id[FAPthr]
            ### set up segment summary row
            segsum_row = lsctables.SegmentSum()

            segsum_row.segment_sum_id = segsum.get_next_id()

            segsum_row.comment = ''
            segsum_row.process_id = proc_id
            segsum_row.segment_def_id = segdef_id
            segsum_row.start_time = start_time
            segsum_row.start_time_ns = start_time_ns
            segsum_row.end_time = end_time
            segsum_row.end_time_ns = end_time_ns

            segsum.append(segsum_row)

            ### generate segments for this threshold
            segs, min_TS = idq.timeseries_to_segments(T[:], -TS[:], -FAPthr)