Esempio n. 1
0
def vn_ldas_gap_check(vn_xml_file,vn_flag,ldas_gap_xml_file):
    # read in summary intervals of vn_flag
    vndoc = ligolw_utils.load_url(vn_xml_file, gz = (vn_xml_file or "stdin").endswith(".gz"))
    vn_sums=segmentdb_utils.find_segments(vndoc,"%s" % vn_flag,use_segment_table=False)

    # read in segment and summary intervals of LDAS allowed gaps
    ldasdoc = ligolw_utils.load_url(ldas_gap_xml_file, gz = (ldas_gap_xml_file or "stdin").endswith(".gz"))
    ldas_gaps=segmentdb_utils.find_segments(ldasdoc,'H1:RESULT:1')
    ldas_sums=segmentdb_utils.find_segments(ldasdoc,'H1:DCH-MISSING_LDAS_C02_L2:1',use_segment_table=False)
    if len(ldas_sums) == 0:
       message = "no LDAS info was found within the specified time in the database!"
       print(message)
       return

    # if valid Vn file and ldas files both found, do further testings:
    if len(vn_sums) > 1 :
       vn_sum_gaps=segmentlist([segment(vn_sums[0][0],vn_sums[-1][1])]) - vn_sums
       if vn_sum_gaps == ldas_gaps:
          message = ""
       else:
          message = "test failed. Found unexpected gaps in LDAS frames: %s \n" % vn_sum_gaps - ldas_gaps
          print(message)
          return
    else: 
       if (len(vn_sums & ldas_gaps) == 0):
          message = ""
       else:
          message = "test failed. Found overlap between %s summary intervals and LDAS allowed gaps: \n" % (vn_flag, vn_sums - ldas_gaps)
          print(message)
          return
    print(message)
Esempio n. 2
0
def read_segfile_xml(segfile,verbose):
  """
  Read segment file in ligolw xml type and return in glue.segments.segmentlist
  format.
  """
  from glue.ligolw import ligolw
  from glue.ligolw import table
  from glue.ligolw import utils

  def ContentHandler(xmldoc):
    return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
               (name == ligolw.Table.tagName) and\
               (table.StripTableName(attrs["Name"]) in ["segment"]))
  try:
    table.use_in(ligolw.PartialLIGOLWContentHandler)
  except AttributeError:
    # old glue did not allow .use_in().
    # FIXME:  remove when we can require the latest version of glue
    pass

  xmldoc = utils.load_url(segfile, verbose = verbose,gz = segfile.endswith(".gz"), contenthandler = ContentHandler)
  seg_list = segmentlist()
  for table_elem in xmldoc.getElements(lambda e:\
                                       (e.tagName == ligolw.Table.tagName)):
    for row in table_elem:
      seg_list.append(segment(row.start_time, row.end_time))
  xmldoc.unlink()
  return seg_list
Esempio n. 3
0
def find_version_xml(segfile,seg,verbose):
  """
  Find out the version of the flag for the given seg.
  """
  from glue.ligolw import ligolw
  from glue.ligolw import table
  from glue.ligolw import utils

  def ContentHandler(xmldoc):
    return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
               (name == ligolw.Table.tagName) and\
               (table.StripTableName(attrs["Name"]) in ["segment_definer","segment_summary"]))
  try:
    table.use_in(ligolw.PartialLIGOLWContentHandler)
  except AttributeError:
    # old glue did not allow .use_in().
    # FIXME:  remove when we can require the latest version of glue
    pass

  xmldoc = utils.load_url(segfile, verbose = verbose,gz = segfile.endswith(".gz"), contenthandler = ContentHandler)
  for n, table_elem in enumerate(xmldoc.getElements(lambda e:\
                                       (e.tagName == ligolw.Table.tagName))):
    if n == 0:
      definer = {}
      for row in table_elem:
        if row.name != "RESULT":
          definer[str(row.segment_def_id).split(":")[-1]] = row.version

    if n == 1:
      for row in table_elem:
        if seg[0] >= row.start_time and seg[1] <= row.end_time:
          if str(row.segment_def_id).split(":")[-1] in definer.keys():
            xmldoc.unlink()
            return definer[str(row.segment_def_id).split(":")[-1]]
Esempio n. 4
0
def find_version_xml(segfile,seg,verbose):
  """
  Find out the version of the flag for the given seg.
  """
  from glue.ligolw import ligolw
  from glue.ligolw import table
  from glue.ligolw import utils

  def ContentHandler(xmldoc):
    return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
               (name == ligolw.Table.tagName) and\
               (table.Table.TableName(attrs["Name"]) in ["segment_definer","segment_summary"]))
  try:
    table.use_in(ligolw.PartialLIGOLWContentHandler)
  except AttributeError:
    # old glue did not allow .use_in().
    # FIXME:  remove when we can require the latest version of glue
    pass

  xmldoc = utils.load_url(segfile, verbose = verbose,gz = segfile.endswith(".gz"), contenthandler = ContentHandler)
  for n, table_elem in enumerate(xmldoc.getElements(lambda e:\
                                       (e.tagName == ligolw.Table.tagName))):
    if n == 0:
      definer = {}
      for row in table_elem:
        if row.name != "RESULT":
          definer[str(row.segment_def_id).split(":")[-1]] = row.version

    if n == 1:
      for row in table_elem:
        if seg[0] >= row.start_time and seg[1] <= row.end_time:
          if str(row.segment_def_id).split(":")[-1] in definer.keys():
            xmldoc.unlink()
            return definer[str(row.segment_def_id).split(":")[-1]]
Esempio n. 5
0
def find_version_xml(segfile, seg, verbose):
    """
  Find out the version of the flag for the given seg.
  """
    from glue.ligolw import ligolw, utils, lsctables, table
    lsctables.use_in(ligolw.LIGOLWContentHandler)

    def ContentHandler(xmldoc):
        return ligolw.LIGOLWContentHandler(xmldoc, lambda name, attrs:\
                   (name == ligolw.Table.tagName) and\
                   (table.StripTableName(attrs["Name"]) in ["segment_definer","segment_summary"]))

    utils.ContentHandler = ContentHandler
    xmldoc = utils.load_url(segfile,
                            verbose=verbose,
                            gz=segfile.endswith(".gz"),
                            contenthandler=ligolw.LIGOLWContentHandler)
    for n, table_elem in enumerate(xmldoc.getElements(lambda e:\
                                         (e.tagName == ligolw.Table.tagName))):
        if n == 0:
            definer = {}
            for row in table_elem:
                if row.name != "RESULT":
                    definer[str(
                        row.segment_def_id).split(":")[-1]] = row.version

        if n == 1:
            for row in table_elem:
                if seg[0] >= row.start_time and seg[1] <= row.end_time:
                    if str(row.segment_def_id).split(
                            ":")[-1] in definer.keys():
                        xmldoc.unlink()
                        return definer[str(row.segment_def_id).split(":")[-1]]
Esempio n. 6
0
def read_segfile_xml(segfile,verbose):
  """
  Read segment file in ligolw xml type and return in glue.segments.segmentlist
  format.
  """
  from glue.ligolw import ligolw
  from glue.ligolw import table
  from glue.ligolw import utils

  def ContentHandler(xmldoc):
    return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
               (name == ligolw.Table.tagName) and\
               (table.Table.TableName(attrs["Name"]) in ["segment"]))
  try:
    table.use_in(ligolw.PartialLIGOLWContentHandler)
  except AttributeError:
    # old glue did not allow .use_in().
    # FIXME:  remove when we can require the latest version of glue
    pass

  xmldoc = utils.load_url(segfile, verbose = verbose,gz = segfile.endswith(".gz"), contenthandler = ContentHandler)
  seg_list = segmentlist()
  for table_elem in xmldoc.getElements(lambda e:\
                                       (e.tagName == ligolw.Table.tagName)):
    for row in table_elem:
      seg_list.append(segment(row.start_time, row.end_time))
  xmldoc.unlink()
  return seg_list
Esempio n. 7
0
def read_segfile_xml(segfile, verbose):
    """
  Read segment file in ligolw xml type and return in glue.segments.segmentlist
  format.
  """
    from glue.ligolw import ligolw, utils, lsctables, table
    lsctables.use_in(ligolw.LIGOLWContentHandler)

    def ContentHandler(xmldoc):
        return ligolw.LIGOLWContentHandler(xmldoc, lambda name, attrs:\
                   (name == ligolw.Table.tagName) and\
                   (table.StripTableName(attrs["Name"]) in ["segment"]))

    utils.ContentHandler = ContentHandler

    xmldoc = utils.load_url(segfile,
                            verbose=verbose,
                            gz=segfile.endswith(".gz"),
                            contenthandler=ligolw.LIGOLWContentHandler)
    seg_list = segmentlist()
    rows = table.get_table(xmldoc, lsctables.VetoDefTable.tableName)
    for row in rows:
        seg_list.append(segment(row.start_time, row.end_time))
    xmldoc.unlink()
    return seg_list
Esempio n. 8
0
def read_segfile_xml(segfile, verbose):
    """
  Read segment file in ligolw xml type and return in glue.segments.segmentlist
  format.
  """
    from glue.ligolw import ligolw
    from glue.ligolw import table
    from glue.ligolw import utils

    def ContentHandler(xmldoc):
        return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
                   (name == ligolw.Table.tagName) and\
                   (table.StripTableName(attrs["Name"]) in ["segment"]))

    utils.ContentHandler = ContentHandler

    xmldoc = utils.load_url(segfile,
                            verbose=verbose,
                            gz=segfile.endswith(".gz"))
    seg_list = segmentlist()
    for table_elem in xmldoc.getElements(lambda e:\
                                         (e.tagName == ligolw.Table.tagName)):
        for row in table_elem:
            seg_list.append(segment(row.start_time, row.end_time))
    xmldoc.unlink()
    return seg_list
Esempio n. 9
0
def find_version_xml(segfile,seg,verbose):
  """
  Find out the version of the flag for the given seg.
  """
  from glue.ligolw import ligolw,utils, lsctables, table
  lsctables.use_in(ligolw.LIGOLWContentHandler)
  def ContentHandler(xmldoc):
    return ligolw.LIGOLWContentHandler(xmldoc, lambda name, attrs:\
               (name == ligolw.Table.tagName) and\
               (table.StripTableName(attrs["Name"]) in ["segment_definer","segment_summary"]))

  utils.ContentHandler = ContentHandler
  xmldoc = utils.load_url(segfile, verbose = verbose,gz = segfile.endswith(".gz"),contenthandler=ligolw.LIGOLWContentHandler)
  for n, table_elem in enumerate(xmldoc.getElements(lambda e:\
                                       (e.tagName == ligolw.Table.tagName))):
    if n == 0:
      definer = {}
      for row in table_elem:
        if row.name != "RESULT":
          definer[str(row.segment_def_id).split(":")[-1]] = row.version

    if n == 1:
      for row in table_elem:
        if seg[0] >= row.start_time and seg[1] <= row.end_time:
          if str(row.segment_def_id).split(":")[-1] in definer.keys():
            xmldoc.unlink()
            return definer[str(row.segment_def_id).split(":")[-1]]
Esempio n. 10
0
def vn_ldas_gap_check(vn_xml_file, vn_flag, ldas_gap_xml_file):
    # read in summary intervals of vn_flag
    vndoc = ligolw_utils.load_url(vn_xml_file,
                                  gz=(vn_xml_file or "stdin").endswith(".gz"))
    vn_sums = segmentdb_utils.find_segments(vndoc,
                                            "%s" % vn_flag,
                                            use_segment_table=False)

    # read in segment and summary intervals of LDAS allowed gaps
    ldasdoc = ligolw_utils.load_url(ldas_gap_xml_file,
                                    gz=(ldas_gap_xml_file
                                        or "stdin").endswith(".gz"))
    ldas_gaps = segmentdb_utils.find_segments(ldasdoc, 'H1:RESULT:1')
    ldas_sums = segmentdb_utils.find_segments(ldasdoc,
                                              'H1:DCH-MISSING_LDAS_C02_L2:1',
                                              use_segment_table=False)
    if len(ldas_sums) == 0:
        message = "no LDAS info was found within the specified time in the database!"
        print(message)
        return

    # if valid Vn file and ldas files both found, do further testings:
    if len(vn_sums) > 1:
        vn_sum_gaps = segmentlist([segment(vn_sums[0][0], vn_sums[-1][1])
                                   ]) - vn_sums
        if vn_sum_gaps == ldas_gaps:
            message = ""
        else:
            message = "test failed. Found unexpected gaps in LDAS frames: %s \n" % vn_sum_gaps - ldas_gaps
            print(message)
            return
    else:
        if (len(vn_sums & ldas_gaps) == 0):
            message = ""
        else:
            message = "test failed. Found overlap between %s summary intervals and LDAS allowed gaps: \n" % (
                vn_flag, vn_sums - ldas_gaps)
            print(message)
            return
    print(message)
Esempio n. 11
0
def read_segfile_xml(segfile,verbose):
  """
  Read segment file in ligolw xml type and return in glue.segments.segmentlist
  format.
  """
  from glue.ligolw import ligolw,utils, lsctables, table
  lsctables.use_in(ligolw.LIGOLWContentHandler)
  def ContentHandler(xmldoc):
    return ligolw.LIGOLWContentHandler(xmldoc, lambda name, attrs:\
               (name == ligolw.Table.tagName) and\
               (table.StripTableName(attrs["Name"]) in ["segment"]))

  utils.ContentHandler = ContentHandler

  xmldoc = utils.load_url(segfile, verbose = verbose,gz = segfile.endswith(".gz"),contenthandler=ligolw.LIGOLWContentHandler)
  seg_list = segmentlist()
  rows = table.get_table(xmldoc, lsctables.VetoDefTable.tableName)
  for row in rows:
    seg_list.append(segment(row.start_time, row.end_time))
  xmldoc.unlink()
  return seg_list
Esempio n. 12
0
def get_trigs_xml(GWcursor, trigger_file, segs, min_thresh, tracker, verbose):
    """
    Read trigger data from xml file that has ligolw xml format.
    Many lines in this function are adapted from ligolw_print by Kipp Cannon
    and modified to suit the need.
    """
    from glue.ligolw import ligolw
    from glue.ligolw import table
    from glue.ligolw import lsctables
    from glue.ligolw import utils
    # speed hacks
    # replace Glue's pure Python LIGOTimeGPS class with pyLAL's C version
    from pylal.xlal.datatypes.ligotimegps import LIGOTimeGPS
    lsctables.LIGOTimeGPS = LIGOTimeGPS

    # Enable column interning to save memory
    table.RowBuilder = table.InterningRowBuilder

    # for now, hardcode the table/column names
    # FIXME: assuming there is only one of those tables in the file
    tables = ['sngl_burst', 'sngl_inspiral', 'sngl_ringdown']
    columns = ['end_time', 'end_time_ns', 'snr']

    # don't parse other tables so as to improve parsing speed and reduce memory
    # requirements.

    def ContentHandler(xmldoc):
        return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
                           (name == ligolw.Table.tagName) and\
                           (table.StripTableName(attrs["Name"]) in tables))

    try:
        lsctables.use_in(ligolw.PartialLIGOLWContentHandler)
    except AttributeError:
        # old glue did not allow .use_in().
        # FIXME:  remove when we can require the latest version of glue
        pass

    # FIXME: find a way to load only columns necessary
    # something like lsctables.SnglInspiral.loadcolumns = columns?

    xmldoc = utils.load_url(trigger_file, verbose = verbose,\
                                 gz = trigger_file.endswith(".gz"),
                                 contenthandler = ContentHandler)
    table.InterningRowBuilder.strings.clear()
    for table_elem in xmldoc.getElements(lambda e:\
                                        (e.tagName == ligolw.Table.tagName)):
        # trigger specific time retrieval functions
        if table_elem.tableName[:-6] in ('sngl_inspiral'):
            get_time = lambda row: row.get_end()
        elif table_elem.tableName[:-6] in ('sngl_burst'):
            get_time = lambda row: row.get_peak()
        elif table_elem.tableName[:-6] in ('sngl_ringdown'):
            get_time = lambda row: row.get_start()
        else:
            print >> sys.stderr, "Error: This should not be happening. Please contact to the author with the error trace."
            sys.exit(1)

        for row in table_elem:
            t = get_time(row)
            if t in segs:
                if row.snr > min_thresh:
                    # insert into the database
                    # micro second for GPS time is accurate enough
                    GWcursor.execute("insert into GWtrigs values (?, ?)",
                                     ("%.3f" % t, "%.2f" % row.snr))
                    tracker['counter'] += 1
            else:
                # some triggers are outside of segments
                tracker['outside'] = True
    xmldoc.unlink()
    return GWcursor
Esempio n. 13
0
def get_trigs_xml(GWcursor,trigger_file,segs,min_thresh,tracker,verbose):
    """
    Read trigger data from xml file that has ligolw xml format.
    Many lines in this function are adapted from ligolw_print by Kipp Cannon
    and modified to suit the need.
    """
    from glue.ligolw import ligolw
    from glue.ligolw import table
    from glue.ligolw import lsctables
    from glue.ligolw import utils
    # speed hacks
    # replace Glue's pure Python LIGOTimeGPS class with pyLAL's C version
    from pylal.xlal.datatypes.ligotimegps import LIGOTimeGPS
    lsctables.LIGOTimeGPS = LIGOTimeGPS 

    # Enable column interning to save memory
    table.RowBuilder = table.InterningRowBuilder

    # for now, hardcode the table/column names
    # FIXME: assuming there is only one of those tables in the file
    tables = ['sngl_burst','sngl_inspiral','sngl_ringdown']
    columns = ['end_time','end_time_ns','snr']
    

    # don't parse other tables so as to improve parsing speed and reduce memory 
    # requirements.
    
    def ContentHandler(xmldoc):
        return ligolw.PartialLIGOLWContentHandler(xmldoc, lambda name, attrs:\
                           (name == ligolw.Table.tagName) and\
                           (table.Table.TableName(attrs["Name"]) in tables))
    try:
      lsctables.use_in(ligolw.PartialLIGOLWContentHandler)
    except AttributeError:
      # old glue did not allow .use_in().
      # FIXME:  remove when we can require the latest version of glue
      pass

    # FIXME: find a way to load only columns necessary
    # something like lsctables.SnglInspiral.loadcolumns = columns?

    xmldoc = utils.load_url(trigger_file, verbose = verbose,\
                                 gz = trigger_file.endswith(".gz"),
                                 contenthandler = ContentHandler)
    table.InterningRowBuilder.strings.clear()
    for table_elem in xmldoc.getElements(lambda e:\
                                        (e.tagName == ligolw.Table.tagName)):
      # trigger specific time retrieval functions
      if table_elem.tableName[:-6] in ('sngl_inspiral'):
        get_time = lambda row: row.get_end()
      elif table_elem.tableName[:-6] in ('sngl_burst'):
        get_time = lambda row: row.get_peak()
      elif table_elem.tableName[:-6] in ('sngl_ringdown'):
        get_time = lambda row: row.get_start()
      else:
        print >> sys.stderr, "Error: This should not be happening. Please contact to the author with the error trace."
        sys.exit(1)

      for row in table_elem:
        t = get_time(row)
        if t in segs:
          if row.snr > min_thresh:
            # insert into the database
            # micro second for GPS time is accurate enough
            GWcursor.execute("insert into GWtrigs values (?, ?)",("%.3f"%t, "%.2f"%row.snr))
            tracker['counter'] += 1
        else:
          # some triggers are outside of segments
          tracker['outside'] = True
    xmldoc.unlink()
    return GWcursor