3 # Copyright (C) 2020 Leo Tsukada
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 """Reproduce the psd frequnecy arraies used for whitening a template bank from the given svd bank files and dump it to a xml file."""
23 ### $ gstlal_svd_bank_calc_psd --write-psd ./reproduce_svd_bank_psd.xml.gz \\
24 ### --svd-bank-files H1-GSTLAL_SVD_BANK.xml.gz \\
25 ### --svd-bank-files L1-GSTLAL_SVD_BANK.xml.gz \\
26 ### --svd-bank-files V1-GSTLAL_SVD_BANK.xml.gz \\
32 ### - :any:`gstlal_svd_bank`
40 from optparse
import OptionParser
42 from ligo.lw
import ligolw
43 from ligo.lw
import array as ligolw_array
44 from ligo.lw
import param as ligolw_param
45 from ligo.lw
import lsctables
46 from ligo.lw
import utils as ligolw_utils
48 from lal
import series as lalseries
50 from gstlal
import svd_bank
55 class LIGOLWContentHandler(ligolw.LIGOLWContentHandler):
58 def parse_command_line():
59 parser = OptionParser(description = __doc__)
62 parser.add_option("--write-psd", metavar = "filename", help = "Write measured noise spectrum to this LIGO light-weight XML file (required).")
63 parser.add_option("--svd-bank-files", action="append", metavar = "filename", default=[], help = "Set svd bank files from which to make psd xml file. One can set this multiple times, e.g. --svd-bank-files H1-SVD-BANK...xml.gz --svd-bank-files L1-SVD-BANK...xml.gz --svd-bank-files V1-SVD-BANK...xml.gz.")
64 parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose (optional).")
66 options, filenames = parser.parse_args()
68 # check our own options
69 if options.write_psd is None:
70 raise ValueError("Must specify --write-psd")
72 return options, filenames
76 # =============================================================================
80 # =============================================================================
84 options, filenames = parse_command_line()
89 for svd_bank_path in options.svd_bank_files:
90 bank = svd_bank.read_banks(svd_bank_path, contenthandler = LIGOLWContentHandler, verbose = options.verbose)[0]
91 psds.update({bank.sngl_inspiral_table[0].ifo: bank.processed_psd})
94 ligolw_utils.write_filename(lalseries.make_psd_xmldoc(psds), options.write_psd, verbose = options.verbose)