gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 235c86a 2/2: MakeCatalog output clump magnitud


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 235c86a 2/2: MakeCatalog output clump magnitudes corrected
Date: Sun, 21 May 2017 17:32:17 -0400 (EDT)

branch: master
commit 235c86a27e1424c917e7f014c84919dc561d937d
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    MakeCatalog output clump magnitudes corrected
    
    When NoiseChisel is run with `grownclumps', detections that have one or no
    clumps over them will be fully covered by a "clump". In that case, there
    will be no rivers, so the magnitude and brightness measurements needed to
    be corrected to account for no rivers.
    
    Also, the output file names of MakeCatalog were corrected to deal with
    directories in the value given to `--output'.
    
    Finally, to aviod confusion, instead of having a negative S/N, MakeCatalog,
    will just print a NaN value.
---
 bin/mkcatalog/columns.c | 27 +++++++++++++++++--------
 bin/mkcatalog/ui.c      | 52 ++++++++++++++++++++++++++++++++-----------------
 2 files changed, 53 insertions(+), 26 deletions(-)

diff --git a/bin/mkcatalog/columns.c b/bin/mkcatalog/columns.c
index ebe378c..69a6d54 100644
--- a/bin/mkcatalog/columns.c
+++ b/bin/mkcatalog/columns.c
@@ -989,6 +989,7 @@ columns_sn(struct mkcatalogparams *p, double *row, int o0c1)
   std = MKC_RATIO( row[ o0c1 ? CCOL_SUMSTD : OCOL_SUMSTD ], Ni );
   var = (p->skysubtracted ? 2.0f : 1.0f) * std * std;
 
+
   /* Calculate the S/N. Note that when grown clumps are requested from
      NoiseChisel, some "clumps" will completely cover their objects and
      there will be no rivers. So if this is a clump, and the river area is
@@ -998,11 +999,13 @@ columns_sn(struct mkcatalogparams *p, double *row, int 
o0c1)
       /* If the Sky is already subtracted, the varience should be counted
          two times. */
       O   = row[ CCOL_RIV_SUM ] / row[ CCOL_RIV_NUM ];  /* Outside.  */
-      sn  = ( sqrt(Ni/p->cpscorr) * (I-O)
-              / sqrt( (I>0?I:-1*I) + (O>0?O:-1*O) + var ) );
+      sn  = ( (I-O)>0
+              ? ( sqrt(Ni/p->cpscorr) * (I-O)
+                  / sqrt( (I>0?I:-1*I) + (O>0?O:-1*O) + var ) )
+              : NAN );
     }
   else
-    sn  = sqrt(Ni/p->cpscorr) * I / sqrt( (I>0?I:-1*I) + var );
+    sn  = I>0 ? sqrt(Ni/p->cpscorr) * I / sqrt( (I>0?I:-1*I) + var ) : NAN;
 
   /* Return the derived value. */
   return sn;
@@ -1381,8 +1384,13 @@ columns_fill(struct mkcatalog_passparams *pp)
             break;
 
           case UI_KEY_BRIGHTNESS:
-            /* Calculate the river flux over the clump area. */
-            tmp = ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM ]*ci[ CCOL_NUM ];
+            /* Calculate the river flux over the clump area. But only when
+               rivers are present. When grown clumps are requested, the
+               clumps can fully cover a detection (that has one or no
+               clumps). */
+            tmp = ( ci[ CCOL_RIV_NUM ]
+                    ? ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM ]*ci[ CCOL_NUM ]
+                    : 0 );
 
             /* Subtract it from the clump's brightness. */
             ((float *)colarr)[cind] = ci[ CCOL_SUM ] - tmp;
@@ -1393,7 +1401,9 @@ columns_fill(struct mkcatalog_passparams *pp)
             break;
 
           case UI_KEY_MAGNITUDE: /* Similar: brightness for clumps */
-            tmp = ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM ]*ci[ CCOL_NUM ];
+            tmp = ( ci[ CCOL_RIV_NUM ]
+                    ? ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM ]*ci[ CCOL_NUM ]
+                    : 0 );
             ((float *)colarr)[cind] = MKC_MAG(ci[ CCOL_SUM ]-tmp);
             break;
 
@@ -1410,8 +1420,9 @@ columns_fill(struct mkcatalog_passparams *pp)
             break;
 
           case UI_KEY_RIVERAVE:
-            ((float *)colarr)[cind] = ( ci[ CCOL_RIV_SUM]
-                                        / ci[ CCOL_RIV_NUM] );
+            ((float *)colarr)[cind] = ( ci[ CCOL_RIV_NUM]
+                                        ? ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM]
+                                        : NAN );
             break;
 
           case UI_KEY_RIVERNUM:
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 71d49da..fac76a3 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -686,23 +686,43 @@ ui_one_tile_per_object(struct mkcatalogparams *p)
    given). In both cases, the operations are the same, just the base name
    differs. So to keep things clean, we have defined this function. */
 static void
-ui_preparations_both_names(struct mkcatalogparams *p, char *basename)
+ui_preparations_both_names(struct mkcatalogparams *p)
 {
-  char *end, suffix[50];
+  char *basename;
+  char *end, *tend, suffix[50];
+  uint8_t keepinputdir=p->cp.keepinputdir;  /* See below. */
+
+  /* Set the type ending. */
+  if(p->cp.output)
+    {
+      /* When the user has specified a name, any possible directories in
+         that name must be respected. So we will keep the actual
+         `keepinputdir' value in a temporary variable, set it to 1 only for
+         this operation, then set it back to what it was. */
+      p->cp.keepinputdir=1;
+
+      /* Set the basic strings. */
+      basename = p->cp.output;
+      tend = gal_fits_name_is_fits(p->cp.output)     ? "fits" : "txt";
+    }
+  else
+    {
+      basename = p->inputname;
+      tend = p->cp.tableformat==GAL_TABLE_FORMAT_TXT ? "txt"  : "fits";
+    }
 
   /* Set the objects name */
   end="_o";
-  sprintf(suffix, "%s.%s", end,
-          p->cp.tableformat==GAL_TABLE_FORMAT_TXT ? "txt" : "fits");
-  p->objectsout=gal_checkset_automatic_output(&p->cp, p->inputname,
-                                              suffix);
+  sprintf(suffix, "%s.%s", end, tend);
+  p->objectsout=gal_checkset_automatic_output(&p->cp, basename, suffix);
 
   /* Set the clumps name */
   end="_c";
-  sprintf(suffix, "%s.%s", end,
-          p->cp.tableformat==GAL_TABLE_FORMAT_TXT ? "txt" : "fits");
-  p->clumpsout=gal_checkset_automatic_output(&p->cp, p->inputname,
-                                             suffix);
+  sprintf(suffix, "%s.%s", end, tend);
+  p->clumpsout=gal_checkset_automatic_output(&p->cp, basename, suffix);
+
+  /* Revert `keepinputdir' to what it was. */
+  if(p->cp.output) p->cp.keepinputdir=keepinputdir;
 }
 
 
@@ -722,18 +742,14 @@ ui_preparations_outnames(struct mkcatalogparams *p)
          `tableformat' option. */
       gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
 
-      /* If a clumps image has been read (and there are any clumps in the
-         image), then we have two outputs. */
-      if(p->clumps)
-        ui_preparations_both_names(p, p->cp.output);
-      else
-        p->objectsout=p->cp.output;
+      /* If a clumps image has been read, then we have two outputs. */
+      if(p->clumps) ui_preparations_both_names(p);
+      else          p->objectsout=p->cp.output;
     }
   else
     {
       /* Both clumps and object catalogs are necessary. */
-      if(p->clumps)
-        ui_preparations_both_names(p, p->inputname);
+      if(p->clumps) ui_preparations_both_names(p);
 
       /* We only need one objects catalog. */
       else



reply via email to

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