IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 30, 2012, 1:46:12 PM (14 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-20120405

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r14181 r33963  
    33int dot (int argc, char **argv) {
    44 
    5   int kapa;
     5  int kapa, N;
    66  Graphdata graphmode;
    77  float x, y;
    88
    99  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
     10
     11  /* FracPositions uses coordinates of 0-1 relative to axis range */
     12  int FracPositions = FALSE;
     13  if ((N = get_argument (argc, argv, "-frac"))) {
     14    remove_argument (N, &argc, argv);
     15    FracPositions = TRUE;
     16  }
    1017
    1118  if (argc != 3) {
     
    1522  x = atof(argv[1]);
    1623  y = atof(argv[2]);
     24
     25  if (FracPositions) {
     26    x =  x * (graphmode.xmax - graphmode.xmin) + graphmode.xmin;
     27    y =  y * (graphmode.ymax - graphmode.ymin) + graphmode.ymin;
     28  }   
    1729
    1830  /* set point style and errorbar mode (these are NOT sticky) */
  • trunk/Ohana/src/opihi/cmd.data/gridify.c

    r31450 r33963  
    55  int i, Nx, Ny, Xb, Yb, Normalize, N;
    66  float Xmin, Xmax, dX, Ymin, Ymax, dY, initValue;
    7   float *buf, *val;
     7  float *buf, *val, *cnt;
    88  int *Nval;
    9   Buffer *bf;
    109  Vector *vx, *vy, *vz;
    1110  opihi_flt *x, *y, *z;
     11
     12  Buffer *bf = NULL;
     13  Buffer *ct = NULL;
    1214
    1315  Normalize = TRUE;
     
    1517    remove_argument (N, &argc, argv);
    1618    Normalize = FALSE;
     19    if ((ct = SelectBuffer (argv[N], ANYBUFFER, TRUE)) == NULL) return (FALSE);
     20    remove_argument (N, &argc, argv);
    1721  }
    1822
     
    2428  }
    2529
    26   if (argc != 11) {
    27     gprint (GP_ERR, "USAGE: gridify x y z buffer Xmin Xmax dX Ymin Ymax dY\n");
     30  Xmin = Xmax = dX = NAN;
     31  if ((N = get_argument (argc, argv, "-x"))) {
     32    remove_argument (N, &argc, argv);
     33    Xmin = atof (argv[N]);
     34    remove_argument (N, &argc, argv);
     35    Xmax = atof (argv[N]);
     36    remove_argument (N, &argc, argv);
     37    dX   = atof (argv[N]);
     38    remove_argument (N, &argc, argv);
     39  }   
     40
     41  Ymin = Ymax = dY = NAN;
     42  if ((N = get_argument (argc, argv, "-y"))) {
     43    remove_argument (N, &argc, argv);
     44    Ymin = atof (argv[N]);
     45    remove_argument (N, &argc, argv);
     46    Ymax = atof (argv[N]);
     47    remove_argument (N, &argc, argv);
     48    dY   = atof (argv[N]);
     49    remove_argument (N, &argc, argv);
     50  }   
     51
     52  if (argc != 5) {
     53    gprint (GP_ERR, "USAGE: gridify x y z buffer [-x Xmin Xmax dX] [-y Ymin Ymax dY] [-init-value value] [-raw]\n");
    2854    return (FALSE);
    2955  }
     
    4167  REQUIRE_VECTOR_FLT (vz, FALSE);
    4268
    43   Xmin = atof (argv[5]);
    44   Xmax = atof (argv[6]);
    45   dX   = atof (argv[7]);
     69  if (isnan(dX)) {
     70    Xmin = 0;
     71    Xmax = bf[0].matrix.Naxis[0];
     72    dX = 1;
     73  }
    4674
    47   Ymin = atof (argv[8]);
    48   Ymax = atof (argv[9]);
    49   dY   = atof (argv[10]);
     75  if (isnan(dY)) {
     76    Ymin = 0;
     77    Ymax = bf[0].matrix.Naxis[1];
     78    dY = 1;
     79  }
    5080
    51   Nx = (Xmax - Xmin) / dX + 1;
    52   Ny = (Ymax - Ymin) / dY + 1;
     81  Nx = (Xmax - Xmin) / dX;
     82  Ny = (Ymax - Ymin) / dY;
    5383 
    54   gfits_free_matrix (&bf[0].matrix);
    55   gfits_free_header (&bf[0].header);
    56   CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0);
    57   strcpy (bf[0].file, "(empty)");
     84  if ((Nx != bf[0].matrix.Naxis[0]) || (Ny != bf[0].matrix.Naxis[1])) {
     85    gfits_free_matrix (&bf[0].matrix);
     86    gfits_free_header (&bf[0].header);
     87    CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0);
     88    strcpy (bf[0].file, "(empty)");
     89  }
    5890
    5991  ALLOCATE (val, float, Nx*Ny);
     
    68100    Xb = (*x - Xmin) / dX;
    69101    Yb = (*y - Ymin) / dY;
     102    if (Xb < 0) continue;
     103    if (Yb < 0) continue;
    70104    if (Xb >= Nx) continue;
    71105    if (Yb >= Ny) continue;
     
    74108  }
    75109
     110  if (!Normalize) {
     111    gfits_free_matrix (&ct[0].matrix);
     112    gfits_free_header (&ct[0].header);
     113    CreateBuffer (ct, Nx, Ny, -32, 0.0, 1.0);
     114    strcpy (ct[0].file, "(empty)");
     115
     116    buf = (float *) bf[0].matrix.buffer;
     117    cnt = (float *) ct[0].matrix.buffer;
     118    for (i = 0; i < Nx*Ny; i++) {
     119      if (Nval[i] == 0) continue;
     120      buf[i] = val[i];
     121      cnt[i] = Nval[i];
     122    }
     123    free (val);
     124    free (Nval);
     125    return TRUE;
     126  }
     127
    76128  buf = (float *) bf[0].matrix.buffer;
    77129  for (i = 0; i < Nx*Ny; i++) {
    78130    buf[i] = initValue;
    79     if (Normalize) {
    80       if (Nval[i] == 0) {
    81         continue;
    82       }
    83       buf[i] = val[i] / Nval[i];
    84     } else {
    85       buf[i] = val[i];
    86     }
     131    if (Nval[i] == 0) continue;
     132    buf[i] = val[i] / Nval[i];
    87133  }
    88134
  • trunk/Ohana/src/opihi/cmd.data/match2d.c

    r30610 r33963  
    167167  NMATCH = X1->Nelements;
    168168  ResetVector (index, OPIHI_INT, NMATCH);
     169
     170  for (i = 0; i < index->Nelements; i++) { index->elements.Int[i] = -1; }
    169171
    170172  ALLOCATE (N1, off_t, X1->Nelements);
  • trunk/Ohana/src/opihi/cmd.data/threshold.c

    r33662 r33963  
    6969    x0 = isFltX ? vecx[0].elements.Flt[Nhi] : vecy[0].elements.Int[Nhi];
    7070    x1 = isFltX ? vecx[0].elements.Flt[Nhi+1]   : vecy[0].elements.Int[Nhi+1];
    71     Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0;
     71    if (y0 == y1) {
     72      Xvalue = 0.5*(x0 + x1);
     73    } else {
     74      Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0;
     75    }   
    7276  } else {
    7377    // interpolate to value:
     
    7680    x0 = isFltX ? vecx[0].elements.Flt[Nhi-1] : vecy[0].elements.Int[Nhi-1];
    7781    x1 = isFltX ? vecx[0].elements.Flt[Nhi]   : vecy[0].elements.Int[Nhi];
    78     Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0;
     82    if (y0 == y1) {
     83      Xvalue = 0.5*(x0 + x1);
     84    } else {
     85      Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0;
     86    }
    7987  }
    8088
  • trunk/Ohana/src/opihi/cmd.data/vgroup.c

    r25757 r33963  
    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  }
  • trunk/Ohana/src/opihi/cmd.data/vstats.c

    r32632 r33963  
    144144      }     
    145145    }
    146     stdev = sqrt (var / N);
     146    stdev = sqrt (var / (N - 1));
    147147
    148148    Nmode = 0;
  • trunk/Ohana/src/opihi/cmd.data/write_vectors.c

    r33662 r33963  
    2121  FITS = NULL;
    2222  if ((N = get_argument (argc, argv, "-fits"))) {
     23    if (format) {
     24      gprint (GP_ERR, "ERROR: do not mix -fits and -format\n");
     25      free (format);
     26      return (FALSE);
     27    }
    2328    remove_argument (N, &argc, argv);
    2429    FITS = strcreate (argv[N]);
    2530    remove_argument (N, &argc, argv);
     31  }
     32
     33  /* option generate a FITS output table */
     34  int CSV = FALSE;
     35  if ((N = get_argument (argc, argv, "-csv"))) {
     36    if (format) {
     37      gprint (GP_ERR, "ERROR: do not mix -csv and -format\n");
     38      free (format);
     39      return (FALSE);
     40    }
     41    if (FITS) {
     42      gprint (GP_ERR, "ERROR: do not mix -csv and -fits\n");
     43      free (FITS);
     44      return (FALSE);
     45    }
     46    remove_argument (N, &argc, argv);
     47    CSV = TRUE;
    2648  }
    2749
     
    3052    remove_argument (N, &argc, argv);
    3153    append = TRUE;
     54  }
     55
     56  int ADD_HEADER = FALSE;
     57  if ((N = get_argument (argc, argv, "-header"))) {
     58    remove_argument (N, &argc, argv);
     59    ADD_HEADER = TRUE;
    3260  }
    3361
     
    83111
    84112  /* default output format */
     113  if (ADD_HEADER) {
     114    for (j = 0; j < Nvec; j++) {
     115      if (CSV) {
     116        fprintf (f, "%s,", vec[j][0].name);
     117      } else {
     118        if (j == 0) fprintf (f, "# ");
     119        fprintf (f, "%s ", vec[j][0].name);
     120      }
     121    }
     122    fprintf (f, "\n");
     123  }
     124
     125  /* default output format */
    85126  if (format == (char *) NULL) {
    86127    for (i = 0; i < vec[0][0].Nelements; i++) {
    87128      for (j = 0; j < Nvec; j++) {
    88129        if (vec[j][0].type == OPIHI_FLT) {
    89           fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]);
     130          if (CSV) {
     131            fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]);
     132          } else {
     133            fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]);
     134          }
    90135        } else {
    91           fprintf (f, "%d ", vec[j][0].elements.Int[i]);
     136          if (CSV) {
     137            fprintf (f, "%d,", vec[j][0].elements.Int[i]);
     138          } else {
     139            fprintf (f, "%d ", vec[j][0].elements.Int[i]);
     140          }
    92141        }
    93142      }
Note: See TracChangeset for help on using the changeset viewer.