gstlal 1.13.0
Loading...
Searching...
No Matches
gstlal_query_dqsegdb_veto_segments
1#!/usr/bin/env python3
2#
3# Copyright (C) 2020-2021 Heather Fong, Patrick Godwin, Ryan Magee, Cody Messick
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
19
20import argparse
21import sys
22
23from ligo.lw import ligolw
24from ligo.lw import utils as ligolw_utils
25from ligo.lw.utils import process as ligolw_process
26from ligo.lw.utils import segments as ligolw_segments
27
28from gstlal.segments import DEFAULT_DQSEGDB_SERVER, query_dqsegdb_veto_segments
29
30#
31# Define/parse command line options
32#
33
34parser = argparse.ArgumentParser(description='Download GWOSC veto segments.')
35parser.add_argument("start", metavar="START", type=int, help="Set the start GPS time.")
36parser.add_argument("end", metavar="END", type=int, help="Set the end GPS time.")
37parser.add_argument("ifo", metavar="IFO", nargs="+", help="Set the instruments to process, e.g. H1.")
38parser.add_argument("-v", "--veto-definer-file", metavar="file", help="The veto definer file in which to query DQSegDB for.")
39parser.add_argument("-s", "--server", metavar="url", default=DEFAULT_DQSEGDB_SERVER, help=f"Set the URL of the DQSegDB server to query. Default: {DEFAULT_DQSEGDB_SERVER}")
40parser.add_argument("-c", "--category", help="Set the veto category to generate veto segments for.")
41parser.add_argument("--cumulative", action="store_true", help="Set whether veto categories are cumulative, e.g. if CAT2 and cumulative, combine both CAT1 and CAT2 vetoes.")
42parser.add_argument("-o", "--output", metavar="file", default="vetoes.xml.gz", help="Set the name of the segments file generated. Default: vetoes.xml.gz")
43args = parser.parse_args()
44
45instruments = set([])
46for x in args.ifo:
47 # assume all instruments are two characters and split combos like H1L1 if they exist
48 instruments |= set([x[i*2:i*2+2] for i in range(int(len(x) / 2))])
49
50#
51# Query veto segments
52#
53
54print("Downloading veto segments ...", file=sys.stderr)
55vetoes = query_dqsegdb_veto_segments(
56 instruments,
57 args.start,
58 args.end,
59 args.veto_definer_file,
60 category=args.category,
61 cumulative=args.cumulative,
62 server=args.server,
63)
64
65#
66# Write vetoes to disk
67#
68
69xmldoc = ligolw.Document()
70xmldoc.appendChild(ligolw.LIGO_LW())
71process = ligolw_process.register_to_xmldoc(xmldoc, sys.argv[0], vars(args))
72with ligolw_segments.LigolwSegments(xmldoc, process) as lwseglists:
73 lwseglists.insert_from_segmentlistdict(vetoes, "vetoes")
74process.set_end_time_now()
75
76ligolw_utils.write_filename(xmldoc, args.output, verbose=True)
77xmldoc.unlink()