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

Source Code for Package glue.ligolw

 1  # Copyright (C) 2006,2007,2009,2011,2013  Kipp Cannon 
 2  # 
 3  # This program is free software; you can redistribute it and/or modify it 
 4  # under the terms of the GNU General Public License as published by the 
 5  # Free Software Foundation; either version 3 of the License, or (at your 
 6  # option) any later version. 
 7  # 
 8  # This program is distributed in the hope that it will be useful, but 
 9  # WITHOUT ANY WARRANTY; without even the implied warranty of 
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
11  # Public License for more details. 
12  # 
13  # You should have received a copy of the GNU General Public License along 
14  # with this program; if not, write to the Free Software Foundation, Inc., 
15  # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
16   
17  # 
18  # ============================================================================= 
19  # 
20  #                                   Preamble 
21  # 
22  # ============================================================================= 
23  # 
24   
25  """ 
26  DOM-like library for handling LIGO Light Weight XML files.  For more 
27  information on the Python DOM specification and SAX document content 
28  handlers, please refer to the Python standard library reference and the 
29  documentation it links to. 
30   
31  Here is a brief tutorial for a common use case:  load a LIGO Light-Weight 
32  XML document containing tabular data complying with the LSC table 
33  definitions, access rows in the tables including the use of ID-based cross 
34  references, modify the contents of a table, and finally write the document 
35  back to disk.  Please see the documentation for the modules, classes, 
36  functions, and methods shown below for more information. 
37   
38  Example: 
39   
40  >>> # import modules 
41  >>> from glue.ligolw import ligolw 
42  >>> from glue.ligolw import lsctables 
43  >>> from glue.ligolw import utils as ligolw_utils 
44  >>> 
45  >>> # define a content handler 
46  >>> class LIGOLWContentHandler(ligolw.LIGOLWContentHandler): 
47  ...     pass 
48  ... 
49  >>> lsctables.use_in(LIGOLWContentHandler) 
50  >>> 
51  >>> # load a document.  gzip'ed files are auto-detected 
52  >>> filename = "demo.xml.gz" 
53  >>> xmldoc = ligolw_utils.load_filename(filename, contenthandler = LIGOLWContentHandler, verbose = True) 
54  >>>  
55  >>> # retrieve the process and sngl_inspiral tables.  these are list-like 
56  >>> # objects of rows.  the row objects' attributes are the column names 
57  >>> process_table = lsctables.ProcessTable.get_table(xmldoc) 
58  >>> sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc) 
59  >>>  
60  >>> # fix the mtotal column in the sngl_inspiral table 
61  >>> for row in sngl_inspiral_table: 
62  ...     row.mtotal = row.mass1 + row.mass2 
63  ... 
64  >>> # construct a look-up table mapping process_id to row in process table 
65  >>> index = dict((row.process_id, row) for row in process_table) 
66  >>>  
67  >>> # for each trigger in the sngl_inspiral table, print the name of the user 
68  >>> # who ran the job that produced it, the computer on which the job ran, and 
69  >>> # the GPS end time of the trigger 
70  >>> for row in sngl_inspiral_table: 
71  ...     process = index[row.process_id] 
72  ...     print "%s@%s: %s s" % (process.username, process.node, str(row.get_end())) 
73  ... 
74  >>> # write document.  must explicitly state whether or not the file is to be 
75  >>> # gzip compressed 
76  >>> ligolw_utils.write_filename(xmldoc, filename, gz = filename.endswith(".gz"), verbose = True) 
77  """ 
78   
79   
80  from glue import git_version 
81   
82   
83  __author__ = "Kipp Cannon <kipp.cannon@ligo.org>" 
84  __version__ = "git id %s" % git_version.id 
85  __date__ = git_version.date 
86   
87   
88  __all__ = [ 
89          "ligolw", 
90          "types", 
91          "ilwd", 
92          "table", 
93          "array", 
94          "param", 
95          "lsctables", 
96          "utils" 
97  ] 
98