IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37684


Ignore:
Timestamp:
Nov 28, 2014, 7:02:38 AM (12 years ago)
Author:
eugene
Message:

fix issues with saving the tmp coords (and restoring after a failure)

Location:
branches/eam_branches/ipp-20140904/Ohana/src/relastro
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/Makefile

    r37665 r37684  
    6060$(SRC)/CoordOps.$(ARCH).o            \
    6161$(SRC)/extra.$(ARCH).o            \
    62 $(SRC)/FixProblemImages.$(ARCH).o    \
    6362$(SRC)/StarMaps.$(ARCH).o    \
    6463$(SRC)/high_speed_catalogs.$(ARCH).o  \
     
    125124$(SRC)/relastro_objects.$(ARCH).o    \
    126125$(SRC)/save_catalogs.$(ARCH).o       \
    127 $(SRC)/CoordOps.$(ARCH).o            \
    128126$(SRC)/extra.$(ARCH).o            \
    129127$(SRC)/high_speed_catalogs.$(ARCH).o  \
     
    141139$(SRC)/BrightCatalog.$(ARCH).o
    142140
    143 #$(SRC)/FitChip.$(ARCH).o             \
    144 #$(SRC)/FitMosaic.$(ARCH).o           \
    145 #$(SRC)/UpdateChips.$(ARCH).o         \
    146 #$(SRC)/UpdateMosaic.$(ARCH).o        \
    147 #$(SRC)/UpdateSimple.$(ARCH).o        \
    148 #$(SRC)/write_coords.$(ARCH).o        \
    149 #$(SRC)/FixProblemImages.$(ARCH).o    \
    150 #$(SRC)/StarMaps.$(ARCH).o    \
    151 
    152141$(RELASTRO_CLIENT): $(INC)/relastro.h
    153142$(BIN)/relastro_client.$(ARCH): $(RELASTRO_CLIENT)
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/include/relastro.h

    r37677 r37684  
    489489int relastroGetVisual(void);
    490490
    491 int FixProblemImages (SkyList *skylist);
    492491int *getCatlist (int *N, off_t im);
    493492
    494 void initCoords (void);
    495 void getOffsets (double *dPos, off_t *nPos, off_t N);
    496 void saveOffsets (double dPos, off_t nPos, off_t N);
    497 void setBadCoords (off_t N);
    498 int badCoords (off_t N);
    499 Coords *getCoords (off_t N);
    500 int saveCoords (Coords *coords, off_t N);
    501 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im);
     493void SaveCoords (Coords *tgt, Coords *src);
     494void RestoreCoords (Coords *tgt, Coords *src, Image *image);
    502495
    503496int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath);
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/FitChip.c

    r37681 r37684  
    1414
    1515  for (Niter = 0; Niter < IMFIT_CLIP_NITER; Niter ++) {
    16    
     16
    1717    // measure the scatter for the unmarked (good) measurements with dM < limit
    1818    // SIGMA_LIM here is redundant with ImageOps.c:915
     
    119119        lockUpdateChips ();
    120120        AstromOffsetTable *table = get_astrom_table ();
    121         AstromOffsetTableNewMap(table, order_use, image);
     121        AstromOffsetTableNewMap(table, order_use, order_use, image);
    122122        unlockUpdateChips ();
    123123      }
     124      // XXX Need to check / update the order of the map here.  if we already have a map, it might have been
     125      // allocated with too small arrays
     126      AstromOffsetMapSetOrder (image[0].coords.offsetMap, order_use, order_use, image);
     127      image[0].coords.offsetMap->keep = TRUE; // if we are trying or re-trying this map, we should keep it unless it fails
    124128      fit_map (image[0].coords.offsetMap, raw, ref, Nmatch);
    125129      image[0].coords.Npolyterms = -1;
     
    262266   L,M -> X,Y (polynomial transformation : WRP)
    263267
    264 Some details about this function:
    265 
    266 - the initial value of the clipping radius is set based on the distribution of the dR
    267   values for the bright sources.
    268 
    269 - NITER clipping passes are performed
    270 
    271 - the per-star astrometric errors are included in the fit.  The photcode table controls
    272   whether only the reported positional errors are used, or if the magnitudes errors are
    273   scaled to determine the error, and if there is a systematic floor for all sources.
    274 
    275 - input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
    276 
    277 - outlying detections are clipped in the iterative passes, but the clipped detections are
    278   not recorded
     268   Some details about this function:
     269
     270   - the initial value of the clipping radius is set based on the distribution of the dR
     271   values for the bright sources.
     272
     273   - NITER clipping passes are performed
     274
     275   - the per-star astrometric errors are included in the fit.  The photcode table controls
     276   whether only the reported positional errors are used, or if the magnitudes errors are
     277   scaled to determine the error, and if there is a systematic floor for all sources.
     278
     279   - input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
     280
     281   - outlying detections are clipped in the iterative passes, but the clipped detections are
     282   not recorded
    279283
    280284*/
     
    282286/* example using fit_apply() :
    283287
    284   f = fopen ("test3.dat", "w");
    285 
    286   // apply new coords to raw (X,Y -> L,M)
    287   for (i = 0; i < Nmatch; i++) {
    288     fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
    289     fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
    290     fprintf (f, "%f %f\n", L1, M1);
    291   }
    292   fclose (f);
     288   f = fopen ("test3.dat", "w");
     289
     290   // apply new coords to raw (X,Y -> L,M)
     291   for (i = 0; i < Nmatch; i++) {
     292   fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
     293   fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
     294   fprintf (f, "%f %f\n", L1, M1);
     295   }
     296   fclose (f);
    293297*/
    294298
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/ImageOps.c

    r37682 r37684  
    336336# endif
    337337
    338 /*
    339 Coords *getCoords (off_t meas, int cat) {
    340 
    341   off_t i;
    342 
    343   i = MeasureToImage[cat][meas];
    344   if (i == -1) return (NULL);
    345   return (&image[i].coords);
    346 }
    347 */
    348 
    349338float getColorBlue (off_t meas, int cat) {
    350339
     
    434423  Mosaic *mosaic;
    435424  Coords *moscoords, *imcoords;
    436 
    437   // check if this image is bad and should be skipped
    438   if (badCoords(im)) return;
    439425
    440426  // WRP images need to have an associated mosaic
     
    598584  int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
    599585  if (VERBOSE2 && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori);
    600   saveOffsets (dPos, nPos, im);
    601586
    602587  return;
     
    605590void printNcatTotal () {
    606591  fprintf (stderr, "NcatTotal: %d\n", NcatTotal);
    607 }
    608 
    609 // return StarData values for detections in the specified image, converting coordinates from the
    610 // chip positions: X,Y -> L,M -> P,Q -> R,D
    611 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
    612 
    613   off_t i, m, c, n;
    614   double X, Y, L, M, P, Q, R, D;
    615 
    616   Mosaic *mosaic;
    617   Coords *moscoords, *imcoords, *oldcoords;
    618 
    619   fprintf (stderr, "fix resetImageRaw wrt MeasureTiny\n");
    620   abort();
    621 
    622   // check if this image is bad and should be skipped
    623   if (!badCoords(im)) {
    624     fprintf (stderr, "ERROR: inconsistent result?");
    625     abort();
    626   }
    627 
    628   // replace the current coords with the old coords:
    629   oldcoords = getCoords (im);
    630   memcpy (&image[im].coords, oldcoords, sizeof(Coords));
    631 
    632   // WRP images need to have an associated mosaic
    633   moscoords = NULL;
    634   if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
    635     mosaic = getMosaicForImage (im);
    636     if (mosaic == NULL) return;  // if we cannot find the associated image, skip it
    637     moscoords = &mosaic[0].coords;
    638   }
    639   imcoords = &image[im].coords;
    640 
    641   for (i = 0; i < N_onImage[im]; i++) {
    642     m = ImageToMeasure[im][i];
    643     c = ImageToCatalog[im][i];
    644 
    645     // XXX unclear if this should use Measure or MeasureTiny; it is only called by FixProblemImages, which has not been updated
    646     Measure *measure = &catalog[c].measure[m];
    647 
    648     X = measure[0].Xccd;
    649     Y = measure[0].Yccd;
    650     if (USE_FIXED_PIXCOORDS) {
    651       if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
    652         float dX = measure[0].Xfix - measure[0].Xccd;
    653         float dY = measure[0].Yfix - measure[0].Yccd;
    654         if (hypot(dX,dY) < 2.0) {
    655           X = measure[0].Xfix;
    656           Y = measure[0].Yfix;
    657         }
    658       }
    659     }
    660     n = measure[0].averef;
    661 
    662     if (moscoords == NULL) {
    663       // this is a Simple image (not a mosaic)
    664       // note that for a Simple image, L,M = P,Q
    665       XY_to_LM (&L, &M, X, Y, imcoords);
    666       LM_to_RD (&R, &D, L, M, imcoords);
    667     } else {
    668       XY_to_LM (&L, &M, X, Y, imcoords);
    669       XY_to_LM (&P, &Q, L, M, moscoords);
    670       LM_to_RD (&R, &D, P, Q, moscoords);
    671     }
    672     measure[0].R = R;
    673     measure[0].D = D;
    674 
    675     float dRoff = dvoOffsetR(measure, &catalog[c].average[n]);
    676 
    677     if (dRoff > +180.0*3600.0) {
    678       // average on high end of boundary, move star up
    679       measure[0].R += 360.0;
    680       dRoff -= 360.0*3600.0;
    681     }
    682     if (dRoff < -180.0*3600.0) {
    683       measure[0].R -= 360.0;
    684       dRoff += 360.0*3600.0;
    685     }
    686   }
    687 
    688   return;
    689592}
    690593
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/UpdateChips.c

    r37677 r37684  
    3636  off_t i, Nraw, Nref, nFitAstr;
    3737  StarData *raw, *ref;
    38   Coords *oldCoords;
    3938  float dXpixSys, dYpixSys;
    4039  double *Ro, *Do;
     
    9695
    9796    // save these in case of failure
    98     saveCoords (&image[i].coords, i);
     97    Coords oldCoords;
     98    SaveCoords (&oldCoords, &image[i].coords);
     99
    99100    dXpixSys = image[i].dXpixSys;
    100101    dYpixSys = image[i].dYpixSys;
     
    106107      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name,  i,  Nraw, image[i].nstar);
    107108
    108       // restore status quo ante
    109       oldCoords = getCoords (i);
    110       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     109      // restore status quo ante (replace truMap with tmpMap)
     110      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    111111      image[i].dXpixSys = dXpixSys;
    112112      image[i].dYpixSys = dYpixSys;
     
    123123    if (!checkStarMap (i)) {
    124124      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
    125       // restore status quo ante
    126       oldCoords = getCoords (i);
    127       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     125
     126      // restore status quo ante (replace truMap with tmpMap)
     127      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    128128      image[i].dXpixSys = dXpixSys;
    129129      image[i].dYpixSys = dYpixSys;
     
    139139    }
    140140
    141     // apply the modified R,D back to the measures
     141    // Apply the modified coords back to the measure.R,D.  Note that raw.R,D, ref.L,M, etc
     142    // are all automatically updated in this block because they are re-generated from
     143    // image.coords on each pass.
    142144    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_MOSAIC);
    143145    if (USE_GALAXY_MODEL) {
     
    247249  off_t Nraw, Nref, nFitAstr;
    248250  StarData *raw, *ref;
    249   Coords *oldCoords;
    250251  float dXpixSys, dYpixSys;
    251252
     
    294295
    295296    // save these in case of failure
    296     saveCoords (&image[i].coords, i);
     297    Coords oldCoords;
     298    SaveCoords (&oldCoords, &image[i].coords);
    297299    dXpixSys = image[i].dXpixSys;
    298300    dYpixSys = image[i].dYpixSys;
     
    304306      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name,  i,  Nraw, image[i].nstar);
    305307
    306       // restore status quo ante
    307       oldCoords = getCoords (i);
    308       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     308      // restore status quo ante (replace truMap with tmpMap)
     309      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    309310      image[i].dXpixSys = dXpixSys;
    310311      image[i].dYpixSys = dYpixSys;
     
    321322    if (!checkStarMap (i)) {
    322323      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
    323       // restore status quo ante
    324       oldCoords = getCoords (i);
    325       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     324
     325      // restore status quo ante (replace truMap with tmpMap)
     326      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    326327      image[i].dXpixSys = dXpixSys;
    327328      image[i].dYpixSys = dYpixSys;
     
    522523}
    523524
     525// save the coords and offset map in src at tgt
     526void SaveCoords (Coords *tgt, Coords *src) {
     527  myAssert (tgt, "oops");
     528  myAssert (src, "oops");
     529  CopyCoords (tgt, src); // src retains a pointer to the AstromOffsetMap table, to be saved
     530  tgt->offsetMap = AstromOffsetMapCopy(src->offsetMap); // oldCoords now saves the old values in a new structure
     531}
     532
     533// restore the coords and offset map at tgt from src
     534void RestoreCoords (Coords *tgt, Coords *src, Image *image) {
     535
     536  AstromOffsetMap *truMap = tgt->offsetMap;
     537  AstromOffsetMap *tmpMap = src->offsetMap;
     538
     539  // copy the coords structure data first, then fix the offsetMap pointers
     540  CopyCoords (tgt, src);
     541
     542  // we want to keep the old solution, which is (maybe) a pointer to a stand-alone
     543  // map.  the image has a bad solution, but it is a pointer to the map in the I/O
     544  // table.  those values will be saved on exit.
     545
     546  if (!tmpMap && !truMap) return;
     547
     548  if (tmpMap && truMap) {
     549    AstromOffsetMapSetOrder (truMap, tmpMap->Nx, tmpMap->Ny, image);
     550    AstromOffsetMapCopyData (truMap, tmpMap);
     551    return;
     552  }
     553
     554  if (tmpMap && !truMap) {
     555    // is this even possible?
     556    lockUpdateChips ();
     557    AstromOffsetTable *table = get_astrom_table ();
     558    AstromOffsetTableNewMap(table, tmpMap->Nx, tmpMap->Ny, image);  // registers the map with the image
     559    unlockUpdateChips ();
     560    AstromOffsetMapCopyData (truMap, tmpMap);
     561    return;
     562  }
     563  if (!tmpMap && truMap) {
     564    truMap->keep = FALSE;
     565    return;
     566  }
     567  myAbort ("oops");
     568}
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/relastro_images.c

    r37658 r37684  
    2323  MARKTIME("load images: %f sec\n", dtime);
    2424
    25   initCoords();
    26 
    2725  /* load catalog data from region files : subselect high-quality measurements */
    28   // XXX pass in the image table
    29   // XXX who carries the image grid?
    3026
    3127  // photcodesKeep is used here to allow measurements from the images being calibrated
     
    119115  UpdateObjectOffsets (skylist, 0, NULL);
    120116
    121   // iterate over catalogs to make detection coordinates consistant
    122   // FixProblemImages (skylist);
    123 
    124117  if (!PARALLEL) {
    125118    // save the updated image parameters
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/relastro_parallel_images.c

    r37665 r37684  
    5656  SkyTableSetFilenames (sky, CATDIR, "cpt");
    5757  SkyList *skylist = SkyListByBounds (sky, -1, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    58 
    59   initCoords();
    6058
    6159  /* load catalog data from region files (hostID is 0 since we are not a client */
Note: See TracChangeset for help on using the changeset viewer.