gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 5dd9ec3: gal_statistics_number returns size_t


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5dd9ec3: gal_statistics_number returns size_t dataset
Date: Mon, 12 Mar 2018 13:36:14 -0400 (EDT)

branch: master
commit 5dd9ec3dae6dcf529035e412ba423568ca63b55f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    gal_statistics_number returns size_t dataset
    
    Until now, `gal_statistics_number' would return a dataset with type
    `uint64_t', but that is a little hard to manage (especially for 32-bit
    systems). Also, in Gnuastro, we follow the convention of using `size_t' for
    all countings and sizes. So the output dataset of this function now has a
    `size_t' type (dependent on the host system).
    
    Also, Lee Kelvin kindly noted that NoiseChisel's error message when enough
    tiles can't be found for interpolation of the quantile threshold value is
    not too clear. Indeed, since the error would be printed by multiple
    threads, it was hard to read and very dense. So a test is now added (thanks
    to the `gal_statistics_number' function above) to see how many tiles passed
    and report an error before NoiseChisel goes into
    interpolation/mult-threaded mode. Since several other users had previously
    also complained about not understanding the problem, a very thorough
    explanation was added to the error message along with suggestions and links
    for further reading.
---
 NEWS                         | 14 ++++++++++----
 bin/noisechisel/threshold.c  | 35 +++++++++++++++++++++++++++++++++++
 bin/statistics/sky.c         |  2 +-
 doc/announce-acknowledge.txt |  1 +
 doc/gnuastro.texi            |  4 ++--
 lib/statistics.c             |  9 ++++-----
 6 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index bfb38e8..4efa940 100644
--- a/NEWS
+++ b/NEWS
@@ -35,14 +35,20 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
 ** Changed features
 
-  Libraries: `gal_statistics_quantile_function' returns `inf' or `-inf' if
-  the given value is smaller than the minimum or larger than the maximum of
-  the input dataset's range.
-
   Fits: The `--comment' and `--history' command may be called multiple
   times to write multiple COMMENT/HISTORY keywords into the input FITS
   file.
 
+  Libraries:
+
+   - `gal_statistics_quantile_function': returns `inf' or `-inf' if the
+     given value is smaller than the minimum or larger than the maximum of
+     the input dataset's range. Until now, it would return blank in such
+     cases.
+
+   - `gal_statistics_number': the output dataset now has a `size_t'
+     type. Until now it was `uint64_t'.
+
 ** Bug fixes
 
   Many unused result warnings for asprintf in some compilers (bug #52979).
diff --git a/bin/noisechisel/threshold.c b/bin/noisechisel/threshold.c
index 565e9ac..098f69e 100644
--- a/bin/noisechisel/threshold.c
+++ b/bin/noisechisel/threshold.c
@@ -648,6 +648,8 @@ void
 threshold_quantile_find_apply(struct noisechiselparams *p)
 {
   char *msg;
+  size_t nval;
+  gal_data_t *num;
   struct timeval t1;
   struct qthreshparams qprm;
   struct gal_options_common_params *cp=&p->cp;
@@ -734,6 +736,39 @@ threshold_quantile_find_apply(struct noisechiselparams *p)
                             p->qthreshname);
 
 
+  /* Check if the number of acceptable tiles is more than the minimum
+     interpolated number. Since this is a common problem for users, it is
+     much more useful to do the check here rather than printing multiple
+     errors in parallel. */
+  num=gal_statistics_number(qprm.erode_th);
+  nval=((size_t *)(num->array))[0];
+  if( nval < cp->interpnumngb)
+    error(EXIT_FAILURE, 0, "%zu tiles can be used for interpolation of the "
+          "quantile threshold values over the full dataset. This is smaller "
+          "than the requested minimum value of %zu (value to the "
+          "`--interpnumngb' option).\n\n"
+          "There are several ways to address the problem. The best and most "
+          "highly recommended is to use a larger input if possible (when the "
+          "input is a crop from a larger dataset). If that is not the case, "
+          "or it doesn't solve the problem, you need to loosen the "
+          "parameters (and therefore cause scatter in the final result). "
+          "Thus don't loosen them too much. Recall that you can see all the "
+          "option values to Gnuastro's programs by appending `-P' to the "
+          "end of your command.\n\n"
+          " - Decrease `--interpnumngb' to be smaller than the number "
+          "mentioned above.\n"
+          " - Slightly decrease `--tilesize' to have more tiles.\n"
+          " - Slightly increase `--modmedqdiff' to accept more tiles.\n\n"
+          "Try appending your command with `--checkqthresh' to see the "
+          "successful tiles (and get a feeling of the cause/solution, note "
+          "that the output is a multi-extension FITS file). To better "
+          "understand this important step, please run the following "
+          "command (press `SPACE'/arrow-keys to navigate and `Q'-key to "
+          "return back to the command-line):\n\n"
+          "    $ info gnuastro \"Quantifying signal in a tile\"\n",
+          nval, cp->interpnumngb);
+
+
   /* Interpolate and smooth the derived values. */
   threshold_interp_smooth(p, &qprm.erode_th, &qprm.noerode_th,
                           qprm.expand_th ? &qprm.expand_th : NULL,
diff --git a/bin/statistics/sky.c b/bin/statistics/sky.c
index a77d70a..ffd56c1 100644
--- a/bin/statistics/sky.c
+++ b/bin/statistics/sky.c
@@ -185,7 +185,7 @@ sky(struct statisticsparams *p)
     {
       num=gal_statistics_number(p->sky_t);
       if( asprintf(&msg, "Sky and its STD found on %zu/%zu tiles.",
-                   (size_t)(*((uint64_t *)(num->array))), tl->tottiles )<0 )
+                   *((size_t *)(num->array)), tl->tottiles )<0 )
         error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
       gal_timing_report(&t1, msg, 1);
       gal_data_free(num);
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index ae2f34c..28df3bd 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -3,6 +3,7 @@ People who's help must be acknowledged in the next release.
 Leindert Boogaard
 Nima Dehdilani
 Antonio Diaz Diaz
+Lee Kelvin
 Guillaume Mahler
 Ole Streicher
 Michel Tallon
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 659a8fa..0f17c04 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -23581,8 +23581,8 @@ Macros used to identify if the regularity of the bins 
when defining bins.
 
 @cindex Number
 @deftypefun {gal_data_t *} gal_statistics_number (gal_data_t @code{*input})
-Return a single-element @code{uint64} dataset containing the number of
-non-blank elements in @code{input}.
+Return a single-element dataset with type @code{size_t} which contains the
+number of non-blank elements in @code{input}.
 @end deftypefun
 
 @cindex Minimum
diff --git a/lib/statistics.c b/lib/statistics.c
index 6c19f36..405e535 100644
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@ -54,13 +54,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  ********               Simple statistics                 *******
  ****************************************************************/
 /* Return the number of non-blank elements in an array as a single element,
-   uint64 type data structure. */
+   `size_t' type data structure. */
 gal_data_t *
 gal_statistics_number(gal_data_t *input)
 {
-  size_t dsize=1;
-  uint64_t counter=0;
-  gal_data_t *out=gal_data_alloc(NULL, GAL_TYPE_UINT64, 1, &dsize,
+  size_t counter=0, dsize=1;
+  gal_data_t *out=gal_data_alloc(NULL, GAL_TYPE_SIZE_T, 1, &dsize,
                                  NULL, 1, -1, NULL, NULL, NULL);
 
   /* If there is no blank values in the input, then the total number is
@@ -71,7 +70,7 @@ gal_statistics_number(gal_data_t *input)
     counter = input->size;
 
   /* Write the value into memory. */
-  *((uint64_t *)(out->array)) = counter;
+  *((size_t *)(out->array)) = counter;
   return out;
 }
 



reply via email to

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