gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b0175af: Physical nature agnostic WCS columns


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b0175af: Physical nature agnostic WCS columns in MakeCatalog
Date: Mon, 23 Oct 2017 07:43:45 -0400 (EDT)

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

    Physical nature agnostic WCS columns in MakeCatalog
    
    To generalize the use of MakeCatalog, it now defines the generic `--w1' and
    `--w2' instead of the specific `--ra' and `--dec'. The latter two cases can
    still be used however. They are each just aliases for one of the former two
    cases depending on the input dataset's `CTYPE' keywords. The other
    WCS-related options were also renamed to allow this general new naming
    convention.
---
 NEWS                      |  14 ++++
 bin/mkcatalog/args.h      |  68 ++++++++++++-----
 bin/mkcatalog/columns.c   | 181 +++++++++++++++++++++++++++++++++-------------
 bin/mkcatalog/main.h      |   4 +-
 bin/mkcatalog/mkcatalog.c |  24 +++---
 bin/mkcatalog/ui.c        |  51 ++++++++++++-
 bin/mkcatalog/ui.h        |  18 +++--
 doc/gnuastro.texi         |  66 ++++++++++++-----
 8 files changed, 313 insertions(+), 113 deletions(-)

diff --git a/NEWS b/NEWS
index 0fa2662..071cc80 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,20 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   keywords in that HDU will be printed (as if only `--printallkeys' was
   called).
 
+  MakeCatalog: physical nature agnostic WCS column names. Previously the
+  first WCS axis was always assumed to be RA and the second DEC. So for
+  example even if you had a spectrum (with X and wavelength as the two WCS
+  dimensions), you would have to ask for `--ra' and `--dec'. The new `--w1'
+  and `--w2' options are now generic and don't assume any particular type
+  only their order in the FITS header. MakeCatalog now also uses the CTYPE
+  and CUNIT keywords to set the names and units of its output columns. The
+  `--ra' and `--dec' options are now just internal aliases for `--w1' or
+  `--w2' which will be determined based on the input's CTYPE keyword. Also
+  the new `--geow1', `--geow2', `--clumpsw1', `--clumpsw2',
+  `--clumpsgeow1', `--clumpsgeow2' options replace the old options
+  `--geora', `--geodec', `--clumpsra', `--clumpsdec', `--clumpsgeora',
+  `--clumpsgeodec'. No alias is currently defined for the latter group.
+
   NoiseChisel: with the new `--widekernel' option it is now possible to use
   a wider kernel to identify which tiles contain signal. The rest of the
   steps (identifying the quantile threshold on the selected tiles and etc)
diff --git a/bin/mkcatalog/args.h b/bin/mkcatalog/args.h
index 94e841b..30db17b 100644
--- a/bin/mkcatalog/args.h
+++ b/bin/mkcatalog/args.h
@@ -534,7 +534,7 @@ struct argp_option program_options[] =
       UI_KEY_RA,
       0,
       0,
-      "Right ascension of flux weighted center.",
+      "Flux weighted center right ascension.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -548,7 +548,7 @@ struct argp_option program_options[] =
       UI_KEY_DEC,
       0,
       0,
-      "Declination of flux weighted center.",
+      "Flux weighted center declination.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -558,11 +558,11 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
-      "geora",
-      UI_KEY_GEORA,
+      "w1",
+      UI_KEY_W1,
       0,
       0,
-      "Right ascension of geometric center.",
+      "Flux weighted center in first WCS axis.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -572,11 +572,11 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
-      "geodec",
-      UI_KEY_GEODEC,
+      "w2",
+      UI_KEY_W2,
       0,
       0,
-      "Declination of geometric center.",
+      "Flux weighted center in second WCS axis.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -586,11 +586,11 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
-      "clumpsra",
-      UI_KEY_CLUMPSRA,
+      "geow1",
+      UI_KEY_GEOW1,
       0,
       0,
-      "Right ascension of f.wht center of all clumps.",
+      "Geometric center in first WCS axis.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -600,11 +600,11 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
-      "clumpsdec",
-      UI_KEY_CLUMPSDEC,
+      "geow2",
+      UI_KEY_GEOW2,
       0,
       0,
-      "Declination of f.wht center of all clumps.",
+      "Geometric center in second WCS axis.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -614,11 +614,11 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
-      "clumpsgeora",
-      UI_KEY_CLUMPSGEORA,
+      "clumpsw1",
+      UI_KEY_CLUMPSW1,
       0,
       0,
-      "Right ascension of geo. center of all clumps.",
+      "Flux.wht center of all clumps in 1st WCS.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
@@ -628,11 +628,39 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
-      "clumpsgeodec",
-      UI_KEY_CLUMPSGEODEC,
+      "clumpsw2",
+      UI_KEY_CLUMPSW2,
       0,
       0,
-      "Declination of geometric center of all clumps.",
+      "Flux.wht center of all clumps in 2nd WCS.",
+      ARGS_GROUP_COLUMNS,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "clumpsgeow1",
+      UI_KEY_CLUMPSGEOW1,
+      0,
+      0,
+      "Geometric center of all clumps in 1st WCS.",
+      ARGS_GROUP_COLUMNS,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "clumpsgeow2",
+      UI_KEY_CLUMPSGEOW2,
+      0,
+      0,
+      "Geometric center of all clumps in 2nd WCS.",
       ARGS_GROUP_COLUMNS,
       0,
       GAL_TYPE_INVALID,
diff --git a/bin/mkcatalog/columns.c b/bin/mkcatalog/columns.c
index 809f673..a3e08f4 100644
--- a/bin/mkcatalog/columns.c
+++ b/bin/mkcatalog/columns.c
@@ -27,8 +27,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <errno.h>
 #include <error.h>
 #include <stdlib.h>
+#include <string.h>
 #include <pthread.h>
 
+#include <gnuastro-internal/checkset.h>
+
 #include "main.h"
 #include "mkcatalog.h"
 
@@ -196,6 +199,74 @@ columns_alloc_clumpsgeoradec(struct mkcatalogparams *p)
 /******************************************************************/
 /**********       Column definition/allocation      ***************/
 /******************************************************************/
+static void
+columns_wcs_preparation(struct mkcatalogparams *p)
+{
+  size_t i;
+  gal_list_i32_t *colcode;
+  int continue_wcs_check=1;
+
+  /* Make sure a WCS structure is present if we need it. */
+  for(colcode=p->columnids; colcode!=NULL; colcode=colcode->next)
+    {
+      if(continue_wcs_check)
+        {
+          switch(colcode->v)
+            {
+            /* High-level. */
+            case UI_KEY_RA:
+            case UI_KEY_DEC:
+
+            /* Low-level. */
+            case UI_KEY_W1:
+            case UI_KEY_W2:
+            case UI_KEY_GEOW1:
+            case UI_KEY_GEOW2:
+            case UI_KEY_CLUMPSW1:
+            case UI_KEY_CLUMPSW2:
+            case UI_KEY_CLUMPSGEOW1:
+            case UI_KEY_CLUMPSGEOW2:
+              if(p->input->wcs)
+                continue_wcs_check=0;
+              else
+                error(EXIT_FAILURE, 0, "input doesn't have WCS meta-data for "
+                      "defining world coordinates (like RA and Dec). Atleast "
+                      "one of the requested columns requires this "
+                      "information");
+              break;
+            }
+        }
+      else
+        break;
+    }
+
+  /* Convert the high-level WCS columns to low-level ones. */
+  for(colcode=p->columnids; colcode!=NULL; colcode=colcode->next)
+    switch(colcode->v)
+      {
+      case UI_KEY_RA:
+      case UI_KEY_DEC:
+        /* Check all the CTYPES. */
+        for(i=0;i<p->input->ndim;++i)
+          if( !strcmp(p->ctype[i], colcode->v==UI_KEY_RA ? "RA" : "DEC") )
+            {
+              colcode->v = i==0 ? UI_KEY_W1 : UI_KEY_W2;
+              break;
+            }
+
+        /* Make sure it actually existed. */
+        if(i==p->input->ndim)
+          error(EXIT_FAILURE, 0, "%s (hdu: %s): %s not present in any of "
+                "the WCS axis types (CTYPE)", p->inputname, p->cp.hdu,
+                colcode->v==UI_KEY_RA ? "RA" : "DEC");
+        break;
+      }
+}
+
+
+
+
+
 /* Set the necessary parameters for each output column and allocate the
    space necessary to keep the values. */
 void
@@ -207,6 +278,13 @@ columns_define_alloc(struct mkcatalogparams *p)
   char *name=NULL, *unit=NULL, *ocomment=NULL, *ccomment=NULL;
   uint8_t otype=GAL_TYPE_INVALID, ctype=GAL_TYPE_INVALID, *oiflag, *ciflag;
 
+  /* If there is any columns that need WCS, the input image needs to have a
+     WCS in its headers. So before anything, we need to check if a WCS is
+     present or not. This can't be done after the initial setting of column
+     properties because the WCS-related columns use information that is
+     based on it (for units and names). */
+  columns_wcs_preparation(p);
+
   /* Allocate the array for which intermediate parameters are
      necessary. The basic issue is that higher-level calculations require a
      smaller domain of raw measurements. So to avoid having to calculate
@@ -427,10 +505,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           oiflag[ OCOL_C_GY ] = 1;
           break;
 
-        case UI_KEY_RA:
-          name           = "RA";
-          unit           = "degrees";
-          ocomment       = "Flux weighted center right ascension.";
+        case UI_KEY_W1:
+          name           = p->ctype[0];
+          unit           = p->input->wcs->cunit[0];
+          ocomment       = "Flux weighted center in first WCS axis.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_FLOAT64;
@@ -442,10 +520,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_radec(p);
           break;
 
-        case UI_KEY_DEC:
-          name           = "DEC";
-          unit           = "degrees";
-          ocomment       = "Flux weighted center declination.";
+        case UI_KEY_W2:
+          name           = p->ctype[1];
+          unit           = p->input->wcs->cunit[1];
+          ocomment       = "Flux weighted center in second WCS axis.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_FLOAT64;
@@ -457,10 +535,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_radec(p);
           break;
 
-        case UI_KEY_GEORA:
-          name           = "GEO_RA";
-          unit           = "degrees";
-          ocomment       = "Geometric center right ascension.";
+        case UI_KEY_GEOW1:
+          name           = gal_checkset_malloc_cat("GEO_", p->ctype[0]);
+          unit           = p->input->wcs->cunit[0];
+          ocomment       = "Geometric center in first WCS axis.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_FLOAT64;
@@ -474,10 +552,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_georadec(p);
           break;
 
-        case UI_KEY_GEODEC:
-          name           = "GEO_DEC";
-          unit           = "degrees";
-          ocomment       = "Geometric center declination.";
+        case UI_KEY_GEOW2:
+          name           = gal_checkset_malloc_cat("GEO_", p->ctype[1]);
+          unit           = p->input->wcs->cunit[1];
+          ocomment       = "Geometric center in second WCS axis.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_FLOAT64;
@@ -491,10 +569,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_georadec(p);
           break;
 
-        case UI_KEY_CLUMPSRA:
-          name           = "CLUMPS_RA";
-          unit           = "degrees";
-          ocomment       = "RA of all clumps flux weighted center.";
+        case UI_KEY_CLUMPSW1:
+          name           = gal_checkset_malloc_cat("CLUMPS_", p->ctype[0]);
+          unit           = p->input->wcs->cunit[0];
+          ocomment       = "Flux.wht center of all clumps in 1st WCS axis.";
           ccomment       = NULL;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_INVALID;
@@ -506,10 +584,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_clumpsradec(p);
           break;
 
-        case UI_KEY_CLUMPSDEC:
-          name           = "CLUMPS_DEC";
-          unit           = "degrees";
-          ocomment       = "Declination of all clumps flux weighted center.";
+        case UI_KEY_CLUMPSW2:
+          name           = gal_checkset_malloc_cat("CLUMPS_", p->ctype[1]);
+          unit           = p->input->wcs->cunit[1];
+          ocomment       = "Flux.wht center of all clumps in 2nd WCS axis.";
           ccomment       = NULL;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_INVALID;
@@ -521,10 +599,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_clumpsradec(p);
           break;
 
-        case UI_KEY_CLUMPSGEORA:
-          name           = "CLUMPS_RA";
-          unit           = "degrees";
-          ocomment       = "RA of all clumps geometric center.";
+        case UI_KEY_CLUMPSGEOW1:
+          name           = gal_checkset_malloc_cat("CLUMPS_GEO", p->ctype[0]);
+          unit           = p->input->wcs->cunit[0];
+          ocomment       = "Geometric center of all clumps in 1st WCS axis.";
           ccomment       = NULL;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_INVALID;
@@ -536,10 +614,10 @@ columns_define_alloc(struct mkcatalogparams *p)
           columns_alloc_clumpsgeoradec(p);
           break;
 
-        case UI_KEY_CLUMPSGEODEC:
-          name           = "CLUMPS_DEC";
-          unit           = "degrees";
-          ocomment       = "Declination of all clumps geometric center.";
+        case UI_KEY_CLUMPSGEOW2:
+          name           = gal_checkset_malloc_cat("CLUMPS_GEO", p->ctype[1]);
+          unit           = p->input->wcs->cunit[1];
+          ocomment       = "Geometric center of all clumps in 2nd WCS axis.";
           ccomment       = NULL;
           otype          = GAL_TYPE_FLOAT64;
           ctype          = GAL_TYPE_INVALID;
@@ -650,8 +728,7 @@ columns_define_alloc(struct mkcatalogparams *p)
           disp_fmt       = GAL_TABLE_DISPLAY_FMT_GENERAL;
           disp_width     = 8;
           disp_precision = 3;
-          p->upperlimit  = 1;
-          /* Upper limit measurement doesn't need per-pixel calculations. */
+          p->upperlimit  = 1;   /* Doesn't need per-pixel calculations. */
           break;
 
         case UI_KEY_UPPERLIMITMAG:
@@ -665,8 +742,7 @@ columns_define_alloc(struct mkcatalogparams *p)
           disp_width     = 8;
           disp_precision = 3;
           p->upperlimit  = 1;
-          p->hasmag      = 1;
-          /* Upper limit magnitude doesn't need per-pixel calculations. */
+          p->hasmag      = 1;   /* Doesn't need per-pixel calculations. */
           break;
 
         case UI_KEY_RIVERAVE:
@@ -896,6 +972,7 @@ columns_define_alloc(struct mkcatalogparams *p)
                 "column code", __func__, PACKAGE_BUGREPORT, colcode->v);
         }
 
+
       /* If this is an objects column, add it to the list of columns. We
          will be using the `status' element to keep the MakeCatalog code
          for the columns. */
@@ -1246,40 +1323,44 @@ columns_fill(struct mkcatalog_passparams *pp)
                                                oi[OCOL_C_NUMALL] );
           break;
 
-        case UI_KEY_RA:
-        case UI_KEY_DEC:
+        case UI_KEY_W1:
+        case UI_KEY_W2:
           p->rd_vo[0][oind] = POS_V_G(oi, OCOL_SUMWHT, OCOL_NUMALL,
                                       OCOL_VX, OCOL_GX);
           p->rd_vo[1][oind] = POS_V_G(oi, OCOL_SUMWHT, OCOL_NUMALL,
                                       OCOL_VY, OCOL_GY);
           break;
 
-        case UI_KEY_GEORA:
-        case UI_KEY_GEODEC:
+        case UI_KEY_GEOW1:
+        case UI_KEY_GEOW2:
           p->rd_go[0][oind] = MKC_RATIO( oi[OCOL_GX], oi[OCOL_NUMALL] );
           p->rd_go[1][oind] = MKC_RATIO( oi[OCOL_GY], oi[OCOL_NUMALL] );
           break;
 
-        case UI_KEY_CLUMPSRA:
-        case UI_KEY_CLUMPSDEC:
+        case UI_KEY_CLUMPSW1:
+        case UI_KEY_CLUMPSW2:
           p->rd_vcc[0][oind] = POS_V_G(oi, OCOL_C_SUMWHT, OCOL_C_NUMALL,
                                        OCOL_C_VX, OCOL_C_GX);
           p->rd_vcc[1][oind] = POS_V_G(oi, OCOL_C_SUMWHT, OCOL_C_NUMALL,
                                        OCOL_C_VY, OCOL_C_GY);
           break;
 
-        case UI_KEY_CLUMPSGEORA:
-        case UI_KEY_CLUMPSGEODEC:
+        case UI_KEY_CLUMPSGEOW1:
+        case UI_KEY_CLUMPSGEOW2:
           p->rd_gcc[0][oind] = MKC_RATIO( oi[OCOL_C_GX], oi[OCOL_C_NUMALL] );
           p->rd_gcc[1][oind] = MKC_RATIO( oi[OCOL_C_GY], oi[OCOL_C_NUMALL] );
           break;
 
         case UI_KEY_BRIGHTNESS:
-          ((float *)colarr)[oind] = oi[ OCOL_NUM ]>0.0f ? oi[ OCOL_SUM ] : NAN;
+          ((float *)colarr)[oind] = ( oi[ OCOL_NUM ]>0.0f
+                                      ? oi[ OCOL_SUM ]
+                                      : NAN );
           break;
 
         case UI_KEY_CLUMPSBRIGHTNESS:
-          ((float *)colarr)[oind] = oi[ OCOL_C_NUM ]>0.0f ?oi[ OCOL_C_SUM 
]:NAN;
+          ((float *)colarr)[oind] = ( oi[ OCOL_C_NUM ]>0.0f
+                                      ? oi[ OCOL_C_SUM ]
+                                      : NAN );
           break;
 
         case UI_KEY_MAGNITUDE:
@@ -1407,16 +1488,16 @@ columns_fill(struct mkcatalog_passparams *pp)
                                                  ci[CCOL_NUMALL] );
             break;
 
-          case UI_KEY_RA:
-          case UI_KEY_DEC:
+          case UI_KEY_W1:
+          case UI_KEY_W2:
             p->rd_vc[0][cind] = POS_V_G(ci, CCOL_SUMWHT, CCOL_NUMALL,
                                         CCOL_VX, CCOL_GX);
             p->rd_vc[1][cind] = POS_V_G(ci, CCOL_SUMWHT, CCOL_NUMALL,
                                         CCOL_VY, CCOL_GY);
             break;
 
-          case UI_KEY_GEORA:
-          case UI_KEY_GEODEC:
+          case UI_KEY_GEOW1:
+          case UI_KEY_GEOW2:
             p->rd_gc[0][cind] = MKC_RATIO( ci[CCOL_GX], ci[CCOL_NUMALL] );
             p->rd_gc[1][cind] = MKC_RATIO( ci[CCOL_GY], ci[CCOL_NUMALL] );
             break;
diff --git a/bin/mkcatalog/main.h b/bin/mkcatalog/main.h
index 0dd53e9..39db6f6 100644
--- a/bin/mkcatalog/main.h
+++ b/bin/mkcatalog/main.h
@@ -136,7 +136,7 @@ struct mkcatalogparams
 {
   /* From command-line */
   struct gal_options_common_params cp; /* Common parameters.            */
-  gal_list_i32_t   *columnids; /* The desired column codes.   */
+  gal_list_i32_t   *columnids;  /* The desired column codes.            */
   char             *inputname;  /* Input filename.                      */
   char           *objectsfile;  /* File name of objects file.           */
   char            *objectshdu;  /* HDU of objects image.                */
@@ -195,6 +195,8 @@ struct mkcatalogparams
   double             **rd_vcc;  /* All clumps RA-Dec flx. wht. X, Y.    */
   double             **rd_gcc;  /* All clumps RA-Dec geometric X, Y.    */
 
+  char                **ctype;  /* Type of WCS axis.                    */
+
   uint8_t            hasblank;  /* Dataset has blank values.            */
   uint8_t              hasmag;  /* Catalog has magnitude columns.       */
   uint8_t          upperlimit;  /* Calculate upper limit magnitude.     */
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index 5a90129..7b2772e 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -604,14 +604,14 @@ mkcatalog_wcs_conversion(struct mkcatalogparams *p)
          probably columns that don't need any correction. */
       switch(column->status)
         {
-        case UI_KEY_RA:           c=p->rd_vo[0];   break;
-        case UI_KEY_DEC:          c=p->rd_vo[1];   break;
-        case UI_KEY_GEORA:        c=p->rd_go[0];   break;
-        case UI_KEY_GEODEC:       c=p->rd_go[1];   break;
-        case UI_KEY_CLUMPSRA:     c=p->rd_vcc[0];  break;
-        case UI_KEY_CLUMPSDEC:    c=p->rd_vcc[1];  break;
-        case UI_KEY_CLUMPSGEORA:  c=p->rd_gcc[0];  break;
-        case UI_KEY_CLUMPSGEODEC: c=p->rd_gcc[1];  break;
+        case UI_KEY_W1:           c=p->rd_vo[0];   break;
+        case UI_KEY_W2:           c=p->rd_vo[1];   break;
+        case UI_KEY_GEOW1:        c=p->rd_go[0];   break;
+        case UI_KEY_GEOW2:        c=p->rd_go[1];   break;
+        case UI_KEY_CLUMPSW1:     c=p->rd_vcc[0];  break;
+        case UI_KEY_CLUMPSW2:     c=p->rd_vcc[1];  break;
+        case UI_KEY_CLUMPSGEOW1:  c=p->rd_gcc[0];  break;
+        case UI_KEY_CLUMPSGEOW2:  c=p->rd_gcc[1];  break;
         }
 
       /* Copy the elements. */
@@ -630,10 +630,10 @@ mkcatalog_wcs_conversion(struct mkcatalogparams *p)
          probably columns that don't need any correction. */
       switch(column->status)
         {
-        case UI_KEY_RA:           c=p->rd_vc[0];   break;
-        case UI_KEY_DEC:          c=p->rd_vc[1];   break;
-        case UI_KEY_GEORA:        c=p->rd_gc[0];   break;
-        case UI_KEY_GEODEC:       c=p->rd_gc[1];   break;
+        case UI_KEY_W1:           c=p->rd_vc[0];   break;
+        case UI_KEY_W2:           c=p->rd_vc[1];   break;
+        case UI_KEY_GEOW1:        c=p->rd_gc[0];   break;
+        case UI_KEY_GEOW2:        c=p->rd_gc[1];   break;
         }
 
       /* Copy the elements. */
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 4e89812..9b86483 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -29,7 +29,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <inttypes.h>
 
-#include <gnuastro/wcs.h>
 #include <gnuastro/fits.h>
 #include <gnuastro/blank.h>
 #include <gnuastro/threads.h>
@@ -325,6 +324,42 @@ ui_check_options_and_arguments(struct mkcatalogparams *p)
 /**************************************************************/
 /***************       Preparations         *******************/
 /**************************************************************/
+/* If a WCS structure is present, then read its basic information to use in
+   the table meta-data. */
+static void
+ui_wcs_info(struct mkcatalogparams *p)
+{
+  char *c;
+  size_t i;
+
+  /* Read the basic WCS information. */
+  if(p->input->wcs)
+    {
+      /* Allocate space for the array of strings. */
+      errno=0;
+      p->ctype=malloc(p->input->ndim * sizeof *p->ctype);
+      if(p->ctype==NULL)
+        error(EXIT_FAILURE, 0, "%s: %zu bytes for `p->ctype'", __func__,
+              p->input->ndim * sizeof *p->ctype);
+
+      /* Fill in the values. */
+      for(i=0;i<p->input->ndim;++i)
+        {
+          /* CTYPE might contain `-' characters, we just want the first
+             non-dash characters. The loop will either stop either at the end
+             or where there is a dash. So we can just replace it with an
+             end-of-string character. */
+          gal_checkset_allocate_copy(p->input->wcs->ctype[i], &p->ctype[i]);
+          for(c=p->ctype[i]; *c!='\0' && *c!='-'; ++c) c=c;
+          *c='\0';
+        }
+    }
+}
+
+
+
+
+
 static void
 ui_preparations_read_inputs(struct mkcatalogparams *p)
 {
@@ -343,9 +378,13 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
                                      GAL_TYPE_FLOAT32, p->cp.minmapsize, 0,0);
 
 
+  /* Read basic WCS information for final table meta-data. */
+  ui_wcs_info(p);
+
+
   /* Currently MakeCatalog is only implemented for 2D images. */
   if(p->input->ndim!=2)
-    error(EXIT_FAILURE, 0, "%s (%s) has %zu dimensions, MakeCatalog "
+    error(EXIT_FAILURE, 0, "%s (hdu %s) has %zu dimensions, MakeCatalog "
           "currently only supports 2D inputs", p->inputname, p->cp.hdu,
           p->input->ndim);
 
@@ -994,6 +1033,14 @@ ui_free_report(struct mkcatalogparams *p, struct timeval 
*t1)
       if(p->rd_gcc) free(p->rd_gcc);
     }
 
+  /* Free the types of the WCS coordinates (for catalog meta-data). */
+  if(p->ctype)
+    {
+      for(d=0;d<p->input->ndim;++d)
+        free(p->ctype[d]);
+      free(p->ctype);
+    }
+
   /* If a random number generator was allocated, free it. */
   if(p->rng) gsl_rng_free(p->rng);
 
diff --git a/bin/mkcatalog/ui.h b/bin/mkcatalog/ui.h
index c5ab69a..5173056 100644
--- a/bin/mkcatalog/ui.h
+++ b/bin/mkcatalog/ui.h
@@ -29,7 +29,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Available letters for short options:
 
-   f g k l u v w x y
+   f g k l u v w x y z
    H J L W X Y
 */
 enum option_keys_enum
@@ -39,7 +39,6 @@ enum option_keys_enum
   UI_KEY_CLUMPSFILE      = 'C',
   UI_KEY_SKYFILE         = 's',
   UI_KEY_STDFILE         = 't',
-  UI_KEY_ZEROPOINT       = 'z',
   UI_KEY_SKYSUBTRACTED   = 'E',
   UI_KEY_THRESHOLD       = 'R',
   UI_KEY_ENVSEED         = 'e',
@@ -68,6 +67,7 @@ enum option_keys_enum
   UI_KEY_CLUMPSHDU,
   UI_KEY_SKYHDU,
   UI_KEY_STDHDU,
+  UI_KEY_ZEROPOINT,
   UI_KEY_SFMAGNSIGMA,
   UI_KEY_SFMAGAREA,
   UI_KEY_UPMASKFILE,
@@ -86,12 +86,14 @@ enum option_keys_enum
   UI_KEY_CLUMPSY,
   UI_KEY_CLUMPSGEOX,
   UI_KEY_CLUMPSGEOY,
-  UI_KEY_GEORA,
-  UI_KEY_GEODEC,
-  UI_KEY_CLUMPSRA,
-  UI_KEY_CLUMPSDEC,
-  UI_KEY_CLUMPSGEORA,
-  UI_KEY_CLUMPSGEODEC,
+  UI_KEY_W1,
+  UI_KEY_W2,
+  UI_KEY_GEOW1,
+  UI_KEY_GEOW2,
+  UI_KEY_CLUMPSW1,
+  UI_KEY_CLUMPSW2,
+  UI_KEY_CLUMPSGEOW1,
+  UI_KEY_CLUMPSGEOW2,
   UI_KEY_CLUMPSBRIGHTNESS,
   UI_KEY_NORIVERBRIGHTNESS,
   UI_KEY_CLUMPSMAGNITUDE,
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 9ea71f8..3ea5c93 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -14127,7 +14127,7 @@ only one of them. The latter cases are explicitly 
marked with [Objects] or
 
 @item --i
 @itemx --ids
-This is a unique option it can add multiple columns to the final
+This is a unique option which can add multiple columns to the final
 catalog(s). Calling this option will put the object IDs (@option{--objid})
 in the objects catalog and host-object-ID (@option{--hostobjid}) and
 ID-in-host-object (@option{--idinhostobj}) into the clumps catalog. Hence
@@ -14203,35 +14203,61 @@ the second FITS axis. See @option{--geox}.
 
 @item -r
 @itemx --ra
-Flux weighted right ascension of all objects or clumps, see @option{--x}.
+Flux weighted right ascension of all objects or clumps, see
address@hidden This is just an alias for one of the lower-level
address@hidden or @option{--w2} options. Using the FITS WCS keywords
+(@code{CTYPE}), MakeCatalog will determine which axis corresponds to the
+right ascension. If no @code{CTYPE} keywords start with @code{RA}, an error
+will be printed when requesting this column and MakeCatalog will abort.
 
 @item -d
 @itemx --dec
-Flux weighted declination of all objects or clumps, see @option{--x}.
+Flux weighted declination of all objects or clumps, see @option{--x}. This
+is just an alias for one of the lower-level @option{--w1} or @option{--w2}
+options. Using the FITS WCS keywords (@code{CTYPE}), MakeCatalog will
+determine which axis corresponds to the declination. If no @code{CTYPE}
+keywords start with @code{DEC}, an error will be printed when requesting
+this column and MakeCatalog will abort.
+
address@hidden --w1
+Flux weighted first WCS axis of all objects or clumps, see
address@hidden The first WCS axis is commonly used as right ascension in
+images.
 
address@hidden --geora
-Geometric center right ascension of all objects or clumps, see
address@hidden
address@hidden --w2
+Flux weighted second WCS axis of all objects or clumps, see
address@hidden The second WCS axis is commonly used as declination in
+images.
 
address@hidden --geodec
-Geometric center declination of all objects or clumps, see
address@hidden
address@hidden --geow1
+Geometric center in first WCS axis of all objects or clumps, see
address@hidden The first WCS axis is commonly used as right ascension in
+images.
 
address@hidden --clumpsra
-[Objects] Flux weighted right ascension of all clumps in this object,
-see @option{--x}.
address@hidden --geow2
+Geometric center in second WCS axis of all objects or clumps, see
address@hidden The second WCS axis is commonly used as declination in
+images.
 
address@hidden --clumpsdec
address@hidden --clumpsw1
+[Objects] Flux weighted center in first WCS axis of all clumps in this
+object, see @option{--x}. The first WCS axis is commonly used as right
+ascension in images.
+
address@hidden --clumpsw2
 [Objects] Flux weighted declination of all clumps in this object, see
address@hidden
address@hidden The second WCS axis is commonly used as declination in
+images.
 
address@hidden --clumpsgeora
-[Objects] Geometric center right ascension of all clumps in this
-object, see @option{--geox}.
address@hidden --clumpsgeow1
+[Objects] Geometric center right ascension of all clumps in this object,
+see @option{--geox}. The first WCS axis is commonly used as right ascension
+in images.
 
address@hidden --clumpsgeodec
-[Objects] Geometric center declination of all clumps in this object,
-see @option{--geox}.
address@hidden --clumpsgeow2
+[Objects] Geometric center declination of all clumps in this object, see
address@hidden The second WCS axis is commonly used as declination in
+images.
 
 @item -b
 @itemx --brightness



reply via email to

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