gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master e664564 2/2: Statistics will use the single co


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e664564 2/2: Statistics will use the single column when input has only one
Date: Thu, 1 Nov 2018 17:33:27 -0400 (EDT)

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

    Statistics will use the single column when input has only one
    
    When the input only has one column, it is redundant to explicitly has for
    the column to use. However, until now, it would complain if no column was
    specified. With this commit, if the input table only has one column, it
    will just use it and won't complain.
---
 NEWS                |  8 +++++-
 bin/statistics/ui.c | 74 ++++++++++++++++++++++++++++-------------------------
 doc/gnuastro.texi   |  6 ++---
 3 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/NEWS b/NEWS
index e84f45c..0a8b68b 100644
--- a/NEWS
+++ b/NEWS
@@ -51,7 +51,13 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
           across the image.
 
   Statistics:
-    - Sky estimation: new outlier estimation algorithm similar to NoiseChisel.
+    - If an input table has only one column, Statistics won't complain and
+      abort when no `--column' (`-c') is given: there is only one column to
+      use anyway, so it will be used. In the absence of which column to
+      use, it will still complain and abort if the input has more than one
+      column.
+    - Sky estimation: new outlier estimation algorithm similar to
+      NoiseChisel.
 
   Library:
     - gal_blank_flag_apply: Set all flagged/masked elements to blank.
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index 4503fb2..21f43b4 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -508,8 +508,6 @@ ui_read_check_only_options(struct statisticsparams *p)
 static void
 ui_check_options_and_arguments(struct statisticsparams *p)
 {
-  char *name=NULL;
-
   if(p->inputname)
     {
       /* If input is FITS. */
@@ -523,36 +521,14 @@ ui_check_options_and_arguments(struct statisticsparams *p)
                   "(starting from zero), extension name, or anything "
                   "acceptable by CFITSIO");
 
-          /* If its a table, make sure a column is also specified. */
+          /* If its an image, make sure column isn't given (in case the
+             user confuses an image with a table). */
           p->hdu_type=gal_fits_hdu_format(p->inputname, p->cp.hdu);
-          if(p->hdu_type==IMAGE_HDU)
-            {
-              if(p->column)
-                error(EXIT_FAILURE, 0, "%s (hdu: %s): is a FITS image "
-                      "extension. The `--column' option is only applicable "
-                      "to tables.", p->inputname, p->cp.hdu);
-            }
-          else if(p->column==NULL)
-            if( asprintf(&name, "%s (hdu: %s)", p->inputname, p->cp.hdu)<0 )
-              error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
-        }
-
-      /* If its not FITS, it must be a table. */
-      else
-        {
-          if(p->column==NULL) name=p->inputname;
+          if(p->hdu_type==IMAGE_HDU && p->column)
+            error(EXIT_FAILURE, 0, "%s (hdu: %s): is a FITS image "
+                  "extension. The `--column' option is only applicable "
+                  "to tables.", p->inputname, p->cp.hdu);
         }
-
-      /* If a column was necessary, but not given, print an error. */
-      if(name)
-        error(EXIT_FAILURE, 0, "%s is a table but no column is "
-              "specified. Please use the `--column' (`-c') option to "
-              "specify a column.\n\nYou can either give it the column number "
-              "(couting from 1), or a match/search in its meta-data (e.g., "
-              "column names). For more information, please run the "
-              "following command (press the `SPACE' key to go down and "
-              "`q' to return to the command-line):\n\n"
-              "    $ info gnuastro \"Selecting table columns\"\n", name);
     }
   else
     error(EXIT_FAILURE, 0, "no input file is specified");
@@ -721,15 +697,43 @@ ui_make_sorted_if_necessary(struct statisticsparams *p)
 void
 ui_read_columns(struct statisticsparams *p)
 {
-  int toomanycols=0;
-  size_t size, counter=0;
-  gal_data_t *cols, *tmp;
+  int toomanycols=0, tformat;
   gal_list_str_t *column=NULL;
+  gal_data_t *cols, *tmp, *cinfo;
+  size_t size, ncols, nrows, counter=0;
 
-  /* Define the columns that we want, note that they should be added to the
-     list in reverse. */
+  /* If a reference column is also given, add it to the list of columns to
+     read. */
   if(p->refcol)
     gal_list_str_add(&column, p->refcol, 0);
+
+  /* If no column is specified, Statistics will abort and an error will be
+     printed when the table has more than one column. If there is only one
+     column, there is no need to specify any, so Statistics will use it. */
+  if(p->column==NULL)
+    {
+      /* Get the basic table information. */
+      cinfo=gal_table_info(p->inputname, p->cp.hdu, &ncols, &nrows, &tformat);
+      gal_data_array_free(cinfo, ncols, 1);
+
+      /* See how many columns it has and take the proper action. */
+      if(ncols==1)
+        gal_checkset_allocate_copy("1", &p->column);
+      else
+        error(EXIT_FAILURE, 0, "%s is a table containing more than one "
+              "column. However, the specific column to work on isn't "
+              "specified.\n\n"
+              "Please use the `--column' (`-c') option to specify a "
+              "column. You can either give it the column number "
+              "(couting from 1), or a match/search in its meta-data (e.g., "
+              "column names).\n\n"
+              "For more information, please run the following command "
+              "(press the `SPACE' key to go down and `q' to return to the "
+              "command-line):\n\n"
+              "    $ info gnuastro \"Selecting table columns\"\n",
+              gal_checkset_dataset_name(p->inputname, p->cp.hdu));
+
+    }
   gal_list_str_add(&column, p->column, 0);
 
   /* Read the desired column(s). */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index c2977ed..a07dacb 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -15122,9 +15122,9 @@ for those.
 
 @item -c STR/INT
 @itemx --column=STR/INT
-The input column selector when the input file is a table. See
address@hidden table columns} for a full description of how to use this
-option. For more on how tables are read in Gnuastro, please see
+The column to use when the input file is a table with more than one
+column. See @ref{Selecting table columns} for a full description of how to
+use this option. For more on how tables are read in Gnuastro, please see
 @ref{Tables}.
 
 @item -r STR/INT



reply via email to

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