From e8f4b286fd3d812f9dc0077444da785f384678fe Mon Sep 17 00:00:00 2001 From: sadeh Date: Tue, 18 May 2021 15:26:14 +0200 Subject: [PATCH] avoid math errors in exponent in _predict_flux --- cscripts/cssens.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cscripts/cssens.py b/cscripts/cssens.py index a09fd20..fdc75a5 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -515,11 +515,14 @@ class cssens(ctools.csobservation): # the log(TS) and log(crab_flux) values that have so far been # computed. If not enough results are available than use a simple # TS scaling relation. + correct = math.sqrt(ts_thres / ts) if len(results) > 1: - pred_crab_flux, regcoeff = self._predict_flux(results, ts_thres) - correct = pred_crab_flux / crab_flux - else: - correct = math.sqrt(ts_thres/ts) + try: + pred_crab_flux, regcoeff = self._predict_flux(results, ts_thres) + correct = pred_crab_flux / crab_flux + except Exception as e: + # if the regression fails, retain the simple scaling with ts_thres + self._log_value(gammalib.TERSE, 'skipping failed regression with error:', e) # Compute extrapolated fluxes based on the flux correction factor crab_flux = correct * crab_flux -- libgit2 0.21.4