gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
simulation.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2010
3 # Chad Hanna <chad.hanna@ligo.org>
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 
20 
21 from glue import segments
22 from glue.ligolw import ligolw
23 from glue.ligolw import lsctables
24 from glue.ligolw import utils as ligolw_utils
25 from pylal.datatypes import LIGOTimeGPS
26 
27 
28 ## @file
29 # the simulation module
30 #
31 # Review status
32 #
33 # | Names | Hash | Date |
34 # | ------------------------------------------- | ------------------------------------------- | ---------- |
35 # | Sathya, Duncan Me, Jolien, Kipp, Chad | 7536db9d496be9a014559f4e273e1e856047bf71 | 2014-05-02 |
36 #
37 
38 
39 ## @package python.simulation
40 # The simulation module code
41 
42 class ContentHandler(ligolw.LIGOLWContentHandler):
43  pass
44 lsctables.use_in(ContentHandler)
45 
46 
47 #
48 # open ligolw_xml file containing sim_inspiral and create a segment list
49 #
50 
51 ## Turn a file containing a sim inspiral into a segment list
52 def sim_inspiral_to_segment_list(fname, pad=3, verbose=False):
53  """!
54  Given an xml file create a segment list that marks the time of an
55  injection with padding
56 
57  - fname: the xml file name
58  - pad: duration in seconds to pad the coalescence time when producint a segment, e.g., [tc-pad, tc+pad)
59  """
60 
61  # initialization
62 
63  seglist = segments.segmentlist()
64 
65  # Parse the XML file
66 
67  xmldoc = ligolw_utils.load_filename(fname, contenthandler=ContentHandler, verbose=verbose)
68 
69  # extract the padded geocentric end times into segment lists
70 
71  for row in lsctables.SimInspiralTable.get_table(xmldoc):
72  t = LIGOTimeGPS(row.get_time_geocent())
73  seglist.append(segments.segment(t-pad, t+pad))
74 
75  # help the garbage collector
76 
77  xmldoc.unlink()
78 
79  return seglist.coalesce()