IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 27, 2014, 5:06:54 AM (12 years ago)
Author:
eugene
Message:

debugging grid fitting; adding pretty print

File:
1 edited

Legend:

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

    r37674 r37680  
    295295  ALLOCATE (Empty, int, Nx*Ny);
    296296
     297  // find the max value
     298  double MaxPivot = 0.0;
     299  for (i = 0; i < Nx*Ny; i++) {
     300    MaxPivot = MAX(A[i][i], MaxPivot);
     301  }
     302
     303  // elements of A[i][j] are just the fractional weight of the number of input points to the pixel.
     304  // any pixels which have < 5% contribution are not very well constrained.  NAN them for now...
     305  double MinPivot = 0.05 * MaxPivot;
    297306  for (i = 0; i < Nx*Ny; i++) {
    298307    Empty[i] = 0;
    299     if (fabs(A[i][i]) < 1.e-2) {
     308    if (fabs(A[i][i]) < MinPivot) {
    300309      Empty[i] = 1;
    301310      for (j = 0; j < Nx*Ny; j++) {
     
    352361}
    353362
     363// this function repairs an image with NAN pixels (only valid for a small-scale map -- no robust mean)
     364int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir) {
     365
     366  // we are going to repair the image by:
     367  // 1) finding NAN pixels
     368  // 2) if any of the neighbors are valid,
     369  //    replace with the mean of the neighbors
     370  // 3) otherwise, replace with the image mean
     371
     372  int Nx = map->Nx;
     373  int Ny = map->Ny;
     374
     375  int ix, iy;
     376
     377  float **Vfix = NULL;
     378  ALLOCATE (Vfix, float *, Nx);
     379  for (ix = 0; ix < Nx; ix++) {
     380    ALLOCATE (Vfix[ix], float, Ny);
     381    for (iy = 0; iy < Ny; iy++) {
     382      Vfix[ix][iy] = NAN;
     383    }
     384  }
     385
     386  // find the global mean
     387  float mean = 0.0;
     388  float npix = 0.0;
     389
     390  for (ix = 0; ix < Nx; ix++) {
     391    for (iy = 0; iy < Ny; iy++) {
     392      float value = xdir ? map->dXv[ix][iy] : map->dYv[ix][iy];
     393      if (isnan(value)) continue;
     394      mean += value;
     395      npix += 1.0;
     396    }
     397  }
     398  mean /= npix;
     399
     400  // find the NAN pixels:
     401  for (ix = 0; ix < Nx; ix++) {
     402    for (iy = 0; iy < Ny; iy++) {
     403
     404      float value = xdir ? map->dXv[ix][iy] : map->dYv[ix][iy];
     405      if (!isnan(value)) {
     406        Vfix[ix][iy] = value;
     407        continue;
     408      }
     409
     410      // find mean of all possible neighbors
     411      float meanLocal = 0.0;
     412      float npixLocal = 0.0;
     413
     414      int jx, jy;
     415      for (jx = -1; jx <= +1; jx++) {
     416        int nx = ix + jx;
     417        if (nx < 0) continue;
     418        if (nx >= Nx) continue;
     419        for (jy = -1; jy <= +1; jy++) {
     420          int ny = iy + jy;
     421          if (ny < 0) continue;
     422          if (ny >= Ny) continue;
     423          float value = xdir ? map->dXv[nx][ny] : map->dYv[nx][ny];
     424          if (isnan(value)) continue;
     425
     426          meanLocal += value;
     427          npixLocal += 1.0;
     428        }
     429      }
     430      // if there are no valid (non-NAN) local pixels, use global mean
     431      meanLocal = (npixLocal > 0.0) ? meanLocal / npixLocal : mean;
     432      Vfix[ix][iy] = meanLocal;
     433    }
     434  }
     435   
     436  // replace the bad pixels:
     437  for (ix = 0; ix < Ny; ix++) {
     438    for (iy = 0; iy < Ny; iy++) {
     439      if (xdir) {
     440        map->dXv[ix][iy] = Vfix[ix][iy];
     441      } else {
     442        map->dYv[ix][iy] = Vfix[ix][iy];
     443      }
     444    }
     445  }
     446  for (ix = 0; ix < Nx; ix++) {
     447    free (Vfix[ix]);
     448  }
     449  free (Vfix);
     450
     451  return TRUE;
     452}
     453
    354454int dump_map_data (float *x, float *y, float *f, int Npts, char *filename) {
    355455
Note: See TracChangeset for help on using the changeset viewer.