3 # Copyright (C) 2013 Kipp Cannon, Chad Hanna, Drew Keppel
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.
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.
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.
20 # A program to read data, possibly downsample and add injections and cache it to local disks.
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).
28 # =============================================================================
32 # =============================================================================
38 from optparse
import OptionParser
41 # The following snippet is taken from http://gstreamer.freedesktop.org/wiki/FAQ#Mypygstprogramismysteriouslycoredumping.2Chowtofixthis.3F
45 gobject.threads_init()
51 from gstlal
import datasource
52 from gstlal
import pipeparts
53 from gstlal
import hoftcache
55 pipeparts.mkchecktimestamps = lambda
pipeline, src, *args: src
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.
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)
70 sys.excepthook = excepthook
74 # =============================================================================
78 # =============================================================================
82 def parse_command_line():
83 parser = OptionParser(
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)
91 options, filenames = parser.parse_args()
93 options.description = "CBC_TMP"
96 output_cache_filename, = filenames
98 raise ValueError("must provide exactly one output cache filename")
100 return options, output_cache_filename
104 # =============================================================================
108 # =============================================================================
117 options, output_cache_filename = parse_command_line()
118 data_source_info = datasource.GWDataSourceInfo(options)
126 cache = hoftcache.cache_hoft(data_source_info, output_path = options.output_path, sample_rate = options.sample_rate, description = options.description, verbose = options.verbose)
135 print >>sys.stderr, "writing %s ..." % output_cache_filename
136 cache_file = open(output_cache_filename, "w")
138 print >>cache_file, str(entry)