gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 4b0fccc 6/7: Merged MakeCatalog not making a c


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 4b0fccc 6/7: Merged MakeCatalog not making a clump catalog branch
Date: Tue, 16 Aug 2016 14:30:38 +0000 (UTC)

branch: master
commit 4b0fccced200209dbca136ceca0002f81a6024fc
Merge: ce19153 e74f2b6
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Merged MakeCatalog not making a clump catalog branch
    
    The branch (ending with e74f2b6) is now merged into master. Some minor
    issues were also fixed after the merge.
---
 bootstrap.conf                |    1 +
 lib/fits.c                    |   69 +++++++++++-----
 lib/gnuastro/fits.h           |   23 +++---
 lib/gnuastro/statistics.h     |    8 ++
 lib/statistics.c              |   41 ++++++++++
 src/mkcatalog/Makefile.am     |    8 +-
 src/mkcatalog/mkcatalog.c     |   43 ++++++----
 src/mkcatalog/ui.c            |  175 ++++++++++++++++++++++++++++++-----------
 src/mkprof/ui.c               |   22 +++++-
 src/noisechisel/noisechisel.c |   23 +++---
 10 files changed, 306 insertions(+), 107 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 5908d99..88ca654 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -163,6 +163,7 @@ gnulib_modules="
     argp
     error
     nproc
+    strcase
     gendocs
     progname
     git-version-gen
diff --git a/lib/fits.c b/lib/fits.c
index a48cfb7..1168bd3 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -361,7 +361,7 @@ blanktovalue(void *array, int bitpix, size_t size, void 
*value)
 
 void
 gal_fits_change_type(void *in, int inbitpix, size_t size, int anyblank,
-                          void **out, int outbitpix)
+                     void **out, int outbitpix)
 {
   size_t i=0;
   unsigned char *b, *bf, *ib=in, *iib=in;
@@ -773,11 +773,19 @@ gal_fits_read_hdu(char *filename, char *hdu, int 
desiredtype,
 /* Read keywords from a FITS file. The gal_fits_read_header_keys pointer is
    an array of gal_fits_read_header_keys structures, which keep the basic
    information for each keyword that is to be read and also stores the
-   value in the appropriate type.*/
+   value in the appropriate type.
+
+   ABOUT THE STRING VALUES:
+
+   The space for a string value is statically allocated within the
+   `gal_fits_read_header_keys' structure (to be `FLEN_VALUE' characters,
+   `FLEN_VALUE' is defined by CFITSIO). So if the value is necessary where
+   `gal_fits_read_header_keys' is no longer available, then you have to
+   allocate space dynamically and copy the string there.
+*/
 void
 gal_fits_read_keywords(char *filename, char *hdu,
-                            struct gal_fits_read_header_keys *keys,
-                            size_t num)
+                       struct gal_fits_read_header_keys *keys, size_t num)
 {
   int status=0;
   char *ffname;
@@ -800,10 +808,14 @@ gal_fits_read_keywords(char *filename, char *hdu,
   /* Get the desired keywords. */
   for(i=0;i<num;++i)
     {
+      /* Initialize the status: */
+      keys[i].status=0;
+
+      /* Set the value-pointer based on the required type. */
       switch(keys[i].datatype)
         {
         case TSTRING:
-          valueptr=&keys[i].c;
+          valueptr=keys[i].str;
           break;
         case TBYTE:
           valueptr=&keys[i].u;
@@ -827,9 +839,26 @@ gal_fits_read_keywords(char *filename, char *hdu,
           error(EXIT_FAILURE, 0, "the value of keys[%lu].datatype (=%d) "
                 "is not recognized", i, keys[i].datatype);
         }
-      if( fits_read_key(fptr, keys[i].datatype, keys[i].keyname,
-                        valueptr, NULL, &status) )
-        gal_fits_io_error(status, "reading the keyword");
+
+      /* Read the keyword and place its value in the poitner. */
+      fits_read_key(fptr, keys[i].datatype, keys[i].keyname,
+                    valueptr, NULL, &keys[i].status);
+
+
+      /* In some cases, the caller might be fine with some kinds of errors,
+         so we will only report an error here is the situation is not
+         expected. For example, the caller might have alternatives for a
+         keyword if it doesn't exist, or the non-existence of a keyword
+         might itself be meaningful. So when the key doesn't exist, this
+         function will not abort, it will just keep the status.
+
+         The reason only non-existance is acceptable is this: if the
+         keyword does exist, but CFITSIO cannot read it due to some
+         technical difficulty, then the user probably wanted to give the
+         value. But is not aware of the technical problem.
+       */
+      if(keys[i].status!=0 && keys[i].status!=KEY_NO_EXIST)
+        gal_fits_io_error(keys[i].status, "reading the keyword");
     }
 
   /* Close the FITS file. */
@@ -1049,7 +1078,7 @@ gal_fits_add_wcs_to_header(fitsfile *fptr, char 
*wcsheader, int nkeyrec)
    the pointer to the linked list (to correct it after we finish). */
 void
 gal_fits_update_keys(fitsfile *fptr,
-                          struct gal_fits_header_ll **keylist)
+                     struct gal_fits_header_ll **keylist)
 {
   int status=0;
   struct gal_fits_header_ll *tmp, *ttmp;
@@ -1094,8 +1123,8 @@ gal_fits_update_keys(fitsfile *fptr,
 
 void
 gal_fits_copyright_end(fitsfile *fptr,
-                            struct gal_fits_header_ll *headers,
-                            char *spack_string)
+                       struct gal_fits_header_ll *headers,
+                       char *spack_string)
 {
   size_t i;
   int status=0;
@@ -1496,8 +1525,8 @@ gal_fits_atof_correct_wcs(char *filename, char *hdu, int 
bitpix,
    to the appropriate value. */
 void
 gal_fits_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
-                               char **othername, char *ohdu, int ohduset,
-                               char *type)
+                          char **othername, char *ohdu, int ohduset,
+                          char *type)
 {
   if(othernameset)
     {
@@ -1540,8 +1569,8 @@ gal_fits_file_or_ext_name(char *inputname, char *inhdu, 
int othernameset,
    return it back to the input type if you please. */
 void
 gal_fits_file_to_float(char *inputname, char *maskname, char *inhdu,
-                            char *mhdu, float **img, int *inbitpix,
-                            int *anyblank, size_t *ins0, size_t *ins1)
+                       char *mhdu, float **img, int *inbitpix,
+                       int *anyblank, size_t *ins0, size_t *ins1)
 {
   void *array;
   int maskbitpix;
@@ -1605,8 +1634,8 @@ gal_fits_file_to_float(char *inputname, char *maskname, 
char *inhdu,
 /* Similar to filetofloat, but for double type */
 void
 gal_fits_file_to_double(char *inputname, char *maskname, char *inhdu,
-                             char *mhdu, double **img, int *inbitpix,
-                             int *anyblank, size_t *ins0, size_t *ins1)
+                        char *mhdu, double **img, int *inbitpix,
+                        int *anyblank, size_t *ins0, size_t *ins1)
 {
   void *array;
   int maskbitpix;
@@ -1671,8 +1700,8 @@ gal_fits_file_to_double(char *inputname, char *maskname, 
char *inhdu,
 
 void
 gal_fits_file_to_long(char *inputname, char *inhdu, long **img,
-                           int *inbitpix, int *anyblank, size_t *ins0,
-                           size_t *ins1)
+                      int *inbitpix, int *anyblank, size_t *ins0,
+                      size_t *ins1)
 {
   void *array;
 
@@ -1695,7 +1724,7 @@ gal_fits_file_to_long(char *inputname, char *inhdu, long 
**img,
 
 void
 gal_fits_prep_float_kernel(char *inputname, char *inhdu, float **outkernel,
-                                size_t *ins0, size_t *ins1)
+                           size_t *ins0, size_t *ins1)
 {
   size_t i, size;
   double sum=0.0f;
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index cca2c14..a0456a4 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -103,15 +103,16 @@ struct gal_fits_header_ll
 
 struct gal_fits_read_header_keys
 {
-  char   *keyname;
-  int    datatype;
-  char         *c;
-  unsigned char u;
-  short         s;
-  long          l;
-  LONGLONG      L;
-  float         f;
-  double        d;
+  int            status;
+  char         *keyname;
+  int          datatype;
+  char  str[FLEN_VALUE];
+  unsigned char       u;
+  short               s;
+  long                l;
+  LONGLONG            L;
+  float               f;
+  double              d;
 };
 
 
@@ -137,7 +138,7 @@ gal_fits_add_to_fits_header_ll_end(struct 
gal_fits_header_ll **list,
 
 void
 gal_fits_file_name_in_keywords(char *keynamebase, char *filename,
-                                    struct gal_fits_header_ll **list);
+                               struct gal_fits_header_ll **list);
 
 void
 gal_fits_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec);
@@ -179,7 +180,7 @@ gal_fits_bitpix_alloc(size_t size, int bitpix);
 
 void
 gal_fits_change_type(void *in, int inbitpix, size_t size, int anyblank,
-                          void **out, int outbitpix);
+                     void **out, int outbitpix);
 
 void
 gal_fits_read_wcs_from_pointer(fitsfile *fptr, int *nwcs,
diff --git a/lib/gnuastro/statistics.h b/lib/gnuastro/statistics.h
index ad910e1..d4df04b 100644
--- a/lib/gnuastro/statistics.h
+++ b/lib/gnuastro/statistics.h
@@ -31,6 +31,14 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  *****************    Mininum and Maximum    ********************
  ****************************************************************/
 void
+gal_statistics_long_non_blank_min(long *in, size_t size, long *min,
+                                  long blank);
+
+void
+gal_statistics_long_non_blank_max(long *in, size_t size, long *max,
+                                  long blank);
+
+void
 gal_statistics_float_min(float *in, size_t size, float *min);
 
 void
diff --git a/lib/statistics.c b/lib/statistics.c
index 9d25b69..b6a0b81 100644
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@ -27,6 +27,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <errno.h>
 #include <error.h>
 #include <float.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include <gnuastro/qsort.h>
@@ -44,6 +45,46 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /****************************************************************
  *****************    Mininum and Maximum    ********************
  ****************************************************************/
+/* Find the the minimum (non-blank) value in an array of type long. Note
+   that the long type doesn't have a NaN value like the floats above. So as
+   blank pixels, a value in the range of acceptable values is given. so we
+   have to explicitly ignore those values.*/
+void
+gal_statistics_long_non_blank_min(long *in, size_t size, long *min,
+                                  long blank)
+{
+  long tmin=INT32_MAX, *lpt;
+  lpt=in+size;
+  do
+    if(*in!=blank && *in<tmin)
+      tmin=*in;
+  while(++in<lpt);
+  *min=tmin;
+}
+
+
+
+
+
+/* Find the the minimum (non-blank) value in an array of type long. See the
+   explanation above `gal_statistics_long_min'. */
+void
+gal_statistics_long_non_blank_max(long *in, size_t size, long *max,
+                                  long blank)
+{
+  long tmax=INT32_MIN, *lpt;
+  lpt=in+size;
+  do
+    if(*in!=blank && *in>tmax)
+      tmax=*in;
+  while(++in<lpt);
+  *max=tmax;
+}
+
+
+
+
+
 void
 gal_statistics_float_min(float *in, size_t size, float *min)
 {
diff --git a/src/mkcatalog/Makefile.am b/src/mkcatalog/Makefile.am
index 2f96074..2077c3c 100644
--- a/src/mkcatalog/Makefile.am
+++ b/src/mkcatalog/Makefile.am
@@ -25,12 +25,12 @@
 ## Utility and its sources
 bin_PROGRAMS = astmkcatalog
 
-astmkcatalog_SOURCES = main.c main.h cite.h ui.c ui.h args.h   \
+astmkcatalog_SOURCES = main.c main.h cite.h ui.c ui.h args.h          \
 mkcatalog.c mkcatalog.h columns.c columns.h
 
-astmkcatalog_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la        \
--lgalconfigfiles -lgalfits -lgalwcs -lgalcheckset -lgaltiming  \
--lgallinkedlist -lgaltxtarray
+astmkcatalog_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la       \
+-lgalconfigfiles -lgalstatistics -lgalarraymanip -lgalqsort -lgalfits \
+-lgalwcs -lgalcheckset -lgaltiming -lgallinkedlist -lgaltxtarray
 
 
 
diff --git a/src/mkcatalog/mkcatalog.c b/src/mkcatalog/mkcatalog.c
index af178c3..80352d9 100644
--- a/src/mkcatalog/mkcatalog.c
+++ b/src/mkcatalog/mkcatalog.c
@@ -154,7 +154,7 @@ firstpass(struct mkcatalogparams *p)
               }
           }
 
-        if(clumps[i]>0)
+        if(clumps && clumps[i]>0)
           {
             /* The largest clump ID over each object is the number of
                clumps that object has. */
@@ -191,11 +191,10 @@ firstpass(struct mkcatalogparams *p)
 
 
 
-/* In the second pass, we have the number of clumps so we can find
-   store the total values for the clumps. In this second round we can
-   also find second order moments of the objects if we want to. */
+/* In the second pass, we have the number of clumps so we can find the
+   total values for the clumps. */
 void
-secondpass(struct mkcatalogparams *p)
+clumppass(struct mkcatalogparams *p)
 {
   float imgss;
   double x, y, sx, sy;
@@ -412,6 +411,11 @@ makeoutput(struct mkcatalogparams *p)
   for(p->obj0clump1=0;p->obj0clump1<2;++p->obj0clump1)
     {
 
+      /* If no clumps image was provided, then ignore the clumps
+         catalog. */
+      if(p->obj0clump1==1 && p->clumps==NULL)
+        continue;
+
 
       /* Do the preparations for this round: */
       p->intcounter=p->accucounter=p->curcol=0;
@@ -483,13 +487,16 @@ makeoutput(struct mkcatalogparams *p)
       strcat(comment, p->line);
 
       sn = p->obj0clump1 ? p->clumpsn : p->detsn;
-      sprintf(tline, "%s limiting Signal to noise ratio: ",
-              p->obj0clump1 ? "Clump" : "Detection");
-      sprintf(p->line, "# "CATDESCRIPTLENGTH"%.3f\n", tline, sn);
-      strcat(comment, p->line);
-      if(p->obj0clump1==0)
-          strcat(comment, "# (NOTE: limits above are for detections, not "
-                 "objects)\n");
+      if(!isnan(sn))
+        {
+          sprintf(tline, "%s limiting Signal to noise ratio: ",
+                  p->obj0clump1 ? "Clump" : "Detection");
+          sprintf(p->line, "# "CATDESCRIPTLENGTH"%.3f\n", tline, sn);
+          strcat(comment, p->line);
+          if(p->obj0clump1==0)
+            strcat(comment, "# (NOTE: limits above are for detections, not "
+                   "objects)\n");
+        }
 
 
       /* If cpscorr was used, report it: */
@@ -518,8 +525,9 @@ makeoutput(struct mkcatalogparams *p)
       strcat(comment, "#\n# Columns:\n# --------\n");
 
 
-      /* Fill the catalog array, in the end set the last elements in intcols 
and
-         accucols to -1, so gal_txtarray_array_to_txt knows when to stop. */
+      /* Fill the catalog array, in the end set the last elements in
+         intcols and accucols to -1, so gal_txtarray_array_to_txt knows
+         when to stop. */
       for(p->curcol=0;p->curcol<p->numcols;++p->curcol)
         {
           col=cols[p->curcol];
@@ -687,8 +695,9 @@ makeoutput(struct mkcatalogparams *p)
 
 
       /* Write the catalog to file: */
-      gal_txtarray_array_to_txt(p->cat, p->num, p->numcols, comment, 
p->intcols,
-                                p->accucols, space, prec, 'f', p->filename);
+      gal_txtarray_array_to_txt(p->cat, p->num, p->numcols, comment,
+                                p->intcols, p->accucols, space, prec,
+                                'f', p->filename);
 
       /* Clean up: */
       free(p->intcols);
@@ -723,7 +732,7 @@ mkcatalog(struct mkcatalogparams *p)
 {
   /* Run through the data for the first time: */
   firstpass(p);
-  secondpass(p);
+  if(p->clumps) clumppass(p);
 
   /* Write the output: */
   makeoutput(p);
diff --git a/src/mkcatalog/ui.c b/src/mkcatalog/ui.c
index f982081..8035f7d 100644
--- a/src/mkcatalog/ui.c
+++ b/src/mkcatalog/ui.c
@@ -36,6 +36,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/statistics.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
 
@@ -836,51 +837,43 @@ checkifset(struct mkcatalogparams *p)
 void
 sanitycheck(struct mkcatalogparams *p)
 {
-  struct gal_fits_read_header_keys keys[2];
+  struct uiparams *up=&p->up;
+  struct gal_fits_read_header_keys keys[1];
 
   /* Make sure the input file exists. */
-  gal_checkset_check_file(p->up.inputname);
+  gal_checkset_check_file(up->inputname);
 
   /* Set the names of the files. */
-  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
-                            &p->up.maskname, p->up.mhdu, p->up.mhduset,
+  gal_fits_file_or_ext_name(up->inputname, p->cp.hdu, up->masknameset,
+                            &up->maskname, up->mhdu, up->mhduset,
                             "mask");
-  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu,
-                            p->up.objlabsnameset, &p->up.objlabsname,
-                            p->up.objhdu, p->up.objhduset,
+  gal_fits_file_or_ext_name(up->inputname, p->cp.hdu,
+                            up->objlabsnameset, &up->objlabsname,
+                            up->objhdu, up->objhduset,
                             "object labels");
-  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu,
-                            p->up.clumplabsnameset, &p->up.clumplabsname,
-                            p->up.clumphdu, p->up.clumphduset,
-                            "clump labels");
-  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.skynameset,
-                            &p->up.skyname, p->up.skyhdu, p->up.skyhduset,
+  gal_fits_file_or_ext_name(up->inputname, p->cp.hdu, up->skynameset,
+                            &up->skyname, up->skyhdu, up->skyhduset,
                             "sky value image");
-  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.stdnameset,
-                            &p->up.stdname, p->up.stdhdu, p->up.stdhduset,
+  gal_fits_file_or_ext_name(up->inputname, p->cp.hdu, up->stdnameset,
+                            &up->stdname, up->stdhdu, up->stdhduset,
                             "sky standard deviation");
 
-  /* Read the number of labels for the objects:  */
-  keys[0].keyname="DETSN";        keys[0].datatype=TDOUBLE;
-  keys[1].keyname="NOBJS";        keys[1].datatype=TLONG;
-  gal_fits_read_keywords(p->up.objlabsname, p->up.objhdu, keys, 2);
-  p->detsn=keys[0].d;
-  p->numobjects=keys[1].l;
-
-  /* Read the clumps information. Note that the datatypes don't change. */
-  keys[0].keyname="CLUMPSN";
-  keys[1].keyname="NCLUMPS";
-  gal_fits_read_keywords(p->up.clumplabsname, p->up.clumphdu, keys, 2);
-  p->clumpsn=keys[0].d;
-  p->numclumps=keys[1].l;
-
-  /* Read the minimum and maximum standard deviation values. */
-  keys[0].keyname="MINSTD";       keys[0].datatype=TFLOAT;
-  keys[1].keyname="MEDSTD";       keys[1].datatype=TFLOAT;
-  gal_fits_read_keywords(p->up.stdname, p->up.stdhdu, keys, 2);
-  p->minstd=keys[0].f;
-  p->medstd=keys[1].f;
-  p->cpscorr = p->minstd>1 ? 1.0f : p->minstd;
+  /* The WCLUMPS (with-clumps) keyword in the object HDU says that there is
+     also a clumps image accompaning the object image. If it exists and its
+     value is `yes' (not case sensitive), then set the image name to the
+     proper string. Otherwise, set the image name to NULL, so future
+     functions can check. */
+  keys[0].str[0]='\0';
+  keys[0].datatype=TSTRING;
+  keys[0].keyname="WCLUMPS";
+  gal_fits_read_keywords(up->objlabsname, up->objhdu, keys, 1);
+  if(strcasecmp(keys[0].str, "yes"))
+    up->clumplabsname=NULL;
+  else
+    gal_fits_file_or_ext_name(up->inputname, p->cp.hdu,
+                              up->clumplabsnameset, &up->clumplabsname,
+                              up->clumphdu, up->clumphduset,
+                              "clump labels");
 
   /* When the RA and Dec are needed, make sure that the X and Y
      columns and the RA and Dec columns in the information array are
@@ -891,7 +884,7 @@ sanitycheck(struct mkcatalogparams *p)
 
      NOTE: the information array is separate from the output array
   */
-  if(p->up.raset || p->up.decset)
+  if(up->raset || up->decset)
     {
       if( OFlxWhtX!=OFlxWhtY-1 || OFlxWhtRA!=OFlxWhtDec-1 )
         error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can "
@@ -909,10 +902,10 @@ sanitycheck(struct mkcatalogparams *p)
     }
   else
     {
-      gal_checkset_automatic_output(p->up.inputname, "_o.txt",
+      gal_checkset_automatic_output(up->inputname, "_o.txt",
                                     p->cp.removedirinfo, p->cp.dontdelete,
                                     &p->ocatname);
-      gal_checkset_automatic_output(p->up.inputname, "_c.txt",
+      gal_checkset_automatic_output(up->inputname, "_c.txt",
                                     p->cp.removedirinfo, p->cp.dontdelete,
                                     &p->ccatname);
     }
@@ -998,6 +991,92 @@ checksetfloat(struct mkcatalogparams *p, char *filename, 
char *hdu,
 
 
 
+/* Read the necessary keywords and if they aren't present do the
+   appropriate action. */
+void
+readkeywords(struct mkcatalogparams *p)
+{
+  long numobjects;
+  size_t size=p->s0*p->s1;
+  struct uiparams *up=&p->up;
+  struct gal_fits_read_header_keys keys[2];
+
+  /* Read keywords from the standard deviation image:  */
+  keys[0].keyname="MINSTD";   keys[0].datatype=TFLOAT;
+  keys[1].keyname="MEDSTD";   keys[1].datatype=TFLOAT;
+  gal_fits_read_keywords(up->stdname, up->stdhdu, keys, 2);
+
+  /* The minimum standard deviation value. */
+  if(keys[0].status)
+    gal_statistics_float_min(p->std, size, &p->minstd);
+  else
+    p->minstd=keys[0].f;
+  p->cpscorr = p->minstd>1 ? 1.0f : p->minstd;
+
+  /* Median standard deviation value (only necessary in catalog
+     comments). */
+  if(keys[1].status)
+    {
+      p->medstd=gal_statistics_median(p->std, size);
+      fprintf(stderr, "Warning: Could not find the MEDSTD keyword in %s "
+              "(hdu: %s). The median standard deviation is thus found on"
+              "the (interpolated) standard deviation image. NoiseChisel "
+              "finds the median before interpolation, so the reported value "
+              "in the final catalog will not be accurate (will depend on "
+              "how many meshs were blank and their spatial position "
+              "relative to the non-blank ones.", up->stdname, up->stdhdu);
+    }
+  else
+    p->medstd=keys[1].f;
+
+  /* Read the keywords from the objects image:  */
+  keys[0].keyname="DETSN";     keys[0].datatype=TDOUBLE;
+  keys[1].keyname="NOBJS";     keys[1].datatype=TLONG;
+  gal_fits_read_keywords(up->objlabsname, up->objhdu, keys, 2);
+
+  /* If DETSN is not given, there is no way we can calculate it here, so we
+     will just set it to NaN to check and not report in the end. */
+  p->detsn = keys[0].status ? NAN : keys[0].d;
+
+  /* Read the total number of objects. */
+  if(keys[1].status)
+    {
+      gal_statistics_long_non_blank_max(p->objects, size, &numobjects,
+                                        GAL_FITS_LONG_BLANK);
+      p->numobjects=numobjects;
+    }
+  else
+    p->numobjects=keys[1].l;
+
+  /* Read the clumps information if it is necessary.
+
+     Note that unlike finding the number of objects, finding the number of
+     clumps is not an easy process, since the clumps of each object start
+     with a label of one. So if the number of clumps is not given, we have
+     to abort. For now, is up to the program that built the clumps to give
+     the total number, later we can take a procedure to find them (for
+     example first only taking the positive labels (that are clumps) and
+     making a binary image, then running the connected component algorithm
+     to find the number of clumps in the image.*/
+  if(up->clumplabsname)
+    {
+      keys[0].keyname="CLUMPSN";
+      keys[1].keyname="NCLUMPS";
+      gal_fits_read_keywords(up->clumplabsname, up->clumphdu, keys, 2);
+      p->clumpsn = keys[0].status ? NAN : keys[0].d;
+      if(keys[1].status)
+        error(EXIT_FAILURE, 0, "couldn't find NCLUMPS in the header of "
+              "%s (hdu: %s).", up->clumplabsname, up->clumphdu);
+      else
+        p->numclumps=keys[1].l;
+    }
+
+}
+
+
+
+
+
 
 void
 preparearrays(struct mkcatalogparams *p)
@@ -1185,12 +1264,19 @@ preparearrays(struct mkcatalogparams *p)
                         &p->wcs);
 
 
-      /* Read and check the other arrays: */
-      checksetlong(p, p->up.objlabsname, p->up.objhdu, &p->objects);
-      checksetlong(p, p->up.clumplabsname, p->up.clumphdu, &p->clumps);
+      /* Read and check the object, sky and skystd HDUs. Note that the
+         clumps image is only used when the objects image says a clumps
+         image exists. */
       checksetfloat(p, p->up.skyname, p->up.skyhdu, &p->sky);
       checksetfloat(p, p->up.stdname, p->up.stdhdu, &p->std);
+      checksetlong(p, p->up.objlabsname, p->up.objhdu, &p->objects);
+      if(p->up.clumplabsname)
+        checksetlong(p, p->up.clumplabsname, p->up.clumphdu, &p->clumps);
+      else
+        p->clumps=NULL;
 
+      /* Read the necessary keywords. */
+      readkeywords(p);
 
       /* Allocate the catalog arrays: */
       if(p->objncols>0 && p->numobjects>0)
@@ -1312,8 +1398,9 @@ setparams(int argc, char *argv[], struct mkcatalogparams 
*p)
         printf("  - Mask   %s (hdu: %s)\n", p->up.maskname, p->up.mhdu);
       printf("  - Objects %s (hdu: %s)\n", p->up.objlabsname,
              p->up.objhdu);
-      printf("  - Clumps  %s (hdu: %s)\n", p->up.clumplabsname,
-             p->up.clumphdu);
+      if(p->up.clumplabsname)
+        printf("  - Clumps  %s (hdu: %s)\n", p->up.clumplabsname,
+               p->up.clumphdu);
       printf("  - Sky     %s (hdu: %s)\n", p->up.skyname, p->up.skyhdu);
       printf("  - Sky STD %s (hdu: %s)\n", p->up.stdname, p->up.stdhdu);
     }
diff --git a/src/mkprof/ui.c b/src/mkprof/ui.c
index 2508923..daafda0 100644
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@ -415,7 +415,27 @@ printvalues(FILE *fp, struct mkprofparams *p)
   if(up->replaceset)
     fprintf(fp, CONF_SHOWFMT"%d\n", "replace", p->replace);
   if(up->typeset)
-    fprintf(fp, CONF_SHOWFMT"%s\n", "type", up->type);
+    {
+      switch(up->type)
+        {
+        case BYTE_IMG:
+          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "byte");
+        case SHORT_IMG:
+          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "short");
+        case LONG_IMG:
+          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "long");
+        case LONGLONG_IMG:
+          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "longlong");
+        case FLOAT_IMG:
+          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "float");
+        case DOUBLE_IMG:
+          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "double");
+        default:
+          error(EXIT_FAILURE, 0, "a bug! the value of up->type is not "
+                "recognized in `ui.c'. Please contact us at %s so we can "
+                "address the problem.", PACKAGE_BUGREPORT);
+        }
+    }
 
   fprintf(fp, "\n# Profiles:\n");
   if(up->tunitinpset)
diff --git a/src/noisechisel/noisechisel.c b/src/noisechisel/noisechisel.c
index cd65b3e..6a57abf 100644
--- a/src/noisechisel/noisechisel.c
+++ b/src/noisechisel/noisechisel.c
@@ -70,16 +70,19 @@ makeoutput(struct noisechiselparams *p)
                          s0, s1, 0, p->wcs, NULL, SPACK_STRING);
 
 
-  /* The object labels image with a keyword mentioning the number of
-     objects. */
+  /* Add the necessary FITS keywords for MakeCatalog when reading the
+     objects image. */
+  gal_fits_add_to_fits_header_ll(&keys, TSTRING, "WCLUMPS", 0, "yes", 0,
+                                 "Is there a clumps image companion?",
+                                 0, NULL);
   num[0]=p->numobjects-1;
   gal_fits_add_to_fits_header_ll(&keys, TLONG, "NOBJS", 0, num, 0,
-                                      "Number of objects in the image.", 0,
-                                      NULL);
+                                 "Number of objects in the image.", 0,
+                                 NULL);
   dpt=&p->detsn;
   gal_fits_add_to_fits_header_ll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
-                                      "Signal to noise of true "
-                                      "pseudo-detections.", 0, NULL);
+                                 "Signal to noise of true "
+                                 "pseudo-detections.", 0, NULL);
   gal_fits_array_to_file(p->cp.output, "Objects", LONG_IMG, p->olab,
                          s0, s1, p->anyblank, p->wcs, keys,
                          SPACK_STRING);
@@ -92,12 +95,12 @@ makeoutput(struct noisechiselparams *p)
      on the 3rd and 4th extensions. */
   num[0] = p->detectonly ? 0 : p->numclumps-1;
   gal_fits_add_to_fits_header_ll(&keys, TLONG, "NCLUMPS", 0, num, 0,
-                                      "Number of clumps in the image.", 0,
-                                      NULL);
+                                 "Number of clumps in the image.", 0,
+                                 NULL);
   dpt=&p->clumpsn;
   gal_fits_add_to_fits_header_ll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
-                                      "Signal to noise of true clumps.", 0,
-                                      NULL);
+                                 "Signal to noise of true clumps.", 0,
+                                 NULL);
   gal_fits_array_to_file(p->cp.output, "Clumps", LONG_IMG, p->clab, s0,
                          s1, p->anyblank, p->wcs, keys, SPACK_STRING);
   keys=NULL;



reply via email to

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