gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 388c6be: MakeCatalog outputs minimum and maxim


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 388c6be: MakeCatalog outputs minimum and maximum positions
Date: Sun, 22 Jul 2018 16:12:24 -0400 (EDT)

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

    MakeCatalog outputs minimum and maximum positions
    
    The minimum and maximum positions of the labels can be very useful in some
    contexts (for example to crop later, or measure the over-all size along
    each dimension). With this commit, four new options were added to
    MakeCatalog: `--minx', `--maxx', `--miny' and `--maxy' for this purpose.
---
 NEWS                    |   6 +++
 bin/mkcatalog/args.h    |  56 +++++++++++++++++++++++
 bin/mkcatalog/columns.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++
 bin/mkcatalog/main.h    |   4 ++
 bin/mkcatalog/parse.c   |  28 +++++++++++-
 bin/mkcatalog/ui.c      |   4 ++
 bin/mkcatalog/ui.h      |   4 ++
 doc/gnuastro.texi       |  12 +++++
 8 files changed, 230 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 00c6e4b..a0c9680 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,12 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
     - `collapse-mean': collapse/remove a dimension by averaging over it.
     - `collapse-number': Number of elements included in the collapse.
 
+  MakeCatalog:
+    --minx: minimum position along first FITS axis.
+    --maxx: maximum position along first FITS axis.
+    --miny: minimum position along second FITS axis.
+    --maxy: maximum position along second FITS axis.
+
   Table:
     --colinfoinstdout: column information when writing to standard output.
 
diff --git a/bin/mkcatalog/args.h b/bin/mkcatalog/args.h
index 58e7d77..ea20522 100644
--- a/bin/mkcatalog/args.h
+++ b/bin/mkcatalog/args.h
@@ -483,6 +483,62 @@ struct argp_option program_options[] =
       ui_column_codes_ll
     },
     {
+      "minx",
+      UI_KEY_MINX,
+      0,
+      0,
+      "Minimum first FITS axis position.",
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "maxx",
+      UI_KEY_MAXX,
+      0,
+      0,
+      "Maximum first FITS axis position.",
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "miny",
+      UI_KEY_MINY,
+      0,
+      0,
+      "Minimum second FITS axis position.",
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "maxy",
+      UI_KEY_MAXY,
+      0,
+      0,
+      "Maximum second FITS axis position.",
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
       "clumpsx",
       UI_KEY_CLUMPSX,
       0,
diff --git a/bin/mkcatalog/columns.c b/bin/mkcatalog/columns.c
index 00ebaed..fd098a6 100644
--- a/bin/mkcatalog/columns.c
+++ b/bin/mkcatalog/columns.c
@@ -515,6 +515,58 @@ columns_define_alloc(struct mkcatalogparams *p)
           oiflag[ OCOL_C_NUMALL ] = 1;
           break;
 
+        case UI_KEY_MINX:
+          name           = "MIN_X";
+          unit           = "pixel";
+          ocomment       = "Minimum X axis pixel position.";
+          ccomment       = ocomment;
+          otype          = GAL_TYPE_UINT32;
+          ctype          = GAL_TYPE_UINT32;
+          disp_fmt       = 0;
+          disp_width     = 10;
+          disp_precision = 0;
+          ciflag[ CCOL_MINX ] = 1;
+          break;
+
+        case UI_KEY_MAXX:
+          name           = "MAX_X";
+          unit           = "pixel";
+          ocomment       = "Maximum X axis pixel position.";
+          ccomment       = ocomment;
+          otype          = GAL_TYPE_UINT32;
+          ctype          = GAL_TYPE_UINT32;
+          disp_fmt       = 0;
+          disp_width     = 10;
+          disp_precision = 0;
+          ciflag[ CCOL_MAXX ] = 1;
+          break;
+
+        case UI_KEY_MINY:
+          name           = "MIN_Y";
+          unit           = "pixel";
+          ocomment       = "Minimum Y axis pixel position.";
+          ccomment       = ocomment;
+          otype          = GAL_TYPE_UINT32;
+          ctype          = GAL_TYPE_UINT32;
+          disp_fmt       = 0;
+          disp_width     = 10;
+          disp_precision = 0;
+          ciflag[ CCOL_MINY ] = 1;
+          break;
+
+        case UI_KEY_MAXY:
+          name           = "MAX_Y";
+          unit           = "pixel";
+          ocomment       = "Maximum Y axis pixel position.";
+          ccomment       = ocomment;
+          otype          = GAL_TYPE_UINT32;
+          ctype          = GAL_TYPE_UINT32;
+          disp_fmt       = 0;
+          disp_width     = 10;
+          disp_precision = 0;
+          ciflag[ CCOL_MAXY ] = 1;
+          break;
+
         case UI_KEY_W1:
           name           = p->ctype[0];
           unit           = p->objects->wcs->cunit[0];
@@ -1389,6 +1441,46 @@ columns_clump_brightness(double *ci)
 
 
 
+/* Measure the minimum and maximum positions. */
+static uint32_t
+columns_xy_extrema(struct mkcatalog_passparams *pp, size_t *coord, int key)
+{
+  gal_data_t *tile=pp->tile, *block=tile->block;
+
+  /* We only want to do the coordinate estimation once: in `columns_fill',
+     we initialized the coordinates with `GAL_BLANK_SIZE_T'. When the
+     coordinate has already been measured already, it won't have this value
+     any more. */
+  if(coord[0]==GAL_BLANK_SIZE_T)
+    gal_dimension_index_to_coord(gal_pointer_num_between(block->array,
+                                                         tile->array,
+                                                         block->type),
+                                 block->ndim, block->dsize, coord);
+
+  /* Return the proper value: note that `coord' is in C standard: starting
+     from the slowest dimension and counting from zero.*/
+  switch(key)
+    {
+    case UI_KEY_MINX: return coord[1] + 1;              break;
+    case UI_KEY_MAXX: return coord[1] + tile->dsize[1]; break;
+    case UI_KEY_MINY: return coord[0] + 1;              break;
+    case UI_KEY_MAXY: return coord[0] + tile->dsize[0]; break;
+    default:
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us to fix the "
+            "problem. The value %d is not a recognized value", __func__,
+            key);
+    }
+
+  /* Control should not reach here. */
+  error(EXIT_FAILURE, 0, "%s: a bug! please contact us to fix the problem. "
+        "Control should not reach the end of this function", __func__);
+  return GAL_BLANK_UINT32;
+}
+
+
+
+
+
 /* The magnitude error is directly derivable from the S/N:
 
    To derive the error in measuring the magnitude from the S/N, let's take
@@ -1443,6 +1535,8 @@ columns_fill(struct mkcatalog_passparams *pp)
   void *colarr;
   gal_data_t *column;
   double *ci, *oi=pp->oi;
+  size_t coord[2]={GAL_BLANK_SIZE_T, GAL_BLANK_SIZE_T};
+
   size_t sr=pp->clumpstartindex, cind, coind;
   size_t oind=pp->object-1; /* IDs start from 1, indexs from 0. */
   double **vo=NULL, **vc=NULL, **go=NULL, **gc=NULL, **vcc=NULL, **gcc=NULL;
@@ -1528,6 +1622,13 @@ columns_fill(struct mkcatalog_passparams *pp)
                                                oi[OCOL_C_NUMALL] );
           break;
 
+        case UI_KEY_MINX:
+        case UI_KEY_MAXX:
+        case UI_KEY_MINY:
+        case UI_KEY_MAXY:
+          ((uint32_t *)colarr)[oind]=columns_xy_extrema(pp, coord, key);
+          break;
+
         case UI_KEY_W1:
         case UI_KEY_W2:
           vo[0][oind] = POS_V_G(oi, OCOL_SUMWHT, OCOL_NUMALL, OCOL_VX,
@@ -1740,6 +1841,22 @@ columns_fill(struct mkcatalog_passparams *pp)
                                                  ci[CCOL_NUMALL] );
             break;
 
+         case UI_KEY_MINX:
+            ((uint32_t *)colarr)[cind] = ci[CCOL_MINX];
+            break;
+
+         case UI_KEY_MAXX:
+            ((uint32_t *)colarr)[cind] = ci[CCOL_MAXX];
+            break;
+
+         case UI_KEY_MINY:
+            ((uint32_t *)colarr)[cind] = ci[CCOL_MINY];
+            break;
+
+         case UI_KEY_MAXY:
+            ((uint32_t *)colarr)[cind] = ci[CCOL_MAXY];
+            break;
+
           case UI_KEY_W1:
           case UI_KEY_W2:
             vc[0][cind] = POS_V_G(ci, CCOL_SUMWHT, CCOL_NUMALL, CCOL_VX,
diff --git a/bin/mkcatalog/main.h b/bin/mkcatalog/main.h
index f226442..0461a7a 100644
--- a/bin/mkcatalog/main.h
+++ b/bin/mkcatalog/main.h
@@ -130,6 +130,10 @@ enum clumpcols
     CCOL_GXX,            /* Second order geometric moment.            */
     CCOL_GYY,            /* Second order geometric moment.            */
     CCOL_GXY,            /* Second order geometric moment.            */
+    CCOL_MINX,           /* Minimum X value of clump.                 */
+    CCOL_MAXX,           /* Maximum X value of clump.                 */
+    CCOL_MINY,           /* Minimum Y value of clump.                 */
+    CCOL_MAXY,           /* Maximum Y value of clump.                 */
     CCOL_UPPERLIMIT_B,   /* Upper limit brightness.                   */
     CCOL_UPPERLIMIT_S,   /* Upper limit one-sigma value.              */
     CCOL_UPPERLIMIT_Q,   /* Quantile of object in random distribution.*/
diff --git a/bin/mkcatalog/parse.c b/bin/mkcatalog/parse.c
index 8202d93..195239c 100644
--- a/bin/mkcatalog/parse.c
+++ b/bin/mkcatalog/parse.c
@@ -310,6 +310,19 @@ parse_objects(struct mkcatalog_passparams *pp)
 
 
 
+/* Macro to help in finding the minimum and maximum coordinates. */
+#define CMIN(COL, DIM) ( ci[ CCOL_NUMALL ]==1.0f                        \
+                         ? (c[ DIM ]+1)                                 \
+                         : ( (c[ DIM ]+1) < ci[ COL ]                   \
+                             ? (c[ DIM ]+1) : ci[ COL ] ) )
+#define CMAX(COL, DIM) ( ci[ CCOL_NUMALL ]==1.0f                        \
+                         ? (c[ DIM ]+1)                                 \
+                         : ( (c[ DIM ]+1) > ci[ COL ]                   \
+                             ? (c[ DIM ]+1) : ci[ COL ] ) )
+
+
+
+
 /* Parse over the clumps within an object.  */
 void
 parse_clumps(struct mkcatalog_passparams *pp)
@@ -342,6 +355,10 @@ parse_clumps(struct mkcatalog_passparams *pp)
                   || cif[ CCOL_GY   ]
                   || cif[ CCOL_VX   ]
                   || cif[ CCOL_VY   ]
+                  || cif[ CCOL_MINX ]
+                  || cif[ CCOL_MAXX ]
+                  || cif[ CCOL_MINY ]
+                  || cif[ CCOL_MAXY ]
                   || sc
                   || tid==GAL_BLANK_SIZE_T )
                 ? gal_pointer_allocate(GAL_TYPE_SIZE_T, ndim, 0, __func__,
@@ -384,7 +401,10 @@ parse_clumps(struct mkcatalog_passparams *pp)
                   ci=&pp->ci[ (*C-1) * CCOL_NUMCOLS ];
 
                   /* Add to the area of this object. */
-                  if(cif[ CCOL_NUMALL ]) ci[ CCOL_NUMALL ]++;
+                  if( cif[ CCOL_NUMALL ]
+                      || cif[ CCOL_MINX ] || cif[ CCOL_MAXX ]
+                      || cif[ CCOL_MINY ] || cif[ CCOL_MAXY ] )
+                    ci[ CCOL_NUMALL ]++;
 
                   /* Raw-position related measurements. */
                   if(c)
@@ -392,6 +412,12 @@ parse_clumps(struct mkcatalog_passparams *pp)
                       /* Get "C" the coordinates of this point. */
                       gal_dimension_index_to_coord(O-objects, ndim, dsize, c);
 
+                      /* Position extrema measurements. */
+                      if(cif[ CCOL_MINX ]) ci[CCOL_MINX]=CMIN(CCOL_MINX, 1);
+                      if(cif[ CCOL_MAXX ]) ci[CCOL_MAXX]=CMAX(CCOL_MAXX, 1);
+                      if(cif[ CCOL_MINY ]) ci[CCOL_MINY]=CMIN(CCOL_MINY, 0);
+                      if(cif[ CCOL_MAXY ]) ci[CCOL_MAXY]=CMAX(CCOL_MAXY, 0);
+
                       /* If we need tile-ID, get the tile ID now. */
                       if(tid!=GAL_BLANK_SIZE_T)
                         tid=gal_tile_full_id_from_coord(&p->cp.tl, c);
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 5f0eaf7..d9f3c6a 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -764,6 +764,10 @@ ui_necessary_inputs(struct mkcatalogparams *p, int 
*values, int *sky,
           case CCOL_GXX:              /* Only clump labels. */     break;
           case CCOL_GYY:              /* Only clump labels. */     break;
           case CCOL_GXY:              /* Only clump labels. */     break;
+          case CCOL_MINX:             /* Only clump labels. */     break;
+          case CCOL_MAXX:             /* Only clump labels. */     break;
+          case CCOL_MINY:             /* Only clump labels. */     break;
+          case CCOL_MAXY:             /* Only clump labels. */     break;
           case CCOL_UPPERLIMIT_B:     *values        = 1;          break;
           case CCOL_UPPERLIMIT_S:     *values        = 1;          break;
           case CCOL_UPPERLIMIT_Q:     *values        = 1;          break;
diff --git a/bin/mkcatalog/ui.h b/bin/mkcatalog/ui.h
index 0b7a255..36f2216 100644
--- a/bin/mkcatalog/ui.h
+++ b/bin/mkcatalog/ui.h
@@ -110,6 +110,10 @@ enum option_keys_enum
   UI_KEY_CLUMPSY,
   UI_KEY_CLUMPSGEOX,
   UI_KEY_CLUMPSGEOY,
+  UI_KEY_MINX,
+  UI_KEY_MAXX,
+  UI_KEY_MINY,
+  UI_KEY_MAXY,
   UI_KEY_W1,
   UI_KEY_W2,
   UI_KEY_GEOW1,
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 40ba6d5..aeaedaf 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -18043,6 +18043,18 @@ irrespective of their pixel values.
 The geometric center of all objects and clumps along the second FITS
 axis axis, see @option{--geox}.
 
address@hidden --minx
+The minimum position of all objects and clumps along the first FITS axis.
+
address@hidden --maxx
+The maximum position of all objects and clumps along the first FITS axis.
+
address@hidden --miny
+The minimum position of all objects and clumps along the second FITS axis.
+
address@hidden --maxy
+The maximum position of all objects and clumps along the second FITS axis.
+
 @item --clumpsx
 [Objects] The flux weighted center of all the clumps in this
 object along the first FITS axis. See @option{--x}.



reply via email to

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