IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 28, 2014, 4:03:11 PM (12 years ago)
Author:
eugene
Message:

add option to measure map using medians not chisq

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapOps.c

    r37680 r37691  
    55
    66int dump_map_data (float *x, float *y, float *f, int Npts, char *filename);
     7int AstromOffsetMapFit_Chisq (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
     8int AstromOffsetMapFit_Median (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
    79
    810float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir) {
     
    6365}
    6466
     67int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
     68
     69  int status = AstromOffsetMapFit_Median (map, x, y, f, Npts, xdir);
     70  return status;
     71}
     72
    6573// given (x,y),value vector sets, choose the map that minimizes the difference between
    6674// the values and bilinear interpolation of the map
    67 int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
     75int AstromOffsetMapFit_Chisq (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
    6876
    6977  int i, j, ix, iy, jx, jy;
     
    361369}
    362370
     371// given (x,y),value vector sets, choose the map that minimizes the difference between
     372// the values and bilinear interpolation of the map
     373int AstromOffsetMapFit_Median (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
     374
     375  int i, ix, iy;
     376
     377  // choose to map direction:
     378  float **V = xdir ? map->dXv : map->dYv;
     379
     380  // measure clipped median in each bin
     381  VStatsType stats;
     382  stats.statmode = VSTATS_INNER_MEAN;
     383
     384  int Nx = map->Nx;
     385  int Ny = map->Ny;
     386  int Npix = Nx*Ny;
     387
     388  double **values;
     389  int    *Nvalue;
     390  ALLOCATE (Nvalue, int, Npix);
     391  ALLOCATE (values, double *, Npix);
     392  for (i = 0; i < Npix; i++) {
     393    ALLOCATE (values[i], double, Npts);
     394    Nvalue[i] = 0;
     395  }
     396
     397  // assign the points to the map cells
     398  for (i = 0; i < Npts; i++) {
     399
     400    // data value & weight for this point
     401    if (!isfinite(f[i])) continue;
     402
     403    // if (mask && (mask[i] & maskValue)) continue;
     404   
     405    // base coordinate offset for this point (x,y) relative to this map element (n,m)
     406    // double dx = psImageBinningGetRuffX (map->binning, x->data.F32[i]) - (n + 0.5);
     407    // double dy = psImageBinningGetRuffY (map->binning, y->data.F32[i]) - (m + 0.5);
     408
     409    // bin for this point
     410    ix = MAX(0, MIN(Nx, (int)(x[i] * map->dX)));
     411    iy = MAX(0, MIN(Ny, (int)(y[i] * map->dY)));
     412    int I = ix + Nx * iy;
     413
     414    int N = Nvalue[I];
     415    values[I][N] = f[i];
     416    Nvalue[I] ++;
     417  }   
     418
     419  for (ix = 0; ix < Nx; ix++) {
     420    for (iy = 0; iy < Ny; iy++) {
     421      int I = ix + Nx * iy;
     422      if (Nvalue[I] > 5) {
     423        vstats_getstats (values[I], NULL, NULL, Nvalue[I], &stats);
     424        V[ix][iy] = stats.mean;
     425      } else {
     426        V[ix][iy] = NAN;
     427      }
     428    }
     429  }
     430
     431  // XXX free someone?
     432  for (i = 0; i < Npix; i++) {
     433    free (values[i]);
     434  }   
     435  free (values);
     436  free (Nvalue);
     437
     438  return TRUE;
     439}
     440
    363441// this function repairs an image with NAN pixels (only valid for a small-scale map -- no robust mean)
    364442int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir) {
Note: See TracChangeset for help on using the changeset viewer.