2 Short cutting gstlal inspiral pipeline to produce SNR for gstlal_svd_bank.
3 A gstlal-based direct matched filter in time domain is also implemented.
6 from collections
import defaultdict
13 from gstlal
import cbc_template_fir
14 from gstlal
import templates
15 from gstlal
import inspiral
16 from gstlal
import lloidhandler
17 from gstlal
import lvalert_helper
18 from gstlal
import pipeio
19 from gstlal
import streamthinca
20 from gstlal
import simplehandler
21 from gstlal
import svd_bank
22 from gstlal.lloidhandler
import SegmentsTracker
23 from gstlal.snglinspiraltable
import GSTLALSnglInspiral
as SnglInspiral
26 gi.require_version(
'Gst',
'1.0')
27 gi.require_version(
'GstAudio',
'1.0')
28 from gi.repository
import GObject, Gst, GstAudio
29 GObject.threads_init()
34 from lal
import LIGOTimeGPS
35 from lal.utils
import CacheEntry
38 import lalsimulation
as lalsim
40 from ligo.gracedb
import rest
as gracedb
41 from ligo.lw
import array
as ligolw_array
42 from ligo.lw
import ligolw
43 from ligo.lw
import lsctables
44 from ligo.lw
import param
as ligolw_param
45 from ligo.lw
import utils
as ligolw_utils
65 """LIGO_LW xml document for Signal to Noise Ratio.
67 This xml document contains the SNRs timeseries and their corresponding templates
68 autocorrelation. Some meta data are recorded in the xml document for
70 def __init__(self, bank_snrs_dict, verbose=False):
74 def write_output_url(self, outdir, row_number=None, counts=1, root_name="gstlal_inspiral_bank_SNRs"):
75 """Writing the LIGO_LW xmldoc to disk.
78 outdir (str): The output diretory.
79 row_number (int, default=None): The row number of the SNR to be outputed. Default=None is to output all.
80 root_name (str, default="gstlal_inspiral_bank_SNRs"): The root name of the xml document.
83 xmldoc: The file object representing the xmldoc.
86 assert counts >= 1,
"Number of rows must be larger than or equals to 1."
88 for instrument, bank_SNRs
in self.bank_snrs_dict.items():
90 xmldoc = ligolw.Document()
91 root = xmldoc.appendChild(ligolw.LIGO_LW())
95 for bank_SNR
in bank_SNRs:
96 branch = root.appendChild(ligolw.LIGO_LW())
97 branch.Name =
"bank_SNR"
98 branch.appendChild(ligolw_param.Param.from_pyvalue(
'bank_id', bank_SNR.bank_id))
99 self.
_append_content(branch, bank_SNR, instrument, row_number=row_number, counts=counts)
101 if row_number
is not None and len(bank_SNRs) == 1
and counts == 1:
102 outname =
"%s-%s_bank_SNR_%d_%d-%d-%d.xml.gz" % (instrument, bank_SNRs[0].method, bank_SNRs[0].bank_number, row_number, bank_SNRs[0].start, bank_SNRs[0].duration)
104 outname =
"%s-%s_bank_SNR_%s_%s-%d-%d.xml.gz" % (instrument, bank_SNRs[0].method,
"ALL",
"ALL", bank_SNRs[0].start, bank_SNRs[0].duration)
105 write_url(xmldoc, os.path.join(outdir, outname), verbose = self.
verbose)
108 def _append_content(self, branch, bank_SNR, instrument, row_number=None, counts=1):
109 """For internal use only."""
110 slicing = slice(
None,
None,
None)
if row_number
is None else slice(row_number, row_number+counts, 1)
111 for template_id, autocorrelation, snr
in zip(bank_SNR.template_id[slicing], bank_SNR.bank.autocorrelation_bank[slicing], bank_SNR[slicing]):
113 row_number = int(snr.name.split(
"_")[1])
114 tmp_branch = branch.appendChild(ligolw.LIGO_LW())
115 tmp_branch.Name =
"SNR_and_Autocorrelation"
116 tmp_branch.appendChild(ligolw_param.Param.from_pyvalue(
'template_id', template_id))
119 if snr.data.data.dtype == numpy.float32:
120 tseries = tmp_branch.appendChild(lal.series.build_REAL4TimeSeries(snr))
121 elif snr.data.data.dtype == numpy.float64:
122 tseries = tmp_branch.appendChild(lal.series.build_REAL8TimeSeries(snr))
123 elif snr.data.data.dtype == numpy.complex64:
124 tseries = tmp_branch.appendChild(lal.series.build_COMPLEX8TimeSeries(snr))
125 elif snr.data.data.dtype == numpy.complex128:
126 tseries = tmp_branch.appendChild(lal.series.build_COMPLEX16TimeSeries(snr))
128 raise ValueError(
"unsupported type : %s" % snr.data.data.dtype)
131 tmp_branch.appendChild(ligolw_array.Array.build(
'autocorrelation_bank', autocorrelation))
141 """An data interface between the SNRPipelineHandler and the SNR pipeline.
143 This is a class that defines the approximate start time and end time for which
144 the SNR should be collected.
146 def __init__(self, start, end, instrument, bank, bank_number=0, method="LLOID"):
148 raise ValueError(
"Start time must be less than end time.")
154 self.
template_id = [row.template_id
for row
in bank.sngl_inspiral_table]
168 """float: The approximate start time of all SNRs timeseries based on the buffer timestamp.
180 """float: The end time of all SNRs timeseries calculated from buffer timestamp and data.
188 return round(self.
_end)
192 """float: The approximate duration of all SNRs timeseries."""
202 """str: The instrument of the SNR."""
206 """:obj:`LAL series`: Allow access SNRs timeseries object by index."""
212 return self.
data[index]
215 """int: Return the number of SNRs timeseries."""
216 return len(self.
data)
218 def finish(self, COMPLEX = False):
219 """Settling down the collected SNRs and parse them to LAL series.
222 This method can only be called once.
225 COMPLEX (bool): True if required complex SNR, False otherwise.
228 assert self.
epoch is not None,
"No SNRs are obtained."
229 tmp_snrs = numpy.concatenate(numpy.array(self.
data), axis = 0)
230 gps_start = self.epoch.gpsSeconds + self.epoch.gpsNanoSeconds * 10.**-9
231 gps = gps_start + numpy.arange(len(tmp_snrs)) * self.
deltaT
233 if self.
s - gps[0] < 0
or self.
e - gps[-1] > 0:
234 raise ValueError(
"Invalid choice of start time or end time. The data spans from %f to %f." % (gps[0], gps[-1]))
236 s = abs(gps - self.
s).argmin()
237 e = abs(gps - self.
e).argmin()
242 tmp_snrs = tmp_snrs[s:e].T
if COMPLEX
else numpy.abs(tmp_snrs[s:e].T)
245 self.
data = [self.
_make_series(array, self.
epoch, row_number)
for row_number, array
in enumerate(tmp_snrs)]
249 raise NotImplementedError(
"Cannot .finish() because SNR has been .finish()ed.")
252 def _make_series(self, array, epoch, row_number):
253 """For internal use only."""
258 "sampleUnits" : lal.DimensionlessUnit,
259 "length" : len(array)}
260 if array.dtype == numpy.float32:
261 tseries = lal.CreateREAL4TimeSeries(**para)
262 elif array.dtype == numpy.float64:
263 tseries = lal.CreateREAL8TimeSeries(**para)
264 elif array.dtype == numpy.complex64:
265 tseries = lal.CreateCOMPLEX8TimeSeries(**para)
266 elif array.dtype == numpy.complex128:
267 tseries = lal.CreateCOMPLEX16TimeSeries(**para)
269 raise ValueError(
"unsupported type : %s " % array.dtype)
271 tseries.data.data = array
275 def __init__(self, *arg, **kwargs):
276 super(SNRHandlerMixin, self).__init__(*arg, **kwargs)
279 """Callback function for SNR appsink."""
282 instrument = elem.name.split(
"_")[0]
283 index = int(elem.name.split(
"_")[1])
284 cur_bank = self.snr_document.bank_snrs_dict[instrument][index]
286 sample = elem.emit(
"pull-sample")
288 return Gst.FlowReturn.OK
290 success, rate = sample.get_caps().get_structure(0).get_int(
"rate")
291 assert success ==
True
293 if cur_bank.deltaT
is None:
294 cur_bank.deltaT = 1. / rate
297 assert cur_bank.deltaT == 1. / rate,
"Data has different sampling rate."
299 buf = sample.get_buffer()
300 if buf.mini_object.flags & Gst.BufferFlags.GAP
or buf.n_memory() == 0:
301 return Gst.FlowReturn.OK
303 cur_time_stamp = LIGOTimeGPS(0, sample.get_buffer().pts) + cur_bank.sngl_inspiral_table[0].end
305 if cur_bank.s >= cur_time_stamp
and cur_bank.e > cur_time_stamp:
307 cur_bank.epoch = cur_time_stamp
308 cur_bank.data = [pipeio.array_from_audio_sample(sample)]
309 elif cur_bank.s <= cur_time_stamp < cur_bank.e:
310 cur_bank.data.append(pipeio.array_from_audio_sample(sample))
314 return Gst.FlowReturn.OK
316 def write_snrs(self, outdir, row_number=None, counts=1, COMPLEX=False):
317 """Writing SNRs timeseries to LIGO_LW xml files."""
318 for snrs
in self.snr_document.bank_snrs_dict.values():
322 self.snr_document.write_output_url(outdir, row_number=row_number, counts=counts)
326 """Simple SNR pipeline handler.
328 This is the SNR pipeline handler derived from simplehandler. It
329 only implements the controls for collecting SNR timeseries.
332 def __init__(self, pipeline, mainloop, snr_document, verbose=False):
333 super(SimpleSNRHandler, self).__init__(mainloop, pipeline)
334 self.
lock = threading.Lock()
339 """Simplified version of lloidhandler.Handler.
341 This is the SNR pipeline handler derived from lloidhandler. In
342 addition to the control for collecting SNR timeseries, it
343 implements controls for trigger generator.
346 def __init__(self, snr_document, verbose=False):
347 self.
lock = threading.Lock()
352 def init(self, mainloop, pipeline, coincs_document, rankingstat, horizon_distance_func, gracedbwrapper, zerolag_rankingstatpdf_url=None, rankingstatpdf_url=None, ranking_stat_output_url=None, ranking_stat_input_url=None, likelihood_snapshot_interval=None, sngls_snr_threshold=None, FAR_trialsfactor=1.0, verbose=False):
353 super(Handler, self).__init__(
358 horizon_distance_func,
359 gracedbwrapper = gracedbwrapper,
360 zerolag_rankingstatpdf_url = zerolag_rankingstatpdf_url,
361 rankingstatpdf_url = rankingstatpdf_url,
362 ranking_stat_output_url = ranking_stat_output_url,
363 ranking_stat_input_url = ranking_stat_input_url,
364 likelihood_snapshot_interval = likelihood_snapshot_interval,
365 sngls_snr_threshold = sngls_snr_threshold,
366 FAR_trialsfactor = FAR_trialsfactor,
378 def write_simplified_sngl_inspiral_table(m1, m2, s1x, s1y, s1z, s2x, s2y, s2z, instrument, approximant, filename=None):
379 """Writing a simplified sngl_inspiral_table containing only one template.
384 s1x (float): spin 1 x-axis.
385 s1y (float): spin 1 y-axis.
386 s1z (float): spin 1 z-axis.
387 s2x (float): spin 2 x-axis.
388 s2y (float): spin 2 y-axis.
389 s2z (float): spin 2 z-axis.
390 instrument (str): The instrument for the template.
391 approximant (str): The approximant used to simulate the waveform.
392 filename (str, default=None): The output filename.
395 The file object representing the xmldoc.
401 xmldoc = ligolw.Document()
402 root = xmldoc.appendChild(ligolw.LIGO_LW())
404 table = lsctables.New(lsctables.SnglInspiralTable)
405 rows = table.RowType()
408 for t, c
in zip(table.columntypes, table.columnnames):
409 if t ==
u"real_4" or t ==
u"real_8":
410 rows.__setattr__(c, 0)
411 elif t ==
u"int_4s" or t ==
u"int_8s":
412 rows.__setattr__(c, 0)
413 elif t ==
u"lstring":
414 rows.__setattr__(c,
"")
416 rows.__setattr__(c,
None)
420 rows.mtotal = m1 + m2
421 rows.mchirp = (m1 * m2)**0.6 / (m1 + m2)**0.2
428 rows.ifo = instrument
431 root.appendChild(table)
434 root.appendChild(ligolw_param.Param.from_pyvalue(
"approximant", approximant))
436 if filename
is not None:
437 ligolw_utils.write_filename(xmldoc, filename)
442 def generate_templates(table, approximant, psd, f_low, time_slice, autocorrelation_length = None, f_high = None, verbose = False):
443 """Generate whiten templates from sngl_inspiral_table."""
448 assert len(time_slice) == 1,
"Should contain only one slice."
450 if workspace.autocorrelation_length
is not None:
451 if not (workspace.autocorrelation_length % 2):
452 raise ValueError(
"autocorrelation_length must be odd (got %d)" % autocorrelation_length)
453 autocorrelation_bank = numpy.zeros((len(table), autocorrelation_length), dtype =
"cdouble")
456 autocorrelation_bank =
None
457 autocorrelation_mask =
None
461 for i, row
in enumerate(table):
463 sys.write.stderr(
"generating template %d/%d: m1 = %g, m2 = %g, s1x = %g, s1y = %g, s1z = %g, s2x = %g, s2y = %g, s2z = %g\n" % (i + 1, len(table), row.mass1, row.mass2, row.spin1x, row.spin1y, row.spin1z, row.spin2x, row.spin2y, row.spin2z))
465 template, autocorrelation, sigma = workspace.make_whitened_template(row)
466 templates.append(template)
467 sigmasq.append(sigma)
469 if autocorrelation
is not None:
470 autocorrelation_bank[i, ::-1] = numpy.concatenate((autocorrelation[-(autocorrelation_length // 2):], autocorrelation[:(autocorrelation_length // 2 + 1)]))
472 return numpy.array(templates), autocorrelation_bank, autocorrelation_mask, sigmasq, workspace.psd
476 FIXME: This is a class used to mimic the behavior of the svd bank object.
478 def __init__(self, bank_xmldoc, psd, rate, f_low, f_high = None, autocorrelation_length = None, verbose = False):
493 self.
template_duration = lalsim.SimInspiralChirpTimeBound(f_low, template.mass1 * lal.MSUN_SI, template.mass2 * lal.MSUN_SI, 0., 0.)
498 ligolw_param.get_pyvalue(bank_xmldoc,
"approximant"),
503 autocorrelation_length = autocorrelation_length,
511 def from_url(cls, url, verbose = False):
512 xmldoc = ligolw_utils.load_url(url, contenthandler = ContentHandler, verbose = verbose)
516 for root
in (elem
for elem
in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute(
"Name")
and elem.Name ==
"gstlal_template_bank"):
517 bank = cls.__new__(cls)
519 bank.bank_id = ligolw_param.get_pyvalue(root,
"bank_id")
520 bank.sample_rate = ligolw_param.get_pyvalue(root,
"sample_rate")
521 bank.processed_psd =
None
522 bank.sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(root)
523 bank.template_bank_filename = ligolw_param.get_pyvalue(root,
"template_bank_filename")
524 bank.sigmasq = ligolw_array.get_array(root,
"sigmasq").array
525 bank.templates = ligolw_array.get_array(root,
"templates").array
526 bank.autocorrelation_bank = ligolw_array.get_array(root,
"autocorrelation_bank").array
527 bank.autocorrelation_mask = ligolw_array.get_array(root,
"autocorrelation_mask").array
528 bank.horizon_factors = dict((row.template_id, sigmasq**.5)
for row, sigmasq
in zip(bank.sngl_inspiral_table, bank.sigmasq))
533 horizon_norm, = (bank.horizon_factors[row.template_id]
for row
in bank.sngl_inspiral_table
for bank
in banks
if row.template_id == min_template_id)
535 bank.horizon_distance_func = horizon_distance_func
536 bank.horizon_factors = dict((tid, f / horizon_norm)
for (tid, f)
in bank.horizon_factors.items())
540 def build_bank(bank_url, psd_file, sample_rate, f_low, f_high = None, autocorrelation_length = None, verbose = False):
541 """Return an instance of a Bank class."""
542 bank_xmldoc = ligolw_utils.load_url(bank_url, contenthandler = ContentHandler, verbose = verbose)
543 psd = lal.series.read_psd_xmldoc(ligolw_utils.load_url(psd_file, contenthandler = lal.series.PSDContentHandler))
545 assert numpy.log2(sample_rate).is_integer(),
"sample_rate can only be power of two."
547 bank =
Bank(bank_xmldoc, psd[lsctables.SnglInspiralTable.get_table(bank_xmldoc)[0].ifo], sample_rate, f_low, f_high, autocorrelation_length = autocorrelation_length, verbose = verbose)
548 bank.template_bank_filename = bank_url
555 """Write template bank to LIGO_LW xml file."""
556 xmldoc = ligolw.Document()
557 head = xmldoc.appendChild(ligolw.LIGO_LW())
558 head.Name =
u"gstlal_template_bank"
561 cloned_table = bank.sngl_inspiral_table.copy()
562 cloned_table.extend(bank.sngl_inspiral_table)
563 head.appendChild(cloned_table)
565 head.appendChild(ligolw_param.Param.from_pyvalue(
'template_bank_filename', bank.template_bank_filename))
566 head.appendChild(ligolw_param.Param.from_pyvalue(
'sample_rate', bank.sample_rate))
567 head.appendChild(ligolw_param.Param.from_pyvalue(
'bank_id', bank.bank_id))
568 head.appendChild(ligolw_array.Array.build(
'templates', bank.templates))
569 head.appendChild(ligolw_array.Array.build(
'autocorrelation_bank', bank.autocorrelation_bank))
570 head.appendChild(ligolw_array.Array.build(
'autocorrelation_mask', bank.autocorrelation_mask))
571 head.appendChild(ligolw_array.Array.build(
'sigmasq', numpy.array(bank.sigmasq)))
573 ligolw_utils.write_filename(xmldoc, filename, verbose = verbose)
576 """Parse a dictionary of bank urls key by instrument into a dictionary of
577 bank instance key by instrument."""
579 for instrument, url
in bank_urls.items():
580 banks_dict[instrument] = (Bank.from_url(url))
589 def read_xmldoc(xmldoc, root_name = u"gstlal_inspiral_bank_SNRs"):
590 if root_name
is not None:
591 root, = (elem
for elem
in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute(
u"Name")
if elem.Name == root_name)
593 snrdict = defaultdict(list)
594 autocorrelation_dict = defaultdict(list)
595 for elem
in (elem
for elem
in root.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute(
u"Name")
and elem.Name ==
"bank_SNR"):
597 for snr_acf_elem
in (elem
for elem
in elem.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute(
u"Name")
and elem.Name ==
"SNR_and_Autocorrelation"):
598 snr_elem = snr_acf_elem.getElementsByTagName(ligolw.LIGO_LW.tagName)[0]
599 if snr_elem.Name ==
u"REAL4TimeSeries":
600 tseries = lal.series.parse_REAL4TimeSeries(snr_elem)
601 snrdict[tseries.name.split(
"_")[0]].append(tseries)
602 autocorrelation_dict[tseries.name.split(
"_")[0]].append(ligolw_array.get_array(snr_acf_elem,
"autocorrelation_bank").array)
603 elif snr_elem.Name ==
u"REAL8TimeSeries":
604 tseries = lal.series.parse_REAL8TimeSeries(snr_elem)
605 snrdict[tseries.name.split(
"_")[0]].append(tseries)
606 autocorrelation_dict[tseries.name.split(
"_")[0]].append(ligolw_array.get_array(snr_acf_elem,
"autocorrelation_bank").array)
607 elif snr_elem.Name ==
u"COMPLEX8TimeSeries":
608 tseries = lal.series.parse_COMPLEX8TimeSeries(snr_elem)
609 snrdict[tseries.name.split(
"_")[0]].append(tseries)
610 autocorrelation_dict[tseries.name.split(
"_")[0]].append(ligolw_array.get_array(snr_acf_elem,
"autocorrelation_bank").array)
611 elif snr_elem.Name ==
u"COMPLEX16TimeSeries":
612 tseries = lal.series.parse_COMPLEX16TimeSeries(snr_elem)
613 snrdict[tseries.name.split(
"_")[0]].append(tseries)
614 autocorrelation_dict[tseries.name.split(
"_")[0]].append(ligolw_array.get_array(snr_acf_elem,
"autocorrelation_bank").array)
616 assert snrdict
is not None,
"xmldoc contains no LAL Series or LAL Series is unsupported"
618 return snrdict, autocorrelation_dict
621 def write_url(xmldoc, filename, verbose = False):
622 ligolw_utils.write_filename(xmldoc, filename, verbose = verbose)
625 def read_url(filename, contenthandler = SNRContentHandler, verbose = False):
626 return ligolw_utils.load_url(filename, verbose = verbose, contenthandler = contenthandler)
634 """Scan the sub bank id and row number of an event template from coinc.xml file.
637 coinc_xmldoc (:obj: `xmldoc`): The coinc.xml file from gracedb.
638 banks_dict (dict): A dictionary of SVD banks key by instrument containing the event template.
645 eventid_trigger_dict = dict((row.ifo, row)
for row
in lsctables.SnglInspiralTable.get_table(coinc_xmldoc))
647 assert len(set([row.template_id
for row
in eventid_trigger_dict.values()])) == 1,
"Templates should have the same template_id."
651 for i, bank
in enumerate(banks_dict.values()[0]):
652 for j, row
in enumerate(bank.sngl_inspiral_table):
653 if row.template_id == eventid_trigger_dict.values()[0].template_id:
657 if bank_number
is not None:
659 assert bank_number
is not None,
"Cannot find the template listed in the coinc.xml."
660 return bank_number, row_number
663 """Find location of the SVD banks from gracedb event id.
666 gid (str): The gracedb event id.
667 outdir (str, default="."): The output directory.
668 save (bool, default=False): True if want to save the file, False otherwise.
669 verbose (bool, default=False): Be verbose.
672 banks_dict (dict of :obj: `Bank`): The SVD banks for an event key by instrument.
677 gracedb_client = gracedb.GraceDb()
681 path = [row.value
for row
in lsctables.ProcessParamsTable.get_table(coinc_xmldoc)
if row.param ==
"--gracedb-service-url"]
682 bank_urls =
inspiral.parse_svdbank_string([row.value
for row
in lsctables.ProcessParamsTable.get_table(coinc_xmldoc)
if row.param ==
"--svd-bank"].pop())
685 for ifo, bank_url
in bank_urls.items():
686 bank_urls[ifo] = os.path.join(path, bank_url)
689 sys.stderr.write(
"Files Not Found! Make sure you are on the LIGO-Caltech Computing Cluster or check if files exist.\nAbortting...\n")
694 for bank_url
in bank_urls.values():
695 outname = os.path.join(outdir, os.path.basename(bank_url))
697 sys.stderr.write(
"saving SVD bank files to %s ...\n" % outname)
698 shutil.copyfile(bank_url, outname)
707 return banks_dict, bank_number, row_number
709 def framecache_from_event(gid, observatories, frame_types, time_span = 500, outdir = ".", filename = "frame.cache", verbose = False):
710 """Get the frame cache for an event given the gracedb event id.
713 gid (str): The gracedb event id.
714 observatories (list): See gwdatafind.
715 frame_type (list): See gwdatafind.
716 time_span (float): The time span before and after the trigger time.
717 outdir (str, default="."): The output directory.
718 filename (str, default="frame.cache"): The output filename.
719 verbose (bool): Be verbose.
722 Dictionary of instruments, trigger_times, gps_start_time,
723 gps_end_time, channels_name.
726 assert time_span >= 500.,
"Please use time_span larger or equal to 500."
728 obs2ifo = {
"H":
"H1",
"L":
"L1",
"V":
"V1"}
730 observatories = set(observatories)
731 frame_types = set(frame_types)
733 if len(observatories) != len(frame_types):
734 raise ValueError(
"Must have as many frame_types as observatories.")
736 obs_type_dict = dict([(obs, frame_type)
for obs
in observatories
for frame_type
in frame_types
if obs == frame_type[0]])
738 gracedb_client = gracedb.GraceDb()
740 eventid_trigger_dict = dict((row.ifo, row)
for row
in lsctables.SnglInspiralTable.get_table(coinc_xmldoc))
741 channel_names_dict = dict([(row.value.split(
"=")[0], row.value)
for row
in lsctables.ProcessParamsTable.get_table(coinc_xmldoc)
if row.param ==
"--channel-name"])
743 gwdata_metavar_headers = [
"instruments",
"trigger_times",
"gps_start_time",
"gps_end_time",
"channels_name"]
744 gwdata_metavar_values = []
746 for observatory, frame_type
in obs_type_dict.items():
747 trigger_time = eventid_trigger_dict[obs2ifo[observatory]].end
748 gps_start_time = int(trigger_time - time_span)
749 gps_end_time = int(trigger_time + time_span)
750 gwdata_metavar_values.append((obs2ifo[observatory], trigger_time, gps_start_time, gps_end_time, channel_names_dict[obs2ifo[observatory]]))
752 urls += gwdatafind.find_urls(observatory, frame_type, gps_start_time, gps_end_time)
754 with open(os.path.join(outdir,
"frame.cache"),
"w")
as cache:
756 filename = str(CacheEntry.from_T050017(url))
757 cache.write(
"%s\n" % filename)
759 sys.stderr.write(
"writing %s to %s\n" % (filename, os.path.join(outdir,
"frame.cache")))
761 sys.stderr.write(
"Done.\n")
763 return dict(zip(gwdata_metavar_headers, zip(*gwdata_metavar_values)))
765 def psd_from_event(gid, outdir = ".", save = False, filename = "psd.xml.gz", verbose = False):
766 """Get the psd.xml.gz given a gracedb event id.
769 gid (str): The gracedb event id.
770 outdir (str, default="."): The output directory.
771 filename (str, default="psd.xml.gz"): The output filename.
772 save (bool, default=False): True if want to save the file, False otherwise.
773 verbose (bool, default=False): Be verbose.
776 A dictionary of complex LAL Series key by instrument.
779 gracedb_client = gracedb.GraceDb()
781 xmldoc = ligolw_utils.load_fileobj(psd_fileobj, contenthandler = lal.series.PSDContentHandler)
784 sys.stderr.write(
"saving psd file to %s ...\n" % os.path.join(outdir, filename))
785 ligolw_utils.write_filename(xmldoc, filename)
786 return lal.series.read_psd_xmldoc(xmldoc)
A subclass of simplehandler.Handler to be used with e.g., gstlal_inspiral.
def compute_autocorrelation_mask
def horizon_distance_func
def framecache_from_event
def write_simplified_sngl_inspiral_table
def gstlal_valid_approximant
def appsink_new_snr_buffer
def scan_svd_banks_for_row