gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 49d6c03 3/3: gal_wcs_pixel_area_arcsec2 return


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 49d6c03 3/3: gal_wcs_pixel_area_arcsec2 returns NaN on bad input
Date: Mon, 23 Oct 2017 09:14:53 -0400 (EDT)

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

    gal_wcs_pixel_area_arcsec2 returns NaN on bad input
    
    When the input is unreasonable, `gal_wcs_pixel_area_arcsec2' will return a
    NaN value. Until now it would abort the program.
---
 NEWS                      |  3 +++
 bin/mkcatalog/mkcatalog.c |  7 +++++--
 doc/gnuastro.texi         |  4 +++-
 lib/wcs.c                 | 10 +++++++---
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index e0bc8c9..2a00652 100644
--- a/NEWS
+++ b/NEWS
@@ -88,6 +88,9 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   to limit the range of header keywords to read the WCS, similar to how
   they are used in `gal_wcs_read'.
 
+  `gal_wcs_pixel_area_arcsec2' will return NaN (instead of aborting) when
+  input is unreasonable (not two dimensions or not in units of degrees).
+
 ** Bug fixes
 
   ConvertType crash when changing values (bug #52010).
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index 7b2772e..e41278d 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -718,8 +718,11 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p, 
int o0c1,
   if(p->input->wcs)
     {
       pixarea=gal_wcs_pixel_area_arcsec2(p->input->wcs);
-      asprintf(&str, "Pixel area (arcsec^2): %g", pixarea);
-      gal_list_str_add(&comments, str, 0);
+      if( isnan(pixarea)==0 )
+        {
+          asprintf(&str, "Pixel area (arcsec^2): %g", pixarea);
+          gal_list_str_add(&comments, str, 0);
+        }
     }
 
   if(p->hasmag)
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index a611b64..e3e8395 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -20181,7 +20181,9 @@ for each dimension.
 @end deftypefun
 
 @deftypefun double gal_wcs_pixel_area_arcsec2 (struct wcsprm @code{*wcs})
-Return the pixel area of @code{wcs} in arcsecond squared.
+Return the pixel area of @code{wcs} in arcsecond squared. If the input WCS
+structure is not two dimensional and the units (@code{CUNIT} keywords) are
+not @code{deg} (for degrees), then this function will return a NaN.
 @end deftypefun
 
 @deftypefun void gal_wcs_world_to_img (struct wcsprm @code{*wcs}, double 
@code{*ra}, double @code{*dec}, double @code{**x}, double @code{**y}, size_t 
@code{size})
diff --git a/lib/wcs.c b/lib/wcs.c
index 4f7ec50..0649e57 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -581,9 +581,13 @@ gal_wcs_pixel_area_arcsec2(struct wcsprm *wcs)
   /* A small sanity check. Later, when higher dimensions are necessary, we
      can find which ones correlate to RA and Dec and use them to find the
      pixel area in arcsec^2. */
-  if(wcs->naxis!=2)
-    error(EXIT_FAILURE, 0, "%s: currently only 2D datasets supported. "
-          "The input WCS has %d dimensions", __func__, wcs->naxis);
+  if(wcs->naxis!=2) return NAN;
+
+  /* Check if the units of the axis are degrees or not. Currently all FITS
+     images I have worked with use `deg' for degrees. If other alternatives
+     exist, we can add corrections later. */
+  if( strcmp("deg", wcs->cunit[0]) || strcmp("deg", wcs->cunit[1]) )
+    return NAN;
 
   /* Get the pixel scales along each axis in degrees, then multiply. */
   pixscale=gal_wcs_pixel_scale(wcs);



reply via email to

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