IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 9, 2012, 2:07:40 PM (14 years ago)
Author:
eugene
Message:

add -min-time, -max-time to skycoverage; add several stats options to vgroup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120405/Ohana/src/opihi/cmd.data/vgroup.c

    r25757 r33737  
    11# include "data.h"
     2
     3enum {USE_MEDIAN, USE_COUNT, USE_SUM, USE_MEAN};
    24
    35int vgroup (int argc, char **argv) {
     
    2325  // }
    2426
     27  int mode = USE_MEDIAN;
     28  if ((N = get_argument (argc, argv, "-sum"))) {
     29    remove_argument (N, &argc, argv);
     30    mode = USE_SUM;
     31  }
     32  if ((N = get_argument (argc, argv, "-mean"))) {
     33    remove_argument (N, &argc, argv);
     34    mode = USE_MEAN;
     35  }
     36
     37  float binsize = NAN;
     38  if ((N = get_argument (argc, argv, "-binsize"))) {
     39    remove_argument (N, &argc, argv);
     40    binsize = atof(argv[N]);
     41    remove_argument (N, &argc, argv);
     42  }
     43
    2544  if (argc != 5) {
    26     gprint (GP_ERR, "USAGE: vbin <xin> <yin> <xout> <yout>\n");
     45    gprint (GP_ERR, "USAGE: vgroup <xin> <yin> <xout> <yout>\n");
    2746    gprint (GP_ERR, " group x,y values in bins defined by <xout>\n");
     47    gprint (GP_ERR, " by default, yout has the median of the associated input values\n");
     48    gprint (GP_ERR, " use -sum to add values in the bin\n");
     49    gprint (GP_ERR, " use <yin> = histogram count matching values\n");
     50    gprint (GP_ERR, " use -binsize to specify a fixed bin width (<xout> will define the bin center)\n");
    2851    return (FALSE);
    2952  }
    3053
    3154  if ((xin  = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    32   if ((yin  = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    3355  if ((xout = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    3456  if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE);
     57  yin = NULL;
     58
     59  // this should conflict with the -sum option...
     60  if (!strcmp(argv[2], "histogram")) {
     61    mode = USE_COUNT;
     62  } else {
     63    if ((yin  = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     64  }
    3565
    3666  // re-binning creates a float vector
     
    4171
    4272  for (i = 0; i < xout[0].Nelements - 1; i++) {
    43     xmin = xout[0].elements.Flt[i];
    44     xmax = xout[0].elements.Flt[i+1];
     73    if (isnan(binsize)) {
     74      xmin = xout[0].elements.Flt[i];
     75      xmax = xout[0].elements.Flt[i+1];
     76    } else {
     77      xmin = xout[0].elements.Flt[i] - 0.5*binsize;
     78      xmax = xout[0].elements.Flt[i] + 0.5*binsize;
     79    }
    4580
    4681    N = 0;
     
    4883      if (xin[0].elements.Flt[j] < xmin) continue;
    4984      if (xin[0].elements.Flt[j] > xmax) continue;
    50       values[N] = yin[0].elements.Flt[j];
     85      if (yin) {
     86        values[N] = yin[0].elements.Flt[j];
     87      }
    5188      N++;
    5289    }
    5390   
    54     dsort (values, N);
    55     if (N > 1) {
    56       sum = (N % 2) ? values[(int)(0.5*N)] : 0.5*(values[N/2] + values[N/2 + 1]);
    57     } else {
    58       sum = values[0];
     91    sum = NAN;
     92    switch (mode) {
     93      case USE_MEDIAN:
     94        dsort (values, N);
     95        if (N > 1) {
     96          sum = (N % 2) ? values[(int)(0.5*N)] : 0.5*(values[N/2] + values[N/2 + 1]);
     97        } else {
     98          sum = values[0];
     99        }
     100        break;
     101
     102      case USE_SUM:
     103        sum = 0.0;
     104        for (j = 0; j < N; j++) {
     105          sum += values[j];
     106        }
     107        break;
     108       
     109      case USE_COUNT:
     110        sum = N;
     111        break;
     112
     113      case USE_MEAN:
     114        sum = 0.0;
     115        for (j = 0; j < N; j++) {
     116          sum += values[j];
     117        }
     118        sum /= N;
     119        break;
    59120    }
    60 
    61     // measure the stat for this bin
    62     // sum = 0.0;
    63     // for (j = 0; j < N; j++) {
    64     //   sum += values[j];
    65     // }
    66     // sum /= N;
    67121    yout[0].elements.Flt[i] = sum;
    68122  }
Note: See TracChangeset for help on using the changeset viewer.