IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36922


Ignore:
Timestamp:
Jun 20, 2014, 11:30:04 AM (12 years ago)
Author:
eugene
Message:

addstar work with lensing and without lensing entries; resort also works

Location:
branches/eam_branches/ipp-20140610/Ohana/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/build_links.c

    r36921 r36922  
    237237
    238238  ALLOCATE (next_lens, off_t, Nlensing);
    239   for (i = 0; i < Naverage; i++, N++) {
     239  for (i = 0; i < Naverage; i++) {
     240    if (!average[i].Nlensing) continue;
    240241    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
    241242      next_lens[N] = N + 1;
     
    253254      abort ();
    254255    }
     256    N++;
    255257  }
    256258  return (next_lens);
     
    346348  ALLOCATE (tmplensing, Lensing, Nlensing);
    347349  for (i = 0; i < Naverage; i++) {
     350    if (!average[i].Nlensing) continue;
    348351    n = average[i].lensingOffset;
    349352    average[i].lensingOffset = N;
  • branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/find_matches_closest.c

    r36921 r36922  
    182182    if (Nlens >= NLENS) {
    183183      NLENS = Nlens + 1000;
    184       // REALLOCATE (next_lens, off_t, NLENS);
     184      REALLOCATE (next_lens, off_t, NLENS);
    185185      REALLOCATE (catalog[0].lensing, Lensing, NLENS);
    186186    }
     
    188188    /* add to end of measurement list */
    189189    add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS);
    190     add_lens_link (&catalog[0].average[n], next_lens, Nlens, NLENS); // ?
    191190       
    192191    /** add measurements for this star **/
     
    232231    // add the lensing values if they exist
    233232    if (stars[N].lensing) {
     233      add_lens_link (&catalog[0].average[n], next_lens, Nlens, NLENS); // ?
    234234      catalog[0].lensing[Nlens] = stars[N].lensing[0];
    235235     
  • branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/resort_catalog.c

    r35760 r36922  
    11# include "addstar.h"
     2
     3void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N);
     4void resort_catalog_measure (Catalog *catalog);
     5void resort_catalog_lensing (Catalog *catalog);
    26
    37void resort_catalog_old (Catalog *catalog) {
     
    2731
    2832  return;
    29 }
    30 
    31 // sort the measure Sequence based on the average Sequence entries
    32 void SortAveMeasMatch (off_t *MEAS, off_t *AVE, off_t N) {
    33 
    34 # define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;          \
    35     tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;  \
    36     tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;   \
    37   }
    38 # define COMPARE(A,B)(AVE[A] < AVE[B])
    39   OHANA_SORT (N, COMPARE, SWAPFUNC);
    40 # undef SWAPFUNC
    41 # undef COMPARE
    4233}
    4334
     
    5344void resort_catalog (Catalog *catalog) {
    5445
     46  if (catalog[0].sorted == TRUE) return;
     47
     48  resort_catalog_measure (catalog);
     49  resort_catalog_lensing (catalog);
     50}
     51
     52void resort_catalog_measure (Catalog *catalog) {
     53
    5554  off_t Naverage, Nmeasure;
    5655  Measure *measure;
     
    6261  Measure *measureTMP = NULL;
    6362
    64   if (catalog[0].sorted == TRUE) return;
    65 
    6663  // struct timeval start, stop;
    6764  // gettimeofday (&start, NULL);
     
    7067  Nmeasure = catalog[0].Nmeasure;
    7168  Naverage = catalog[0].Naverage;
     69
     70  if (!Nmeasure) return;
    7271
    7372  measure = catalog[0].measure;
     
    113112  // fprintf (stderr, "\n");
    114113
    115   SortAveMeasMatch(measureSeq, averageSeq, Nmeasure);
     114  SortAveMatch(measureSeq, averageSeq, Nmeasure);
    116115  // MARKTIME("sort : %f sec\n", dtime);
    117116
     
    188187}
    189188
     189void resort_catalog_lensing (Catalog *catalog) {
     190
     191  off_t Naverage, Nlensing;
     192  Lensing *lensing;
     193  Average *average;
     194  off_t i, j, N, currentAve;
     195
     196  off_t *lensingSeq = NULL;
     197  off_t *averageSeq = NULL;
     198  Lensing *lensingTMP = NULL;
     199
     200  // struct timeval start, stop;
     201  // gettimeofday (&start, NULL);
     202
     203  /* internal counters */
     204  Nlensing = catalog[0].Nlensing;
     205  Naverage = catalog[0].Naverage;
     206
     207  if (!Nlensing) return;
     208
     209  lensing = catalog[0].lensing;
     210  average = catalog[0].average;
     211 
     212  // we have a table of average objects and an unsorted table of measurements.  each measurement
     213  // has a reference to the average object sequence (as well as an ID)
     214  // lensing[i].averef -> average[averef]
     215  // lensing[i].objID = average[averef].objID
     216  // lensing[i].catID = average[averef].catID
     217
     218  // we want a sorted lensing array with all averef entries in sequence
     219
     220  ALLOCATE (lensingSeq, off_t,   Nlensing);
     221  ALLOCATE (averageSeq, off_t,   Nlensing);
     222
     223  for (i = 0; i < Nlensing; i++) {
     224    lensingSeq[i] = i;
     225    averageSeq[i] = lensing[i].averef;
     226   
     227    if (catalog[0].catformat >= DVO_FORMAT_PS1_V1) {
     228      // earlier formats did not carry the objID or catID, so they are not available (we could assign on load, but we don't)
     229      myAssert(average[averageSeq[i]].catID == lensing[lensingSeq[i]].catID, "object / detection mismatch");
     230# if (1)
     231      myAssert(average[averageSeq[i]].objID == lensing[lensingSeq[i]].objID, "object / detection mismatch");
     232# else
     233      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     234      // this happened for 28 detections in the dbs on /data/stsci1?.0/eugene/dvo3pi.20130616, but not at all (as far as I know) in the rest of LAP DVO
     235      if (average[averageSeq[i]].objID != lensing[lensingSeq[i]].objID) {
     236        fprintf (stderr, "R");
     237        lensing[lensingSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     238      }
     239# endif
     240    }
     241  }
     242 
     243  // check that averageSeq is now in order
     244  // for (i = 1; i < Nlensing; i++) {
     245  //   if (averageSeq[i] < averageSeq[i-1]) {
     246  //     fprintf (stderr, "%d ", (int) i);
     247  //   }
     248  // }
     249  // fprintf (stderr, "\n");
     250
     251  SortAveMatch(lensingSeq, averageSeq, Nlensing);
     252  // MARKTIME("sort : %f sec\n", dtime);
     253
     254  // check that averageSeq is now in order
     255  // for (i = 1; i < Nlensing; i++) {
     256  //   if (averageSeq[i] < averageSeq[i-1]) {
     257  //     fprintf (stderr, "%d ", (int) i);
     258  //   }
     259  // }
     260  // fprintf (stderr, "\n");
     261
     262  // copy the lensing entries in the sorted order
     263  ALLOCATE (lensingTMP, Lensing, Nlensing);
     264  for (i = 0; i < Nlensing; i++) {
     265    j = lensingSeq[i];
     266    lensingTMP[i] = lensing[j];
     267  }
     268  // MARKTIME("assign lensing : %f sec\n", dtime);
     269
     270  // update the values of average.lensingOffset and average.Nlensing
     271  FREE(lensing);
     272  catalog[0].lensing = lensingTMP;
     273
     274  N = 0;
     275  currentAve = averageSeq[0];
     276  average[currentAve].lensingOffset = 0;
     277  for (i = 0; i < Nlensing; i++) {
     278    if (averageSeq[i] != currentAve) {
     279      // we have hit the next entry in the list
     280      average[currentAve].Nlensing = N;
     281      N = 0;
     282      currentAve = averageSeq[i];
     283      average[currentAve].lensingOffset = i;
     284    }
     285    N++;
     286  }
     287  // N++;
     288  average[currentAve].Nlensing = N;
     289  // MARKTIME("update Nlensing : %f sec\n", dtime);
     290
     291  int NlensingTotal = 0;
     292  int lensingOffsetOK = TRUE;
     293  for (i = 0; i < Naverage; i++) {
     294    NlensingTotal += catalog[0].average[i].Nlensing;
     295    if (VERBOSE && !(NlensingTotal <= catalog[0].Nlensing)) {
     296      fprintf (stderr, "too few lensing: %d %d %d\n", (int) i, NlensingTotal, (int) catalog[0].Nlensing);
     297    }
     298    lensingOffsetOK &= (catalog[0].average[i].lensingOffset < catalog[0].Nlensing);
     299    if (VERBOSE && !(catalog[0].average[i].lensingOffset < catalog[0].Nlensing)) {
     300      fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nlensing, (int) catalog[0].Nlensing);
     301    }
     302    lensingOffsetOK &= (catalog[0].average[i].lensingOffset + catalog[0].average[i].Nlensing <= catalog[0].Nlensing);
     303    if (VERBOSE && !(catalog[0].average[i].lensingOffset + catalog[0].average[i].Nlensing <= catalog[0].Nlensing)) {
     304      fprintf (stderr, "orrset + Nlensing too large: %d + %d > %d %d\n", (int) i, catalog[0].average[i].lensingOffset, catalog[0].average[i].Nlensing, (int) catalog[0].Nlensing);
     305    }
     306  }
     307
     308  if (!lensingOffsetOK) {
     309    fprintf (stderr, "ERROR: catalog %s has an invalid lensingOffset\n", catalog[0].filename);
     310  }
     311
     312  if (NlensingTotal != catalog[0].Nlensing) {
     313    fprintf (stderr, "ERROR: catalog %s has an invalid Nlensing\n", catalog[0].filename);
     314  }
     315
     316  // MARKTIME("  match time %9.4f sec for %7lld lensings, %6lld average\n", dtime, (long long) Nlensing, (long long) Naverage);
     317
     318  catalog[0].sorted = TRUE;
     319
     320  FREE (lensingSeq);
     321  FREE (averageSeq);
     322
     323  return;
     324}
     325
     326// sort the measure or lensing Sequence based on the average Sequence entries
     327void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N) {
     328
     329# define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;          \
     330    tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;  \
     331    tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;   \
     332  }
     333# define COMPARE(A,B)(AVE[A] < AVE[B])
     334  OHANA_SORT (N, COMPARE, SWAPFUNC);
     335# undef SWAPFUNC
     336# undef COMPARE
     337}
     338
  • branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/resort_threaded.c

    r29938 r36922  
    4141    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    4242    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    43     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     43    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    4444    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4545 
  • branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/resort_unthreaded_catalogs.c

    r33963 r36922  
    3030    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    3131    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    32     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     32    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    3333    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3434
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/dvo.h

    r36921 r36922  
    606606  char catmode;                         /* storage mode (raw, mef, split, mysql) */
    607607  char catformat;                       /* storage format (elixir, panstarrs, etc) */
    608   char sorted;                          /* is measure table average-sorted? */
     608  int sorted;                           /* is measure table average-sorted? (NOTE this is an int only because gfits_scan %t requires it) */
    609609 
    610610  short catflags; /* choices to be loaded */
Note: See TracChangeset for help on using the changeset viewer.