gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master dc1834a: Library (reading WCS): check if lonpo


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master dc1834a: Library (reading WCS): check if lonpole has been inferred properly
Date: Fri, 13 Dec 2019 13:37:48 -0500 (EST)

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

    Library (reading WCS): check if lonpole has been inferred properly
    
    When LONPOLE isn't given in the FITS keywords, and `PV%_1' keywords exist
    that don't correspond to the points properly, we can end up with absurd
    values for `wcs->lonpole' and will given an ambiguous "wcsset ERROR 5:
    Invalid parameter value." error.
    
    With this commit, when the value of `wcs->lonpole' isn't reasonable, a
    warning will be printed to help the user identify the source of the
    problem.
    
    Some minor edits were also made to the warning message of the previous
    commit and another arithmetic warning, now properly ends with a new-line.
---
 bin/arithmetic/ui.c |  2 +-
 lib/wcs.c           | 44 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index 95f23aa..1a6fdb1 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -377,7 +377,7 @@ ui_preparations(struct arithmeticparams *p)
         }
       else
         fprintf(stderr, "WARNING: %s (hdu %s) didn't contain a "
-                "(readable by WCSLIB) WCS.", p->wcsfile, p->wcshdu);
+                "(readable by WCSLIB) WCS.\n", p->wcsfile, p->wcshdu);
 
       /* Correct the WCS dimensions if necessary. Note that we don't need
          the `ndim' or `dsize' any more. */
diff --git a/lib/wcs.c b/lib/wcs.c
index b1fe660..3074e48 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -157,11 +157,11 @@ gal_wcs_read_fitsptr(fitsfile *fptr, size_t hstartwcs, 
size_t hendwcs,
                       "WARNING: You can do this with Gnuastro's `astfits' "
                       "program and the `--update' option. The minimal WCS "
                       "keywords that need a numerical value are: `CRVAL1', "
-                      "`CRVAL2', `CRPIX1', `CRPIX2' and `CD%%_%%' (or "
-                      "`PC%%_%%', where the %% are integers), please see "
-                      "the FITS standard, and inspect your FITS file to "
-                      "identify the full set of keywords that you need "
-                      "correct (for example PV%%_%% keywords).\n\n");
+                      "`CRVAL2', `CRPIX1', `CRPIX2', `EQUINOX' and "
+                      "`CD%%_%%' (or `PC%%_%%', where the %% are integers), "
+                      "please see the FITS standard, and inspect your FITS "
+                      "file to identify the full set of keywords that you "
+                      "need correct (for example PV%%_%% keywords).\n\n");
         }
 
       /* CTYPE is a mandatory WCS keyword, so if it hasn't been given (its
@@ -176,6 +176,34 @@ gal_wcs_read_fitsptr(fitsfile *fptr, size_t hstartwcs, 
size_t hendwcs,
         }
       else
         {
+          /* For a check.
+          printf("flag: %d\n", wcs->flag);
+          printf("naxis: %d\n", wcs->naxis);
+          printf("crpix: %f, %f\n", wcs->crpix[0], wcs->crpix[1]);
+          printf("pc: %f, %f, %f, %f\n", wcs->pc[0], wcs->pc[1], wcs->pc[2],
+                 wcs->pc[3]);
+          printf("cdelt: %f, %f\n", wcs->cdelt[0], wcs->cdelt[1]);
+          printf("crval: %f, %f\n", wcs->crval[0], wcs->crval[1]);
+          printf("cunit: %s, %s\n", wcs->cunit[0], wcs->cunit[1]);
+          printf("ctype: %s, %s\n", wcs->ctype[0], wcs->ctype[1]);
+          printf("lonpole: %f\n", wcs->lonpole);
+          printf("latpole: %f\n", wcs->latpole);
+          */
+
+          /* When LONPOLE isn't given and the PV matrix information is not
+             given properly, `wcs->lonpole' can have absurd values (on the
+             order of 1e50 or something). In such cases, we can have this
+             WCSLIB error: "wcsset ERROR 5: Invalid parameter value.". To
+             avoid confusion for the users in such cases, we'll see if the
+             value is in the reasonable range and if not, we'll inform the
+             user.*/
+          if(wcs->lonpole>360 || wcs->lonpole<-360)
+            fprintf(stderr, "WARNING: the inferred `lonpole' of the input's "
+                    "WCS is not reasonable (with a value of `%f').\n\n"
+                    "If `LONPOLE' isn't in the FITS keywords, this is "
+                    "probably because of the `PV%%_1' keyword(s).\n\n",
+                    wcs->lonpole);
+
           /* Set the WCS structure. */
           status=wcsset(wcs);
           if(status)
@@ -199,11 +227,11 @@ gal_wcs_read_fitsptr(fitsfile *fptr, size_t hstartwcs, 
size_t hendwcs,
         }
     }
 
-
   /* Clean up and return. */
+  status=0;
   if (fits_free_memory(fullheader, &status) )
-    gal_fits_io_error(status, "problem in fitsarrayvv.c for freeing "
-                           "the memory used to keep all the headers");
+    gal_fits_io_error(status, "problem in freeing the memory used to "
+                      "keep all the headers");
   return wcs;
 }
 



reply via email to

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