From 4c188dccbe6bc2064b09d4f50ec411a26f7ed741 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 15 Jul 2020 22:01:08 +0200 Subject: [PATCH] Fix numerical glitch in residual computation (#2765) --- ChangeLog | 3 ++- NEWS | 2 +- cscripts/obsutils.py | 4 ++-- doc/source/admin/release_history/1.7.rst | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c476fce..1fa3800 100755 --- a/ChangeLog +++ b/ChangeLog @@ -15,7 +15,8 @@ Add csscs script for spectral component separation (#2961) Add support for Castro plots to csspec (#2938) Enabling running of example scripts from objects in memory (#2925) - Add support for power-law binning to several tools (#2881) + Add support for power-law binning to several tools (#2881) + Fix numerical glitch in residual computation (#2765) Allow using spectral models without "Prefactor" parameter in cssens and cstsdist (#1889) diff --git a/NEWS b/NEWS index 037ba6d..1a501dd 100755 --- a/NEWS +++ b/NEWS @@ -357,7 +357,7 @@ None obsutils - Observation utilities -------------------------------- -None +Fix numerical glitch in residual computation in residuals() function (#2765). Examples diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index f711fb6..0be9aba 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -897,8 +897,6 @@ def residuals(cls, counts, model): Residuals """ # Find type of objects we are manipulating and set size to iterate later - - # If GNdarray if counts.classname() == 'GNdarray': nelem = counts.size() elif counts.classname() == 'GSkyMap': @@ -947,6 +945,8 @@ def residuals(cls, counts, model): if data_val > 0.0: log_val = math.log(data_val / model_val) residuals[i] = (data_val * log_val) + model_val - data_val + if residuals[i] < 0.0: # See glitch issue #2765 + residuals[i] = 0.0 # ... otherwise compute the reduced value of the above # expression. This is necessary to avoid computing log(0). diff --git a/doc/source/admin/release_history/1.7.rst b/doc/source/admin/release_history/1.7.rst index 1cb3a31..824b26c 100644 --- a/doc/source/admin/release_history/1.7.rst +++ b/doc/source/admin/release_history/1.7.rst @@ -23,7 +23,8 @@ Bug fixes Adapt show_pull_histogram.py to matplotlib > 3.1.0 * [`3066 `_] - Fix log file header repetition in some cscripts - +* [`2765 `_] - + Fix numerical glitch in residual computation Improvements ------------ -- libgit2 0.21.4