gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 799c83b 4/6: Flat profiles in MakeProfiles are


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 799c83b 4/6: Flat profiles in MakeProfiles are given values
Date: Fri, 12 Aug 2016 23:58:02 +0000 (UTC)

branch: master
commit 799c83bb38b49ff73119a9fd37665e527efc0376
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Flat profiles in MakeProfiles are given values
    
    The values of the flat function profiles (codes 4 and 5) in MakeProfiles
    were previously set using the two `--setconsttonan', `--setconsttomin'
    options. It was thus not possible to make flat profiles, each with a
    different value.
    
    With this commit, those two MakeProfiles options were removed and a more
    generic and much more cleaner mechanism was set to manage flat profiles. By
    default, the flat profiles will have the total magnitude given in the
    `--mcol' (magnitude column) of the catalog. However, if the new
    `--mforflatpix' or `-F' option is used, the user can now use the same
    magnitude column to specify the constant pixel value that s/he wants for
    each specific profile. It is also possible to use NaN, or Infinity Floating
    point values in this scheme.
    
    The `--setconsttomin' process can now be replaced with a first call to
    Arithmetic (which can give you the minimum value of the background image)
    to get the minimum or maximum values of the background image, then using
    that value in this column for all the profiles.
    
    Internally, until now the individual profiles were made on a canvas of NaN
    values. But that just made things so much more complicated. It would also
    conflict with the generic and easy to follow process introduced in this
    commit which would allow the creation of NaN profiles. Now, the plain
    canvas is filled with values of `0.0f'. So it is not possible to set a
    constant value of `0.0f' for the profiles. NaN (mask) profiles are much
    more common than zero valued profiles. All the utilities in Gnuastro deal
    NaN pixels as blank, but 0 valued pixels have meaning, so NaNs are much
    better for a mask.
    
    A small typo in `src/mkprof/ui.c' (the `printvalues' function) was also
    corrected, `up->tcolset', was mistakenly written as `up->mcolset' (repeated
    from the top two lines). Some other very minor issues were
    corrected/cleared.
    
    This finishes task #14115
---
 doc/gnuastro.texi                                  |   83 +++++++++++++-------
 src/mkprof/args.h                                  |   50 +++++-------
 src/mkprof/main.h                                  |    6 +-
 src/mkprof/mkprof.c                                |   33 +++-----
 src/mkprof/mkprof.h                                |    1 +
 src/mkprof/oneprofile.c                            |   82 +++++++++++++++----
 src/mkprof/profiles.c                              |    4 +-
 src/mkprof/profiles.h                              |    2 +-
 src/mkprof/ui.c                                    |   67 ++++++++--------
 tests/Makefile.am                                  |    2 +-
 tests/mkprof/ellipticalmasks.sh                    |    6 +-
 .../{mkprofcat1_mask.txt => ellipticalmasks.txt}   |    5 +-
 12 files changed, 197 insertions(+), 144 deletions(-)

diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 88b7e67..c05c3dd 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -12574,39 +12574,29 @@ cases, besides de-convolution, you will have to set
 ImageWarp (see @ref{ImageWarp}), the peak flux will be different.
 @end cartouche
 
address@hidden -M
address@hidden --setconsttomin
-For profiles that have a constant value (no variation from pixel to
-pixel), set the constant value to the minimum value in the image. This
-is very useful if the profiles with constant value are to be used as
-masks. When displaying the images in a document (and inverting the
-images as is automatically done in ConvertType), the masked pixels
-will become white.
-
address@hidden -A
address@hidden --setconsttonan
-Similar to @option{--setconsttomin}, but the constant value is a NaN
-value. Since all Gnuastro programs treat NaN valued pixels as masked,
-this is useful for immediately masking some pixels in the image that
-have an elliptical shape without the need to creating a new mask
-image.
-
 @item -R
 @itemx --replace
-Do not add pixel values to each other, replace them. By default, when
-two profiles overlap, the final pixel value is the sum of all the
-profiles that overlap on that pixel. When this option is given, the
-pixels are not added but replaced by newer profiles.
+Do not add the pixels of each profile over the background (possibly crowded
+by other profiles), replace them. By default, when two profiles overlap,
+the final pixel value is the sum of all the profiles that overlap on that
+pixel. When this option is given, the pixels are not added but replaced by
+the newer profile's pixel and any value under it is lost.
 
 @cindex CPU threads
 @cindex Threads, CPU
-When order does matter, make sure to use this function with
address@hidden When multiple threads are used, the separate
-profiles are built asynchronously and not in order. Since order does
-not matter in an addition, this causes no problems by default but has
-to be considered when this option is given. Using multiple threads is
-no problem if the profiles are to be used as a mask (with
address@hidden) since all their pixel values are the same.
+When order matters, make sure to use this function with
address@hidden'. When multiple threads are used, the separate
+profiles are built asynchronously and not in order. Since order does not
+matter in an addition, this causes no problems by default but has to be
+considered when this option is given. Using multiple threads is no problem
+if the profiles are to be used as a mask with a blank or fixed value (see
address@hidden') since all their pixel values are the same.
+
+Note that only non-zero pixels are replaced. With radial profiles (for
+example S@'ersic or Moffat) only values above zero will be part of the
+profile. However, when using flat profiles with the
address@hidden' option, you should be careful not to give a
address@hidden value as the flat profile's pixel value.
 
 @item -w
 @itemx --circumwidth
@@ -12701,6 +12691,43 @@ is in units of the radial parameter of the profile 
(the value in the
 value is interpreted in units of pixels (prior to oversampling)
 irrespective of the profile.
 
address@hidden -F
address@hidden --mforflatpix
+When making fixed value profiles (flat and circumference, see
address@hidden'), don't use the value in the column specified by
address@hidden' as the magnitude. Instead use it as the exact value that
+all the pixels of these profiles should have. This option is irrelevant for
+other types of profiles. This option is very useful for creating masks, or
+labeled regions in an image. Any integer, or floating point value can used
+in this column with this option, including @code{NaN} (or address@hidden', or
address@hidden', case is irrelevant), and infinities (@code{inf}, @code{-inf},
+or @code{+inf}).
+
+For example, with this option if you set the value in the magnitude column
+(@option{--mcol}) to @code{NaN}, you can create an elliptical or circular
+mask over an image (which can be given as the argument), see @ref{Blank
+pixels}. Another useful application of this option is to create labeled
+elliptical or circular apertures in an image. To do this, set the value in
+the magnitude column to the label you want for this profile. This labeled
+image can then be used in combination with NoiseChisel's output (see
address@hidden output}) to do aperture photometry with MakeCatalog (see
address@hidden).
+
+Alternatively, if you want to mark regions of the image (for example with
+an elliptical circumference) and you don't want to use NaN values (as
+explained above) for some technical reason, you can get the minimum or
+maximum value in the image @footnote{The minimum will give a better result,
+because the maximum can be too high compared to most pixels in the image,
+making it harder to display.} using Arithmetic (see @ref{Arithmetic}), then
+use that value in the magnitude column along with this option for all the
+profiles.
+
+Please note that when using MakeProfiles on an already existing image, you
+have to set address@hidden'. Otherwise all the profiles will be
+scaled up based on the oversampling scale in your configuration files (see
address@hidden files}) unless you have accounted for oversampling in
+your catalog.
+
 @end table
 
 @noindent
diff --git a/src/mkprof/args.h b/src/mkprof/args.h
index 05f18dc..89c0cab 100644
--- a/src/mkprof/args.h
+++ b/src/mkprof/args.h
@@ -61,7 +61,7 @@ const char doc[] =
    Available letters (-V which is used by GNU is also removed):
 
    a d f g j k l u v
-   B C E F G H I J L O Q T U W Z
+   A B C E G H I J L M O Q T U W Z
 
    Maximum integer used so far: 517
 */
@@ -213,22 +213,6 @@ static struct argp_option options[] =
       3
     },
     {
-      "setconsttomin",
-      'M',
-      0,
-      0,
-      "Set constant profile values to input minimum",
-      3
-    },
-    {
-      "setconsttonan",
-      'A',
-      0,
-      0,
-      "Set constant profile values to NaN.",
-      3
-    },
-    {
       "replace",
       'R',
       0,
@@ -351,6 +335,14 @@ static struct argp_option options[] =
       "Truncation in units of --rcol, unless --tunitinp.",
       4
     },
+    {
+      "mforflatpix",
+      'F',
+      0,
+      0,
+      "mcol is flat pixel value (when f is 4 or 5)",
+      4
+    },
 
 
 
@@ -462,12 +454,14 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Output: */
     case 'x':
-      gal_checkset_sizet_l_zero(arg, &tmp, "naxis1", key, p->cp.spack, NULL, 
0);
+      gal_checkset_sizet_l_zero(arg, &tmp, "naxis1", key, p->cp.spack,
+                                NULL, 0);
       p->naxes[0]=tmp;
       p->up.naxis1set=1;
       break;
     case 'y':
-      gal_checkset_sizet_l_zero(arg, &tmp, "naxis2", key, p->cp.spack, NULL, 
0);
+      gal_checkset_sizet_l_zero(arg, &tmp, "naxis2", key, p->cp.spack,
+                                NULL, 0);
       p->naxes[1]=tmp;
       p->up.naxis2set=1;
       break;
@@ -484,12 +478,6 @@ parse_opt(int key, char *arg, struct argp_state *state)
                                   p->cp.spack, MINCIRCUMWIDTH, NULL, 0);
       p->up.circumwidthset=1;
       break;
-    case 'M':
-      p->setconsttomin=1;
-      break;
-    case 'A':
-      p->setconsttonan=1;
-      break;
     case 'R':
       p->replace=1;
       break;
@@ -501,13 +489,13 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->up.numrandomset=1;
       break;
     case 't':
-      gal_checkset_float_l_0(arg, &p->tolerance, "tolerance", key, p->cp.spack,
-                             NULL, 0);
+      gal_checkset_float_l_0(arg, &p->tolerance, "tolerance", key,
+                             p->cp.spack, NULL, 0);
       p->up.toleranceset=1;
       break;
     case 'z':
-      gal_checkset_any_float(arg, &p->zeropoint, "zeropoint", key, p->cp.spack,
-                             NULL, 0);
+      gal_checkset_any_float(arg, &p->zeropoint, "zeropoint", key,
+                             p->cp.spack, NULL, 0);
       p->up.zeropointset=1;
       break;
     case 'p':
@@ -593,6 +581,10 @@ parse_opt(int key, char *arg, struct argp_state *state)
                                  NULL, 0);
       p->up.tcolset=1;
       break;
+    case 'F':
+      p->mforflatpix=1;
+      p->up.mforflatpixset=1;
+      break;
 
 
 
diff --git a/src/mkprof/main.h b/src/mkprof/main.h
index da853d5..1ca4a06 100644
--- a/src/mkprof/main.h
+++ b/src/mkprof/main.h
@@ -49,7 +49,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #define EPSREL_FOR_INTEG   2
 #define MINCIRCUMWIDTH     0.5f
-#define CONSTFORNAN        -FLT_MAX
 
 /* Log columns:
 
@@ -121,6 +120,7 @@ struct uiparams
   int            qcolset;
   int            mcolset;
   int            tcolset;
+  int     mforflatpixset;
 
   int          crpix1set;
   int          crpix2set;
@@ -144,10 +144,7 @@ struct mkprofparams
   int         individual;  /* ==1: Build all catalog separately.       */
 
   /* Profiles */
-  int      setconsttonan;  /* ==1: Constant value = NaN.               */
-  int      setconsttomin;  /* ==1: Constant value = image minimum.     */
   int            replace;  /* Replace overlaping profile pixel values. */
-  float         constant;  /* Value for constant profiles.             */
   size_t       numrandom;  /* Number of radom points for integration.  */
   float        tolerance;  /* Accuracy to stop integration.            */
   float        zeropoint;  /* Magnitude of zero point flux.            */
@@ -168,6 +165,7 @@ struct mkprofparams
   size_t            qcol;  /* Axis ratio column of profile.            */
   size_t            mcol;  /* Magnitude column.                        */
   size_t            tcol;  /* Truncation of the profiles.              */
+  int        mforflatpix;  /* mcol is flat pixel value (f is 4 or 5). */
 
   /* Random number generator */
   gsl_rng           *rng;  /* Main instance of random number generator.*/
diff --git a/src/mkprof/mkprof.c b/src/mkprof/mkprof.c
index 5ad6fe6..82ed3e7 100644
--- a/src/mkprof/mkprof.c
+++ b/src/mkprof/mkprof.c
@@ -140,13 +140,6 @@ saveindividual(struct mkonthread *mkp)
   sprintf(outname, "%s%lu_%s", outdir, ibq->id, p->basename);
   gal_checkset_check_remove_file(outname, p->cp.dontdelete);
 
-  /* Change NaN values to 0.0f: */
-  gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
-                                NAN, 0.0f);
-  if(p->setconsttonan)
-    gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
-                                  CONSTFORNAN, NAN);
-
   /* Write the array to file (A separately built PSF doesn't need WCS
      coordinates): */
   if(ibq->ispsf && p->psfinimg==0)
@@ -159,13 +152,6 @@ saveindividual(struct mkonthread *mkp)
                               p->wcsnkeyrec, crpix, SPACK_STRING);
   ibq->indivcreated=1;
 
-  /* Change 0.0f values to NAN: */
-  if(p->setconsttonan)
-    gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
-                                  NAN, CONSTFORNAN);
-  gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
-                                0.0f, NAN);
-
   /* Report if in verbose mode. */
   if(p->cp.verb)
     {
@@ -498,19 +484,24 @@ write(struct mkprofparams *p)
           rowend=to+iw*w;
           do
             {
+              /* Go over all the pixels in this row and write this profile
+                 into the final output array. Just note that when
+                 replacing, we don't want to replace those pixels that have
+                 a zero value, since no profile existed there. */
               colend=to+jw;
               do
                 {
-                  if(!isnan(*from))
-                    {
-                      *from = p->setconsttonan ? NAN : *from;
-                      sum+=*from;
-                      *to = replace ? *from : *to+*from;
-                    }
+                  *to  = ( replace
+                           ? ( *from==0.0f ? *to : *from )
+                           :  *to + *from );
+                  sum += *from;
                   ++from;
                 }
               while(++to<colend);
-              to+=w-jw; from+=ow-jw;             /* Go to next row. */
+
+              /* Go to the next row. */
+              to   += w-jw;
+              from += ow-jw;
             }
           while(to<rowend);
         }
diff --git a/src/mkprof/mkprof.h b/src/mkprof/mkprof.h
index 379d04d..5092e40 100644
--- a/src/mkprof/mkprof.h
+++ b/src/mkprof/mkprof.h
@@ -51,6 +51,7 @@ struct mkonthread
   int                type;   /* The type of the profile.              */
   long            *onaxes;   /* Sides of the unover-sampled image.    */
   long        fpixel_i[2];   /* fpixel_i before running overlap.      */
+  int          correction;   /* ==1: correct the pixels afterwards.   */
 
   /* Random number generator: */
   gsl_rng            *rng;   /* Copy of main random number generator. */
diff --git a/src/mkprof/oneprofile.c b/src/mkprof/oneprofile.c
index 716c7a0..2c48bfd 100644
--- a/src/mkprof/oneprofile.c
+++ b/src/mkprof/oneprofile.c
@@ -66,6 +66,7 @@ r_el(struct mkonthread *mkp)
 
 
 
+/* Calculate the cercular distance of a pixel to the profile center. */
 float
 r_circle(size_t p, struct mkonthread *mkp)
 {
@@ -440,6 +441,7 @@ setprofparams(struct mkonthread *mkp)
   switch (mkp->type)
     {
     case SERSICCODE:
+      mkp->correction       = 1;
       mkp->profile          = &Sersic;
       mkp->sersic_re        = cat[rcol];
       mkp->sersic_inv_n     = 1.0f/cat[p->ncol];
@@ -447,44 +449,86 @@ setprofparams(struct mkonthread *mkp)
       mkp->truncr           = tp ? cat[tcol] : cat[tcol]*cat[rcol];
       break;
 
+
+
     case MOFFATCODE:
+      mkp->correction       = 1;
       mkp->profile          = &Moffat;
       mkp->moffat_nb        = -1.0f*cat[p->ncol];
       mkp->moffat_alphasq   = moffat_alpha(cat[rcol], cat[p->ncol]);
       mkp->moffat_alphasq  *= mkp->moffat_alphasq;
       mkp->truncr           = tp ? cat[tcol] : cat[tcol]*cat[rcol]/2;
       if(p->psfinimg==0 && p->individual==0)
-        { mkp->brightness=1.0f; cat[p->xcol]=0.0f; cat[p->ycol]=0.0f; }
+        {
+          mkp->brightness   = 1.0f; /* When the PSF is a separate image, */
+          cat[p->xcol]      = 0.0f; /* it should be centered and have a  */
+          cat[p->ycol]      = 0.0f; /* total brightness of 1.0f. */
+        }
       break;
 
+
+
     case GAUSSIANCODE:
+      mkp->correction       = 1;
       mkp->profile          = &Gaussian;
       sigma                 = cat[rcol]/2.35482f;
       mkp->gaussian_c       = -1.0f/(2.0f*sigma*sigma);
       mkp->truncr           = tp ? cat[tcol] : cat[tcol]*cat[rcol]/2;
       if(p->psfinimg==0 && p->individual==0)
-        { mkp->brightness=1.0f; cat[p->xcol]=0.0f; cat[p->ycol]=0.0f; }
+        {
+          mkp->brightness   = 1.0f; /* Same as the explanations for    */
+          cat[p->xcol]      = 0.0f; /* The Moffat profile. */
+          cat[p->ycol]      = 0.0f;
+        }
       break;
 
+
+
     case POINTCODE:
-      mkp->profile          = &Fixed;
-      mkp->fixedvalue       = 1;
+      mkp->correction       = 1;
+      mkp->fixedvalue       = 1.0f;
+      mkp->profile          = &Flat;
       break;
 
+
+
     case FLATCODE:
-      mkp->profile          = &Fixed;
-      mkp->fixedvalue       = p->constant;
+      mkp->profile          = &Flat;
       mkp->truncr           = tp ? cat[tcol] : cat[tcol]*cat[rcol];
+      if(p->mforflatpix)
+        {
+          mkp->correction   = 0;
+          mkp->fixedvalue   = cat[p->mcol];
+        }
+      else
+        {
+          mkp->correction   = 1;
+          mkp->fixedvalue   = 1.0f;
+        }
       break;
 
+
+
     case CIRCUMFERENCECODE:
       mkp->profile          = &Circumference;
-      mkp->fixedvalue       = p->constant;
       mkp->truncr           = tp ? cat[tcol] : cat[tcol]*cat[rcol];
       mkp->intruncr         = mkp->truncr - p->circumwidth;
-      if(mkp->intruncr<0.0f) mkp->intruncr=0.0f;
+      if(p->mforflatpix)
+        {
+          mkp->correction   = 0;
+          mkp->fixedvalue   = cat[p->mcol];
+        }
+      else
+        {
+          mkp->correction   = 1;
+          mkp->fixedvalue   = 1.0f;
+        }
+      if(mkp->intruncr<0.0f)
+        mkp->intruncr       = 0.0f;
       break;
 
+
+
     default:
       error(EXIT_FAILURE, 0, "a bug in setprofparams (oneprofile.c)! "
             "The profile code is not recognized. This should have been "
@@ -548,27 +592,33 @@ makeoneprofile(struct mkonthread *mkp)
   mkp->ibq->imgwidth=mkp->width[0];
 
 
-  /* Allocate the array and build it. */
+  /* Allocate and clear the array for this one profile. */
   errno=0;
   size=mkp->width[0]*mkp->width[1];
-  mkp->ibq->img=malloc(size*sizeof *mkp->ibq->img);
+  mkp->ibq->img=calloc(size, sizeof *mkp->ibq->img);
   if(mkp->ibq->img==NULL)
     error(EXIT_FAILURE, 0, "%lu bytes for object in row %lu of data in %s",
           size*sizeof *mkp->ibq->img, mkp->ibq->id, mkp->p->up.catname);
-  gal_arraymanip_fset_const(mkp->ibq->img, size, NAN);
 
 
   /* Build the profile in the image. */
   makepixbypix(mkp);
 
 
-  /* Correct the sum of pixels in it. If the profile is a fixed
-     constant, then its value is set in the Fixed function in
-     profiles.c. */
-  if(p->setconsttomin==0 && p->setconsttonan==0)
+  /* Correct the sum of pixels in the profile so it has the fixed total
+     magnitude or pixel value, mkp->correction was set in
+     setprofparams. Note that the profiles were not normalized during the
+     building.*/
+  if(mkp->correction)
     {
+      /* First get the sum of all the pixels in the profile. */
       sum=gal_statistics_float_sum(mkp->ibq->img, size);
-      mkp->ibq->accufrac/=sum;
+
+      /* Correct the fraction of brightness that was calculated
+         accurately (not using the pixel center). */
+      mkp->ibq->accufrac /= sum;
+
+      /* Correct all the profile pixels. */
       if(p->magatpeak)
         gal_arraymanip_fmultip_const(mkp->ibq->img, size,
                                      mkp->brightness/mkp->peakflux);
diff --git a/src/mkprof/profiles.c b/src/mkprof/profiles.c
index cd01264..b9e980c 100644
--- a/src/mkprof/profiles.c
+++ b/src/mkprof/profiles.c
@@ -158,7 +158,7 @@ totsersic(double n, double re, double b, double q)
 double
 Circumference(struct mkonthread *mkp)
 {
-  return mkp->r > mkp->intruncr ? mkp->fixedvalue : NAN;
+  return mkp->r > mkp->intruncr ? mkp->fixedvalue : 0.0f;
 }
 
 
@@ -167,7 +167,7 @@ Circumference(struct mkonthread *mkp)
 
 /* Always returns a fixed value: */
 double
-Fixed(struct mkonthread *mkp)
+Flat(struct mkonthread *mkp)
 {
   return mkp->fixedvalue;
 }
diff --git a/src/mkprof/profiles.h b/src/mkprof/profiles.h
index c2310be..3f8cfbd 100644
--- a/src/mkprof/profiles.h
+++ b/src/mkprof/profiles.h
@@ -51,6 +51,6 @@ double
 Circumference(struct mkonthread *mkp);
 
 double
-Fixed(struct mkonthread *mkp);
+Flat(struct mkonthread *mkp);
 
 #endif
diff --git a/src/mkprof/ui.c b/src/mkprof/ui.c
index 7efa550..24d9f54 100644
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@ -275,6 +275,12 @@ readconfig(char *filename, struct mkprofparams *p)
                                      filename, lineno);
           up->tcolset=1;
         }
+      else if(strcmp(name, "mforflatpix")==0)
+        {
+          if(up->mforflatpixset) continue;
+          p->mforflatpix=1;
+          up->mforflatpixset=1;
+        }
 
 
 
@@ -391,8 +397,10 @@ printvalues(FILE *fp, struct mkprofparams *p)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "qcol", p->qcol);
   if(up->mcolset)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "mcol", p->mcol);
-  if(up->mcolset)
+  if(up->tcolset)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "tcol", p->tcol);
+  if(up->mforflatpixset)
+    fprintf(fp, CONF_SHOWFMT"%lu\n", "mforflatpix", p->tcol);
 
   fprintf(fp, "\n# WCS:\n");
   if(up->crpix1set)
@@ -520,9 +528,6 @@ sanitycheck(struct mkprofparams *p)
   char *tmpname=NULL, *xcolstr, *ycolstr;
 
 
-  /* Make sure the input file exists. */
-  gal_checkset_check_file(p->up.catname);
-
 
   /* Check if over-sampling is an odd number, then set/modify the
      respective values.*/
@@ -537,14 +542,6 @@ sanitycheck(struct mkprofparams *p)
 
 
 
-  /* Check if the set constant options are not called together: */
-  if(p->setconsttomin && p->setconsttonan)
-    error(EXIT_FAILURE, 0, "`--setconsttomin' and `--setconsttonan' have "
-          "been called together! The constant profile values can only have "
-          "one value. So these two options cannot be called together");
-
-
-
   /* When the RA and Dec columns have been given use them for the profile
      positions instead of the X and Y columns. In the next step we are
      going to convert the RAs and Decs to Xs and Ys and until then, we are
@@ -580,7 +577,7 @@ sanitycheck(struct mkprofparams *p)
               "all have to be different", columns[i]);
 
 
-  /* If all the columns are within the catalog: */
+  /* If all the columns are within the catalog and have proper values. */
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->xcol, xcolstr);
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->ycol, ycolstr);
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->fcol, "fcol");
@@ -588,10 +585,22 @@ sanitycheck(struct mkprofparams *p)
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->ncol, "ncol");
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->pcol, "pcol");
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->qcol, "qcol");
-  GAL_CHECKSET_CHECK_COL_IN_CAT(p->mcol, "mcol");
+  GAL_CHECKSET_CHECK_COL_NUM_IN_CAT(p->mcol, "mcol");
   GAL_CHECKSET_CHECK_COL_IN_CAT(p->tcol, "tcol");
 
 
+  /* If there were terms that gal_txtarray_txt_to_array could not read,
+     delete the log file. Note that don't care about the whole input
+     catalog, we just want the columns that are important to
+     MakeProfiles. The GAL_CHECKSET_CHECK_COL_IN_CAT tests above checked
+     those columns and they are fine. For example the user might have some
+     alphabetic information in the input file, but as long as the columns
+     we want are correct, we have no problem. We can't remove this line
+     before those tests, because in their errors, those tests guide the
+     reader to check the `txtarray.log' file. */
+  gal_checkset_check_remove_file(GAL_TXTARRAY_LOG, 0);
+
+
   /* Check if all the profile codes are within the desired range: */
   for(i=0;i<p->cs0;++i)
     if(cat[i*cs1+p->fcol]<0 || cat[i*cs1+p->fcol]>MAXIMUMCODE)
@@ -803,19 +812,9 @@ preparearrays(struct mkprofparams *p)
                                p->anyblank, (void **)(&p->out), FLOAT_IMG);
           free(array);
         }
-
-      /* If setconsttomin is called, then there should be an input image: */
-      if(p->setconsttomin)
-        gal_statistics_float_min(p->out, p->naxes[1]*p->naxes[0],
-                                 &p->constant);
     }
   else
-    {
-      p->bitpix=FLOAT_IMG;
-      if(p->setconsttomin)
-        error(EXIT_FAILURE, 0, "the `--setconsttomin' option can only be "
-              "called when an input background image is also provided");
-    }
+    p->bitpix=FLOAT_IMG;
 
 
   /* If there is no WCS structure (either no background image given or the
@@ -874,10 +873,6 @@ preparearrays(struct mkprofparams *p)
       free(wcstoimg);
     }
 
-
-  /* If the constant is to be NaN, then set it: */
-  if(p->setconsttonan) p->constant=CONSTFORNAN;
-
   /* Allocate the random number generator: */
   gsl_rng_env_setup();
   p->rng=gsl_rng_alloc(gsl_rng_default);
@@ -909,8 +904,8 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
 {
   char *jobname;
   struct timeval t1;
-  char message[GAL_TIMING_VERB_MSG_LENGTH_V];
   struct gal_commonparams *cp=&p->cp;
+  char message[GAL_TIMING_VERB_MSG_LENGTH_V];
 
   /* Set the non-zero initial values, the structure was initialized to
      have a zero value for all elements. */
@@ -919,8 +914,8 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
   cp->numthreads    = num_processors(NPROC_CURRENT);
   cp->removedirinfo = 1;
 
-  p->constant       = 1;
   p->wcs            = NULL;
+  p->mforflatpix    = 0;
 
   /* Read the arguments. */
   errno=0;
@@ -945,10 +940,7 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
      which case, cp->output should be the current directory. */
   if(p->cp.outputset==0)
     {
-      p->cp.output=malloc(2+1); /* 2 is length of "./" */
-      if(p->cp.output==NULL)
-        error(EXIT_FAILURE, errno, "space for output");
-      strcpy(p->cp.output, "./");
+      gal_checkset_allocate_copy("./", &p->cp.output);
       p->cp.outputset=1;
     }
 
@@ -956,7 +948,6 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
      created by gal_txtarray_txt_to_array. */
   gettimeofday(&t1, NULL);
   sanitycheck(p);
-  gal_checkset_check_remove_file(GAL_TXTARRAY_LOG, 0);
 
   /* Prepare the necessary arrays: */
   preparearrays(p);
@@ -965,6 +956,7 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
   if(cp->verb)
     {
       printf(SPACK_NAME" started on %s", ctime(&p->rawtime));
+
       errno=0;
       jobname=malloc(strlen(p->up.catname)+100*sizeof *jobname);
       if(jobname==NULL)
@@ -983,6 +975,9 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
                   gsl_rng_default_seed);
           gal_timing_report(NULL, message, 1);
         }
+
+      sprintf(message, "Using %lu threads.", cp->numthreads);
+      gal_timing_report(NULL, message, 1);
     }
 }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d188530..9be84af 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,7 +44,7 @@ noisechisel/noisechisel.sh mkcatalog/simple.sh 
arithmetic/snimage.sh        \
 arithmetic/onlynumbers.sh cosmiccal/simpletest.sh
 
 EXTRA_DIST = $(TESTS) during-dev.sh mkprof/mkprofcat1.txt               \
-mkprof/mkprofcat1_mask.txt mkprof/mkprofcat2.txt mkprof/mkprofcat3.txt \
+mkprof/ellipticalmasks.txt mkprof/mkprofcat2.txt mkprof/mkprofcat3.txt \
 mkprof/mkprofcat4.txt mkprof/radeccat.txt imgcrop/cat.txt
 
 CLEANFILES = *.log *.txt *.jpg *.fits *.pdf *.eps
diff --git a/tests/mkprof/ellipticalmasks.sh b/tests/mkprof/ellipticalmasks.sh
index 2ee109d..6dc8050 100755
--- a/tests/mkprof/ellipticalmasks.sh
+++ b/tests/mkprof/ellipticalmasks.sh
@@ -25,7 +25,7 @@
 prog=mkprof
 execname=../src/$prog/ast$prog
 img=convolve_spatial_warped_noised.fits
-cat=$topsrc/tests/$prog/mkprofcat1_mask.txt
+cat=$topsrc/tests/$prog/ellipticalmasks.txt
 
 
 
@@ -49,5 +49,5 @@ if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
 
 # Actual test script
 # ==================
-$execname $cat $img --setconsttomin --replace --oversample=1 \
-          --output="masks.fits"
+$execname $cat $img --mforflatpix --replace --oversample=1 \
+          --output="ellipticalmasks.fits"
diff --git a/tests/mkprof/mkprofcat1_mask.txt b/tests/mkprof/ellipticalmasks.txt
similarity index 79%
rename from tests/mkprof/mkprofcat1_mask.txt
rename to tests/mkprof/ellipticalmasks.txt
index 0b8a40e..3f1a20a 100644
--- a/tests/mkprof/mkprofcat1_mask.txt
+++ b/tests/mkprof/ellipticalmasks.txt
@@ -1,4 +1,3 @@
-# Random catalog generated by makerandomcat.py
 # Column 0: ID
 # Column 1: X
 # Column 2: Y
@@ -9,5 +8,5 @@
 # Column 7: Axis ratio
 # Column 8: Magnitude
 # Column 9: Truncation radius
-1     100.40     100.40     5     20.00     2.500      45.000     1.000      
-18.0     5.000
-2     50.321     50.827     4     5.978     1.320      77.650     0.801      
-15.0     5.000
+1     100.40     100.40     5     20.00     2.500      45.000     1.000      
NaN     2.000
+2     50.321     50.827     4     5.978     1.320      77.650     0.801      
-1     2.000



reply via email to

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