IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 27, 2021, 11:14:16 AM (5 years ago)
Author:
eugene
Message:

add where option to vstats

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-dev-20210817/Ohana/src/opihi/cmd.data/vstats.c

    r38441 r41819  
    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;
     88      if (tvec) {
     89        // note the logical vector is 0 == bad (ignore)
     90        mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0);
     91      } else {
     92        mask[i] = 1;
     93      }
    6694      if (!finite (*X)) continue;
    6795      if (Ignore && (*X == IgnoreValue)) continue;
     
    7199    opihi_int *X = vec[0].elements.Int;
    72100    for (i = 0; i < vec[0].Nelements; i++, X++) {
    73       mask[i] = 1;
     101      if (tvec) {
     102        // note the logical vector is 0 == bad (ignore)
     103        mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0);
     104      } else {
     105        mask[i] = 1;
     106      }
    74107      if (!finite (*X)) continue;
    75108      if (Ignore && (*X == IgnoreValue)) continue;
Note: See TracChangeset for help on using the changeset viewer.