Commit a4b9d4d40386ce3704b78f3bbc204c88da54d14a

Authored by Iftach Sadeh
1 parent d526f5fe

avoid math errors in exponent in _predict_flux

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