gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 2566ab1b 1/2: Arithmetic: new interpolate-mean


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2566ab1b 1/2: Arithmetic: new interpolate-meanngb operator
Date: Sat, 17 Dec 2022 14:00:42 -0500 (EST)

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

    Arithmetic: new interpolate-meanngb operator
    
    Until now, we could only use the median, minimum and maximum of the
    nearest-neighbor interpolation in the Arithmetic program and the
    interpolation library.
    
    With this commit, we can also ask for interpolating by the mean of the
    nearest neighbors.
---
 NEWS                        | 3 +++
 bin/arithmetic/arithmetic.c | 6 ++++++
 bin/arithmetic/arithmetic.h | 1 +
 doc/gnuastro.texi           | 8 ++++++--
 lib/gnuastro/interpolate.h  | 1 +
 lib/interpolate.c           | 4 ++++
 6 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index c955117b..9f71ce66 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ See the end of the file for license conditions.
        SDSS). This was suggested by Giulia Golini.
      - nanomaggy-to-counts: convert nanomaggy to counts. This was suggested
        by Giulia Golini.
+   - New operators (only in the Arithmetic program):
+     - interpolate-meanngb: interpolate blank values with mean of the
+       requested number of nearest neighbors.
    - Alternative (shorter) names for existing operators, added after
      discussion with Samane Raji.
      - u8:  same as 'uint8'   (to convert to unsigned 8-bit integers).
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index b10362a2..7c6cbdfe 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -879,6 +879,9 @@ arithmetic_interpolate(struct arithmeticparams *p, int 
operator, char *token)
     case ARITHMETIC_OP_INTERPOLATE_MAXNGB:
       interpop=GAL_INTERPOLATE_NEIGHBORS_FUNC_MAX;
       break;
+    case ARITHMETIC_OP_INTERPOLATE_MEANNGB:
+      interpop=GAL_INTERPOLATE_NEIGHBORS_FUNC_MEAN;
+      break;
     case ARITHMETIC_OP_INTERPOLATE_MEDIANNGB:
       interpop=GAL_INTERPOLATE_NEIGHBORS_FUNC_MEDIAN;
       break;
@@ -1328,6 +1331,8 @@ arithmetic_set_operator(char *string, size_t 
*num_operands, int *inlib)
         { op=ARITHMETIC_OP_INTERPOLATE_MINNGB;    *num_operands=0; }
       else if (!strcmp(string, "interpolate-maxngb"))
         { op=ARITHMETIC_OP_INTERPOLATE_MAXNGB;    *num_operands=0; }
+      else if (!strcmp(string, "interpolate-meanngb"))
+        { op=ARITHMETIC_OP_INTERPOLATE_MEANNGB;   *num_operands=0; }
       else if (!strcmp(string, "interpolate-medianngb"))
         { op=ARITHMETIC_OP_INTERPOLATE_MEDIANNGB; *num_operands=0; }
       else if (!strcmp(string, "interpolate-minofregion"))
@@ -1516,6 +1521,7 @@ arithmetic_operator_run(struct arithmeticparams *p, int 
operator,
 
         case ARITHMETIC_OP_INTERPOLATE_MINNGB:
         case ARITHMETIC_OP_INTERPOLATE_MAXNGB:
+        case ARITHMETIC_OP_INTERPOLATE_MEANNGB:
         case ARITHMETIC_OP_INTERPOLATE_MEDIANNGB:
           arithmetic_interpolate(p, operator, operator_string);
           break;
diff --git a/bin/arithmetic/arithmetic.h b/bin/arithmetic/arithmetic.h
index bcc78f2d..3a15f45a 100644
--- a/bin/arithmetic/arithmetic.h
+++ b/bin/arithmetic/arithmetic.h
@@ -42,6 +42,7 @@ enum arithmetic_prog_operators
   ARITHMETIC_OP_INVERT,
   ARITHMETIC_OP_INTERPOLATE_MINNGB,
   ARITHMETIC_OP_INTERPOLATE_MAXNGB,
+  ARITHMETIC_OP_INTERPOLATE_MEANNGB,
   ARITHMETIC_OP_INTERPOLATE_MEDIANNGB,
   ARITHMETIC_OP_INTERPOLATE_MINOFREGION,
   ARITHMETIC_OP_INTERPOLATE_MAXOFREGION,
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 7f89b1fb..d27c4a9e 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -17252,11 +17252,14 @@ When you want to interpolate blank regions and you 
want each blank region to hav
 Because the pixels used to interpolate various parts of the region differ.
 For such scenarios, you may use @code{interpolate-maxofregion} or 
@code{interpolate-inofregion} (described below).
 
+@item interpolate-meanngb
+Similar to @code{interpolate-medianngb}, but will fill the blank values of the 
dataset with the mean value of the requested number of nearest neighbors.
+
 @item interpolate-minngb
-Similar to @code{interpolate-medianngb}, but will fill the blank values of the 
dataset with the minimum value of the nearest neighbors.
+Similar to @code{interpolate-medianngb}, but will fill the blank values of the 
dataset with the minimum value of the requested number of nearest neighbors.
 
 @item interpolate-maxngb
-Similar to @code{interpolate-medianngb}, but will fill the blank values of the 
dataset with the maximum value of the nearest neighbors.
+Similar to @code{interpolate-medianngb}, but will fill the blank values of the 
dataset with the maximum value of the requested number of nearest neighbors.
 One useful implementation of this operator is to fill the saturated pixels of 
stars in images.
 
 @item interpolate-minofregion
@@ -37604,6 +37607,7 @@ A manhattan metric will always be an integer and is 
like steps (but is also much
 
 @deffn Macro GAL_INTERPOLATE_NEIGHBORS_FUNC_MIN
 @deffnx Macro GAL_INTERPOLATE_NEIGHBORS_FUNC_MAX
+@deffnx Macro GAL_INTERPOLATE_NEIGHBORS_FUNC_MEAN
 @deffnx Macro GAL_INTERPOLATE_NEIGHBORS_FUNC_MEDIAN
 @deffnx Macro GAL_INTERPOLATE_NEIGHBORS_FUNC_INVALID
 @cindex Saturated stars
diff --git a/lib/gnuastro/interpolate.h b/lib/gnuastro/interpolate.h
index e929f2cc..de72c71b 100644
--- a/lib/gnuastro/interpolate.h
+++ b/lib/gnuastro/interpolate.h
@@ -65,6 +65,7 @@ enum gal_interpolate_neighbors_func
 
  GAL_INTERPOLATE_NEIGHBORS_FUNC_MIN,
  GAL_INTERPOLATE_NEIGHBORS_FUNC_MAX,
+ GAL_INTERPOLATE_NEIGHBORS_FUNC_MEAN,
  GAL_INTERPOLATE_NEIGHBORS_FUNC_MEDIAN,
 };
 
diff --git a/lib/interpolate.c b/lib/interpolate.c
index 2361ed17..d257c168 100644
--- a/lib/interpolate.c
+++ b/lib/interpolate.c
@@ -284,6 +284,10 @@ interpolate_neighbors_on_thread(void *in_prm)
             case GAL_INTERPOLATE_NEIGHBORS_FUNC_MAX:
               value=gal_statistics_maximum(tnear); break;
               break;
+            case GAL_INTERPOLATE_NEIGHBORS_FUNC_MEAN:
+              value=gal_statistics_mean(tnear); /* Out can be a diff. type */
+              value=gal_data_copy_to_new_type_free(value, tnear->type);
+              break;
             case GAL_INTERPOLATE_NEIGHBORS_FUNC_MEDIAN:
               value=gal_statistics_median(tnear, 1); break;
             default:



reply via email to

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