gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 463dd0c 6/6: MakeProfiles can now use input im


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 463dd0c 6/6: MakeProfiles can now use input image as canvas
Date: Fri, 12 Aug 2016 23:58:02 +0000 (UTC)

branch: master
commit 463dd0c0ced24f1c6ea16a50507b69c0d08117b2
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    MakeProfiles can now use input image as canvas
    
    The `--inputascanvas' option was added to MakeProfiles to allow the users
    to easily specify all the main canvas information from a reference
    image. By canvas it is meant: the image size, the WCS information and the
    blank (NaN) pixels.
    
    This can make things like aperture photometry very easy, since the same
    image that will be used in NoiseChisel (to get an estimate of the Sky value
    and its standard deviation) can now be used to generate an image with
    labeled regions to replace with NoiseChisel's object HDU. A test was also
    added to check this on an image that has NaN pixels.
    
    This finishes task #14116.
---
 doc/gnuastro.texi              |   19 ++++++++++
 src/mkprof/args.h              |   14 +++++++-
 src/mkprof/main.h              |    2 ++
 src/mkprof/mkprof.c            |    4 +--
 src/mkprof/ui.c                |   77 +++++++++++++++++++++++++++-------------
 tests/Makefile.am              |   32 +++++++++--------
 tests/mkprof/inputascanvas.sh  |   53 +++++++++++++++++++++++++++
 tests/mkprof/inputascanvas.txt |   12 +++++++
 8 files changed, 171 insertions(+), 42 deletions(-)

diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index c05c3dd..4613ffd 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -12436,6 +12436,25 @@ option is ignored.
 second FITS axis (vertical when viewed in SAO ds9), see the
 explanation for @option{--naxis1}.
 
address@hidden -C
address@hidden --inputascanvas
+When an image is given as an argument, use the input image as the canvas to
+make all the mock profiles. In practice, this option only changes the
+non-blank pixels (see @ref{Blank pixels}) of the input image (in memory
+after reading, not the actual input file) to zero before making the
+profiles. The profiles are then built on those cleared pixels. With this
+option (like when building on a background image) none of the
address@hidden', address@hidden', address@hidden',
address@hidden', address@hidden', address@hidden', and
address@hidden' are necessary.
+
+This option can be very useful when the mock image is to be made over a
+real sky region and compared to a real image (that might have blank
+pixels. One example can be when you want to make circular or elliptical
+labeled regions to feed into MakeCatalog along with NoiseChisel's outputs
+for aperture photometry. See the discussion and examples under the
address@hidden' for more.
+
 @item -s
 @itemx --oversample
 (@option{=INT}) The scale to over-sample the profiles and final
diff --git a/src/mkprof/args.h b/src/mkprof/args.h
index 89c0cab..209d100 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
-   A B C E G H I J L M O Q T U W Z
+   A B E G H I J L M O Q T U W Z
 
    Maximum integer used so far: 517
 */
@@ -107,6 +107,14 @@ static struct argp_option options[] =
       2
     },
     {
+      "inputascanvas",
+      'C',
+      0,
+      0,
+      "Use input image for output size and WCS.",
+      2
+    },
+    {
       "oversample",
       's',
       "INT",
@@ -465,6 +473,10 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->naxes[1]=tmp;
       p->up.naxis2set=1;
       break;
+    case 'C':
+      p->up.inputascanvas=1;
+      p->up.inputascanvasset=1;
+      break;
     case 's':
       gal_checkset_sizet_l_zero(arg, &p->oversample, "oversample", key,
                                 p->cp.spack, NULL, 0);
diff --git a/src/mkprof/main.h b/src/mkprof/main.h
index 1ca4a06..7c2bb9a 100644
--- a/src/mkprof/main.h
+++ b/src/mkprof/main.h
@@ -89,6 +89,7 @@ struct uiparams
   char          *backhdu;  /* HDU of background image.                 */
   char          *catname;  /* Name of catalog of parameters.           */
   int        prepforconv;  /* Shift and expand by size of first psf.   */
+  int      inputascanvas;  /* Input image's header for size and WCS.   */
 
   /* Check if all parameters are read (use .def file for
      comparison). The non optional parameters (like the catalog and
@@ -100,6 +101,7 @@ struct uiparams
   int          naxis2set;
   int      oversampleset;
   int     circumwidthset;
+  int   inputascanvasset;
 
   int        tunitinpset;
   int       numrandomset;
diff --git a/src/mkprof/mkprof.c b/src/mkprof/mkprof.c
index 82ed3e7..e56c8a5 100644
--- a/src/mkprof/mkprof.c
+++ b/src/mkprof/mkprof.c
@@ -416,8 +416,8 @@ write(struct mkprofparams *p)
   size_t i, j, iw, jw, ii, jj, w=p->naxes[0], ow;
 
 
-  /* Allocate the output array. */
-  if(p->up.backname)
+  /* Allocate the output array if necessary. */
+  if(p->out)
     out=p->out;
   else
     {
diff --git a/src/mkprof/ui.c b/src/mkprof/ui.c
index 24d9f54..7263673 100644
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@ -37,6 +37,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/timing.h>     /* Includes time.h and sys/time.h */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarray.h>
+#include <gnuastro/arraymanip.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
@@ -114,6 +115,13 @@ readconfig(char *filename, struct mkprofparams *p)
           p->naxes[0]=tmp;
           up->naxis1set=1;
         }
+      else if(strcmp(name, "inputascanvas")==0)
+        {
+          if(up->inputascanvasset) continue;
+          gal_checkset_int_zero_or_one(value, &up->inputascanvas, name,
+                                       key, SPACK, filename, lineno);
+          up->inputascanvasset=1;
+        }
       else if(strcmp(name, "naxis2")==0)
         {
           if(up->naxis2set) continue;
@@ -278,7 +286,8 @@ readconfig(char *filename, struct mkprofparams *p)
       else if(strcmp(name, "mforflatpix")==0)
         {
           if(up->mforflatpixset) continue;
-          p->mforflatpix=1;
+          gal_checkset_int_zero_or_one(value, &p->mforflatpix, name, key,
+                                       SPACK, filename, lineno);
           up->mforflatpixset=1;
         }
 
@@ -361,6 +370,8 @@ printvalues(FILE *fp, struct mkprofparams *p)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "naxis1", p->naxes[0]);
   if(up->naxis2set)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "naxis2", p->naxes[1]);
+  if(up->inputascanvasset)
+    fprintf(fp, CONF_SHOWFMT"%d\n", "inputascanvas", up->inputascanvas);
   if(up->oversampleset)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "oversample", p->oversample);
 
@@ -453,24 +464,32 @@ checkifset(struct mkprofparams *p)
     GAL_CONFIGFILES_REPORT_NOTSET("qcol");
   if(up->mcolset==0)
     GAL_CONFIGFILES_REPORT_NOTSET("mcol");
-  if(up->naxis1set==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("naxis1");
-  if(up->naxis2set==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("naxis2");
   if(up->oversampleset==0)
     GAL_CONFIGFILES_REPORT_NOTSET("oversample");
   if(up->circumwidthset==0)
     GAL_CONFIGFILES_REPORT_NOTSET("circumwidth");
-  if(up->crpix1set==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("crpix1");
-  if(up->crpix2set==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("crpix2");
-  if(up->crval1set==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("crval1");
-  if(up->crval2set==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("crval2");
-  if(up->resolutionset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("resolution");
+
+
+  /* The output image size and WCS are only necessary if the user doesn't
+     want to use the input image's properties or doesn't want to make the
+     profiles on a background image. */
+  if(up->inputascanvasset==0 || p->up.backname)
+    {
+      if(up->naxis1set==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("naxis1");
+      if(up->naxis2set==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("naxis2");
+      if(up->crpix1set==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("crpix1");
+      if(up->crpix2set==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("crpix2");
+      if(up->crval1set==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("crval1");
+      if(up->crval2set==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("crval2");
+      if(up->resolutionset==0)
+        GAL_CONFIGFILES_REPORT_NOTSET("resolution");
+    }
 
 
   /* The X and Y columns are only needed when the RA and Dec columns have
@@ -794,11 +813,13 @@ preparearrays(struct mkprofparams *p)
      image to build the profiles over. */
   if(p->up.backname)
     {
+      /* Read the input WCS. */
+      gal_fits_read_wcs(p->up.backname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+
       /* Read in the background image and its coordinates: */
       p->anyblank=gal_fits_hdu_to_array(p->up.backname, p->cp.hdu,
                                         &p->bitpix, &array,
                                         &naxes[1], &naxes[0]);
-      gal_fits_read_wcs(p->up.backname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
       p->naxes[1]=naxes[1];
       p->naxes[0]=naxes[0];
 
@@ -809,9 +830,15 @@ preparearrays(struct mkprofparams *p)
       else
         {
           gal_fits_change_type(array, p->bitpix, p->naxes[1]*p->naxes[0],
-                               p->anyblank, (void **)(&p->out), FLOAT_IMG);
+                               p->anyblank, (void **)(&p->out),
+                               FLOAT_IMG);
           free(array);
         }
+
+      /* If the user just wanted the headers, then change all non-NaN
+         pixels to 0.0f. */
+      if(p->up.inputascanvas)
+        gal_arraymanip_freplace_nonnans(p->out, naxes[0]*naxes[1], 0.0f);
     }
   else
     p->bitpix=FLOAT_IMG;
@@ -909,13 +936,15 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
 
   /* Set the non-zero initial values, the structure was initialized to
      have a zero value for all elements. */
-  cp->spack         = SPACK;
-  cp->verb          = 1;
-  cp->numthreads    = num_processors(NPROC_CURRENT);
-  cp->removedirinfo = 1;
-
-  p->wcs            = NULL;
-  p->mforflatpix    = 0;
+  cp->spack            = SPACK;
+  cp->verb             = 1;
+  cp->numthreads       = num_processors(NPROC_CURRENT);
+  cp->removedirinfo    = 1;
+
+  p->out               = NULL;
+  p->wcs               = NULL;
+  p->mforflatpix       = 0;
+  p->up.inputascanvas  = 0;
 
   /* Read the arguments. */
   errno=0;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9be84af..a040a4a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,22 +30,23 @@ export topsrc=$(top_srcdir);                        \
 export haslibjpeg=$(MAYBE_HASLIBJPEG);              \
 export hasghostscript=$(MAYBE_HASGHOSTSCRIPT);
 
-TESTS = prepconf.sh mkprof/mosaic1.sh mkprof/mosaic2.sh mkprof/mosaic3.sh   \
-mkprof/mosaic4.sh mkprof/radeccat.sh imgcrop/imgcat.sh imgcrop/wcscat.sh    \
-imgcrop/xcyc.sh imgcrop/xcycnoblank.sh imgcrop/section.sh imgcrop/radec.sh  \
-imgcrop/imgpolygon.sh imgcrop/imgoutpolygon.sh imgcrop/wcspolygon.sh        \
-convertt/fitstotxt.sh convertt/fitstojpeg.sh convertt/blankch.sh            \
-convertt/jpegtotxt.sh convertt/fitstojpegcmyk.sh convertt/jpegtofits.sh     \
-convertt/fitstopdf.sh convolve/spatial.sh convolve/frequency.sh                
    \
-imgwarp/imgwarp_scale.sh imgwarp/homographic.sh mknoise/addnoise.sh         \
-mkprof/ellipticalmasks.sh header/write.sh header/print.sh header/update.sh  \
-header/delete.sh imgstat/basicstats.sh subtractsky/subtractsky.sh           \
-noisechisel/noisechisel.sh mkcatalog/simple.sh arithmetic/snimage.sh        \
-arithmetic/onlynumbers.sh cosmiccal/simpletest.sh
+TESTS = prepconf.sh mkprof/mosaic1.sh mkprof/mosaic2.sh mkprof/mosaic3.sh  \
+mkprof/mosaic4.sh mkprof/radeccat.sh imgcrop/imgcat.sh imgcrop/wcscat.sh   \
+imgcrop/xcyc.sh imgcrop/xcycnoblank.sh imgcrop/section.sh imgcrop/radec.sh \
+imgcrop/imgpolygon.sh imgcrop/imgoutpolygon.sh imgcrop/wcspolygon.sh       \
+convertt/fitstotxt.sh convertt/fitstojpeg.sh convertt/blankch.sh           \
+convertt/jpegtotxt.sh convertt/fitstojpegcmyk.sh convertt/jpegtofits.sh    \
+convertt/fitstopdf.sh convolve/spatial.sh convolve/frequency.sh            \
+imgwarp/imgwarp_scale.sh imgwarp/homographic.sh mknoise/addnoise.sh        \
+mkprof/ellipticalmasks.sh mkprof/inputascanvas.sh header/write.sh          \
+header/print.sh header/update.sh header/delete.sh imgstat/basicstats.sh        
   \
+subtractsky/subtractsky.sh 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/ellipticalmasks.txt mkprof/mkprofcat2.txt mkprof/mkprofcat3.txt \
-mkprof/mkprofcat4.txt mkprof/radeccat.txt imgcrop/cat.txt
+EXTRA_DIST = $(TESTS) during-dev.sh mkprof/mkprofcat1.txt                  \
+mkprof/ellipticalmasks.txt mkprof/inputascanvas.txt mkprof/mkprofcat2.txt  \
+mkprof/mkprofcat3.txt mkprof/mkprofcat4.txt mkprof/radeccat.txt            \
+imgcrop/cat.txt
 
 CLEANFILES = *.log *.txt *.jpg *.fits *.pdf *.eps
 
@@ -101,6 +102,7 @@ imgwarp/imgwarp_scale.sh: convolve/spatial.sh.log
 imgwarp/homographic.sh: convolve/spatial.sh.log
 mknoise/addnoise.sh: imgwarp/imgwarp_scale.sh.log
 mkprof/ellipticalmasks.sh: mknoise/addnoise.sh.log
+mkprof/inputascanvas.sh: mkprof/ellipticalmasks.sh.log
 header/write.sh: convolve/spatial.sh.log
 header/print.sh: header/write.sh.log
 header/update.sh: header/write.sh.log
diff --git a/tests/mkprof/inputascanvas.sh b/tests/mkprof/inputascanvas.sh
new file mode 100755
index 0000000..f49519f
--- /dev/null
+++ b/tests/mkprof/inputascanvas.sh
@@ -0,0 +1,53 @@
+# Make labeled regions on an image with blank pixels.
+#
+# See the Tests subsection of the manual for a complete explanation
+# (in the Installing gnuastro section).
+#
+# Original author:
+#     Mohammad Akhlaghi <address@hidden>
+# Contributing author(s):
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+
+
+
+
+# Preliminaries
+# =============
+#
+# Set the variabels (The executable is in the build tree). Do the
+# basic checks to see if the executable is made or if the defaults
+# file exists (basicchecks.sh is in the source tree).
+prog=mkprof
+img=ellipticalmasks.fits
+execname=../src/$prog/ast$prog
+cat=$topsrc/tests/$prog/inputascanvas.txt
+
+
+
+
+
+# Skip?
+# =====
+#
+# If the dependencies of the test don't exist, then skip it. There are two
+# types of dependencies:
+#
+#   - The executable was not made (for example due to a configure option),
+#
+#   - The input data was not made (for example the test that created the
+#     data file failed).
+if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
+
+
+
+
+
+# Actual test script
+# ==================
+$execname $cat $img --mforflatpix --oversample=1 --inputascanvas  \
+          --output="inputascanvas.fits"
diff --git a/tests/mkprof/inputascanvas.txt b/tests/mkprof/inputascanvas.txt
new file mode 100644
index 0000000..d7ca67d
--- /dev/null
+++ b/tests/mkprof/inputascanvas.txt
@@ -0,0 +1,12 @@
+# Column 0: ID
+# Column 1: X
+# Column 2: Y
+# Column 3: Function (0: Sersic, 1: Moffat, 2: Gaussian, 3: Point).
+# Column 4: Effective radius
+# Column 5: Sersic index.
+# Column 6: Position angle
+# Column 7: Axis ratio
+# Column 8: Magnitude
+# Column 9: Truncation radius
+1 21.00 21.00 4 5 1 45.000 1.000  34 2.000
+2 80.00 80.00 4 8 1 77.650 0.501  45 2.000



reply via email to

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