Skip to content
Snippets Groups Projects
Commit 355d9a53 authored by Prathamesh Joshi's avatar Prathamesh Joshi Committed by Prathamesh Joshi
Browse files

OEM pdf health fix

The sum of noise counts may change due to first-round-extinction, so this commit stores the sum of counts in the PDF before extinction in a different variable, and this variable is used for checking the health of the PDF (which is exactly what was being done before)
parent f9538e80
No related branches found
No related tags found
No related merge requests found
Pipeline #588963 passed with warnings
......@@ -645,6 +645,11 @@ class RankingStatPDF(object):
self.signal_lr_lnpdf.array *= rankingstat.numerator.candidate_count_model() / self.signal_lr_lnpdf.array.sum()
self.signal_lr_lnpdf.normalize()
# the sum of noise counts may change due to first-round-extinction,
# so store the sum of counts before extinction in a different variable.
# This will be used for checking the health of the PDF
self.noise_counts_before_extinction = self.noise_lr_lnpdf.array.sum()
def copy(self):
new = self.__class__(None)
......@@ -653,6 +658,7 @@ class RankingStatPDF(object):
new.zero_lag_lr_lnpdf = self.zero_lag_lr_lnpdf.copy()
new.segments = type(self.segments)(self.segments)
new.template_ids = self.template_ids
new.noise_counts_before_extinction = self.noise_counts_before_extinction
return new
......@@ -719,6 +725,7 @@ WHERE
# templates are the same then the segments must be disjoint
self.segments += other.segments
self.template_ids |= other.template_ids
self.noise_counts_before_extinction += other.noise_counts_before_extinction
return self
......@@ -796,7 +803,7 @@ WHERE
def is_healthy(self, verbose = False):
# do we believe the PDFs are sufficiently well-defined to
# compute FAPs and FARs?
health = min(self.noise_lr_lnpdf.array.sum() / 1000000., self.zero_lag_lr_lnpdf.array.sum() / 1000.)
health = min(self.noise_counts_before_extinction / 1000000., self.zero_lag_lr_lnpdf.array.sum() / 1000.)
with tqdm(desc = "ranking stat. health", total = 1., bar_format="{l_bar}{bar}", disable = not verbose) as pbar:
pbar.update(health)
return health >= 1.
......@@ -830,6 +837,13 @@ WHERE
self.segments = ligolw_param.get_pyvalue(xml, u"segments").strip()
self.segments = segmentsUtils.from_range_strings(self.segments.split(",") if self.segments else [], float)
self.template_ids = frozenset(map(int, ligolw_param.get_pyvalue(xml, u"template_ids").split(",")))
try:
self.noise_counts_before_extinction = ligolw_param.get_pyvalue(xml, u"noise_counts_before_extinction")
except ValueError:
# the PDF was using the old extinction model
# in which case noise_counts_before_extinction
# is the same as the sum of the noise array
self.noise_counts_before_extinction = self.noise_lr_lnpdf.array.sum()
return self
def to_xml(self, name):
......@@ -845,6 +859,7 @@ WHERE
xml.appendChild(self.zero_lag_lr_lnpdf.to_xml(u"zero_lag_lr_lnpdf"))
xml.appendChild(ligolw_param.Param.from_pyvalue(u"segments", ",".join(segmentsUtils.to_range_strings(self.segments))))
xml.appendChild(ligolw_param.Param.from_pyvalue(u"template_ids", ",".join("%d" % template_id for template_id in sorted(self.template_ids))))
xml.appendChild(ligolw_param.Param.from_pyvalue(u"noise_counts_before_extinction", int(self.noise_counts_before_extinction)))
return xml
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment