gstlal 1.13.0
Loading...
Searching...
No Matches
gstlal_query_gwosc_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 lal import LIGOTimeGPS
24from ligo import segments
25from ligo.lw import ligolw
26from ligo.lw import utils as ligolw_utils
27from ligo.lw.utils import process as ligolw_process
28from ligo.lw.utils import segments as ligolw_segments
29
30from gstlal.segments import query_gwosc_segments
31
32#
33# Define/parse command line options
34#
35
36parser = argparse.ArgumentParser(description='Download GWOSC segments.')
37parser.add_argument("start", metavar="START", type=int, help="Set the start GPS time.")
38parser.add_argument("end", metavar="END", type=int, help="Set the end GPS time.")
39parser.add_argument("ifo", metavar="IFO", nargs="+", help="Set the instruments to process, e.g. H1.")
40parser.add_argument("--no-cert", action="store_true", help="Turn off SSL certificate validation. Default: False.")
41parser.add_argument("-o", "--output", metavar="file", default="segments.xml.gz", help="Set the name of the segments file generated. Default: segments.xml.gz")
42args = parser.parse_args()
43
44span = segments.segment(LIGOTimeGPS(args.start), LIGOTimeGPS(args.end))
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 segments
52#
53
54print("Downloading segment lists ...", file=sys.stderr)
55segments = query_gwosc_segments(instruments, args.start, args.end, verify_certs=(not args.no_cert))
56
57#
58# Write segments to disk
59#
60
61xmldoc = ligolw.Document()
62xmldoc.appendChild(ligolw.LIGO_LW())
63process = ligolw_process.register_to_xmldoc(xmldoc, sys.argv[0], vars(args))
64with ligolw_segments.LigolwSegments(xmldoc, process) as lwseglists:
65 lwseglists.insert_from_segmentlistdict(segments, "datasegments")
66process.set_end_time_now()
67
68ligolw_utils.write_filename(xmldoc, args.output, verbose=True)
69xmldoc.unlink()