gstlal-inspiral  0.4.2
 All Classes Namespaces Files Functions Variables Pages
gstlal_inspiral_condition_data
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2013 Kipp Cannon, Chad Hanna, Drew Keppel
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 ## @file
20 # A program to read data, possibly downsample and add injections and cache it to local disks.
21 #
22 # ### Command line interface
23 # + `--output-path` [path]: Set the path where the output frame files are to be written (default = value of TMPDIR environment variable if set, otherwise the current working directory).
24 # + `--sample-rate` [Hz] (int): Downsample to this sample rate (default = no resampling).
25 # + `--verbose`: Be verbose (optional).
26 
27 #
28 # =============================================================================
29 #
30 # Preamble
31 #
32 # =============================================================================
33 #
34 
35 
36 import os
37 import sys
38 from optparse import OptionParser
39 
40 
41 # The following snippet is taken from http://gstreamer.freedesktop.org/wiki/FAQ#Mypygstprogramismysteriouslycoredumping.2Chowtofixthis.3F
42 import pygtk
43 pygtk.require("2.0")
44 import gobject
45 gobject.threads_init()
46 import pygst
47 pygst.require("0.10")
48 import gst
49 
50 
51 from gstlal import datasource
52 from gstlal import pipeparts
53 from gstlal import hoftcache
54 
55 pipeparts.mkchecktimestamps = lambda pipeline, src, *args: src
56 
57 def excepthook(*args):
58  # system exception hook that forces hard exit. without this,
59  # exceptions that occur inside python code invoked as a call-back
60  # from the gstreamer pipeline just stop the pipeline, they don't
61  # cause gstreamer to exit.
62 
63  # FIXME: they probably *would* cause if we could figure out why
64  # element errors and the like simply stop the pipeline instead of
65  # crashing it, as well. Perhaps this should be removed when/if the
66  # "element error's don't crash program" problem is fixed
67  sys.__excepthook__(*args)
68  os._exit(1)
69 
70 sys.excepthook = excepthook
71 
72 
73 #
74 # =============================================================================
75 #
76 # Command Line
77 #
78 # =============================================================================
79 #
80 
81 
82 def parse_command_line():
83  parser = OptionParser(
84  description = __doc__
85  )
86  parser.add_option("--output-path", metavar = "path", default = os.environ.get("TMPDIR", "."), help = "Set the path where the output frame files are to be written (default = value of TMPDIR environment variable if set, otherwise the current working directory).")
87  parser.add_option("--sample-rate", metavar = "Hz", type = "int", help = "Downsample to this sample rate (default = no resampling).")
88  parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose (optional).")
89  datasource.append_options(parser)
90 
91  options, filenames = parser.parse_args()
92 
93  options.description = "CBC_TMP"
94 
95  try:
96  output_cache_filename, = filenames
97  except ValueError:
98  raise ValueError("must provide exactly one output cache filename")
99 
100  return options, output_cache_filename
101 
102 
103 #
104 # =============================================================================
105 #
106 # Main
107 #
108 # =============================================================================
109 #
110 
111 
112 #
113 # parse command line
114 #
115 
116 
117 options, output_cache_filename = parse_command_line()
118 data_source_info = datasource.GWDataSourceInfo(options)
119 
120 
121 #
122 # Cache h(t)
123 #
124 
125 
126 cache = hoftcache.cache_hoft(data_source_info, output_path = options.output_path, sample_rate = options.sample_rate, description = options.description, verbose = options.verbose)
127 
128 
129 #
130 # Write cache
131 #
132 
133 
134 if options.verbose:
135  print >>sys.stderr, "writing %s ..." % output_cache_filename
136 cache_file = open(output_cache_filename, "w")
137 for entry in cache:
138  print >>cache_file, str(entry)
139 
140 
141 #
142 # done
143 #