gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 9663e51 1/2: ConvertType: new --globalhdu to o


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 9663e51 1/2: ConvertType: new --globalhdu to only specify HDU once
Date: Tue, 30 Mar 2021 14:23:52 -0400 (EDT)

branch: master
commit 9663e510b63d511537fd09f5f9d6a78ef42e3b5b
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    ConvertType: new --globalhdu to only specify HDU once
    
    Until now, when there was more than one FITS input, it was necessary to
    call the '--hdu' option multiple times (once for every FITS file). But this
    was very annoying when all the three HDUs were the same.
    
    With this commit, following the model of Arithmetic and '--globalhdu' (or
    '-g') option has been added to ConvertType and behaves similarly: when
    given, the same HDU will be read from all the images.
---
 NEWS                |  6 ++++++
 bin/convertt/args.h | 19 +++++++++++++++++++
 bin/convertt/main.h |  1 +
 bin/convertt/ui.c   | 19 ++++++++++++++-----
 bin/convertt/ui.h   |  3 ++-
 doc/gnuastro.texi   |  7 +++++++
 6 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index dc4ac45..7a5ac38 100644
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,12 @@ See the end of the file for license conditions.
      - counts-to-jy: Convert counts to Janskys through a zero point based
           on AB magnitudes.
 
+  ConvertType:
+   --globalhdu: Use a single HDU identifier for all the input files
+     files. Its operation is identical to the similarly named option in
+     Arithmetic. Until now it was necessary to call '--hdu' three times if
+     you had three input FITS files with input in the same HDU.
+
   Fits:
    --wcscoordsys: convert the WCS coordinate system of the input into any
      recognized coordinate system (currently supports: equatorial (J2000,
diff --git a/bin/convertt/args.h b/bin/convertt/args.h
index 5f66e04..bea65cc 100644
--- a/bin/convertt/args.h
+++ b/bin/convertt/args.h
@@ -30,6 +30,25 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /* Array of acceptable options. */
 struct argp_option program_options[] =
   {
+    /* Input */
+    {
+      "globalhdu",
+      UI_KEY_GLOBALHDU,
+      "STR/INT",
+      0,
+      "Use this HDU for all inputs, ignore '--hdu'.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->globalhdu,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
+
+
+
+
     /* Output */
     {
       "quality",
diff --git a/bin/convertt/main.h b/bin/convertt/main.h
index 0d5cda6..bf1bb9b 100644
--- a/bin/convertt/main.h
+++ b/bin/convertt/main.h
@@ -83,6 +83,7 @@ struct converttparams
   struct gal_options_common_params cp;   /* Common parameters.         */
   gal_list_str_t          *inputnames;   /* The names of input files.  */
   gal_list_str_t                *hdus;   /* The names of input hdus.   */
+  char           *globalhdu;  /* Global HDU (for all inputs).          */
   uint8_t           quality;  /* Quality of JPEG image.                */
   float           widthincm;  /* Width in centimeters.                 */
   uint32_t      borderwidth;  /* Width of border in PostScript points. */
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index 48a3d4e..7478aac 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -518,12 +518,21 @@ ui_make_channels_ll(struct converttparams *p)
       if( gal_fits_name_is_fits(name->v) )
         {
           /* Get the HDU value for this channel. */
-          if(p->hdus)
-            hdu=gal_list_str_pop(&p->hdus);
+          if(p->globalhdu)
+            hdu=p->globalhdu;
           else
-            error(EXIT_FAILURE, 0, "not enough HDUs. Every input FITS image "
-                  "needs a HDU, you can use the '--hdu' ('-h') option once "
-                  "for each input FITS image (in the same order)");
+            {
+              if(p->hdus)
+                hdu=gal_list_str_pop(&p->hdus);
+              else
+                error(EXIT_FAILURE, 0, "not enough HDUs. Every input FITS "
+                      "image needs a HDU (identified by name or number, "
+                      "counting from zero). You can use multiple calls to "
+                      "the '--hdu' ('-h') option for each input FITS image "
+                      "(in the same order as the input FITS files), or use "
+                      "'--globalhdu' ('-g') once when the same HDU should "
+                      "be used for all of them");
+            }
 
           /* Read in the array and its WCS information. */
           data=gal_fits_img_read(name->v, hdu, p->cp.minmapsize,
diff --git a/bin/convertt/ui.h b/bin/convertt/ui.h
index f1deb68..b23e8fb 100644
--- a/bin/convertt/ui.h
+++ b/bin/convertt/ui.h
@@ -42,12 +42,13 @@ enum program_args_groups
 
 /* Available letters for short options:
 
-   a d e f g j k l n p r s t v y z
+   a d e f j k l n p r s t v y z
    E G J O Q R W X Y
 */
 enum option_keys_enum
 {
   /* With short-option version. */
+  UI_KEY_GLOBALHDU           = 'g',
   UI_KEY_QUALITY             = 'u',
   UI_KEY_WIDTHINCM           = 'w',
   UI_KEY_BORDERWIDTH         = 'b',
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index e3ad925..3719d6d 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -9878,6 +9878,8 @@ Input:
 @table @option
 @item -h STR/INT
 @itemx --hdu=STR/INT
+Input HDU name or counter (counting from 0) for each input FITS file.
+If the same HDU should be used from all the FITS files, you can use the 
@option{--globalhdu} option described below.
 In ConvertType, it is possible to call the HDU option multiple times for the 
different input FITS or TIFF files in the same order that they are called on 
the command-line.
 Note that in the TIFF standard, one `directory' (similar to a FITS HDU) may 
contain multiple color channels (for example when the image is in RGB).
 
@@ -9886,6 +9888,11 @@ The number of calls to this option cannot be less than 
the number of input FITS
 
 Unlike CFITSIO, libtiff (which is used to read TIFF files) only recognizes 
numbers (counting from zero, similar to CFITSIO) for `directory' identification.
 Hence the concept of names is not defined for the directories and the values 
to this option for TIFF files must be numbers.
+
+@item -g STR/INT
+@itemx --globalhdu=STR/INT
+Use the value given to this option (a HDU name or a counter, starting from 0) 
for the HDU identifier of all the input FITS files.
+This is useful when all the inputs are distributed in different files, but 
have the same HDU in those files.
 @end table
 
 @noindent



reply via email to

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