Package glue :: Package ligolw
[hide private]
[frames] | no frames]

Package ligolw

source code

DOM-like library for handling LIGO Light Weight XML files. For more information on the Python DOM specification and SAX document content handlers, please refer to the Python standard library reference and the documentation it links to.

Here is a brief tutorial for a common use case: load a LIGO Light-Weight XML document containing tabular data complying with the LSC table definitions, access rows in the tables including the use of ID-based cross references, modify the contents of a table, and finally write the document back to disk. Please see the documentation for the modules, classes, functions, and methods shown below for more information.

Example:

>>> # import modules
>>> from glue.ligolw import ligolw
>>> from glue.ligolw import lsctables
>>> from glue.ligolw import utils as ligolw_utils
>>>
>>> # define a content handler
>>> class LIGOLWContentHandler(ligolw.LIGOLWContentHandler):
...     pass
...
>>> lsctables.use_in(LIGOLWContentHandler)
>>>
>>> # load a document.  gzip'ed files are auto-detected
>>> filename = "demo.xml.gz"
>>> xmldoc = ligolw_utils.load_filename(filename, contenthandler = LIGOLWContentHandler, verbose = True)
>>> 
>>> # retrieve the process and sngl_inspiral tables.  these are list-like
>>> # objects of rows.  the row objects' attributes are the column names
>>> process_table = lsctables.ProcessTable.get_table(xmldoc)
>>> sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc)
>>> 
>>> # fix the mtotal column in the sngl_inspiral table
>>> for row in sngl_inspiral_table:
...     row.mtotal = row.mass1 + row.mass2
...
>>> # construct a look-up table mapping process_id to row in process table
>>> index = dict((row.process_id, row) for row in process_table)
>>> 
>>> # for each trigger in the sngl_inspiral table, print the name of the user
>>> # who ran the job that produced it, the computer on which the job ran, and
>>> # the GPS end time of the trigger
>>> for row in sngl_inspiral_table:
...     process = index[row.process_id]
...     print "%s@%s: %s s" % (process.username, process.node, str(row.get_end()))
...
>>> # write document.  must explicitly state whether or not the file is to be
>>> # gzip compressed
>>> ligolw_utils.write_filename(xmldoc, filename, gz = filename.endswith(".gz"), verbose = True)

Version: git id 8cbd1b7187ce3ed9a825d6ed11cc432f3cfde9a5

Date: 2017-12-05 15:29:36 +0000

Author: Kipp Cannon <kipp.cannon@ligo.org>

Submodules [hide private]
  • glue.ligolw._ilwd: C extension module providing the ilwdchar parent class for row ID classes.
  • glue.ligolw.array: While the ligolw module provides classes and parser support for reading and writing LIGO Light Weight XML documents, this module supplements that code with classes and parsers that add intelligence to the in-RAM document representation.
  • glue.ligolw.dbtables: This module provides an implementation of the Table element that uses a database engine for storage.
  • glue.ligolw.ilwd: The ilwd:char type is used to store ID strings for objects within LIGO Light-Weight XML files.
  • glue.ligolw.ligolw: This module provides class definitions corresponding to the elements that can be found in a LIGO Light Weight XML file.
  • glue.ligolw.lsctables: LSC Table definitions.
  • glue.ligolw.param: High-level support for Param elements.
  • glue.ligolw.table: While the ligolw module provides classes and parser support for reading and writing LIGO Light Weight XML documents, this module supplements that code with classes and parsers that add intelligence to the in-RAM document representation.
  • glue.ligolw.tokenizer: This module provides a tokenizer for LIGO Light Weight XML Stream and Array elements, as well as other utilities to assist in packing parsed tokens into various data storage units.
  • glue.ligolw.types: Definitions of type strings found in LIGO Light Weight XML files.
  • glue.ligolw.utils: Library of utility code for LIGO Light Weight XML applications.

Variables [hide private]
  __package__ = 'glue.ligolw'