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