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

far.py: Added ready_for_extinction method

parent 565c0923
No related branches found
No related tags found
1 merge request!564Online new extinction
Pipeline #583204 canceled
......@@ -636,6 +636,10 @@ class RankingStatPDF(object):
self.signal_lr_lnpdf.array *= rankingstat.numerator.candidate_count_model() / self.signal_lr_lnpdf.array.sum()
self.signal_lr_lnpdf.normalize()
self.extinction_fitting_limits = (1/2., 1/100.)
# extinction curve fitting is done for the range of LRs
# corresponding to the 1/2 and 1/100 point of the zl CCDF
def copy(self):
new = self.__class__(None)
......@@ -713,6 +717,33 @@ WHERE
return self
def ready_for_extinction(self):
# ensure we have sufficient zerolag and noise samples before attempting the extinction curve fit
# none of the checks below should evaluate to True even with a small amount of zerolag and noise
# samples. They should only evaluate to True at the start of an online analysis
bg = self.noise_lr_lnpdf.copy().array
fg = self.zero_lag_lr_lnpdf.copy().array
bg[:10] = 0.
fg[:10] = 0.
if fg.sum() == 0 or bg.sum() == 0:
return False
fg_ccdf = numpy.cumsum(fg[::-1])[::-1]
ix_min = (fg_ccdf < fg_ccdf[0] * self.extinction_fitting_limits[0]).argmax()
ix_max = (fg_ccdf < fg_ccdf[0] * self.extinction_fitting_limits[1]).argmax()
if ix_min == ix_max:
return False
if fg[ix_min: ix_max + 1].sum() == 0 or bg[ix_min: ix_max + 1].sum() == 0:
return False
if (fg_ccdf[ix_min: ix_max + 1] == 0).any():
# log will evaluate to -inf, and the curve fitting will crash
return False
return True
def new_with_extinction(self, verbose = False):
self = self.copy()
......@@ -732,8 +763,8 @@ WHERE
# fitting is done between ix_min and ix_max
fg_ccdf = numpy.cumsum(fg[::-1])[::-1]
ix_min = (fg_ccdf < fg_ccdf[0] / 2.).argmax()
ix_max = (fg_ccdf < fg_ccdf[0] / 100.).argmax()
ix_min = (fg_ccdf < fg_ccdf[0] * self.extinction_fitting_limits[0]).argmax()
ix_max = (fg_ccdf < fg_ccdf[0] * self.extinction_fitting_limits[1]).argmax()
bgtotal = bg[ix_min: ix_max + 1].sum()
......
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