gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 19c7634: Crop's checkcenter units now depend o


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 19c7634: Crop's checkcenter units now depend on coordinate mode
Date: Tue, 17 Jul 2018 10:52:42 -0400 (EDT)

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

    Crop's checkcenter units now depend on coordinate mode
    
    Except `--checkcenter', the units of the sizes and coordinates that are
    input into Crop are based on the `--mode' option. This would cause
    confusions.
    
    With this commit, the units of the value given to `--checkcenter' is also
    defined by the `--mode' option. Also, the hard constraint (aborting the
    program, when the given value was even) has been removed. When cropping in
    image mode, if `--checkcenter' is an even number, it will be incremented by
    one so the used value will be odd. To clarify this point, in the verbose
    output, we now also print the value to this option.
    
    This task was suggested by Juan Molina Tobar.
---
 NEWS                         |  3 ++
 THANKS                       |  1 +
 bin/crop/args.h              | 11 +++---
 bin/crop/crop.c              |  4 +-
 bin/crop/main.h              |  3 +-
 bin/crop/ui.c                | 89 +++++++++++++++++++++++++++++++++++++-------
 doc/announce-acknowledge.txt |  1 +
 doc/gnuastro.texi            | 37 ++++++++++--------
 8 files changed, 112 insertions(+), 37 deletions(-)

diff --git a/NEWS b/NEWS
index 5673995..07b2347 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,9 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
 ** Changed features
 
+  Crop:
+    --checkcenter: the units of value depend on mode (image or WCS).
+
   MakeCatalog:
     - `--checkuplim': new name for `--checkupperlimit'.
     - `--brightnessnoriver': new name for `--noriverbrightness'.
diff --git a/THANKS b/THANKS
index 41a23e7..69a9ebc 100644
--- a/THANKS
+++ b/THANKS
@@ -43,6 +43,7 @@ support in Gnuastro. The list is ordered alphabetically (by 
family name).
     Floriane Leclercq                    address@hidden
     Alan Lefor                           address@hidden
     Guillaume Mahler                     address@hidden
+    Juan Molina Tobar                    address@hidden
     Francesco Montanari                  address@hidden
     Dmitrii Oparin                       address@hidden
     Bertrand Pain                        address@hidden
diff --git a/bin/crop/args.h b/bin/crop/args.h
index 714b8d7..3b8a6a7 100644
--- a/bin/crop/args.h
+++ b/bin/crop/args.h
@@ -128,15 +128,16 @@ struct argp_option program_options[] =
     {
       "checkcenter",
       UI_KEY_CHECKCENTER,
-      "INT",
+      "FLT/INT",
       0,
       "Width (in pixels) of box at center to check.",
       UI_GROUP_CENTER_GENERAL,
-      &p->checkcenter,
-      GAL_TYPE_SIZE_T,
-      GAL_OPTIONS_RANGE_0_OR_ODD,
+      &p->incheckcenter,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET
+      GAL_OPTIONS_NOT_SET,
+      gal_options_parse_csv_float64
     },
     {
       "width",
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index 9bcf737..fe05059 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -135,7 +135,7 @@ crop_verbose_final(struct cropparams *p)
       /* Only if the user wanted to check the center. */
       if(p->checkcenter)
         {
-          if( asprintf(&msg, "%zu filled in the center.", numcfilled)<0 )
+          if( asprintf(&msg,"%zu pixels filled in the center.",numcfilled)<0 )
             error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
           gal_timing_report(NULL, msg, 1);
           free(msg);
@@ -469,7 +469,7 @@ crop(struct cropparams *p)
     {
       if(p->checkcenter)
         {
-          if( asprintf(&tmp, "Width of central check box: %zu",
+          if( asprintf(&tmp, "Width of central check box (in pixels): %zu",
                        p->checkcenter)<0 )
             error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
           gal_list_str_add(&comments, tmp, 0);
diff --git a/bin/crop/main.h b/bin/crop/main.h
index 9e2b49a..b2fb4dc 100644
--- a/bin/crop/main.h
+++ b/bin/crop/main.h
@@ -87,7 +87,7 @@ struct cropparams
   uint8_t       zeroisnotblank;  /* ==1: In float or double, keep 0.0.    */
   uint8_t              noblank;  /* ==1: no blank (out of image) pixels.  */
   char                 *suffix;  /* Ending of output file name.           */
-  size_t           checkcenter;  /* width of a box to check for zeros     */
+  gal_data_t    *incheckcenter;  /* Value given to `--checkcenter'.       */
   gal_data_t           *center;  /* Center position of crop.              */
   gal_data_t            *width;  /* Width of crop when defined by center. */
   char                *catname;  /* Name of input catalog.                */
@@ -102,6 +102,7 @@ struct cropparams
   size_t                 numin;  /* Number of input images.               */
   size_t                numout;  /* Number of output images.              */
   double        **centercoords;  /* The center coordinates.               */
+  size_t           checkcenter;  /* width of a box to check for zeros     */
   char                  **name;  /* filename of crop in row.              */
   double             *wpolygon;  /* Array of WCS polygon vertices.        */
   double             *ipolygon;  /* Array of image polygon vertices.      */
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index fde8c46..62507d4 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -307,7 +307,24 @@ ui_read_check_only_options(struct cropparams *p)
     }
 
 
-  /* Section is currentlyl only defined in Image mode. */
+  /* Checkcenter sanity check. */
+  if(p->incheckcenter)
+    {
+      /* We only want a single number. */
+      if(p->incheckcenter->size>1)
+        error(EXIT_FAILURE, 0, "%zu values given to `--checkcenter'. This "
+              "option only takes one value currently",
+              p->incheckcenter->size);
+
+      darray=p->incheckcenter->array;
+      if(*darray<0.0f)
+        error(EXIT_FAILURE, 0, "negative value (%f) given to "
+              "`--checkcenter'. This option only takes positive values",
+              *darray);
+    }
+
+
+  /* Section is currently only defined in Image mode. */
   if(p->section && p->mode!=IMGCROP_MODE_IMG)
     error(EXIT_FAILURE, 0, "The `--section' option is only available in "
           "image coordinate mode, currently it doesn't work with WCS mode. "
@@ -469,12 +486,11 @@ ui_check_options_and_arguments(struct cropparams *p)
    must be in actual number of pixels (an integer). But the user's values
    can be in WCS mode or even in image mode, they may be non-integers. */
 static void
-ui_set_iwidth(struct cropparams *p)
+ui_set_img_sizes(struct cropparams *p)
 {
   gal_data_t *newwidth;
-  double pwidth, *warray;
   size_t i, ndim=p->imgs->ndim;
-
+  double pwidth, pcheckcenter, *warray;
 
   /* Make sure a width value is actually given. */
   if(p->width==NULL)
@@ -509,19 +525,25 @@ ui_set_iwidth(struct cropparams *p)
     }
   else warray=p->width->array;
 
-  /* Fill in `p->iwidth' depending on the mode. */
-  for(i=0;i<ndim;++i)
+  /* WCS mode. */
+  if(p->mode==IMGCROP_MODE_WCS)
     {
-      /* Set iwidth. */
-      if(p->mode==IMGCROP_MODE_WCS)
+      /* Fill in the widths depending on the mode. */
+      for(i=0;i<ndim;++i)
         {
           /* Convert the width in units of the input's WCS into pixels. */
           pwidth = warray[i]/p->pixscale[i];
           if(pwidth<3 || pwidth>50000)
-            error(EXIT_FAILURE, 0, "%g (width along dimension %zu) "
-                  "translates to %.0f pixels. This is probably not what "
-                  "you wanted. Note that the resolution in this dimension "
-                  "is %g", warray[i], i+1, pwidth, p->pixscale[i]);
+            error(EXIT_FAILURE, 0, "value %g (requested width along "
+                  "dimension %zu) translates to %.0f pixels on this "
+                  "dataset. This is probably not what you wanted. Note "
+                  "that the dataset's resolution in this dimension is "
+                  "%g.\n\n"
+                  "You can do the conversion to the dataset's WCS units "
+                  "prior to calling Crop. Alternatively, you can specify "
+                  "all the coordinates/sizes in image (not WCS) units and "
+                  "use the `--mode=img' option", warray[i], i+1, pwidth,
+                  p->pixscale[i]);
 
           /* Write the single valued width in WCS and the image width for
              this dimension. */
@@ -532,11 +554,44 @@ ui_set_iwidth(struct cropparams *p)
               warray[i]    += p->pixscale[i];
             }
         }
-      else
+
+      /* Checkcenter: */
+      if(p->incheckcenter)
+        pcheckcenter=((double *)(p->incheckcenter->array))[0]/p->pixscale[0];
+    }
+  /* Image mode. */
+  else
+    {
+      /* The width (along each dimension). */
+      for(i=0;i<ndim;++i)
         {
           p->iwidth[i]=GAL_DIMENSION_FLT_TO_INT(warray[i]);
           if(p->iwidth[i]%2==0) p->iwidth[i] += 1;
         }
+
+      /* Checkcenter: */
+      if(p->incheckcenter)
+        {
+          /* Write the double value into the temporary variable */
+          pcheckcenter=((double *)(p->incheckcenter->array))[0];
+
+          /* In image-mode it has to be an integer. */
+          if( ceilf(pcheckcenter)!=pcheckcenter )
+            error(EXIT_FAILURE, 0, "%g is not an integer. When cropping in "
+                  "image-mode, the number of pixels to check in the "
+                  "center must be an integer", pcheckcenter);
+        }
+    }
+
+  /* Finalize the number of central pixels to check. */
+  if(p->incheckcenter)
+    {
+      /* Convert the floating point value to an integer. */
+      p->checkcenter=GAL_DIMENSION_FLT_TO_INT(pcheckcenter);
+
+      /* If `checkcenter' isn't zero, but is even, convert it to an odd
+         number (so the actual center can be checked). */
+      if(p->checkcenter && p->checkcenter%2==0) p->checkcenter += 1;
     }
 
   /* For a check:
@@ -712,7 +767,7 @@ ui_prepare_center(struct cropparams *p)
 
 
   /* Set the integer widths of the crop(s) when defined by center. */
-  ui_set_iwidth(p);
+  ui_set_img_sizes(p);
 
   /* For a catalog, we have a separate function, but for a single center
      value, put the center values into an array. This will essentially
@@ -976,6 +1031,12 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct 
cropparams *p)
   if(!p->cp.quiet)
     {
       printf(PROGRAM_NAME" started on %s", ctime(&p->rawtime));
+      if(p->cp.numthreads>1)
+        printf("  - Using %zu CPU thread%s\n", p->cp.numthreads,
+               p->cp.numthreads==1 ? "." : "s.");
+      if(p->checkcenter)
+        printf("  - Number of central pixels to check for blank: %zu\n",
+               p->checkcenter);
       if( asprintf(&msg, "Read metadata of %zu dataset%s.", p->numin,
                    p->numin>1 ? "s" : "")<0 )
         error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 3f0d563..49ab4ba 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -7,6 +7,7 @@ Takashi Ichikawa
 Oryna Ivashtenko
 Geoffry Krouchi
 Alan Lefor
+Juan Molina Tobar
 Dmitrii Oparin
 Teymoor Saifollahi
 Jenny Sorce
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index b60bbd6..3afc708 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -11021,15 +11021,22 @@ instead.
 Output options:
 @table @option
 
address@hidden -c INT
address@hidden --checkcenter=INT
address@hidden -c FLT/INT
address@hidden --checkcenter=FLT/INT
 @cindex Check center of crop
-Box width (odd number of pixels) of region in the center of the image to
-check for blank values. If the value to this option is zero, no checking is
-done. This option is only relevant when the cropped region(s) are defined
-by their center (not by the vertices, see @ref{Crop modes}). If any of the
-pixels in this central region of a crop (defined by its center) are blank,
-then it will not be created.
+Square box width of region in the center of the image to check for blank
+values. If any of the pixels in this central region of a crop (defined by
+its center) are blank, then it will not be stored in an output file. If the
+value to this option is zero, no checking is done. This check is only
+applied when the cropped region(s) are defined by their center (not by the
+vertices, see @ref{Crop modes}).
+
+The units of the value are interpretted based on the @option{--mode} value
+(in WCS or pixel units). The ultimate checked region size (in pixels) will
+be an odd integer around the center (converted from WCS, or when an even
+number of pixels are given to this option). In WCS mode, the value can be
+given as fractions, for example if the WCS untis are in degrees,
address@hidden/3600} will correspond to a check size of 0.1 arcseconds.
 
 Because survey regions don't often have a clean square or rectangle shape,
 some of the pixels on the sides of the survey FITS image don't commonly
@@ -11037,13 +11044,13 @@ have any data and are blank (see @ref{Blank pixels}). 
So when the catalog
 was not generated from the input image, it often happens that the image
 does not have data over some of the points.
 
-When the given center of a crop falls in such regions and this option has a
-non-zero, odd value, no crop will be created. Therefore with this option,
-you can specify a width of a small box (3 pixels is often good enough)
-around the central pixel of the cropped image. You can check which crops
-were created and which weren't from the command-line (if @option{--quiet}
-was not called, see @ref{Operating mode options}), or in Crop's log file
-(see @ref{Crop output}).
+When the given center of a crop falls in such regions or outside the
+dataset, and this option has a non-zero value, no crop will be
+created. Therefore with this option, you can specify a width of a small box
+(3 pixels is often good enough) around the central pixel of the cropped
+image. You can check which crops were created and which weren't from the
+command-line (if @option{--quiet} was not called, see @ref{Operating mode
+options}), or in Crop's log file (see @ref{Crop output}).
 
 @item -p STR
 @itemx --suffix=STR



reply via email to

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