-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_gating_from_omicron
executable file
·74 lines (56 loc) · 2.82 KB
/
make_gating_from_omicron
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env python
import sys
from glue import lal
from gwpy.table.lsctables import SnglBurstTable, SegmentTable
from gwpy.segments import DataQualityFlag, Segment, SegmentList
import numpy
import argparse
dqsegdb_url = "https://segments.ligo.org"
parser = argparse.ArgumentParser(description='Make a PyCBC gating file from Omicron triggers.')
parser.add_argument('-i','--ifo', type=str, help='IFO', required=True)
parser.add_argument('-s','--start', type=int, help='GPS start time.', required=True)
parser.add_argument('-e','--end', type=int, help='GPS end time', required=True)
parser.add_argument('-m','--min-snr', type=int, help='Min SNR cut', default=300)
parser.add_argument('-z','--zeros', type=float, help='Half-width of zeros in window (sec)', default=0.25)
parser.add_argument('-p','--pad', type=float, help='Width of padding (sec)', default=0.25)
parser.add_argument('-c','--cache-file', type=str, help='Cache file contaiing omicron triggers', required=True)
parser.add_argument('-v','--verbose', help='verbose', action='store_true', default=False)
args = parser.parse_args()
hoft_channel = '%s:GDS-CALIB_STRAIN' % args.ifo
sci_flag = '%s:DMT-ANALYSIS_READY:1' % args.ifo
exclude_flag = '%s:DCH-MISSING_%s_HOFT_C00:2' % (args.ifo, args.ifo)
requested_segs = SegmentList([Segment(args.start, args.end)])
if args.verbose: print >> sys.stdout, "querying %s from %s" % (sci_flag,dqsegdb_url)
sci_segs = DataQualityFlag.query_dqsegdb(sci_flag, args.start, args.end, url=dqsegdb_url)
if args.verbose: print >> sys.stdout, "querying %s from %s" % (exclude_flag,dqsegdb_url)
exclude_segs = DataQualityFlag.query_dqsegdb(exclude_flag, args.start, args.end, url=dqsegdb_url)
input_segs = sci_segs.active - exclude_segs.active
needed_segs = SegmentList()
# strip of the two seconds that omicron discards
for i in input_segs:
needed_segs.append( Segment( i[0] + 2, i[1] - 2) )
# Loop through each
trigs_lst = []
omicron_segs = SegmentList()
# build a cache from from command line
file_cache = lal.Cache.fromfilenames([args.cache_file])
# loop over the files in the cache
for pfn in file_cache.pfnlist():
if args.verbose: print >> sys.stdout, pfn
# read in the segments from the omicron files
segs = SegmentTable.read(pfn)
for i in segs:
omicron_segs.append(Segment(i.start_time,i.end_time))
# read in the triggers from the omicron files
trigs = SnglBurstTable.read(pfn)
# make gates
trigs_lst.extend([float(trig.get_peak())
for trig in trigs
if trig.snr > args.min_snr])
print needed_segs - omicron_segs
output_fname = '%s-gating_SNR%u-%u-%u.txt' % (args.ifo, args.min_snr, args.start, args.end-args.start)
fout = open(output_fname,'w')
fout.write('\n'.join(['%10.4f %.4f %.4f' % (x, args.zeros, args.pad)
for x in trigs_lst]))
fout.write('\n')
fout.close()