Skip to content
Snippets Groups Projects
#!/usr/bin/env python3
#
# Copyright (C) 2010--2015 Kipp Cannon, Chad Hanna
# Copyright (C) 2021 Soichiro Kuwawhara
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
### A program to compute the noise probability distributions of likehood ratios for inspiral triggers
#
# =============================================================================
#
# Preamble
#
# =============================================================================
#
from optparse import OptionParser
import sys
from ligo.lw import ligolw
from ligo.lw import lsctables
from ligo.lw import utils as ligolw_utils
from ligo.lw.utils import process as ligolw_process
from lal.utils import CacheEntry
from gstlal import cherenkov
from gstlal.cherenkov import rankingstat as cherenkov_rankingstat
__author__ = "Soichiro Kuwara <soichiro.kuwahara@ligo.org>"
#
# =============================================================================
#
# Command Line
#
# =============================================================================
#
def parse_command_line():
parser = OptionParser(
description = "Rankngstat calculation program for Cherenkov burst search.",
usage = "%prog [options] [candidatesxml ...]"
)
parser.add_option("--candidates-cache", metavar = "filename", help = "Also load the candidates from files listed in this LAL cache. See lalapps_path2cache for information on how to produce a LAL cache file.")
parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
parser.add_option("--ranking-stat-pdf", metavar = "filename", help = "Write zero-lag ranking statistic PDF to this file. Must contain exactly one Cherenkov burst ranking statistic PDF object.")
parser.add_option("--is-timeshifted", action = "store_true", help = "Whether the open(zerolag) or closed(time shifted) box.")
options, urls = parser.parse_args()
paramdict = options.__dict__.copy()
if options.candidates_cache is not None:
urls += [CacheEntry(line).url for line in open(options.candidates_cache)]
if not urls:
raise ValueError("must provide some candidate files")
if options.ranking_stat_pdf is None:
raise ValueError("must set --ranking-stat-pdf")
return options, urls, paramdict
#
# =============================================================================
#
# Main
#
# =============================================================================
#
#
# command line
#
options, urls, paramdict = parse_command_line()
#
# load ranking statistic PDF
#
# FIXME: it would be better to preserve all the contents of the original file instead of just the PDF object
rankingstatpdf = cherenkov_rankingstat.RankingStatPDF.from_xml(ligolw_utils.load_filename(options.ranking_stat_pdf, contenthandler = cherenkov_rankingstat.LIGOLWContentHandler, verbose = options.verbose), "gstlal_cherenkov_rankingstat_pdf")
#
# zero the zero-lag ranking statistic PDF
#
rankingstatpdf.zl_lr_lnpdf.array[:] = 0.
#
# load zero-lag candidates and histogram their ranking statistics
#
for n, url in enumerate(urls, 1):
if options.verbose:
print("%d/%d: " % (n, len(urls)), end = "", file = sys.stderr)
xmldoc = ligolw_utils.load_url(url, contenthandler = cherenkov_rankingstat.LIGOLWContentHandler, verbose = options.verbose)
coinc_def_id = lsctables.CoincDefTable.get_table(xmldoc).get_coinc_def_id(search = cherenkov.CherenkovBBCoincDef.search, search_coinc_type = cherenkov.CherenkovBBCoincDef.search_coinc_type, create_new = False)
if options.is_timeshifted:
zl_time_slide_ids = frozenset(time_slide_id for time_slide_id, offsetvector in lsctables.TimeSlideTable.get_table(xmldoc).as_dict().items() if any(offsetvector.values()))
else:
zl_time_slide_ids = frozenset(time_slide_id for time_slide_id, offsetvector in lsctables.TimeSlideTable.get_table(xmldoc).as_dict().items() if not any(offsetvector.values()))
for coinc in lsctables.CoincTable.get_table(xmldoc):
if coinc.coinc_def_id == coinc_def_id and coinc.time_slide_id in zl_time_slide_ids:
rankingstatpdf.zl_lr_lnpdf.count[coinc.likelihood,] += 1
#
# apply density estimation kernel to zero-lag counts
#
rankingstatpdf.density_estimate(rankingstatpdf.zl_lr_lnpdf, "zero-lag")
rankingstatpdf.zl_lr_lnpdf.normalize()
#
# Write the parameter and ranking statistic distribution data to a file
#
xmldoc = ligolw.Document()
xmldoc.appendChild(ligolw.LIGO_LW())
process = ligolw_process.register_to_xmldoc(xmldoc, "gstlal_cherenkov_calc_rank_pdfs", paramdict = paramdict)
xmldoc.childNodes[-1].appendChild(rankingstatpdf.to_xml("gstlal_cherenkov_rankingstat_pdf"))
process.set_end_time_now()
ligolw_utils.write_filename(xmldoc, options.ranking_stat_pdf, verbose = options.verbose)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
usr/bin/*
usr/lib/*/python*/*/gstlal
usr/lib/python*/*/gstlal
usr/lib/*/*.so.*
usr/lib/*/gstreamer-*/*.so*
usr/lib/python*/*/gstlal
#!/usr/bin/make -f
%:
dh $@ --with=python2
dh $@ --with=python3
override_dh_auto_install:
$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
......