gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master af0ccb2: Library (statistics): properly accoun


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master af0ccb2: Library (statistics): properly accounting for equal values
Date: Tue, 13 Aug 2019 09:28:12 -0400 (EDT)

branch: master
commit af0ccb224d8ae248881b149b97a6a09072470867
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Library (statistics): properly accounting for equal values
    
    Until now, when the sigma-clipped values were all equal, the
    `gal_statistics_sigma_clip' function would return NaN values! This happened
    because when all the elements are equal, their standard deviation is
    zero. But we define the tolerance by division with the standard
    deviation. As a result the tolerance would be infinity (and larger than the
    user's tolerance level). Therefore it would go to the maximum internal
    value and just return NaNs.
    
    With this commit, we now explicity check for the case where the standard
    deviation is zero and when it is, we use the current mean, median and STD
    as the "old" values to return in the end.
    
    This bug was reported by Raúl Infante Sainz.
    
    This fixes bug #56754.
---
 NEWS                         |  1 +
 doc/announce-acknowledge.txt |  2 +-
 lib/statistics.c             | 16 +++++++++++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 8600137..7baa5d2 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ See the end of the file for license conditions.
 ** Bugs fixed
   bug #56736: CosmicCalculator crash when a single value given to --obsline.
   bug #56747: ConvertType's SLS colormap has black pixels which should be 
orange.
+  bug #56754: Wrong sigma clipping output when many values are equal.
 
 
 
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 6edb680..1f9dc27 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -1,6 +1,6 @@
 Alphabetically ordered list to acknowledge in the next release.
 
-
+Raúl Infante Sainz
 
 
 
diff --git a/lib/statistics.c b/lib/statistics.c
index 6a400e3..c942126 100644
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@ -2049,9 +2049,19 @@ gal_statistics_sigma_clip(gal_data_t *input, float 
multip, float param,
              out of the loop. Normally, `oldstd' should be larger than std,
              because the possible outliers have been removed. If it is not,
              it means that we have clipped too much and must stop anyway,
-             so we don't need an absolute value on the difference! */
-          if( bytolerance && num>0 && ((oldstd - *std) / *std) < param )
-            { gal_data_free(meanstd); gal_data_free(median_d); break; }
+             so we don't need an absolute value on the difference!
+
+             Note that when all the elements are identical after the clip,
+             `std' will be zero. In this case we shouldn't calculate the
+             tolerance (because it will be infinity and thus lager than the
+             requested tolerance level value).*/
+          if( bytolerance && num>0 )
+            if( *std==0 || ((oldstd - *std) / *std) < param )
+              {
+                if(*std==0) {oldmed=*med; oldstd=*std; oldmean=*mean;}
+                gal_data_free(meanstd);   gal_data_free(median_d);
+                break;
+              }
 
           /* Clip all the elements outside of the desired range: since the
              array is sorted, this means to just change the starting



reply via email to

[Prev in Thread] Current Thread [Next in Thread]