gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master d599f3b: MakeCatalog: brightnesserr is NaN whe


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master d599f3b: MakeCatalog: brightnesserr is NaN when instd under label is blank
Date: Sun, 13 Jun 2021 20:05:28 -0400 (EDT)

branch: master
commit d599f3b94837fa43721364fc7d3b1e8ee2a74640
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    MakeCatalog: brightnesserr is NaN when instd under label is blank
    
    Until now, when the standard deviation image was NaN over the label's
    pixels, but the values image is non-NaN, the brightness error column would
    be zero. However, Zero is a meaningful number (for example in a mock image
    when there is no error at all). So in the scenario above, the returned
    value should be NaN, not zero.
    
    With this commit, a new internal calculation column has been added for
    counting how many standard deviation pixels were used. The returned
    brightness error will be NaN when this number doesn't correspond to the
    total number of values pixels pixels, or the values pixels are all
    blank. In other words, the value will only be zero when the user explicitly
    set those pixels in the standard deviation image to zero.
    
    While doing this, I also noticed that the '--clumpsmagnitude' column was
    asking for too many extra internal calculation columns that it didn't need!
    So they have been removed.
    
    This bug was found by Zahra Sharbaf.
    
    This fixes bug #60778.
---
 NEWS                         |  2 ++
 bin/mkcatalog/columns.c      | 45 +++++++++++++++++++++++---------------------
 bin/mkcatalog/main.h         |  2 ++
 bin/mkcatalog/parse.c        | 10 ++++++++--
 bin/mkcatalog/ui.c           |  2 ++
 doc/announce-acknowledge.txt |  1 +
 doc/gnuastro.texi            | 15 ++++++++++++++-
 7 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/NEWS b/NEWS
index 70d8c03..2ff621f 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ See the end of the file for license conditions.
 
 ** Bugs fixed
   bug #60725: MakeCatalog doesn't put comment on --halfsumsb column.
+  bug #60778: Brightness error not NaN when all STD pixels are blank,
+              This bug was reported by Zahra Sharbaf.
 
 
 
diff --git a/bin/mkcatalog/columns.c b/bin/mkcatalog/columns.c
index 34aa0c1..fb6ded7 100644
--- a/bin/mkcatalog/columns.c
+++ b/bin/mkcatalog/columns.c
@@ -1190,10 +1190,11 @@ columns_define_alloc(struct mkcatalogparams *p)
           disp_fmt       = GAL_TABLE_DISPLAY_FMT_GENERAL;
           disp_width     = 10;
           disp_precision = 5;
-          oiflag[ OCOL_NUM     ] = ciflag[ CCOL_NUM         ] = 1;
-          oiflag[ OCOL_SUM_VAR ] = ciflag[ CCOL_SUM_VAR     ] = 1;
-                                   ciflag[ CCOL_RIV_NUM     ] = 1;
-                                   ciflag[ CCOL_RIV_SUM_VAR ] = 1;
+          oiflag[ OCOL_NUM         ] = ciflag[ CCOL_NUM         ] = 1;
+          oiflag[ OCOL_SUM_VAR     ] = ciflag[ CCOL_SUM_VAR     ] = 1;
+          oiflag[ OCOL_SUM_VAR_NUM ] = ciflag[ CCOL_SUM_VAR_NUM ] = 1;
+                                       ciflag[ CCOL_RIV_NUM     ] = 1;
+                                       ciflag[ CCOL_RIV_SUM_VAR ] = 1;
           break;
 
         case UI_KEY_CLUMPSBRIGHTNESS:
@@ -1363,8 +1364,9 @@ columns_define_alloc(struct mkcatalogparams *p)
           disp_fmt       = GAL_TABLE_DISPLAY_FMT_FLOAT;
           disp_width     = 8;
           disp_precision = 3;
-          oiflag[ OCOL_SUM         ] = ciflag[ CCOL_SUM         ] = 1;
+          oiflag[ OCOL_NUM         ] = ciflag[ CCOL_NUM         ] = 1;
           oiflag[ OCOL_SUM_VAR     ] = ciflag[ CCOL_SUM_VAR     ] = 1;
+          oiflag[ OCOL_SUM_VAR_NUM ] = ciflag[ CCOL_SUM_VAR_NUM ] = 1;
                                        ciflag[ CCOL_RIV_SUM     ] = 1;
                                        ciflag[ CCOL_RIV_SUM_VAR ] = 1;
           break;
@@ -1380,11 +1382,7 @@ columns_define_alloc(struct mkcatalogparams *p)
           disp_width     = 8;
           disp_precision = 3;
           p->hasmag      = 1;
-          oiflag[ OCOL_SUM         ] = ciflag[ CCOL_SUM         ] = 1;
-          oiflag[ OCOL_SUM_VAR     ] = ciflag[ CCOL_SUM_VAR     ] = 1;
-                                       ciflag[ CCOL_RIV_NUM     ] = 1;
-                                       ciflag[ CCOL_RIV_SUM     ] = 1;
-                                       ciflag[ CCOL_RIV_SUM_VAR ] = 1;
+          oiflag[ OCOL_C_SUM ] = 1;
           break;
 
         case UI_KEY_UPPERLIMIT:
@@ -1530,11 +1528,13 @@ columns_define_alloc(struct mkcatalogparams *p)
           disp_fmt       = GAL_TABLE_DISPLAY_FMT_FLOAT;
           disp_width     = 10;
           disp_precision = 3;
+          oiflag[ OCOL_NUM         ] = ciflag[ CCOL_NUM         ] = 1;
           oiflag[ OCOL_SUM         ] = ciflag[ CCOL_SUM         ] = 1;
           oiflag[ OCOL_SUM_VAR     ] = ciflag[ CCOL_SUM_VAR     ] = 1;
-                                       ciflag[ CCOL_NUM         ] = 1;
+          oiflag[ OCOL_SUM_VAR_NUM ] = ciflag[ CCOL_SUM_VAR_NUM ] = 1;
                                        ciflag[ CCOL_RIV_NUM     ] = 1;
                                        ciflag[ CCOL_RIV_SUM     ] = 1;
+                                       ciflag[ CCOL_RIV_NUM     ] = 1;
                                        ciflag[ CCOL_RIV_SUM_VAR ] = 1;
           break;
 
@@ -2024,13 +2024,20 @@ columns_define_alloc(struct mkcatalogparams *p)
 
 
 
-/* Calculate the error in brightness. */
+/* Calculate the error in brightness (only when the number of pixels used
+   to find variance and number of pixels used to find brightness are the
+   same). */
 static double
 columns_brightness_error(struct mkcatalogparams *p, double *row, int o0c1)
 {
-  double V = row[ o0c1 ? CCOL_SUM_VAR : OCOL_SUM_VAR ];
+  size_t numind = o0c1 ? CCOL_NUM         : OCOL_NUM;
+  double V = row[ o0c1 ? CCOL_SUM_VAR     : OCOL_SUM_VAR ];
+  size_t svnind = o0c1 ? CCOL_SUM_VAR_NUM : OCOL_SUM_VAR_NUM;
   double OV = (o0c1 && row[ CCOL_RIV_NUM ]) ? row[ CCOL_RIV_SUM_VAR ] : 0.0;
-  return sqrt( (V+OV)*p->cpscorr );
+
+  return ( (row[ numind ]>0.0f && row[ numind ] == row[ svnind ] )
+           ? sqrt( (V+OV)*p->cpscorr )
+           : NAN );
 }
 
 
@@ -2041,7 +2048,7 @@ columns_brightness_error(struct mkcatalogparams *p, 
double *row, int o0c1)
 static double
 columns_sn(struct mkcatalogparams *p, double *row, int o0c1)
 {
-  double I = row[ o0c1 ? CCOL_SUM     : OCOL_SUM     ];
+  double I = row[ o0c1 ? CCOL_SUM : OCOL_SUM ];
 
   /* When grown clumps are requested from NoiseChisel, some "clumps" will
      completely cover their objects and there will be no rivers. So if this
@@ -2499,9 +2506,7 @@ columns_fill(struct mkcatalog_passparams *pp)
           break;
 
         case UI_KEY_BRIGHTNESSERR:
-          ((float *)colarr)[oind] = ( oi[ OCOL_NUM ]>0.0f
-                                      ? columns_brightness_error(p, oi, 0)
-                                      : NAN );
+          ((float *)colarr)[oind] = columns_brightness_error(p, oi, 0);
           break;
 
         case UI_KEY_CLUMPSBRIGHTNESS:
@@ -2854,9 +2859,7 @@ columns_fill(struct mkcatalog_passparams *pp)
             break;
 
           case UI_KEY_BRIGHTNESSERR:
-            ((float *)colarr)[cind] = ( ci[ CCOL_NUM ]>0.0f
-                                        ? columns_brightness_error(p, ci, 1)
-                                        : NAN );
+            ((float *)colarr)[cind] = columns_brightness_error(p, ci, 1);
             break;
 
           case UI_KEY_BRIGHTNESSNORIVER:
diff --git a/bin/mkcatalog/main.h b/bin/mkcatalog/main.h
index 11d7ff4..aa2dd34 100644
--- a/bin/mkcatalog/main.h
+++ b/bin/mkcatalog/main.h
@@ -76,6 +76,7 @@ enum objectcols
     OCOL_NUMXY,          /* Number of values in the first two dims.   */
     OCOL_SUM,            /* Sum of (value-sky) in object.             */
     OCOL_SUM_VAR,        /* Variance including values (not just sky). */
+    OCOL_SUM_VAR_NUM,    /* Number of pixels used for OCOL_SUM_VAR.   */
     OCOL_MEDIAN,         /* Median of values in object.               */
     OCOL_MAXIMUM,        /* Maximum value in object.                  */
     OCOL_SIGCLIPNUM,     /* Sigma-clipped mean of this object.        */
@@ -142,6 +143,7 @@ enum clumpcols
     CCOL_NUMXY,          /* Number of values only in first two dims.  */
     CCOL_SUM,            /* River subtracted brightness.              */
     CCOL_SUM_VAR,        /* Variance including values (not just sky). */
+    CCOL_SUM_VAR_NUM,    /* Number of pixels used for CCOL_SUM_VAR.   */
     CCOL_MEDIAN,         /* Median of values in clump.                */
     CCOL_MAXIMUM,        /* Maximum value in clump.                   */
     CCOL_SIGCLIPNUM,     /* Sigma-clipped mean of this clump.         */
diff --git a/bin/mkcatalog/parse.c b/bin/mkcatalog/parse.c
index d42ccee..d4997ad 100644
--- a/bin/mkcatalog/parse.c
+++ b/bin/mkcatalog/parse.c
@@ -704,7 +704,10 @@ parse_objects(struct mkcatalog_passparams *pp)
                     {
                       varval=p->variance ? var : sval;
                       if(!isnan(varval))
-                        oi[ OCOL_SUM_VAR ] += varval + fabs(*V);
+                        {
+                          oi[ OCOL_SUM_VAR_NUM  ]++;
+                          oi[ OCOL_SUM_VAR      ] += varval + fabs(*V);
+                        }
                     }
                 }
             }
@@ -1078,7 +1081,10 @@ parse_clumps(struct mkcatalog_passparams *pp)
                         {
                           varval=p->variance ? var : sval;
                           if(!isnan(varval))
-                            ci[ CCOL_SUM_VAR ] += varval + fabs(*V);
+                            {
+                              ci[ CCOL_SUM_VAR_NUM ]++;
+                              ci[ CCOL_SUM_VAR     ] += varval + fabs(*V);
+                            }
                         }
                     }
                 }
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index a456c79..ebfd357 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -989,6 +989,7 @@ ui_necessary_inputs(struct mkcatalogparams *p, int *values, 
int *sky,
         case OCOL_NUMXY:              *values        = 1;          break;
         case OCOL_SUM:                *values        = 1;          break;
         case OCOL_SUM_VAR:            *values = *std = 1;          break;
+        case OCOL_SUM_VAR_NUM:        *values = *std = 1;          break;
         case OCOL_MEDIAN:             *values        = 1;          break;
         case OCOL_MAXIMUM:            *values        = 1;          break;
         case OCOL_SIGCLIPNUM:         *values        = 1;          break;
@@ -1060,6 +1061,7 @@ ui_necessary_inputs(struct mkcatalogparams *p, int 
*values, int *sky,
           case CCOL_NUMXY:            *values        = 1;          break;
           case CCOL_SUM:              *values        = 1;          break;
           case CCOL_SUM_VAR:          *values = *std = 1;          break;
+          case CCOL_SUM_VAR_NUM:      *values = *std = 1;          break;
           case CCOL_MEDIAN:           *values        = 1;          break;
           case CCOL_MAXIMUM:          *values        = 1;          break;
           case CCOL_SIGCLIPNUM:       *values        = 1;          break;
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 8e985e1..b89910e 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -1,5 +1,6 @@
 Alphabetically ordered list to acknowledge in the next release.
 
+Zahra Sharbaf
 
 
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 86fc00a..08cc670 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -18290,7 +18290,11 @@ So the sum of all the clumps brightness in the clump 
catalog will be smaller tha
 If no usable pixels are present over the clump or object (for example they are 
all blank), the returned value will be NaN (note that zero is meaningful).
 
 @item --brightnesserr
-The (@mymath{1\sigma}) error in measuring the brightness of objects or clumps.
+The (@mymath{1\sigma}) error in measuring the brightness of a label (objects 
or clumps).
+
+The returned value will be NaN when the label covers only NaN pixels in the 
values image, or a pixel is NaN in the @option{--instd} image, but non-NaN in 
the values image.
+The latter situation usually happens when there is a bug in the previous steps 
of your analysis, and is important because those pixels with a NaN in the 
@option{--instd} image may contribute significantly to the final error.
+If you want to ignore those pixels in the error measurement, set them to zero 
(which is a meaningful number in such scenarios).
 
 @item --clumpbrightness
 [Objects] The total brightness of the clumps within an object.
@@ -18348,6 +18352,11 @@ Note that until now this error assumes uncorrelated 
pixel values and also does n
 For now these factors have to be found by other means.
 @url{https://savannah.gnu.org/task/index.php?14124, Task 14124} has been 
defined for work on adding these sources of error too.
 
+The returned value will be NaN when the label covers only NaN pixels in the 
values image, or a pixel is NaN in the @option{--instd} image, but non-NaN in 
the values image.
+The latter situation usually happens when there is a bug in the previous steps 
of your analysis, and is important because those pixels with a NaN in the 
@option{--instd} image may contribute significantly to the final error.
+If you want to ignore those pixels in the error measurement, set them to zero 
(which is a meaningful number in such scenarios).
+
+
 @item --clumpsmagnitude
 [Objects] The magnitude of all clumps in this object, see 
@option{--clumpbrightness}.
 
@@ -18406,6 +18415,10 @@ So note that this value is @emph{not} sky subtracted.
 The Signal to noise ratio (S/N) of all clumps or objects.
 See Akhlaghi and Ichikawa (2015) for the exact equations used.
 
+The returned value will be NaN when the label covers only NaN pixels in the 
values image, or a pixel is NaN in the @option{--instd} image, but non-NaN in 
the values image.
+The latter situation usually happens when there is a bug in the previous steps 
of your analysis, and is important because those pixels with a NaN in the 
@option{--instd} image may contribute significantly to the final error.
+If you want to ignore those pixels in the error measurement, set them to zero 
(which is a meaningful number).
+
 @item --sky
 The sky flux (per pixel) value under this object or clump.
 This is actually the mean value of all the pixels in the sky image that lie on 
the same position as the object or clump.



reply via email to

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