IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42277


Ignore:
Timestamp:
Sep 2, 2022, 11:27:31 AM (4 years ago)
Author:
eugene
Message:

add option to saturate threshold result at end points

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/threshold.c

    r41341 r42277  
    11# include "data.h"
     2
     3int QUIET = FALSE;
     4
     5void _threshold_set_values (double value, int Nbin, double level) {
     6
     7  set_variable ("threshval", value);
     8  set_int_variable ("threshbin", Nbin);
     9  set_variable ("threshold", level);
     10
     11  if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n", level, Nbin, value);
     12  return;
     13}
    214
    315int threshold (int argc, char **argv) {
     
    618  Vector *vecx, *vecy;
    719
    8   int QUIET = FALSE;
    920  if ((N = get_argument (argc, argv, "-q"))) {
    1021    QUIET = TRUE;
     22    remove_argument (N, &argc, argv);
     23  }
     24
     25  int SATURATE = FALSE;
     26  if ((N = get_argument (argc, argv, "-saturate"))) {
     27    SATURATE = TRUE;
     28    remove_argument (N, &argc, argv);
     29  }
     30  if ((N = get_argument (argc, argv, "-sat"))) {
     31    SATURATE = TRUE;
    1132    remove_argument (N, &argc, argv);
    1233  }
     
    95116    // this algorithm assumes vecy[BinMax] > threshold, vecy[BinMin] < threshold
    96117    if (vecy[0].elements.Flt[BinMin] > value) {
    97       gprint (GP_ERR, "ERROR: all values above threshold\n");
    98       return FALSE;
     118      if (SATURATE) {
     119        _threshold_set_values (vecy[0].elements.Flt[BinMin], BinMin, vecx[0].elements.Flt[BinMin]);
     120        return TRUE;
     121      } else {
     122        gprint (GP_ERR, "ERROR: all values above threshold\n");
     123        _threshold_set_values (NAN, -1, NAN);
     124        return FALSE;
     125      }
    99126    }
    100127    if (vecy[0].elements.Flt[BinMax] < value) {
    101       gprint (GP_ERR, "ERROR: all values below threshold\n");
    102       return FALSE;
     128      if (SATURATE) {
     129        _threshold_set_values (vecy[0].elements.Flt[BinMax], BinMax, vecx[0].elements.Flt[BinMax]);
     130        return TRUE;
     131      } else {
     132        gprint (GP_ERR, "ERROR: all values below threshold\n");
     133        _threshold_set_values (NAN, -1, NAN);
     134        return FALSE;
     135      }
    103136    }
    104137    while (Nhi - Nlo > 10) {
     
    122155    // this algorithm assumes vecy[BinMin] > threshold, vecy[BinMax] < threshold
    123156    if (vecy[0].elements.Flt[BinMin] < value) {
    124       gprint (GP_ERR, "ERROR: all values below threshold\n");
    125       return FALSE;
     157      if (SATURATE) {
     158        _threshold_set_values (vecy[0].elements.Flt[BinMin], BinMin, vecx[0].elements.Flt[BinMin]);
     159        return TRUE;
     160      } else {
     161        gprint (GP_ERR, "ERROR: all values below threshold\n");
     162        _threshold_set_values (NAN, -1, NAN);
     163        return FALSE;
     164      }
    126165    }
    127166    if (vecy[0].elements.Flt[BinMax] > value) {
    128       gprint (GP_ERR, "ERROR: all values above threshold\n");
    129       return FALSE;
     167      if (SATURATE) {
     168        _threshold_set_values (vecy[0].elements.Flt[BinMax], BinMax, vecx[0].elements.Flt[BinMax]);
     169        return TRUE;
     170      } else {
     171        gprint (GP_ERR, "ERROR: all values above threshold\n");
     172        _threshold_set_values (NAN, -1, NAN);
     173        return FALSE;
     174      }
    130175    }
    131176    while (Nhi - Nlo > 10) {
     
    174219  }
    175220
    176   set_variable ("threshval", y1);
    177   set_int_variable ("threshbin", Nhi);
    178   set_variable ("threshold", Xvalue);
    179 
    180   if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n", Xvalue, Nhi, y1);
    181 
     221  _threshold_set_values (y1, Nhi, Xvalue);
    182222  return (TRUE);
    183223}
Note: See TracChangeset for help on using the changeset viewer.