gstlal 1.13.0
Loading...
Searching...
No Matches
gstlal_query_gwosc_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 lal import LIGOTimeGPS
24from ligo.lw import ligolw
25from ligo.lw import utils as ligolw_utils
26from ligo.lw.utils import process as ligolw_process
27from ligo.lw.utils import segments as ligolw_segments
28
29from gstlal.segments import query_gwosc_veto_segments
30
31#
32# Define/parse command line options
33#
34
35parser = argparse.ArgumentParser(description='Download GWOSC veto segments.')
36parser.add_argument("start", metavar="START", type=int, help="Set the start GPS time.")
37parser.add_argument("end", metavar="END", type=int, help="Set the end GPS time.")
38parser.add_argument("ifo", metavar="IFO", nargs="+", help="Set the instruments to process, e.g. H1.")
39parser.add_argument("--category", help="Set the veto category to generate veto segments for.")
40parser.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.")
41parser.add_argument("--no-cert", action="store_true", help="Turn off SSL certificate validation. Default: False.")
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_gwosc_veto_segments(
56 instruments,
57 args.start,
58 args.end,
59 category=args.category,
60 cumulative=args.cumulative,
61 verify_certs=(not args.no_cert),
62)
63
64#
65# Write vetoes to disk
66#
67
68xmldoc = ligolw.Document()
69xmldoc.appendChild(ligolw.LIGO_LW())
70process = ligolw_process.register_to_xmldoc(xmldoc, sys.argv[0], vars(args))
71with ligolw_segments.LigolwSegments(xmldoc, process) as lwseglists:
72 lwseglists.insert_from_segmentlistdict(vetoes, "vetoes")
73process.set_end_time_now()
74
75ligolw_utils.write_filename(xmldoc, args.output, verbose=True)
76xmldoc.unlink()