From 15080f1699e4dc83dc27e305b613113ffa50ac3c Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 9 Mar 2016 11:21:33 +0100 Subject: [PATCH] [fix] fixed the nonzero test for pdf definition that all values have to be greater than zero and the integration over the whole interval has to evaluate to 1 with given precision --- pylot/core/util/pdf.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pylot/core/util/pdf.py b/pylot/core/util/pdf.py index 0aad8ad7..556f36ca 100644 --- a/pylot/core/util/pdf.py +++ b/pylot/core/util/pdf.py @@ -151,11 +151,18 @@ class ProbabilityDensityFunction(object): return ProbabilityDensityFunction(x0, incr, npts, pdf) def __nonzero__(self): - return bool(np.round(self.prob_gt_val(self.axis[0]), 4) == 1.) + prec = self.precision(self.incr) + gtzero = np.any(self.data >= 0) + probone = bool(np.round(self.prob_gt_val(self.axis[0]), prec) == 1.) + return (gtzero and probone) def __str__(self): return str(self.data) + @staticmethod + def precision(incr): + return int(np.ceil(np.abs(np.log10(incr)))) + @property def data(self): return self._pdf @@ -307,7 +314,7 @@ class ProbabilityDensityFunction(object): x0 = l2 # calculate index for rounding - ri = int(np.ceil(np.abs(np.log10(incr)))) + ri = self.precision(incr) if r1 < r2: npts = int(round(r2 - x0, ri) // incr)