gstlal 1.13.0
Loading...
Searching...
No Matches
gstlal_query_dqsegdb_segments
1#!/usr/bin/env python3
2#
3# Copyright (C) 2020-2021 Kipp Cannon, Patrick Godwin, Chad Hanna, 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_segments
29
30#
31# Define/parse command line options
32#
33
34parser = argparse.ArgumentParser(description='Download GWOSC 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("-s", "--server", metavar="url", default=DEFAULT_DQSEGDB_SERVER, help=f"Set the URL of the DQSegDB server to query. Default: {DEFAULT_DQSEGDB_SERVER}")
39parser.add_argument("-f", "--flag", metavar="flag", action="append", default=[], help=f"Set the flags to use to query segments, one for each instrument.")
40parser.add_argument("-o", "--output", metavar="file", default="segments.xml.gz", help="Set the name of the segments file generated. Default: segments.xml.gz")
41args = parser.parse_args()
42
43instruments = set([])
44for x in args.ifo:
45 # assume all instruments are two characters and split combos like H1L1 if they exist
46 instruments |= set([x[i*2:i*2+2] for i in range(int(len(x) / 2))])
47
48flags = {}
49for flag in args.flag:
50 ifo, _ = flag.split(":", 1)
51 flags[ifo] = flag
52
53#
54# Query segments
55#
56
57print("Downloading segment lists ...", file=sys.stderr)
58segments = query_dqsegdb_segments(instruments, args.start, args.end, flags=flags, server=args.server)
59
60#
61# Write segments to disk
62#
63
64xmldoc = ligolw.Document()
65xmldoc.appendChild(ligolw.LIGO_LW())
66process = ligolw_process.register_to_xmldoc(xmldoc, sys.argv[0], vars(args))
67with ligolw_segments.LigolwSegments(xmldoc, process) as lwseglists:
68 lwseglists.insert_from_segmentlistdict(segments, "datasegments")
69process.set_end_time_now()
70
71ligolw_utils.write_filename(xmldoc, args.output, verbose=True)
72xmldoc.unlink()