Commit e8f4b286fd3d812f9dc0077444da785f384678fe

Authored by Iftach Sadeh
Committed by Jürgen Knödlseder
1 parent 632aa09f

avoid math errors in exponent in _predict_flux

Showing 1 changed file with 7 additions and 4 deletions
cscripts/cssens.py
@@ -515,11 +515,14 @@ class cssens(ctools.csobservation): @@ -515,11 +515,14 @@ class cssens(ctools.csobservation):
515 # the log(TS) and log(crab_flux) values that have so far been 515 # the log(TS) and log(crab_flux) values that have so far been
516 # computed. If not enough results are available than use a simple 516 # computed. If not enough results are available than use a simple
517 # TS scaling relation. 517 # TS scaling relation.
  518 + correct = math.sqrt(ts_thres / ts)
518 if len(results) > 1: 519 if len(results) > 1:
519 - pred_crab_flux, regcoeff = self._predict_flux(results, ts_thres)  
520 - correct = pred_crab_flux / crab_flux  
521 - else:  
522 - correct = math.sqrt(ts_thres/ts) 520 + try:
  521 + pred_crab_flux, regcoeff = self._predict_flux(results, ts_thres)
  522 + correct = pred_crab_flux / crab_flux
  523 + except Exception as e:
  524 + # if the regression fails, retain the simple scaling with ts_thres
  525 + self._log_value(gammalib.TERSE, 'skipping failed regression with error:', e)
523 526
524 # Compute extrapolated fluxes based on the flux correction factor 527 # Compute extrapolated fluxes based on the flux correction factor
525 crab_flux = correct * crab_flux 528 crab_flux = correct * crab_flux