IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39600


Ignore:
Timestamp:
Jun 16, 2016, 4:55:58 PM (10 years ago)
Author:
eugene
Message:

for repair mode: do not save unless changes are made; make a backup for changed catalogs; add header metadata to record modifications

Location:
trunk/Ohana/src/relastro
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro/include/relastro.h

    r39580 r39600  
    244244} FrameCorrectionSet;
    245245
    246 
    247246typedef struct {
    248247  double *Rave;
     
    252251  int Nicrfobj;
    253252} ICRFobj;
     253
     254typedef struct {
     255  int NfixChipID;
     256  int NfixStackID;
     257  int NfixWarpID;
     258  int NfixWarpImageID;
     259  int NfixWarpCoord;
     260  int NmissWarp;
     261  int NmissStack;
     262  int NbadWarp;
     263  int NbadWarpTime;
     264  int NwarpNoImage;
     265} WarpRepairResult;
    254266
    255267# define ID_MEAS_OBJECT_HAS_2MASS ID_MEAS_POOR_PHOTOM
     
    802814
    803815int RepairWarps (SkyList *skylist, int hostID, char *hostpath);
    804 int RepairWarpMeasures (Catalog *catalog);
     816WarpRepairResult RepairWarpMeasures (Catalog *catalog);
    805817
    806818int FindWarpGroups (void);
  • trunk/Ohana/src/relastro/src/RepairWarpMeasures.c

    r39580 r39600  
    22
    33// XXX need to load_images first and generate some lookup tables
    4 int RepairWarpMeasures (Catalog *catalog) {
     4WarpRepairResult RepairWarpMeasures (Catalog *catalog) {
    55
    66  off_t Nimage;
     
    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, NwarpNoImage = 0;
     11  WarpRepairResult result;
     12  result.NfixChipID = 0;
     13  result.NfixStackID = 0;
     14  result.NfixWarpID = 0;
     15  result.NfixWarpImageID = 0;
     16  result.NfixWarpCoord = 0;
     17  result.NmissWarp = 0;
     18  result.NmissStack = 0;
     19  result.NbadWarp = 0;
     20  result.NbadWarpTime = 0;
     21  result.NwarpNoImage = 0;
    1222
    1323  int onePercent = catalog->Nmeasure / 100;
     
    2535      if (extID != measure->extID) {
    2636        measure->extID = extID;
    27         NfixChipID ++;
     37        result.NfixChipID ++;
    2838      }
    2939      continue;
     
    3444      int im = getImageByID (measure->imageID);
    3545      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 ++;
     46        if (result.NmissStack < 10) fprintf (stderr, "missing stack exposure: %f %f : %d %d\n", measure->R, measure->D, measure->imageID, measure->photcode);
     47        result.NmissStack ++;
    3848        continue;
    3949      }
     
    4151      if (extID != measure->extID) {
    4252        measure->extID = extID;
    43         NfixStackID ++;
     53        result.NfixStackID ++;
    4454      }
    4555      continue;
     
    6474    double Dwrp = measure->D;
    6575
     76    /*
     77       we have a warp detection.  X,Y are correct (never modified).  things which might be wrong:
     78       * imageID (thus the Mcal, R,D, extID may all be broken)
     79       */
     80
     81    int coordsDiffer = FALSE;
    6682    if (USE_IMAGE_COORDS_FOR_REPAIR) {
    6783      off_t idx = getImageByID (measure->imageID);
    6884      if (idx == -1) {
    6985        if (VERBOSE2) fprintf (stderr, "can't match detection to image?\n");
    70         NwarpNoImage ++;
     86        result.NwarpNoImage ++;
    7187        continue;
    7288      }
    7389
    7490      Coords *imcoords = &image[idx].coords;
     91
     92      // save the original warp coordinates for comparison
     93      double Rold = ohana_normalize_angle_to_midpoint(Rwrp, 180.0);
     94      double Dold = ohana_normalize_angle_to_midpoint(Dwrp,   0.0);
    7595
    7696      XY_to_RD (&Rwrp, &Dwrp, X, Y, imcoords);
     
    7898      Rwrp = ohana_normalize_angle_to_midpoint(Rwrp, 180.0);
    7999      Dwrp = ohana_normalize_angle_to_midpoint(Dwrp,   0.0);
     100
     101      // check if the new Rwrp, Dwrp is different from the current R,D:
     102      float csdec = cos(Dold * RAD_DEG);
     103
     104      // find the ra,dec displacement in arcsec:
     105      double dR = 3600.0*(Rwrp - Rold)*csdec;
     106      double dD = 3600.0*(Dwrp - Dold);
     107     
     108      // skip detections which are within a small distance of the expected location
     109      // NOTE: this actually works surprisingly well near the pole
     110      double dPos = hypot(dR,dD);
     111      if (dPos > 0.5) {
     112        // in this case, we should double-check measure.R,D values below
     113        coordsDiffer = TRUE;
     114      }
    80115    }
    81116
     
    93128    double dPos = hypot(dR,dD);
    94129    if (dPos < 2.0) {
     130      // image coord agrees with average coord
     131      if (coordsDiffer) {
     132        // measure coord disagrees with image coord: replace with image coord
     133        measure->R = Rwrp;
     134        measure->D = Dwrp;
     135        result.NfixWarpCoord ++;
     136      }
     137      // check that the current extID value is good for warp detection:
    95138      int im = getImageByID (measure->imageID);
    96139      uint64_t extID = CreatePSPSStackDetectionID (34, image[im].externID, measure->detID);
    97140      if (extID != measure->extID) {
    98141        measure->extID = extID;
    99         NfixWarpID ++;
    100       }
    101       continue;
     142        result.NfixWarpID ++;
     143      }
     144      // check match of obstime:
     145      if ((measure->t != image[im].tzero) && (result.NbadWarpTime < 10)) {
     146        fprintf (stderr, "inconsistent warp measurement times: %d vs %d for %f, %f (%d, %ld)", measure->t, image[im].tzero, Rwrp, Dwrp, measure->photcode, extID);
     147        result.NbadWarpTime ++;
     148        continue;
     149      }
    102150    }
    103151
     
    105153    int warpSeq = GetWarpSeq (image, measure->t, measure->photcode, Rave, Dave, X, Y);
    106154    if (warpSeq < 0) {
    107       if (NmissWarp < 10) fprintf (stderr, "missing warp exposure: %f %f : %d %d\n", Rave, Dave, measure->t, measure->photcode);
    108       NmissWarp ++;
     155      if (result.NmissWarp < 10) fprintf (stderr, "missing warp exposure: %f %f : %d %d\n", Rave, Dave, measure->t, measure->photcode);
     156      result.NmissWarp ++;
    109157      continue;
    110158    }
     
    127175    if (dPos > 5.0) {
    128176      fprintf (stderr, "measurement still far from average location: %f %f vs %f %f : %d %d\n", Rave, Dave, Rnew, Dnew, measure->t, measure->photcode);
    129       NbadWarp ++;
     177      result.NbadWarp ++;
    130178    }
    131179
     
    137185    if (extID != measure->extID) {
    138186      measure->extID = extID;
    139       NfixWarpID ++;
    140     }
    141     NfixWarpImageID ++;
     187      result.NfixWarpID ++;
     188    }
     189    result.NfixWarpImageID ++;
    142190  }
    143191
    144192  fprintf (stderr, "\n");
    145   fprintf (stderr, "repaired %s : warp image ID %d : ext ID chip %d stack %d warp %d : missed warp %d stack %d : bad warp: %d : warp no image: %d\n", catalog->filename, NfixWarpImageID, NfixChipID, NfixStackID, NfixWarpID, NmissWarp, NmissStack, NbadWarp, NwarpNoImage);
    146 
    147   return (TRUE);
     193  fprintf (stderr, "repaired %s : warp image ID %d : ext ID chip %d stack %d warp %d : missed warp %d stack %d : bad warp: %d : warp no image: %d : badWarpTime: %d, fixWarpCoord: %d\n",
     194           catalog->filename,
     195           result.NfixWarpImageID, result.NfixChipID, result.NfixStackID,
     196           result.NfixWarpID, result.NmissWarp, result.NmissStack,
     197           result.NbadWarp, result.NwarpNoImage, result.NbadWarpTime,
     198           result.NfixWarpCoord);
     199
     200  return (result);
    148201}
  • trunk/Ohana/src/relastro/src/RepairWarps.c

    r39580 r39600  
    4545
    4646    // update the detection coordinates using the new image parameters
    47     RepairWarpMeasures (&catalog);
     47    WarpRepairResult result = RepairWarpMeasures (&catalog);
    4848
     49    // track number of corrections and only update if corrections are made
     50    int Nmods = 0;
     51    Nmods += result.NfixChipID;
     52    Nmods += result.NfixStackID;
     53    Nmods += result.NfixWarpID;
     54    Nmods += result.NfixWarpImageID;
     55    Nmods += result.NfixWarpCoord;
     56    Nmods += result.NmissWarp;
     57    Nmods += result.NmissStack;
     58    Nmods += result.NbadWarp;
     59    Nmods += result.NbadWarpTime;
     60    Nmods += result.NwarpNoImage;
     61    if (!Nmods) {
     62      fprintf (stderr, "no changes to %s, no output\n", catalog.filename);
     63      dvo_catalog_unlock (&catalog);
     64      dvo_catalog_free (&catalog);
     65      continue;
     66    }
     67
     68    if (!UPDATE) {
     69      dvo_catalog_unlock (&catalog);
     70      dvo_catalog_free (&catalog);
     71      continue;
     72    }
     73   
    4974    char history[128];
    5075    struct timeval now;
     
    5580    free (moddate);
    5681
    57     if (!UPDATE) {
    58       dvo_catalog_unlock (&catalog);
    59       dvo_catalog_free (&catalog);
    60       continue;
     82    // add metadata to define number of corrections
     83    char line[128];
     84    snprintf (line, 60, "ChipID %d, StackID %d, warpID %d", result.NfixChipID, result.NfixStackID, result.NfixWarpID);
     85    gfits_modify (&catalog.header, "REPAIR_1", "%s", 1, line);
     86    snprintf (line, 60, "WarpImageID %d, WarpCoord %d, WarpNoImage %d", result.NfixWarpImageID, result.NfixWarpCoord, result.NwarpNoImage);
     87    gfits_modify (&catalog.header, "REPAIR_2", "%s", 1, line);
     88    snprintf (line, 60, "missWarp %d, badWarp %d, badWarpTime %d, missStack %d", result.NmissWarp, result.NbadWarp, result.NbadWarpTime, result.NmissStack);
     89    gfits_modify (&catalog.header, "REPAIR_3", "%s", 1, line);
     90
     91    // save backup of original cpm file
     92    if (!dvo_catalog_backup (&catalog, "rp0", TRUE)) {
     93      fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", catalog.filename);
     94      exit (1);
    6195    }
    62    
     96
    6397    // write the updated detections to disk
    6498    save_catalogs (&catalog, 1);
Note: See TracChangeset for help on using the changeset viewer.