IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30201


Ignore:
Timestamp:
Jan 5, 2011, 7:30:11 AM (15 years ago)
Author:
eugene
Message:

little improvements

Location:
branches/eam_branches/ipp-20101205/Ohana/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/libkapa/src/DrawRotString.c

    r10073 r30201  
    2727  unsigned char *bitmap;
    2828  char *currentname, basename[64];
    29   int i, dy, dx, N, X, Y, code;
     29  int i, dy, dx, N, X, Y, code, protect;
    3030  int dX, Xoff, dY, Yoff, YoffBase;
    3131  int currentsize, basesize;
     
    6363
    6464  code = FALSE;
     65  protect = FALSE;
    6566
    6667  YoffBase = Yoff;
     
    7071    if ((N < 0) || (N >= NROTCHARS)) continue;
    7172
     73    if (N == 39) { // single-quote
     74      protect = protect ? FALSE : TRUE;
     75    }
     76
    7277    /* check for special characters */
    73     if (!code) {
     78    if (!code && !protect) {
    7479      if (N == 94) {
    7580        SetRotFont (currentname, (int)(0.8*currentsize));
  • branches/eam_branches/ipp-20101205/Ohana/src/libkapa/src/PSRotFont.c

    r10073 r30201  
    77
    88  char *segment, basename[64], *currentname;
    9   int i, N, code;
     9  int i, N, code, protect;
    1010  int dX, dY, Xoff, Yoff, X, Y, Nseg, NSEG, YoffBase;
    1111  double cs, sn, fscale, currentscale;
     
    6060
    6161  code = FALSE;
     62  protect = FALSE;
     63
    6264  YoffBase = 0;
    6365  /* accumulate string segments with common state */
     
    6668    if ((N < 0) || (N >= NROTCHARS)) continue;
    6769
     70    if (N == 39) { // single-quote
     71      protect = protect ? FALSE : TRUE;
     72    }
     73
    6874    /* check for special characters */
    69     if (!code) {
     75    if (!code && !protect) {
    7076      /* superscript character (^) */
    7177      if (N == 94) {
  • branches/eam_branches/ipp-20101205/Ohana/src/libkapa/src/bDrawRotFont.c

    r29938 r30201  
    1414  unsigned char *bitmap;
    1515  char *currentname, basename[64];
    16   int i, dy, dx, N, X, Y, code;
     16  int i, dy, dx, N, X, Y, code, protect;
    1717  int dX, Xoff, dY, Yoff, YoffBase;
    1818  int currentsize, basesize;
     
    5353
    5454  code = FALSE;
     55  protect = FALSE;
    5556
    5657  YoffBase = Yoff;
     
    6061    if ((N < 0) || (N >= NROTCHARS)) continue;
    6162
     63    if (N == 39) { // single-quote
     64      protect = protect ? FALSE : TRUE;
     65    }
     66
    6267    /* check for special characters */
    63     if (!code) {
     68    if (!code && !protect) {
    6469      if (N == 94) {
    6570        SetRotFont (currentname, (int)(0.8*currentsize));
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/cmd.data/match2d.c

    r27817 r30201  
    11# include "data.h"
     2
    23int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2);
     4int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index);
    35
    46// match2d (X1) (Y1) (X2) (Y2) (Radius) [-index1 (index1)] [-index2 (index2)] [-nomatch1 nomatch1] [-nomatch2 nomatch2]
     
    68int match2d (int argc, char **argv) {
    79 
    8   int N;
     10  int N, CLOSEST;
    911  double Radius;
    1012  char *endptr;
     
    1214  Vector *index1, *index2;
    1315
     16  CLOSEST = FALSE;
     17  if ((N = get_argument (argc, argv, "-closest"))) {
     18    remove_argument (N, &argc, argv);
     19    CLOSEST = TRUE;
     20  }
     21
    1422  if ((N = get_argument (argc, argv, "-index1"))) {
    1523    remove_argument (N, &argc, argv);
     
    3038  if (argc != 6) {
    3139    gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n");
    32     // gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n");
    33     // gprint (GP_ERR, "  if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n");
    34     // gprint (GP_ERR, "    with either the index of the match or a value of -1 for non-matches\n");
    35     return (FALSE);
    36   }
     40    gprint (GP_ERR, "  if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n");
     41    gprint (GP_ERR, "    with either the index of the match or a value of -1 for non-matches\n");
     42    return (FALSE);
     43  }
     44
     45  /*
     46    we have two modes of operation: 
     47
     48    without -closest, we are finding all matched pairs within the match radius.  in this
     49    case, the two index vectors have the same length, one entry per matched pair.
     50    x1[index1],y1[index1] matches to x2[index2],y2[index2].
     51
     52    with -closest selected, we are finding the closest element of set 1 to each of set 2
     53    and vice versa.  in this case, index1 is always the same length as x1,y1, while index2
     54    is the same lengths as x2,y2.  x2[index1],y2[index1] matches x1,y1 while
     55    x1[index2],y1[index2] matches x2,y2
     56
     57   */
    3758
    3859  if ((X1vec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);   
     
    6182  }
    6283
    63   find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2);
     84  if (CLOSEST) {
     85      find_matches2d_closest (X1vec, Y1vec, X2vec, Y2vec, Radius, index1);
     86      find_matches2d_closest (X2vec, Y2vec, X1vec, Y1vec, Radius, index2);
     87  } else {
     88      find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2);
     89  }
    6490
    6591  return (TRUE);
     
    132158  return (TRUE);
    133159}
     160
     161// find the elements of X2,Y2 which are closest to each element of X1,Y1 (-1 if no match)
     162int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index) {
     163 
     164  off_t i, j, Jmin, Ji, I, J, *N1, *N2, NMATCH;
     165  double dX, dY, dR, Radius2, Rmin;
     166
     167  NMATCH = X1->Nelements;
     168  ResetVector (index, OPIHI_INT, NMATCH);
     169
     170  ALLOCATE (N1, off_t, X1->Nelements);
     171  ALLOCATE (N2, off_t, X2->Nelements);
     172
     173  for (i = 0; i < X1->Nelements; i++) { N1[i] = i; }
     174  for (i = 0; i < X2->Nelements; i++) { N2[i] = i; }
     175
     176  sort_coords_indexonly (X1->elements.Flt, Y1->elements.Flt, N1, X1->Nelements);
     177  sort_coords_indexonly (X2->elements.Flt, Y2->elements.Flt, N2, X2->Nelements);
     178
     179  Radius2 = Radius*Radius;
     180
     181  // find the closest entry in list 2 to the current entry in list 1:
     182  for (i = j = 0; (i < X1->Nelements) && (j < X2->Nelements);) {
     183    I = N1[i];
     184    J = N2[j];
     185
     186    dX = X1->elements.Flt[I] - X2->elements.Flt[J];
     187
     188    if (dX <= -1.02*Radius) {
     189      // no match in list 2 to this entry
     190      index->elements.Int[I] = -1;
     191      i++;
     192      continue;
     193    }
     194    if (dX >= +1.02*Radius) { j++; continue; }
     195
     196    // look for closest matches of list2() to list1(i)
     197    Jmin = -1;
     198    Rmin = Radius2;
     199    for (Ji = j; (dX > -1.02*Radius) && (Ji < X2->Nelements); Ji++) {
     200      J = N2[Ji];
     201      dX = X1->elements.Flt[I] - X2->elements.Flt[J];
     202      dY = Y1->elements.Flt[I] - Y2->elements.Flt[J];
     203      dR = dX*dX + dY*dY;
     204      if (dR > Radius2) continue;
     205      if (dR < Rmin) {
     206        Rmin = dR;
     207        Jmin  = J;
     208      }
     209    }
     210
     211    // no match in list 2 to this entry
     212    if (Jmin == -1) {
     213      index->elements.Int[I] = -1;
     214      i++;
     215      continue;
     216    }
     217    index->elements.Int[I] = Jmin;
     218    i++;
     219  }
     220  index->Nelements = NMATCH;
     221
     222  free (N1);
     223  free (N2);
     224
     225  return (TRUE);
     226}
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/cmd.data/vstats.c

    r21508 r30201  
    33int vstats (int argc, char **argv) {
    44 
    5   int i, N;
    6   double max, min, sum, var, dvar, mean, stdev;
    7   float IgnoreValue;
     5  int i, iter, N, Nbin, Niter;
     6  double max, min, pmin, pmax, sum, var, dvar, mean, stdev;
     7  float IgnoreValue, Nsigma;
    88  int Ignore, Quiet;
    99
    10   int *Nval, bin, Nmode, Nmed;
    11   double dx, mode, median;
     10  int *Nval, bin, Nmode, Nmed, Nused;
     11  double dx, mode, median, threshold;
    1212  Vector *vec;
     13  char *mask = NULL;
    1314
    1415  IgnoreValue = 0;
     
    2122  }
    2223
     24  Niter = 1;
     25  Nsigma = 3.0;
     26
     27  if ((N = get_argument (argc, argv, "-sigma-clip"))) {
     28    remove_argument (N, &argc, argv);
     29    Nsigma = atof(argv[N]);
     30    Niter = 3;
     31    remove_argument (N, &argc, argv);
     32  }
     33
     34  if ((N = get_argument (argc, argv, "-iter"))) {
     35    remove_argument (N, &argc, argv);
     36    Niter = atoi(argv[N]);
     37    remove_argument (N, &argc, argv);
     38  }
     39
    2340  Quiet = FALSE;
    2441  if ((N = get_argument (argc, argv, "-q"))) {
     
    3249
    3350  if (argc != 2) {
    34     gprint (GP_ERR, "USAGE: vstat (vector)\n");
     51    gprint (GP_ERR, "USAGE: vstat (vector) [-ignore value] [-q] [-quiet] [-iter Niter] [-sigma-clip Nsigma]\n");
     52    gprint (GP_ERR, "  default is 1 iteration without sigma clipping or 3 with sigma clipping\n");
    3553    return (FALSE);
    3654  }
     
    3957
    4058  /* we need two passes, one for max, min, mean, sum, one for median, stdev, etc */
     59
     60  // set a good / bad mask
     61  ALLOCATE (mask, char, vec[0].Nelements);
     62  if (vec[0].type == OPIHI_FLT) {
     63    opihi_flt *X = vec[0].elements.Flt;
     64    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;
     69    }     
     70  } else {
     71    opihi_int *X = vec[0].elements.Int;
     72    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;
     77    }     
     78  }
    4179
    4280  /* calculate max, min, mean, sum, npix */
     
    4785    opihi_flt *X = vec[0].elements.Flt;
    4886    for (i = 0; i < vec[0].Nelements; i++, X++) {
    49       if (!finite (*X)) continue;
    50       if (Ignore && (*X == IgnoreValue)) continue;
     87      if (mask[i]) continue;
    5188      max = MAX (*X, max);
    5289      min = MIN (*X, min);
     
    5794    opihi_int *X = vec[0].elements.Int;
    5895    for (i = 0; i < vec[0].Nelements; i++, X++) {
    59       if (!finite (*X)) continue;
    60       if (Ignore && (*X == IgnoreValue)) continue;
     96      if (mask[i]) continue;
    6197      max = MAX (*X, max);
    6298      min = MIN (*X, min);
     
    67103  mean = sum / N;
    68104
    69   /* calculate median and mode with resolution of (max - min) / 1000 */
    70   dx = (max - min) / 1000;
    71   if (dx == 0) {
    72     median = mode = min;
    73     stdev = 0.0;
    74     goto skip;
    75   }
    76 
    77   ALLOCATE (Nval, int, 1002);
    78   bzero (Nval, 1000*sizeof(int));
    79   var = 0;
    80   if (vec[0].type == OPIHI_FLT) {
    81     opihi_flt *X = vec[0].elements.Flt;
    82     for (i = 0; i < vec[0].Nelements; i++, X++) {
    83       if (!finite (*X)) continue;
    84       if (Ignore && (*X == IgnoreValue)) continue;
    85       bin = MAX (0, MIN (1000, (*X - min) / dx));
    86       Nval[bin] ++;
    87       dvar = (*X - mean);
    88       var += dvar*dvar;
    89     }     
    90   } else {
    91     opihi_int *X = vec[0].elements.Int;
    92     for (i = 0; i < vec[0].Nelements; i++, X++) {
    93       if (!finite (*X)) continue;
    94       if (Ignore && (*X == IgnoreValue)) continue;
    95       bin = MAX (0, MIN (1000, (*X - min) / dx));
    96       Nval[bin] ++;
    97       dvar = (*X - mean);
    98       var += dvar*dvar;
    99     }     
    100   }
    101   stdev = sqrt (var / N);
    102 
    103   Nmode = 0;
    104   mode = Nval[Nmode];
    105   median = 0;
    106   Nmed = -1;
    107   for (i = 0; i < 1001; i++) {
    108     if (Nmed == -1) {
    109       median += Nval[i];
    110       if (median >= N / 2.0) {
    111         Nmed = i;
    112         median = i * dx + min;
     105  // we do Niter passes; on each pass, we exclude entries > Nsigma from the median
     106  pmin = min;
     107  pmax = max;
     108
     109  for (iter = 0; iter < Niter; iter ++) {
     110
     111    // reduce Nbin after the first iteration?
     112    Nbin = 1000;
     113
     114    /* calculate median and mode with resolution of (max - min) / 1000 */
     115    dx = (pmax - pmin) / Nbin;
     116    if (dx == 0) {
     117      median = mode = min;
     118      stdev = 0.0;
     119      goto skip;
     120    }
     121
     122    ALLOCATE (Nval, int, Nbin + 2);
     123    bzero (Nval, Nbin*sizeof(int));
     124    var = 0;
     125    if (vec[0].type == OPIHI_FLT) {
     126      opihi_flt *X = vec[0].elements.Flt;
     127      for (i = 0; i < vec[0].Nelements; i++, X++) {
     128        if (mask[i]) continue;
     129        bin = MAX (0, MIN (Nbin, (*X - pmin) / dx));
     130        Nval[bin] ++;
     131        dvar = (*X - mean);
     132        var += dvar*dvar;
     133      }     
     134    } else {
     135      opihi_int *X = vec[0].elements.Int;
     136      for (i = 0; i < vec[0].Nelements; i++, X++) {
     137        if (mask[i]) continue;
     138        bin = MAX (0, MIN (Nbin, (*X - pmin) / dx));
     139        Nval[bin] ++;
     140        dvar = (*X - mean);
     141        var += dvar*dvar;
     142      }     
     143    }
     144    stdev = sqrt (var / N);
     145
     146    Nmode = 0;
     147    mode = Nval[Nmode];
     148    median = 0;
     149    Nmed = -1;
     150    for (i = 0; i < Nbin + 1; i++) {
     151      if (Nmed == -1) {
     152        median += Nval[i];
     153        if (median >= N / 2.0) {
     154          Nmed = i;
     155          median = i * dx + pmin;
     156        }
    113157      }
    114     }
    115     if (mode < Nval[i]) {
    116       Nmode = i;
    117       mode = Nval[Nmode];
    118     }
    119   }
    120   mode = Nmode * dx + min;
    121   free (Nval);
     158      if (mode < Nval[i]) {
     159        Nmode = i;
     160        mode = Nval[Nmode];
     161      }
     162    }
     163    mode = Nmode * dx + pmin;
     164    free (Nval);
     165
     166    threshold = Nsigma * stdev;
     167
     168    // we are going to do another pass: mark the entries to skip
     169    pmin = max;
     170    pmax = min;
     171    if (iter < Niter - 1) {
     172      if (vec[0].type == OPIHI_FLT) {
     173        opihi_flt *X = vec[0].elements.Flt;
     174        for (i = 0; i < vec[0].Nelements; i++, X++) {
     175          if (mask[i]) continue;
     176          if (fabs(*X - median) > threshold) {
     177            mask[i] = 1;
     178          } else {
     179            pmin = MIN (*X, pmin);
     180            pmax = MAX (*X, pmax);
     181          }     
     182        }
     183      } else {
     184        opihi_int *X = vec[0].elements.Int;
     185        for (i = 0; i < vec[0].Nelements; i++, X++) {
     186          if (mask[i]) continue;
     187          if (fabs(*X - median) > threshold) {
     188            mask[i] = 1;
     189          } else {
     190            pmin = MIN (*X, pmin);
     191            pmax = MAX (*X, pmax);
     192          }
     193        }     
     194      }
     195    }
     196    // gprint (GP_ERR, "iter %d, mean: %g, stdev: %g, min: %g, max: %g, median: %g, mode: %g, Npts: %d\n",
     197    // iter, mean, stdev, min, max, median, mode, N);
     198  }
     199
     200  Nused = 0;
     201  for (i = 0; i < vec[0].Nelements; i++) {
     202    if (mask[i]) continue;
     203    Nused ++;
     204  }
    122205
    123206skip:
     207  FREE(mask);
     208
    124209  if (!Quiet) {
    125210    gprint (GP_ERR, "mean: %g, stdev: %g, min: %g, max: %g, median: %g, mode: %g, Npts: %d\n",
    126              mean, stdev, min, max, median, mode, N);
    127   }
    128 
     211            mean, stdev, min, max, median, mode, N);
     212  }
     213
     214  set_variable ("PMIN",      pmin);
     215  set_variable ("PMAX",      pmax);
    129216  set_variable ("MIN",      min);
    130217  set_variable ("MAX",      max);
     
    134221  set_variable ("TOTAL",    sum);
    135222  set_int_variable ("NPIX", N);
     223  set_int_variable ("NPTS", N);
     224  set_int_variable ("NUSED", Nused);
    136225  set_variable ("SIGMA",    stdev);
    137226  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.