3 # Copyright (C) 2010 Kipp Cannon, Chad Hanna, Leo Singer
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.
18 """Estimate power spectra from LIGO frames or simulated h(t)."""
20 ### This program will measure a power spectral density from data
22 ### This program will measure the PSD of data Its input is anything
23 ### supported by datasource.py.
25 ### Graph of the gsreamer pipeline
26 ### ------------------------------
28 ### Please see :py:func:`reference_psd.measure_psd`
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.,::
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
40 ### See :any:`gstlal_plot_psd` to plot the result
42 ### 2. Measuring the PSD of low-latency data (e.g. on CIT cluster)::
44 ### $ gstlal_reference_psd --data-source framexmit --channel-name=L1=FAKE-STRAIN \\
45 ### --write-psd psd.xml.gz
47 ### 3. Other things are certainly possible, please add them!
52 ### - :any:`gstlal_plot_psd`
53 ### - :any:`gstlal_plot_psd_horizon`
54 ### - :any:`gstlal_spectrum_movie`
62 from optparse import OptionParser
63 from gstlal import datasource
64 from gstlal import reference_psd
67 def parse_command_line():
68 parser = OptionParser(description = __doc__)
70 # generic "source" options
71 datasource.append_options(parser)
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).")
79 options, filenames = parser.parse_args()
81 # check our own options
82 if options.write_psd is None:
83 raise ValueError("Must specify --write-psd")
85 return options, filenames
89 # =============================================================================
93 # =============================================================================
97 options, filenames = parse_command_line()
100 # parse the generic "source" options, check for inconsistencies is done inside
101 # the class init method
102 detectors = datasource.GWDataSourceInfo(options)
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)