gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 903faf76: Crop: new option to let users set th


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 903faf76: Crop: new option to let users set the name of the output HDU
Date: Tue, 25 Oct 2022 12:49:54 -0400 (EDT)

branch: master
commit 903faf76b9268357e0bbcb1f6ca5d592012e7f10
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Crop: new option to let users set the name of the output HDU
    
    Until now, if the user wanted to set the name ('EXTNAME' keyword) of the
    output HDU, they would have to call 'astfits' afterwards. But this is a
    pretty basic operation that like Arithmetic, the user expects to do in the
    same command that they produced the HDU.
    
    With this commit, based on the experience with Arithmetic, a new
    '--metaname' option has been added to Crop (same long version name as the
    same option in Arithmetic).
---
 NEWS                  |  4 ++++
 bin/crop/args.h       | 13 +++++++++++++
 bin/crop/astcrop.conf |  1 +
 bin/crop/main.h       |  1 +
 bin/crop/onecrop.c    |  6 ++++++
 bin/crop/ui.c         |  1 +
 bin/crop/ui.h         |  3 ++-
 doc/gnuastro.texi     | 12 ++++++++++--
 8 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index f78d62c2..86b6da49 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ See the end of the file for license conditions.
 
 ** New features
 
+   Crop:
+   --metaname: Specify the name of the cropped output HDU (value to the
+     'EXTNAME' keyword in FITS).
+
 ** Removed features
 
 ** Changed features
diff --git a/bin/crop/args.h b/bin/crop/args.h
index f8f04f5b..97fcc435 100644
--- a/bin/crop/args.h
+++ b/bin/crop/args.h
@@ -141,6 +141,19 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
     },
+    {
+      "metaname",
+      UI_KEY_METANAME,
+      "STR",
+      0,
+      "Name of output HDU (EXTNAME keyword in FITS).",
+      GAL_OPTIONS_GROUP_OUTPUT,
+      &p->metaname,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
 
 
 
diff --git a/bin/crop/astcrop.conf b/bin/crop/astcrop.conf
index e61671ed..1d33a972 100644
--- a/bin/crop/astcrop.conf
+++ b/bin/crop/astcrop.conf
@@ -26,6 +26,7 @@
 
 # Output parameters:
  checkcenter    0
+ metaname       CROP
  suffix         _cropped.fits
 
 # Crop by center (when a catalog is given)
diff --git a/bin/crop/main.h b/bin/crop/main.h
index c1a2801d..b0ccc505 100644
--- a/bin/crop/main.h
+++ b/bin/crop/main.h
@@ -100,6 +100,7 @@ struct cropparams
   gal_data_t          *polygon;  /* Input string of polygon vertices.     */
   uint8_t           polygonout;  /* ==1: Keep the inner polygon region.   */
   uint8_t          polygonsort;  /* Don't sort polygon vertices.          */
+  char               *metaname;  /* Output's EXTNAME keyword.             */
 
   /* Internal */
   size_t                 numin;  /* Number of input images.               */
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index 16c2ee35..de267552 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -573,6 +573,12 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
   status=0;
 
 
+  /* Name of extension. */
+  fits_update_key(ofp, TSTRING, "EXTNAME", crp->p->metaname,
+                  "Name of HDU (extension).", &status);
+  gal_fits_io_error(status, "writing EXTNAME");
+
+
   /* Read the units of the input dataset and store them in the output. */
   rkey->next=NULL;
   rkey->name="BUNIT";
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index d053b9e4..30b775f8 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -1282,6 +1282,7 @@ ui_free_report(struct cropparams *p, struct timeval *t1)
   size_t i;
 
   /* Free the simple arrays (if they were set). */
+  free(p->metaname);
   free(p->blankptrread);
   free(p->blankptrwrite);
   gal_data_free(p->center);
diff --git a/bin/crop/ui.h b/bin/crop/ui.h
index c1bcee4a..d5068e5d 100644
--- a/bin/crop/ui.h
+++ b/bin/crop/ui.h
@@ -45,7 +45,7 @@ enum program_args_groups
 
 /* Available letters for short options:
 
-   a d e f g i j k m r u v y
+   d e f g i j k m r u v y
    A B E G H J L Q R W Y
 */
 enum option_keys_enum
@@ -64,6 +64,7 @@ enum option_keys_enum
   UI_KEY_CENTER         = 'c',
   UI_KEY_COORDCOL       = 'x',
   UI_KEY_ONEELEMSTDOUT  = 't',
+  UI_KEY_METANAME       = 'a',
 
   /* Only with long version (start with a value 1000, the rest will be set
      automatically). */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 76fdbf3b..b0f37949 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -15639,8 +15639,10 @@ $ astcrop --catalog=cat.txt image.fits
 ## ending in `_drz.fits' in `/mnt/data/COSMOS/':
 $ astcrop --mode=wcs --catalog=cat.txt /mnt/data/COSMOS/*_drz.fits
 
-## Crop the outer 10 border pixels of the input image:
-$ astcrop --section=10:*-10,10:*-10 --hdu=2 image.fits
+## Crop the outer 10 border pixels of the input image and give
+## the output HDU a name ('EXTNAME' keyword in FITS) of 'mysection'.
+$ astcrop --section=10:*-10,10:*-10 --hdu=2 image.fits \
+          --metaname=mysection
 
 ## Crop region around RA and Dec of (189.16704, 62.218203):
 $ astcrop --mode=wcs --center=189.16704,62.218203 goodsnorth.fits
@@ -15892,6 +15894,12 @@ When this column is not given, the row number will be 
used instead.
 Output options:
 @table @option
 
+@item -a STR
+@itemx --metaname=STR
+Name of cropped HDU (value to the @code{EXTNAME} keyword of FITS).
+If not given, a default @code{CROP} will be placed there (so the 
@code{EXTNAME} keyword will always be present in the output).
+If crop produces many outputs from a catalog, they will be given the same 
string as @code{EXTNAME} (the file names containing the cropped HDU will be 
different).
+
 @item -c FLT/INT
 @itemx --checkcenter=FLT/INT
 @cindex Check center of crop



reply via email to

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