Commit 4c188dccbe6bc2064b09d4f50ec411a26f7ed741

Authored by Jürgen Knödlseder
1 parent e17cd5ff

Fix numerical glitch in residual computation (#2765)

ChangeLog
... ... @@ -15,7 +15,8 @@
15 15 Add csscs script for spectral component separation (#2961)
16 16 Add support for Castro plots to csspec (#2938)
17 17 Enabling running of example scripts from objects in memory (#2925)
18   - Add support for power-law binning to several tools (#2881)
  18 + Add support for power-law binning to several tools (#2881)
  19 + Fix numerical glitch in residual computation (#2765)
19 20 Allow using spectral models without "Prefactor" parameter in cssens
20 21 and cstsdist (#1889)
21 22  
... ...
... ... @@ -357,7 +357,7 @@ None
357 357  
358 358 obsutils - Observation utilities
359 359 --------------------------------
360   -None
  360 +Fix numerical glitch in residual computation in residuals() function (#2765).
361 361  
362 362  
363 363 Examples
... ...
cscripts/obsutils.py
... ... @@ -897,8 +897,6 @@ def residuals(cls, counts, model):
897 897 Residuals
898 898 """
899 899 # Find type of objects we are manipulating and set size to iterate later
900   -
901   - # If GNdarray
902 900 if counts.classname() == 'GNdarray':
903 901 nelem = counts.size()
904 902 elif counts.classname() == 'GSkyMap':
... ... @@ -947,6 +945,8 @@ def residuals(cls, counts, model):
947 945 if data_val > 0.0:
948 946 log_val = math.log(data_val / model_val)
949 947 residuals[i] = (data_val * log_val) + model_val - data_val
  948 + if residuals[i] < 0.0: # See glitch issue #2765
  949 + residuals[i] = 0.0
950 950  
951 951 # ... otherwise compute the reduced value of the above
952 952 # expression. This is necessary to avoid computing log(0).
... ...
doc/source/admin/release_history/1.7.rst
... ... @@ -23,7 +23,8 @@ Bug fixes
23 23 Adapt show_pull_histogram.py to matplotlib > 3.1.0
24 24 * [`3066 <https://cta-redmine.irap.omp.eu/issues/3066>`_] -
25 25 Fix log file header repetition in some cscripts
26   -
  26 +* [`2765 <https://cta-redmine.irap.omp.eu/issues/2765>`_] -
  27 + Fix numerical glitch in residual computation
27 28  
28 29 Improvements
29 30 ------------
... ...