gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 157d4955: MakeCatalog: informative error when


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 157d4955: MakeCatalog: informative error when labeled image is blank
Date: Mon, 8 Jan 2024 18:24:33 -0500 (EST)

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

    MakeCatalog: informative error when labeled image is blank
    
    Until now, when the labeled image was all blank, MakeCatalog would complain
    with a cryptic error that was hard to unerstand (it crashed!).
    
    With this commit, a check has been added that in such cases, MakeCatalog
    aborts with the same error message as the case when there are no non-zero
    labels.
    
    This bug was reported by Sepideh Eskandarlou.
    
    This fixes bug #65141.
---
 NEWS               |  2 ++
 bin/mkcatalog/ui.c | 14 +++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 78e7b817..c9060e42 100644
--- a/NEWS
+++ b/NEWS
@@ -227,6 +227,8 @@ See the end of the file for license conditions.
   - bug #65106: Necessity of using --oversample with
     astscript-radial-profile when a 2D profile is to be created with
     '--customtable' of MakeProfile; reported by Sepideh Eskandarlou.
+  - bug #65141: MakeCatalog crash when labled image is all blank; reported
+    by Sepideh Eskandarlou.
 
 
 
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index f1511b95..7fda4c96 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -954,20 +954,24 @@ ui_read_labels(struct mkcatalogparams *p)
   keys[0].type=GAL_TYPE_SIZE_T;
   keys[0].array=&p->numobjects;
   gal_fits_key_read(p->objectsfile, p->cp.hdu, keys, 0, 0, "--hdu");
-  if(keys[0].status) /* status!=0: the key couldn't be read by CFITSIO. */
+  if(keys[0].status) /* status!=0: the key didn't exist. */
     {
+      /* Get the maximum of the labels.*/
       tmp=gal_statistics_maximum(p->objects);
       p->numobjects=*((int32_t *)(tmp->array)); /*numobjects is int32_t.*/
+
+      /* In case the input is all blank, the maximum will be blank, so in
+         effect, there we no objects. */
+      if(p->numobjects==GAL_BLANK_INT32) p->numobjects=0;
       gal_data_free(tmp);
     }
 
-
   /* If there were no objects in the input, then inform the user with an
      error (it is pointless to build a catalog). */
   if(p->numobjects==0)
-    error(EXIT_FAILURE, 0, "no object labels (non-zero pixels) in "
-          "%s (hdu %s). To make a catalog, labeled regions must be "
-          "defined", p->objectsfile, p->cp.hdu);
+    error(EXIT_FAILURE, 0, "no object labels (non-zero and non-blank "
+          "pixels) in %s (hdu %s). To make a catalog, labeled regions "
+          "must be defined", p->objectsfile, p->cp.hdu);
 
 
   /* See if the labels image has blank pixels and set the flags



reply via email to

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