IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 23, 2016, 12:26:55 PM (10 years ago)
Author:
eugene
Message:

finish code to repair warps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro/src/RepairWarpMeasures.c

    r39471 r39474  
    99  myAssert (!catalog->Nmeasure || catalog->measure, "programming error");
    1010
     11  int NfixChipID = 0, NfixStackID = 0, NfixWarpID = 0, NfixWarpImageID = 0, NmissWarp = 0, NmissStack = 0, NbadWarp = 0;
     12
     13  int onePercent = catalog->Nmeasure / 100;
     14
    1115  for (off_t j = 0; j < catalog->Nmeasure; j++) {
     16    if (j % onePercent == 0) fprintf (stderr, ".");
     17
    1218    Measure *measure = &catalog->measure[j];
    1319
    14     // we are only going to repair warp detections
    15     if (!isGPC1warp(measure->photcode))  {
    16       // XXX fix extID
     20    // repair extID for non-warps:
     21    if (isGPC1chip(measure->photcode))  {
     22      double mjd = ohana_sec_to_mjd (measure->t);
     23      int ccdnum = measure->photcode % 100;
     24      uint64_t extID = CreatePSPSDetectionID (mjd, ccdnum, measure->detID);
     25      if (extID != measure->extID) {
     26        measure->extID = extID;
     27        NfixChipID ++;
     28      }
    1729      continue;
    1830    }
     31
     32    // repair extID for non-warps:
     33    if (isGPC1stack(measure->photcode))  {
     34      int im = getImageByID (measure->imageID);
     35      if (im < 0) {
     36        if (NmissStack < 10) fprintf (stderr, "missing stack exposure: %f %f : %d %d\n", measure->R, measure->D, measure->imageID, measure->photcode);
     37        NmissStack ++;
     38        continue;
     39      }
     40      uint64_t extID = CreatePSPSStackDetectionID (35, image[im].externID, measure->detID);
     41      if (extID != measure->extID) {
     42        measure->extID = extID;
     43        NfixStackID ++;
     44      }
     45      continue;
     46    }
     47
     48    // we are only going to repair warp detections
     49    if (!isGPC1warp(measure->photcode)) continue;
    1950
    2051    // get the associated average value:
     
    2354
    2455    // double-check for consistency
    25     myAssert (average->objID == measure->objID, "mismatch");
     56    myAssert (average->objID == measure->objID, "objID mismatch: %f %f : %d %d\n", average->R, average->D, average->objID, measure->objID);
     57
     58    // warp coordinates to confirm warp
     59    double X = measure->Xccd;
     60    double Y = measure->Yccd;
    2661
    2762    // check if this detection is far from its correct location
     
    3974
    4075    // skip detections which are within a small distance of the expected location
     76    // NOTE: this actually works surprisingly well near the pole
    4177    double dPos = hypot(dR,dD);
    42     if (dPos < 2.0) continue;
    43 
    44     // warp coordinates to confirm warp
    45     double X = measure->Xccd;
    46     double Y = measure->Yccd;
     78    if (dPos < 2.0) {
     79      int im = getImageByID (measure->imageID);
     80      uint64_t extID = CreatePSPSStackDetectionID (34, image[im].externID, measure->detID);
     81      if (extID != measure->extID) {
     82        measure->extID = extID;
     83        NfixWarpID ++;
     84      }
     85      continue;
     86    }
    4787
    4888    // find the corrected warp ID:
    49     int warpID = GetWarpID (image, measure->t, measure->photcode, Rave, Dave, X, Y);
    50     myAssert (warpID >= 0, "error finding match");
     89    int warpSeq = GetWarpSeq (image, measure->t, measure->photcode, Rave, Dave, X, Y);
     90    if (warpSeq < 0) {
     91      if (NmissWarp < 10) fprintf (stderr, "missing warp exposure: %f %f : %d %d\n", Rave, Dave, measure->t, measure->photcode);
     92      NmissWarp ++;
     93      continue;
     94    }
    5195
    5296    // assert on coords being TAN?
    53     Coords *imcoords = &image[warpID].coords;
     97    Coords *imcoords = &image[warpSeq].coords;
    5498
    5599    double Rnew, Dnew;
     
    63107    double dDnew = 3600.0*(Dnew - Dave);
    64108
    65     // skip detections which are within a small distance of the expected location
     109    // detections should now be repaired; fail if not
    66110    dPos = hypot(dRnew,dDnew);
    67     if (dPos > 2.0) {
    68       // complain. abort?
    69       fprintf (stderr, "measurement still far from average location\n");
    70       abort();
     111    if (dPos > 5.0) {
     112      fprintf (stderr, "measurement still far from average location: %f %f vs %f %f : %d %d\n", Rave, Dave, Rnew, Dnew, measure->t, measure->photcode);
     113      NbadWarp ++;
    71114    }
    72115
     116    measure->imageID = image[warpSeq].imageID;
    73117    measure->R = Rnew;
    74118    measure->D = Dnew;
    75119
    76     // XXX fix extID
     120    uint64_t extID = CreatePSPSStackDetectionID (34, image[warpSeq].externID, measure->detID);
     121    if (extID != measure->extID) {
     122      measure->extID = extID;
     123      NfixWarpID ++;
     124    }
     125    NfixWarpImageID ++;
    77126  }
     127
     128  fprintf (stderr, "\n");
     129  fprintf (stderr, "repaired %s : warp image ID %d : ext ID chip %d stack %d warp %d : missed warp %d stack %d : bad warp: %d\n", catalog->filename, NfixWarpImageID, NfixChipID, NfixStackID, NfixWarpID, NmissWarp, NmissStack, NbadWarp);
     130
    78131  return (TRUE);
    79132}
Note: See TracChangeset for help on using the changeset viewer.