gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master dd688a1: MakeCatalog: order-based measurements


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master dd688a1: MakeCatalog: order-based measurements account for no clumps
Date: Sat, 26 Dec 2020 21:25:22 -0500 (EST)

branch: master
commit dd688a1f02ea766ee11f3e9539d257c40c5766a1
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    MakeCatalog: order-based measurements account for no clumps
    
    Until now, the order-based measurements (like the median and etc) would
    only write a NaN in the column if the full object wasn't present in the
    values image. However, it can happen that the object is partially covered
    while the clump(s) isn't. In such cases, MakeCatalog would crash (saying
    that it can't allocate a zero-sized dataset).
    
    With this commit, the necessary checks have been added to avoid this crash
    and simply put a NaN in any of those clump columns.
    
    In the process two other minor corrections were made:
    
     - The possibly printed message that says the Sky value has been subtracted
       from the values is now printed within the main set of messages. Until
       now, it was mistakenly printed even before the name of MakeCatalog!
    
     - The apostrophe was removed from the description of the minimum and
       maximum position columns because it would go as two apostrophes in the
       final table.
---
 bin/mkcatalog/columns.c   | 12 +++---
 bin/mkcatalog/mkcatalog.c |  1 -
 bin/mkcatalog/parse.c     | 94 +++++++++++++++++++++++++++++++----------------
 bin/mkcatalog/ui.c        | 12 +++---
 4 files changed, 74 insertions(+), 45 deletions(-)

diff --git a/bin/mkcatalog/columns.c b/bin/mkcatalog/columns.c
index ee0aedb..6574bb6 100644
--- a/bin/mkcatalog/columns.c
+++ b/bin/mkcatalog/columns.c
@@ -724,7 +724,7 @@ columns_define_alloc(struct mkcatalogparams *p)
         case UI_KEY_MINVX:
           name           = "MIN_V_X";
           unit           = "pixel";
-          ocomment       = "Minimum value's X pixel position.";
+          ocomment       = "Minimum value X pixel position.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT32;
           ctype          = GAL_TYPE_FLOAT32;
@@ -738,7 +738,7 @@ columns_define_alloc(struct mkcatalogparams *p)
         case UI_KEY_MAXVX:
           name           = "MAX_V_X";
           unit           = "pixel";
-          ocomment       = "Maximum value's X pixel position.";
+          ocomment       = "Maximum value X pixel position.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT32;
           ctype          = GAL_TYPE_FLOAT32;
@@ -752,7 +752,7 @@ columns_define_alloc(struct mkcatalogparams *p)
         case UI_KEY_MINVY:
           name           = "MIN_V_Y";
           unit           = "pixel";
-          ocomment       = "Minimum value's Y pixel position.";
+          ocomment       = "Minimum value Y pixel position.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT32;
           ctype          = GAL_TYPE_FLOAT32;
@@ -766,7 +766,7 @@ columns_define_alloc(struct mkcatalogparams *p)
         case UI_KEY_MAXVY:
           name           = "MAX_V_Y";
           unit           = "pixel";
-          ocomment       = "Maximum value's Y pixel position.";
+          ocomment       = "Maximum value Y pixel position.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT32;
           ctype          = GAL_TYPE_FLOAT32;
@@ -780,7 +780,7 @@ columns_define_alloc(struct mkcatalogparams *p)
         case UI_KEY_MINVZ:
           name           = "MIN_V_Z";
           unit           = "pixel";
-          ocomment       = "Minimum value's Z pixel position.";
+          ocomment       = "Minimum value Z pixel position.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT32;
           ctype          = GAL_TYPE_FLOAT32;
@@ -794,7 +794,7 @@ columns_define_alloc(struct mkcatalogparams *p)
         case UI_KEY_MAXVZ:
           name           = "MAX_V_Z";
           unit           = "pixel";
-          ocomment       = "Maximum value's Z pixel position.";
+          ocomment       = "Maximum value Z pixel position.";
           ccomment       = ocomment;
           otype          = GAL_TYPE_FLOAT32;
           ctype          = GAL_TYPE_FLOAT32;
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index 22b628c..2d396a6 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -142,7 +142,6 @@ mkcatalog_single_object(void *in_prm)
   else
     pp.up_vals=NULL;
 
-
   /* Fill the desired columns for all the objects given to this thread. */
   for(i=0; tprm->indexs[i]!=GAL_BLANK_SIZE_T; ++i)
     {
diff --git a/bin/mkcatalog/parse.c b/bin/mkcatalog/parse.c
index 0fc3d14..eeda287 100644
--- a/bin/mkcatalog/parse.c
+++ b/bin/mkcatalog/parse.c
@@ -1386,25 +1386,29 @@ parse_order_based(struct mkcatalog_passparams *pp)
                          p->cp.minmapsize, p->cp.quietmmap, NULL, NULL,
                          NULL);
 
-  /* Allocate space for the clump values. */
+  /* Clump preparations. */
   if(p->clumps)
     {
+      /* Allocate the necessary space. */
       errno=0;
       clumpsvals=malloc(pp->clumpsinobj * sizeof *clumpsvals);
       if(clumpsvals==NULL)
         error(EXIT_FAILURE, errno, "%s: couldn't allocate 'clumpsvals' for "
               "%zu clumps", __func__, pp->clumpsinobj);
 
-
       /* Allocate the array necessary to keep the values of each clump. */
       ccounter=gal_pointer_allocate(GAL_TYPE_SIZE_T, pp->clumpsinobj, 1,
                                     __func__, "ccounter");
       for(i=0;i<pp->clumpsinobj;++i)
         {
           tmpsize=pp->ci[ i * CCOL_NUMCOLS + CCOL_NUM ];
-          clumpsvals[i]=gal_data_alloc(NULL, p->values->type, 1, &tmpsize,
-                                       NULL, 0, p->cp.minmapsize,
-                                       p->cp.quietmmap, NULL, NULL, NULL);
+          clumpsvals[i] = ( tmpsize
+                            ? gal_data_alloc(NULL, p->values->type, 1,
+                                             &tmpsize, NULL, 0,
+                                             p->cp.minmapsize,
+                                             p->cp.quietmmap,
+                                             NULL, NULL, NULL)
+                            : NULL );
         }
     }
 
@@ -1432,7 +1436,7 @@ parse_order_based(struct mkcatalog_passparams *pp)
                       gal_type_sizeof(p->values->type) );
 
               /* We are also on a clump. */
-              if(p->clumps && *C>0)
+              if(p->clumps && *C>0 && clumpsvals[*C-1]!=NULL)
                 memcpy( gal_pointer_increment(clumpsvals[*C-1]->array,
                                               ccounter[*C-1]++,
                                               p->values->type), V,
@@ -1503,39 +1507,51 @@ parse_order_based(struct mkcatalog_passparams *pp)
           /* Set the main row to fill. */
           ci=&pp->ci[ i * CCOL_NUMCOLS ];
 
-          /* Do the necessary calculation. */
+          /* Median. */
           if(p->ciflag[ CCOL_MEDIAN ])
             {
-              result=gal_statistics_median(clumpsvals[i], 1);
-              result=gal_data_copy_to_new_type_free(result, GAL_TYPE_FLOAT64);
-              ci[ CCOL_MEDIAN ] = ( *((double *)(result->array))
-                                    - (ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM ]) 
);
-              gal_data_free(result);
+              if(clumpsvals[i])
+                {
+                  result=gal_statistics_median(clumpsvals[i], 1);
+                  result=gal_data_copy_to_new_type_free(result, 
GAL_TYPE_FLOAT64);
+                  ci[ CCOL_MEDIAN ] = ( *((double *)(result->array))
+                                        - (ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM 
]) );
+                  gal_data_free(result);
+                }
+              else ci[ CCOL_MEDIAN ] = NAN;
             }
+
+          /* Sigma-clipping measurements. */
           if(p->ciflag[ CCOL_SIGCLIPNUM ]
              || p->ciflag[ CCOL_SIGCLIPSTD ]
              || p->ciflag[ CCOL_SIGCLIPMEAN ]
              || p->ciflag[ CCOL_SIGCLIPMEDIAN ])
             {
-              /* Calculate the sigma-clipped results and write them in any
-                 requested column. */
-              result=gal_statistics_sigma_clip(clumpsvals[i], p->sigmaclip[0],
-                                               p->sigmaclip[1], 1, 1);
-              sigcliparr=result->array;
-              if(p->ciflag[ CCOL_SIGCLIPNUM ])
-                ci[CCOL_SIGCLIPNUM]=sigcliparr[0];
-              if(p->ciflag[ CCOL_SIGCLIPSTD ])
-                ci[CCOL_SIGCLIPSTD]=( sigcliparr[3]
-                                      - (ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM 
]));
-              if(p->ciflag[ CCOL_SIGCLIPMEAN ])
-                ci[CCOL_SIGCLIPMEAN]=( sigcliparr[2]
-                                       - (ci[ CCOL_RIV_SUM ]/ci[ CCOL_RIV_NUM 
]));
-              if(p->ciflag[ CCOL_SIGCLIPMEDIAN ])
-                ci[CCOL_SIGCLIPMEDIAN]=( sigcliparr[1]
-                                         - (ci[ CCOL_RIV_SUM ]/ci[ 
CCOL_RIV_NUM ]));
-
-              /* Clean up the sigma-clipped values. */
-              gal_data_free(result);
+              if(clumpsvals[i])
+                {
+                  result=gal_statistics_sigma_clip(clumpsvals[i], 
p->sigmaclip[0],
+                                                   p->sigmaclip[1], 1, 1);
+                  sigcliparr=result->array;
+                  if(p->ciflag[ CCOL_SIGCLIPNUM ])
+                    ci[CCOL_SIGCLIPNUM]=sigcliparr[0];
+                  if(p->ciflag[ CCOL_SIGCLIPSTD ])
+                    ci[CCOL_SIGCLIPSTD]=( sigcliparr[3]
+                                          - (ci[ CCOL_RIV_SUM ]/ci[ 
CCOL_RIV_NUM ]));
+                  if(p->ciflag[ CCOL_SIGCLIPMEAN ])
+                    ci[CCOL_SIGCLIPMEAN]=( sigcliparr[2]
+                                           - (ci[ CCOL_RIV_SUM ]/ci[ 
CCOL_RIV_NUM ]));
+                  if(p->ciflag[ CCOL_SIGCLIPMEDIAN ])
+                    ci[CCOL_SIGCLIPMEDIAN]=( sigcliparr[1]
+                                             - (ci[ CCOL_RIV_SUM ]/ci[ 
CCOL_RIV_NUM ]));
+                  gal_data_free(result);
+                }
+              else
+                {
+                  if(p->ciflag[ CCOL_SIGCLIPNUM    ]) ci[ CCOL_SIGCLIPNUM  
]=NAN;
+                  if(p->ciflag[ CCOL_SIGCLIPSTD    ]) ci[ CCOL_SIGCLIPSTD  
]=NAN;
+                  if(p->ciflag[ CCOL_SIGCLIPMEAN   ]) ci[ CCOL_SIGCLIPMEAN 
]=NAN;
+                  if(p->ciflag[ CCOL_SIGCLIPMEDIAN ]) 
ci[CCOL_SIGCLIPMEDIAN]=NAN;
+                }
             }
 
           /* Estimate half of the total sum. */
@@ -1547,7 +1563,21 @@ parse_order_based(struct mkcatalog_passparams *pp)
               || p->ciflag[ CCOL_FRACMAX1SUM ]
               || p->ciflag[ CCOL_FRACMAX2NUM ]
               || p->ciflag[ CCOL_FRACMAX2SUM ] )
-            parse_area_of_frac_sum(pp, clumpsvals[i], ci, 0);
+            {
+              if(clumpsvals[i])
+                parse_area_of_frac_sum(pp, clumpsvals[i], ci, 0);
+              else
+                {
+                  if( p->ciflag[ CCOL_MAXIMUM     ]) ci[ CCOL_MAXIMUM     
]=NAN;
+                  if( p->ciflag[ CCOL_HALFMAXNUM  ]) ci[ CCOL_HALFMAXNUM  
]=NAN;
+                  if( p->ciflag[ CCOL_HALFMAXSUM  ]) ci[ CCOL_HALFMAXSUM  
]=NAN;
+                  if( p->ciflag[ CCOL_HALFSUMNUM  ]) ci[ CCOL_HALFSUMNUM  
]=NAN;
+                  if( p->ciflag[ CCOL_FRACMAX1NUM ]) ci[ CCOL_FRACMAX1NUM 
]=NAN;
+                  if( p->ciflag[ CCOL_FRACMAX1SUM ]) ci[ CCOL_FRACMAX1SUM 
]=NAN;
+                  if( p->ciflag[ CCOL_FRACMAX2NUM ]) ci[ CCOL_FRACMAX2NUM 
]=NAN;
+                  if( p->ciflag[ CCOL_FRACMAX2SUM ]) ci[ CCOL_FRACMAX2SUM 
]=NAN;
+                }
+            }
 
           /* Clean up this clump's values. */
           gal_data_free(clumpsvals[i]);
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 5af29b5..f7e1a8d 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -1207,10 +1207,6 @@ ui_subtract_sky(struct mkcatalogparams *p)
     error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix "
           "the problem. For some reason, the size doesn't match", __func__,
           PACKAGE_BUGREPORT);
-
-  /* Inform the user that this operation is done (if necessary). */
-  if(!p->cp.quiet)
-    printf("  - Sky subtracted from input values.\n");
 }
 
 
@@ -1909,16 +1905,20 @@ ui_read_check_inputs_setup(int argc, char *argv[], 
struct mkcatalogparams *p)
       if(p->subtractsky || p->sky)
         {
           if(p->sky->size==1)
-            printf("  - Sky: %g\n", *((float *)(p->sky->array)) );
+            printf("  - Sky: %g (single value for all pixels)\n",
+                   *((float *)(p->sky->array)) );
           else
             printf("  - Sky: %s (hdu: %s)\n", p->usedskyfile, p->skyhdu);
+          if(p->subtractsky)
+            printf("    - Sky has been subtracted from values internally.\n");
         }
 
       if(p->std)
         {
           tmp = p->variance ? "VAR" : "STD";
           if(p->std->size==1)
-            printf("  - Sky %s: %g\n", tmp, *((float *)(p->std->array)) );
+            printf("  - Sky %s: %g (single value for all pixels)\n", tmp,
+                   *((float *)(p->std->array)) );
           else
             printf("  - Sky %s: %s (hdu: %s)\n", tmp, p->usedstdfile,
                    p->stdhdu);



reply via email to

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