gstlal 1.13.0
Loading...
Searching...
No Matches
gstlal_reference_psd
1#!/usr/bin/env python3
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
56
57#
58# parse command line
59#
60
61
62from optparse import OptionParser
63
64from gstlal import datasource
65from gstlal.psd import measure_psd, write_psd
66
67
68def parse_command_line():
69 parser = OptionParser(description = __doc__)
70
71 # generic "source" options
72 datasource.append_options(parser)
73
74 # add our own options
75 parser.add_option("--write-psd", metavar = "filename", help = "Write measured noise spectrum to this LIGO light-weight XML file (required).")
76 parser.add_option("--sample-rate", metavar = "Hz", default = 16384, type = "int", help = "Sample rate at which to generate the PSD, default 16384 Hz")
77 parser.add_option("--psd-fft-length", metavar = "s", default = 8, type = "int", help = "FFT length, default 8s")
78 parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose (optional).")
79
80 options, filenames = parser.parse_args()
81
82 # check our own options
83 if options.write_psd is None:
84 raise ValueError("Must specify --write-psd")
85
86 return options, filenames
87
88
89#
90# =============================================================================
91#
92# Main
93#
94# =============================================================================
95#
96
97
98options, filenames = parse_command_line()
99
100
101# parse the generic "source" options, check for inconsistencies is done inside
102# the class init method
103detectors = datasource.DataSourceInfo.from_optparse(options)
104
105psds = {}
106for instrument in detectors.channel_dict:
107 psds[instrument] = measure_psd(
108 detectors,
109 instrument,
110 options.sample_rate,
111 psd_fft_length=options.psd_fft_length,
112 verbose=options.verbose,
113 )
114
115write_psd(options.write_psd, psds, verbose=options.verbose)