IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37680


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

debugging grid fitting; adding pretty print

Location:
branches/eam_branches/ipp-20140904/Ohana/src/libdvo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h

    r37664 r37680  
    6464  int Nmap;
    6565  AstromOffsetMap **map;
    66   int *IDtoSeq;
     66   int *imageIDtoTableSeq;
    6767  int MaxImageID;
    6868  int MaxTableID;
     
    174174void AstromOffsetTableFree(AstromOffsetTable *table);
    175175int AstromOffsetTableAddMapFromImage (AstromOffsetTable *table, Image *image);
     176void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename);
     177int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir);
    176178
    177179# endif
  • branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c

    r37575 r37680  
    116116
    117117  // generate the index and init values to -1
    118   ALLOCATE (table->IDtoSeq, int, MaxImageID + 1);
     118  ALLOCATE (table->imageIDtoTableSeq, int, MaxImageID + 1);
    119119  for (i = 0; i <= MaxImageID; i++) {
    120     table->IDtoSeq[i] = -1;
     120    table->imageIDtoTableSeq[i] = -1;
    121121  }
    122122
     
    124124  for (i = 0; i < Nmap; i++) {
    125125    int ImageID = map_disk[i].imageID;
    126     myAssert (table->IDtoSeq[ImageID] == -1, "oops, duplicate image IDs");
    127     table->IDtoSeq[ImageID] = i;
     126    myAssert (table->imageIDtoTableSeq[ImageID] == -1, "oops, duplicate image IDs");
     127    table->imageIDtoTableSeq[ImageID] = i;
    128128  }
    129129
  • 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
  • branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c

    r37664 r37680  
    66  // each of the maps so we can assign the map to the image.coords.offsetMap entry
    77
    8   // we have the lookup table of table->IDtoSeq to find the match by imageID
    9  
    10   // we are just going to assume that table->IDtoSeq is correct and complete
     8  // we have the lookup table of table->imageIDtoTableSeq to find the match by imageID
     9 
     10  // we are just going to assume that table->imageIDtoTableSeq is correct and complete
    1111  off_t i;
    1212  for (i = 0; i < Nimages; i++) {
     
    1515    if (imageID > table->MaxImageID) continue;
    1616   
    17     int seq = table->IDtoSeq[imageID];
     17    int seq = table->imageIDtoTableSeq[imageID];
    1818    if (seq < 0) continue;
    1919    if (seq >= table->Nmap) continue; // this one is probably not valid, right?
     
    8383    FREE (table->map[i][0].dYv);
    8484  }
    85   FREE (table->IDtoSeq);
     85  FREE (table->imageIDtoTableSeq);
    8686  FREE (table->map);
    8787}
     
    101101    int oldMaxID = table->MaxImageID;
    102102    table->MaxImageID = image->imageID;
    103     REALLOCATE (table->IDtoSeq, int, table->MaxImageID + 1);
     103    REALLOCATE (table->imageIDtoTableSeq, int, table->MaxImageID + 1);
    104104    for (i = oldMaxID + 1; i < table->MaxImageID + 1; i++) {
    105       table->IDtoSeq[i] = -1;
    106     }
    107   }
    108   myAssert (table->IDtoSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision");
    109   table->IDtoSeq[image->imageID] = Nmap;
     105      table->imageIDtoTableSeq[i] = -1;
     106    }
     107  }
     108  int seq = table->imageIDtoTableSeq[image->imageID];
     109  if (seq != -1) {
     110    // already assigned (but not used)
     111    // XXX this is probably wrong : I need to mark failed maps so they are not saved.
     112    image[0].coords.offsetMap = table->map[seq];   
     113    return TRUE;
     114  }
     115
     116  myAssert (table->imageIDtoTableSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision");
     117  table->imageIDtoTableSeq[image->imageID] = Nmap;
    110118 
    111119  table->map[Nmap] = AstromOffsetMapInit (Nx, Ny);
     
    129137  REALLOCATE (table->map, AstromOffsetMap *, table->Nmap);
    130138
    131   // find the imageID and update the IDtoSeq allocation if needed
     139  // find the imageID and update the imageIDtoTableSeq allocation if needed
    132140  off_t i;
    133141  if (image->imageID > table->MaxImageID) {
    134142    int oldMaxID = table->MaxImageID;
    135143    table->MaxImageID = image->imageID;
    136     REALLOCATE (table->IDtoSeq, int, table->MaxImageID + 1);
     144    REALLOCATE (table->imageIDtoTableSeq, int, table->MaxImageID + 1);
    137145    for (i = oldMaxID + 1; i < table->MaxImageID + 1; i++) {
    138       table->IDtoSeq[i] = -1;
    139     }
    140   }
    141   myAssert (table->IDtoSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision");
    142   table->IDtoSeq[image->imageID] = Nmap;
     146      table->imageIDtoTableSeq[i] = -1;
     147    }
     148  }
     149  myAssert (table->imageIDtoTableSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision");
     150  table->imageIDtoTableSeq[image->imageID] = Nmap;
    143151 
    144152  table->map[Nmap] = image[0].coords.offsetMap;
     
    158166
    159167  // generate the index and init values to -1
    160   ALLOCATE (table->IDtoSeq, int, 1);
    161   table->IDtoSeq[0] = -1;
     168  ALLOCATE (table->imageIDtoTableSeq, int, 1);
     169  table->imageIDtoTableSeq[0] = -1;
    162170
    163171  return table;
    164172}
     173
     174void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename) {
     175
     176  FILE *f = stderr;
     177  if (strcasecmp(filename, "stderr") && strcasecmp(filename, "stdout")) {
     178    f = fopen (filename, "w");
     179    if (!f) {
     180      fprintf (stderr, "failed to open output file %s\n", filename);
     181    }
     182  }
     183
     184  fprintf (f, "imageID: %d, tableID: %d (dX: %f, dY: %f)\n", map->imageID, map->tableID, map->dX, map->dY);
     185  int ix, iy;
     186  fprintf (f, "dXv map:\n");
     187  for (ix = 0; ix < map->Nx; ix++) {
     188    for (iy = 0; iy < map->Ny; iy++) {
     189      fprintf (f, "%9.5f ", map->dXv[ix][iy]);
     190    }
     191    fprintf (f, "\n");
     192  }
     193  fprintf (f, "dYv map:\n");
     194  for (ix = 0; ix < map->Nx; ix++) {
     195    for (iy = 0; iy < map->Ny; iy++) {
     196      fprintf (f, "%9.5f ", map->dYv[ix][iy]);
     197    }
     198    fprintf (f, "\n");
     199  }
     200  if (f != stderr) fclose (f);
     201  return;
     202}
Note: See TracChangeset for help on using the changeset viewer.