IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 4, 2021, 6:02:11 PM (5 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-dev-20210817 (add chebyshev, add fit2d_full, add inner_fraction to medimage, change dvoImageOverlap test to CERSTD)

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/opihi/cmd.data/vstats.c

    r38441 r41891  
    4848  }
    4949
    50   if (argc != 2) {
    51     gprint (GP_ERR, "USAGE: vstat (vector) [-ignore value] [-q] [-quiet] [-iter Niter] [-sigma-clip Nsigma]\n");
     50  int valid = (argc == 2);
     51  valid |= (argc > 3) && !strcmp (argv[2], "where");
     52  if (!valid) {
     53    gprint (GP_ERR, "USAGE: vstat (vector) [-ignore value] [-q] [-quiet] [-iter Niter] [-sigma-clip Nsigma] [where (logical expression)]\n");
    5254    gprint (GP_ERR, "  default is 1 iteration without sigma clipping or 3 with sigma clipping\n");
    5355    return (FALSE);
     
    5860  /* we need two passes, one for max, min, mean, sum, one for median, stdev, etc */
    5961
    60   // set a good / bad mask
     62  // tvec is used for logical test (truth vector)
     63  Vector *tvec = NULL;
     64  if (argc > 3) {
     65    int size;
     66    char *out = dvomath (argc - 3, &argv[3], &size, 1);
     67    if (out == NULL) {
     68      print_error ();
     69      return FALSE;
     70    }
     71    if ((tvec = SelectVector (out, OLDVECTOR, TRUE)) == NULL) {
     72      gprint (GP_ERR, " invalid logic result\n");
     73      DeleteNamedVector (out);
     74      free (out);
     75      return (FALSE);
     76    }
     77    if (tvec->Nelements != vec->Nelements) {
     78      gprint (GP_ERR, "logical vector does not match in length\n");
     79      return FALSE;
     80    }
     81  }
     82
     83  // set a good / bad mask (mask == 1 means 'bad')
    6184  ALLOCATE (mask, char, vec[0].Nelements);
    6285  if (vec[0].type == OPIHI_FLT) {
    6386    opihi_flt *X = vec[0].elements.Flt;
    6487    for (i = 0; i < vec[0].Nelements; i++, X++) {
    65       mask[i] = 1;
    66       if (!finite (*X)) continue;
    67       if (Ignore && (*X == IgnoreValue)) continue;
    68       mask[i] = 0;
     88      mask[i] = 0; // do not mask unless we have a reason below
     89      if (tvec) {
     90        // note the logical vector is 0 == bad (ignore) while mask[i] has the opposite sense (0 is good)
     91        mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0);
     92      }
     93      if (!finite (*X)) { mask[i] = 1; }
     94      if (Ignore && (*X == IgnoreValue)) { mask[i] = 1; }
    6995    }     
    7096  } else {
    7197    opihi_int *X = vec[0].elements.Int;
    7298    for (i = 0; i < vec[0].Nelements; i++, X++) {
    73       mask[i] = 1;
    74       if (!finite (*X)) continue;
    75       if (Ignore && (*X == IgnoreValue)) continue;
    76       mask[i] = 0;
     99      mask[i] = 0; // do not mask unless we have a reason below
     100      if (tvec) {
     101        // note the logical vector is 0 == bad (ignore) while mask[i] has the opposite sense (0 is good)
     102        mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0);
     103      }
     104      if (!finite (*X)) { mask[i] = 1; }
     105      if (Ignore && (*X == IgnoreValue)) { mask[i] = 1; }
    77106    }     
    78107  }
Note: See TracChangeset for help on using the changeset viewer.