gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 1051429e: MakeProfiles: ignore profiles where


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1051429e: MakeProfiles: ignore profiles where coordinates cannot be read
Date: Thu, 13 Oct 2022 09:53:39 -0400 (EDT)

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

    MakeProfiles: ignore profiles where coordinates cannot be read
    
    Until now, when a single RA/Dec coordinate couldn't be converted to image
    coordinates for any reason (for example having a wrong value, or too far on
    the sky), MakeProfiles would crash! Even if there were positions that could
    be converted properly!
    
    This was the result of the behavior until recently: even a single bad
    conversion, would make all results blanks in the 'gal_wcs_world_to_img'
    function. However, we now only set the values to NaN that WCSLIB flagged.
    
    With this commit, using the new behavior of 'gal_wcs_world_to_img', we now
    separte the rows that have a bad fit and ignore them in MakeProfiles.
    
    This issue was reported by Sepideh Eskandarlou.
---
 bin/mkprof/ui.c   | 29 ++++++++++++++++++++---------
 doc/gnuastro.texi |  7 +++++--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index e1fa9ea6..0aebbc88 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -1691,8 +1691,8 @@ ui_finalize_coordinates(struct mkprofparams *p)
 {
   void *arr=NULL;
   size_t i=0, ndim=p->ndim;
-  uint8_t os=p->oversample;
-  gal_data_t *tmp, *coords=NULL;
+  uint8_t *fl, os=p->oversample;
+  gal_data_t *tmp, *flag, *coords=NULL;
   double *cdelt=p->wcs->cdelt, *crpix=p->wcs->crpix;
 
   /* When the user specified RA and Dec columns, the respective values
@@ -1729,14 +1729,25 @@ ui_finalize_coordinates(struct mkprofparams *p)
       /* Convert the world coordinates to image coordinates (inplace). */
       gal_wcs_world_to_img(coords, p->wcs, 1);
 
+      /* Remove all blank elements (where WCSLIB couldn't do the
+         conversion) and print a warning for those rows. IMPORTANT: we
+         don't want to update 'p->num' just yet since 'flag' has the size
+         of the pre-blank-removal rows. */
+      flag=gal_blank_remove_rows(coords, NULL);
+      if(p->cp.quiet==0)
+        {
+          fl=flag->array;
+          for(i=0;i<p->num;++i)
+            if(fl[i])
+              error(EXIT_SUCCESS, 0, "catalog row %zu ignored because "
+                    "WCSLIB could not convert coordinates into image "
+                    "coordinates, you can remove this message with "
+                    "'--quiet'", i);
+        }
 
-      /* If any conversions created a WCSLIB error, both the outputs will
-         be set to NaN. */
-      for(i=0;i<p->num;++i)
-        if( isnan(p->x[i]) )
-          error(EXIT_FAILURE, 0, "catalog row %zu: WCSLIB could not "
-                "convert (%f, %f) coordinates into image coordinates",
-                i, p->x[i], p->y[i]);
+      /* Update the number of profiles and free the flags. */
+      p->num=coords->size;
+      gal_data_free(flag);
 
       /* We want the actual arrays of each 'coords' column. So, first we'll
          set all the array elements to NULL, then free it. */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 7e7c7812..53b27cff 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -30559,12 +30559,15 @@ Similar to @code{gal_blank_remove}, but also 
shrinks/re-allocates the dataset's
 @end deftypefun
 
 @deftypefun {gal_data_t *} gal_blank_remove_rows (gal_data_t @code{*columns}, 
gal_list_sizet_t @code{*column_indexs})
-Remove any row that has at least one blank value in any of the input columns.
+Remove (in place) any row that has at least one blank value in any of the 
input columns and return a ``flag'' dataset (that should be freed later).
 The input @code{columns} is a list of @code{gal_data_t}s (see @ref{List of 
gal_data_t}).
 After this function, all the elements in @code{columns} will still have the 
same size as each other, but if any of the searched columns has blank elements, 
all their sizes will decrease together.
 
-If @code{column_indexs==NULL}, then all the columns (nodes in the list) will 
be checked for blank elements, and any row that has at least one blank element 
will be removed.
+The returned flag dataset has the same size as the original input dataset, 
with a type of @code{uint8_t}.
+Every row that has been removed from the original dataset has a value of 1, 
and the rest have a value of 0.
+
 When @code{column_indexs!=NULL}, only the columns whose index (counting from 
zero) is in @code{column_indexs} will be used to check for blank values (see 
@ref{List of size_t}.
+Therefore, if you want to check all columns, just set this to @code{NULL}.
 In any case (no matter which columns are checked for blanks), the selected 
rows from all columns will be removed.
 @end deftypefun
 



reply via email to

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