gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 906d302a: Statistics: --ontile operations done


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 906d302a: Statistics: --ontile operations done as expected
Date: Sat, 8 Jun 2024 18:44:51 -0400 (EDT)

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

    Statistics: --ontile operations done as expected
    
    Until now, when any statistical operation was requested from Statistics
    (for example in the command below), it would crash with a warning about not
    being able to print one-row options with '--printparams'. This warning has
    nothing to do with the '--ontile' option and was confusing!
    
    With this commit, the cause of the problem was found to be the writing of
    option values in the output FITS header keywords (which call the same
    low-level function as '--printparams'). The problem was fixed by actually
    printing a "1" for the called options in such cases (because only the
    called options would be printed).
    
    Also, as part of this commit, I noticed that the clipping operators were
    not implemented with the '--ontile' option! So I added them.
    
    This fixes bug #65853.
---
 NEWS                        |   2 +
 bin/statistics/statistics.c | 120 ++++++++++++++++++++++++++++++++++++++++----
 bin/statistics/ui.c         |  12 ++---
 lib/options.c               |   2 +-
 4 files changed, 119 insertions(+), 17 deletions(-)

diff --git a/NEWS b/NEWS
index c3aab97d..5c124049 100644
--- a/NEWS
+++ b/NEWS
@@ -208,6 +208,8 @@ See the end of the file for license conditions.
   - bug #65847: make check FAILs on color-faint-gray script when libjpeg
     not found. Reported by Takashi Ichikawa.
 
+  - bug #65853: Statistics crashes with the --ontile option.
+
 
 
 
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index aeb59e27..baae8abf 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -415,6 +415,80 @@ statistics_interpolate_and_write(struct statisticsparams 
*p,
 
 
 
+static gal_data_t *
+statistics_on_tile_clip(struct statisticsparams *p, gal_data_t *tile,
+                        int operator)
+{
+  int s1m0=0;
+  uint8_t cflag;
+  size_t ind, one=1;
+  gal_data_t *clip, *out;
+
+  /* Pre-operation settings. */
+  switch(operator)
+    {
+    /* MAD-clipping */
+    case UI_KEY_MADCLIPMAD:
+      s1m0=0; cflag=0; ind=GAL_STATISTICS_CLIP_OUTCOL_MAD; break;
+    case UI_KEY_MADCLIPNUMBER:
+      s1m0=0; cflag=0; ind=GAL_STATISTICS_CLIP_OUTCOL_NUMBER_USED; break;
+    case UI_KEY_MADCLIPMEDIAN:
+      s1m0=0; cflag=0; ind=GAL_STATISTICS_CLIP_OUTCOL_MEDIAN; break;
+    case UI_KEY_MADCLIPSTD:
+      s1m0=0; cflag=GAL_STATISTICS_CLIP_OUTCOL_OPTIONAL_STD;
+      ind=GAL_STATISTICS_CLIP_OUTCOL_STD; break;
+    case UI_KEY_MADCLIPMEAN:
+      s1m0=0; cflag=GAL_STATISTICS_CLIP_OUTCOL_OPTIONAL_MEAN;
+      ind=GAL_STATISTICS_CLIP_OUTCOL_MEAN; break;
+
+    /* Sigma-clipping */
+    case UI_KEY_SIGCLIPSTD:
+      s1m0=1; cflag=0; ind=GAL_STATISTICS_CLIP_OUTCOL_STD; break;
+    case UI_KEY_SIGCLIPNUMBER:
+      s1m0=1; cflag=0; ind=GAL_STATISTICS_CLIP_OUTCOL_NUMBER_USED; break;
+    case UI_KEY_SIGCLIPMEDIAN:
+      s1m0=1; cflag=0; ind=GAL_STATISTICS_CLIP_OUTCOL_MEDIAN; break;
+    case UI_KEY_SIGCLIPMAD:
+      s1m0=0; cflag=GAL_STATISTICS_CLIP_OUTCOL_OPTIONAL_MAD;
+      ind=GAL_STATISTICS_CLIP_OUTCOL_MAD; break;
+    case UI_KEY_SIGCLIPMEAN:
+      s1m0=0; cflag=GAL_STATISTICS_CLIP_OUTCOL_OPTIONAL_MEAN;
+      ind=GAL_STATISTICS_CLIP_OUTCOL_MEAN; break;
+
+    /* None of the above (a bug!). */
+    default:
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix "
+            "the problem. The operator identifier %d should not have "
+            "been given to this function", __func__, PACKAGE_BUGREPORT,
+            operator);
+    }
+
+  /* Do the clipping, and a small sanity check on the type of the output
+     (in case it changes in the future). */
+  clip = ( s1m0
+           ? gal_statistics_clip_mad(tile, p->mclipparams[0],
+                                     p->mclipparams[1], cflag,
+                                     0, 1)
+           : gal_statistics_clip_sigma(tile, p->sclipparams[0],
+                                       p->sclipparams[1], cflag,
+                                       0, 1) );
+
+  /* Write the desired value into the output. */
+  out=gal_data_alloc(NULL, clip->type, 1, &one, NULL, 0, -1, 1,
+                     NULL, NULL, NULL);
+  memcpy( out->array,
+          gal_pointer_increment(clip->array, ind, clip->type),
+          gal_type_sizeof(clip->type) );
+
+  /* Return the clipped dataset */
+  gal_data_free(clip);
+  return out;
+}
+
+
+
+
+
 static void
 statistics_on_tile(struct statisticsparams *p)
 {
@@ -440,22 +514,34 @@ statistics_on_tile(struct statisticsparams *p)
         case UI_KEY_NUMBER:
           type=GAL_TYPE_INT32; break;
 
+        case UI_KEY_MODE:
+        case UI_KEY_MEDIAN:
         case UI_KEY_MINIMUM:
         case UI_KEY_MAXIMUM:
-        case UI_KEY_MEDIAN:
-        case UI_KEY_MODE:
         case UI_KEY_QUANTFUNC:
           type=p->input->type; break;
 
         case UI_KEY_SUM:
-        case UI_KEY_MEAN:
         case UI_KEY_STD:
+        case UI_KEY_MEAN:
+        case UI_KEY_MODESYM:
         case UI_KEY_QUANTILE:
         case UI_KEY_MODEQUANT:
-        case UI_KEY_MODESYM:
         case UI_KEY_MODESYMVALUE:
           type=GAL_TYPE_FLOAT64; break;
 
+        case UI_KEY_MADCLIPSTD:
+        case UI_KEY_SIGCLIPSTD:
+        case UI_KEY_MADCLIPMAD:
+        case UI_KEY_SIGCLIPMAD:
+        case UI_KEY_MADCLIPMEAN:
+        case UI_KEY_SIGCLIPMEAN:
+        case UI_KEY_MADCLIPNUMBER:
+        case UI_KEY_SIGCLIPNUMBER:
+        case UI_KEY_MADCLIPMEDIAN:
+        case UI_KEY_SIGCLIPMEDIAN:
+          type=GAL_TYPE_FLOAT32; break;
+
         default:
           error(EXIT_FAILURE, 0, "%s: a bug! %d is not a recognized "
                 "operation code", __func__, operation->v);
@@ -532,10 +618,24 @@ statistics_on_tile(struct statisticsparams *p)
               tmp=ttmp;
               break;
 
+            case UI_KEY_MADCLIPSTD:
+            case UI_KEY_SIGCLIPSTD:
+            case UI_KEY_MADCLIPMAD:
+            case UI_KEY_SIGCLIPMAD:
+            case UI_KEY_MADCLIPMEAN:
+            case UI_KEY_SIGCLIPMEAN:
+            case UI_KEY_MADCLIPNUMBER:
+            case UI_KEY_SIGCLIPNUMBER:
+            case UI_KEY_MADCLIPMEDIAN:
+            case UI_KEY_SIGCLIPMEDIAN:
+              tmp=statistics_on_tile_clip(p, tile, operation->v);
+              break;
+
             default:
-              error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s to "
-                    "fix the problem. The operation code %d is not "
-                    "recognized", __func__, PACKAGE_BUGREPORT, operation->v);
+              error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s "
+                    "to fix the problem. The operation code %d is not "
+                    "recognized", __func__, PACKAGE_BUGREPORT,
+                    operation->v);
             }
 
           /* Put the output value into the 'values' array and clean up. */
@@ -1249,9 +1349,11 @@ print_clip(struct statisticsparams *p, int sig1_mad0)
      call other operators also. */
   result = ( sig1_mad0
              ? gal_statistics_clip_sigma(p->sorted, clipparams[0],
-                                         clipparams[1], flags, 0, p->cp.quiet)
+                                         clipparams[1], flags, 0,
+                                         p->cp.quiet)
              : gal_statistics_clip_mad(p->sorted, clipparams[0],
-                                       clipparams[1], flags, 0, p->cp.quiet) );
+                                       clipparams[1], flags, 0,
+                                       p->cp.quiet) );
   a=result->array;
 
   /* Finish the introduction. */
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index ca63694e..41966e9a 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -218,19 +218,17 @@ ui_add_to_single_value(struct argp_option *option, char 
*arg,
                       char *filename, size_t lineno, void *params)
 {
   size_t i;
+  char *str;
   double *d;
   gal_data_t *inputs=NULL;
   struct statisticsparams *p=(struct statisticsparams *)params;
 
   /* In case of printing the option values. */
   if(lineno==-1)
-    error(EXIT_FAILURE, 0, "currently the options to be printed in one "
-          "row (like '--number', '--mean', and etc) do not support "
-          "printing with the '--printparams' ('-P'), or writing into "
-          "configuration files due to lack of time when implementing "
-          "these features. You can put them into configuration files "
-          "manually. Please get in touch with us at '%s', so we can "
-          "implement it", PACKAGE_BUGREPORT);
+    {
+      gal_checkset_allocate_copy("1", &str);
+      return str;
+    }
 
   /* Some of these options take values and some don't. */
   if(option->type==GAL_OPTIONS_NO_ARG_TYPE)
diff --git a/lib/options.c b/lib/options.c
index 9105ddec..906c341f 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -3336,7 +3336,7 @@ gal_options_print_state(struct gal_options_common_params 
*cp)
   switch(sum)
     {
     /* No printing option has been called, so just return. */
-    case 0:  return;
+    case 0: return;
 
     /* (Only) one of the printing options has been called, so we'll need to
        print the values in the proper place. */



reply via email to

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