gstlal  1.4.1
gstlal_reference_psd
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2010 Kipp Cannon, Chad Hanna, Leo Singer
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 """Estimate power spectra from LIGO frames or simulated h(t)."""
19 
20 ### This program will measure a power spectral density from data
21 ###
22 ### This program will measure the PSD of data Its input is anything
23 ### supported by datasource.py.
24 ###
25 ### Graph of the gsreamer pipeline
26 ### ------------------------------
27 ###
28 ### Please see :py:func:`reference_psd.measure_psd`
29 ###
30 ### Usage
31 ### -----
32 ###
33 ### 1. Measure the PSD of frame data found in a file called frame.cache. Note: you can make frame cache with lalapps_path2cache, e.g.,::
34 ###
35 ### $ gstlal_reference_psd --data-source frames --frame-cache frame.cache \\
36 ### --gps-start-time=900000000 --gps-end-time=900005000 \\
37 ### --channel-name=H1=FAKE-STRAIN --channel-name=L1=FAKE-STRAIN \\
38 ### --write-psd psd.xml.gz --verbose
39 ###
40 ### See :any:`gstlal_plot_psd` to plot the result
41 ###
42 ### 2. Measuring the PSD of low-latency data (e.g. on CIT cluster)::
43 ###
44 ### $ gstlal_reference_psd --data-source framexmit --channel-name=L1=FAKE-STRAIN \\
45 ### --write-psd psd.xml.gz
46 ###
47 ### 3. Other things are certainly possible, please add them!
48 ###
49 ### Related programs
50 ### ----------------
51 ###
52 ### - :any:`gstlal_plot_psd`
53 ### - :any:`gstlal_plot_psd_horizon`
54 ### - :any:`gstlal_spectrum_movie`
55 ###
56 
57 #
58 # parse command line
59 #
60 
61 
62 from optparse import OptionParser
63 from gstlal import datasource
64 from gstlal import reference_psd
65 
66 
67 def parse_command_line():
68  parser = OptionParser(description = __doc__)
69 
70  # generic "source" options
71  datasource.append_options(parser)
72 
73  # add our own options
74  parser.add_option("--write-psd", metavar = "filename", help = "Write measured noise spectrum to this LIGO light-weight XML file (required).")
75  parser.add_option("--sample-rate", metavar = "Hz", default = 16384, type = "int", help = "Sample rate at which to generate the PSD, default 16384 Hz")
76  parser.add_option("--psd-fft-length", metavar = "s", default = 8, type = "int", help = "FFT length, default 8s")
77  parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose (optional).")
78 
79  options, filenames = parser.parse_args()
80 
81  # check our own options
82  if options.write_psd is None:
83  raise ValueError("Must specify --write-psd")
84 
85  return options, filenames
86 
87 
88 #
89 # =============================================================================
90 #
91 # Main
92 #
93 # =============================================================================
94 #
95 
96 
97 options, filenames = parse_command_line()
98 
99 
100 # parse the generic "source" options, check for inconsistencies is done inside
101 # the class init method
102 detectors = datasource.GWDataSourceInfo(options)
103 
104 
105 reference_psd.write_psd(options.write_psd, dict((instrument, reference_psd.measure_psd(detectors, instrument, options.sample_rate, psd_fft_length = options.psd_fft_length, verbose = options.verbose)) for instrument in detectors.channel_dict), verbose = options.verbose)