"Fossies" - the Fresh Open Source Software Archive

Member "gnuastro-0.8/bin/mkcatalog/main.h" (27 Dec 2018, 13041 Bytes) of package /linux/privat/gnuastro-0.8.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "main.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.7_vs_0.8.

    1 /*********************************************************************
    2 MakeCatalog - Make a catalog from an input and labeled image.
    3 MakeCatalog is part of GNU Astronomy Utilities (Gnuastro) package.
    4 
    5 Original author:
    6      Mohammad Akhlaghi <mohammad@akhlaghi.org>
    7 Contributing author(s):
    8 Copyright (C) 2016-2018, Free Software Foundation, Inc.
    9 
   10 Gnuastro is free software: you can redistribute it and/or modify it
   11 under the terms of the GNU General Public License as published by the
   12 Free Software Foundation, either version 3 of the License, or (at your
   13 option) any later version.
   14 
   15 Gnuastro is distributed in the hope that it will be useful, but
   16 WITHOUT ANY WARRANTY; without even the implied warranty of
   17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18 General Public License for more details.
   19 
   20 You should have received a copy of the GNU General Public License
   21 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
   22 **********************************************************************/
   23 #ifndef MAIN_H
   24 #define MAIN_H
   25 
   26 /* Include necessary headers */
   27 #include <gsl/gsl_rng.h>
   28 #include <gnuastro/data.h>
   29 #include <gnuastro-internal/options.h>
   30 
   31 /* Progarm names.  */
   32 #define PROGRAM_NAME   "MakeCatalog"  /* Program full name.       */
   33 #define PROGRAM_EXEC   "astmkcatalog" /* Program executable name. */
   34 #define PROGRAM_STRING PROGRAM_NAME" (" PACKAGE_NAME ") " PACKAGE_VERSION
   35 
   36 
   37 
   38 
   39 /* Multiple of given number to stop searching for upper-limit magnitude. */
   40 #define MKCATALOG_UPPERLIMIT_MINIMUM_NUM     20
   41 #define MKCATALOG_UPPERLIMIT_MAXFAILS_MULTIP 10
   42 
   43 
   44 /* Unit string to use if values dataset doesn't have any. */
   45 #define MKCATALOG_NO_UNIT "input-units"
   46 
   47 
   48 
   49 /* Intermediate/raw array elements
   50    ===============================
   51 
   52    Commonly, several high-level calculations need the same low-level
   53    measurements. So to avoid having to do these low-level calculations on
   54    each pixel multiple tiles, each thread/object will have one array of
   55    intermediate values which will be filled in the pass over the
   56    pixels. After this intermediate array is filled, and we don't need to
   57    pass over the pixels any more, we will use the intermediate values to
   58    derive the higher-level steps.
   59 
   60    According to the C standard, the first enum variable has a value of 0
   61    (int), and when none are explicitly set (with an = sign), the values of
   62    the subsequent enum variables are 1 larger. We want column indexs that
   63    also start with zero, but setting the values by hand manually as
   64    preprocessor macros can be buggy (repeated numbers). So defining them as
   65    an enum is the perfect solution. Any future column that is to be added
   66    (or if any are removed), we (the developers) don't have to worry.
   67 
   68    --------------------- POSITIONS IN FITS standard ---------------------
   69    Like the final output, positions in this intermediate array are also in
   70    the FITS standard (fastest dimension is first). */
   71 enum objectcols
   72   {
   73     OCOL_NUMALL,         /* Number of all pixels with this label.     */
   74     OCOL_NUM,            /* Number of pixels with a value.            */
   75     OCOL_SUM,            /* Sum of (value-sky) in object.             */
   76     OCOL_SUM_VAR,        /* Varience of sum (for brightness error).   */
   77     OCOL_MEDIAN,         /* Median of value in object.                */
   78     OCOL_VX,             /* Sum of (value-sky) * x.                   */
   79     OCOL_VY,             /* Sum of (value-sky) * y.                   */
   80     OCOL_VXX,            /* Sum of (value-sky) * x * x.               */
   81     OCOL_VYY,            /* Sum of (value-sky) * y * y.               */
   82     OCOL_VXY,            /* Sum of (value-sky) * x * y.               */
   83     OCOL_SUMSKY,         /* Sum of sky value on this object.          */
   84     OCOL_SUMSTD,         /* Sum of sky STD value on this object.      */
   85     OCOL_SUMWHT,         /* Sum of positive image pixels.             */
   86     OCOL_NUMWHT,         /* Number of positive pixels used for wht.   */
   87     OCOL_GX,             /* Geometric center of object in X.          */
   88     OCOL_GY,             /* Geometric center of object in Y.          */
   89     OCOL_GXX,            /* Second order geometric variable: X*X.     */
   90     OCOL_GYY,            /* Second order geometric variable: Y*Y.     */
   91     OCOL_GXY,            /* Second order geometric variable: X*Y.     */
   92     OCOL_UPPERLIMIT_B,   /* Upper limit brightness.                   */
   93     OCOL_UPPERLIMIT_S,   /* Upper limit one-sigma value.              */
   94     OCOL_UPPERLIMIT_Q,   /* Quantile of object in random distribution.*/
   95     OCOL_UPPERLIMIT_SKEW,/* (Mean-Median)/STD of random distribution. */
   96     OCOL_C_NUMALL,       /* Value independent no. of pixels in clumps.*/
   97     OCOL_C_NUM,          /* Area of clumps in this object.            */
   98     OCOL_C_SUM,          /* Brightness in object clumps.              */
   99     OCOL_C_VX,           /* Sum of (value-sky)*x on clumps.           */
  100     OCOL_C_VY,           /* Sum of (value-sky)*y on obj. clumps.      */
  101     OCOL_C_GX,           /* Geometric center of clumps in object X.   */
  102     OCOL_C_GY,           /* Geometric center of clumps in object Y.   */
  103     OCOL_C_SUMWHT,       /* Sum of positive image pixels for wht.     */
  104     OCOL_C_NUMWHT,       /* Num of positive image pixels for wht.     */
  105 
  106     OCOL_NUMCOLS,        /* SHOULD BE LAST: total number of columns.  */
  107   };
  108 
  109 enum clumpcols
  110   {
  111     CCOL_NUMALL,         /* Number of pixels in clump.                */
  112     CCOL_NUM,            /* Number of values used in clump.           */
  113     CCOL_SUM,            /* River subtracted brightness.              */
  114     CCOL_SUM_VAR,        /* Variance of sum (for brightness error).   */
  115     CCOL_MEDIAN,         /* Median of values in clump.                */
  116     CCOL_RIV_NUM,        /* Num river pixels around this clump.       */
  117     CCOL_RIV_SUM,        /* Sum of rivers around clump.               */
  118     CCOL_RIV_SUM_VAR,    /* Variance of sum (for error measurements). */
  119     CCOL_VX,             /* Sum of (value-sky) * x.                   */
  120     CCOL_VY,             /* Sum of (value-sky) * y.                   */
  121     CCOL_VXX,            /* Sum of flux*x*x of this clump.            */
  122     CCOL_VYY,            /* Sum of flux*y*y of this clump.            */
  123     CCOL_VXY,            /* Sum of flux*x*y of this clump.            */
  124     CCOL_SUMSKY,         /* Sum of sky value on this object.          */
  125     CCOL_SUMSTD,         /* Sum of sky STD value on this object.      */
  126     CCOL_SUMWHT,         /* Sum of positive image pixels for wht.     */
  127     CCOL_NUMWHT,         /* Num of positive image pixels for wht.     */
  128     CCOL_GX,             /* Geometric center of clump in X.           */
  129     CCOL_GY,             /* Geometric center of clump in Y.           */
  130     CCOL_GXX,            /* Second order geometric moment.            */
  131     CCOL_GYY,            /* Second order geometric moment.            */
  132     CCOL_GXY,            /* Second order geometric moment.            */
  133     CCOL_MINX,           /* Minimum X value of clump.                 */
  134     CCOL_MAXX,           /* Maximum X value of clump.                 */
  135     CCOL_MINY,           /* Minimum Y value of clump.                 */
  136     CCOL_MAXY,           /* Maximum Y value of clump.                 */
  137     CCOL_UPPERLIMIT_B,   /* Upper limit brightness.                   */
  138     CCOL_UPPERLIMIT_S,   /* Upper limit one-sigma value.              */
  139     CCOL_UPPERLIMIT_Q,   /* Quantile of object in random distribution.*/
  140     CCOL_UPPERLIMIT_SKEW,/* (Mean-Median)/STD of random distribution. */
  141 
  142     CCOL_NUMCOLS,        /* SHOULD BE LAST: total number of columns.  */
  143   };
  144 
  145 
  146 
  147 
  148 
  149 
  150 
  151 /* Main program parameters structure */
  152 struct mkcatalogparams
  153 {
  154   /* From command-line */
  155   struct gal_options_common_params cp; /* Common parameters.            */
  156   gal_list_i32_t   *columnids;  /* The desired column codes.            */
  157   char           *objectsfile;  /* Input filename.                      */
  158   char            *valuesfile;  /* File name of objects file.           */
  159   char             *valueshdu;  /* HDU of objects image.                */
  160   char            *clumpsfile;  /* File name of objects file.           */
  161   char             *clumpshdu;  /* HDU of objects image.                */
  162   char               *skyfile;  /* File name of sky file.               */
  163   char                *skyhdu;  /* HDU of sky image.                    */
  164   char               *stdfile;  /* File name of sky STD file.           */
  165   char                *stdhdu;  /* HDU of sky STD image.                */
  166 
  167   uint8_t           clumpscat;  /* ==1: create clumps catalog.          */
  168   uint8_t         noclumpsort;  /* Don't sort the clumps catalog.       */
  169   float             zeropoint;  /* Zero-point magnitude of object.      */
  170   uint8_t            variance;  /* Input STD file is actually variance. */
  171   uint8_t         subtractsky;  /* ==1: subtract the Sky from values.   */
  172   float           sfmagnsigma;  /* Surface brightness multiple of sigma.*/
  173   float             sfmagarea;  /* Surface brightness area (arcsec^2).  */
  174 
  175   char            *upmaskfile;  /* Name of upper limit mask file.       */
  176   char             *upmaskhdu;  /* HDU of upper limit mask file.        */
  177   size_t                upnum;  /* Number of upper-limit random samples.*/
  178   size_t             *uprange;  /* Range of random pos. around target.  */
  179   uint8_t             envseed;  /* Use the environment for random seed. */
  180   double       upsigmaclip[2];  /* Sigma clip to measure upper limit.   */
  181   float              upnsigma;  /* Multiple of sigma to define up-lim.  */
  182   int32_t       checkuplim[2];  /* Object & clump ID to check dist.     */
  183 
  184   /* Internal. */
  185   time_t              rawtime;  /* Starting time of the program.        */
  186   gal_data_t          *values;  /* Input.                               */
  187   gal_data_t         *objects;  /* Object labels.                       */
  188   gal_data_t          *clumps;  /* Clump labels.                        */
  189   gal_data_t             *sky;  /* Sky.                                 */
  190   gal_data_t             *std;  /* Sky standard deviation.              */
  191   gal_data_t          *upmask;  /* Upper limit magnitude mask.          */
  192   float                medstd;  /* Median standard deviation value.     */
  193   float               cpscorr;  /* Counts-per-second correction.        */
  194   size_t           numobjects;  /* Number of object labels in image.    */
  195   float               clumpsn;  /* Clump S/N threshold.                 */
  196   size_t            numclumps;  /* Number of clumps in image.           */
  197   gal_data_t      *objectcols;  /* Output columns for the objects.      */
  198   gal_data_t       *clumpcols;  /* Output columns for the clumps.       */
  199   gal_data_t           *tiles;  /* Tiles to cover each object.          */
  200   char            *objectsout;  /* Output objects catalog.              */
  201   char             *clumpsout;  /* Output clumps catalog.               */
  202   char            *upcheckout;  /* Name of upperlimit check table.      */
  203   uint8_t             *oiflag;  /* Intermediate flags for objects.      */
  204   uint8_t             *ciflag;  /* Intermediate flags for clumps.       */
  205   pthread_mutex_t       mutex;  /* Mutex to change the total numbers.   */
  206   size_t      clumprowsfilled;  /* No. filled clump rows at this moment.*/
  207   gsl_rng                *rng;  /* Main random number generator.        */
  208   unsigned long int  rng_seed;  /* Random number generator seed.        */
  209   const char        *rng_name;  /* Name of random number generator.     */
  210   size_t               rngmin;  /* Minimum possible value of RNG.       */
  211   size_t              rngdiff;  /* Difference of RNG max and min.       */
  212   uint8_t      uprangewarning;  /* A warning must be printed.           */
  213   size_t         *hostobjid_c;  /* To sort the clumps table by Obj.ID.  */
  214   size_t         *numclumps_c;  /* To sort the clumps table by Obj.ID.  */
  215 
  216   char        *usedvaluesfile;  /* Ptr to final name used for values.   */
  217   char        *usedclumpsfile;  /* Ptr to final name used for clumps.   */
  218   char           *usedskyfile;  /* Ptr to final fname used for sky.     */
  219   char           *usedstdfile;  /* Ptr to final name used for sky std.  */
  220 
  221   gal_data_t          *wcs_vo;  /* Object RA-Dec flux weighted X, Y.    */
  222   gal_data_t          *wcs_vc;  /* Clump RA-Dec flux weighted X, Y.     */
  223   gal_data_t          *wcs_go;  /* Object RA-Dec geometric X,Y.         */
  224   gal_data_t          *wcs_gc;  /* Clump RA-Dec geometric X, Y.         */
  225   gal_data_t         *wcs_vcc;  /* All clumps RA-Dec flx. wht. X, Y.    */
  226   gal_data_t         *wcs_gcc;  /* All clumps RA-Dec geometric X, Y.    */
  227 
  228   char                **ctype;  /* Type of WCS axis.                    */
  229 
  230   uint8_t            hasblank;  /* Dataset has blank values.            */
  231   uint8_t              hasmag;  /* Catalog has magnitude columns.       */
  232   uint8_t          upperlimit;  /* Calculate upper limit magnitude.     */
  233 };
  234 
  235 #endif