IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39142 for trunk


Ignore:
Timestamp:
Nov 15, 2015, 10:13:54 AM (11 years ago)
Author:
eugene
Message:

add galphot to the merge options

Location:
trunk/Ohana/src/dvomerge
Files:
5 edited

Legend:

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

    r38986 r39142  
    164164StarPar   *sort_starpar           PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next));
    165165
     166off_t     *build_galphot_links    PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot));
     167off_t     *init_galphot_links     PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot));
     168int        add_galp_link          PROTO((Average *average, off_t *next, off_t Ngalphot, off_t NGALPHOT));
     169GalPhot   *sort_galphot           PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next));
     170
    166171off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    167172int        add_miss_link          PROTO((Average *average, off_t *next, off_t Nmissing));
  • trunk/Ohana/src/dvomerge/src/build_links.c

    r38986 r39142  
    2323
    2424*/
     25
     26/*** Measure ****************************************************************************************/
    2527
    2628/* build the initial links assuming the table is sorted,
     
    159161}
    160162
    161 /*******************************************************************************************/
     163/*** Missing ****************************************************************************************/
    162164
    163165/* build the initial links assuming the table is sorted */
     
    229231}
    230232
    231 /*******************************************************************************************/
     233/*** Lensing ****************************************************************************************/
    232234
    233235/* build the initial links assuming the table is sorted,
     
    384386}
    385387
    386 /******** StarPar ********************************************************************************/
     388/*** StarPar ********************************************************************************/
    387389
    388390/* build the initial links assuming the table is sorted,
     
    535537}
    536538
    537 
     539/*** GalPhot ****************************************************************************************/
     540
     541/* build the initial links assuming the table is sorted,
     542   not partial, and has a correct set of average[].galphotOffset,Ngalphot values */
     543off_t *init_galphot_links (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot) {
     544
     545  off_t i, j, N;
     546  off_t *next_galp;
     547
     548  N = 0;
     549
     550  ALLOCATE (next_galp, off_t, Ngalphot);
     551  for (i = 0; i < Naverage; i++) {
     552    if (!average[i].Ngalphot) continue;
     553    off_t m = average[i].galphotOffset;
     554    myAssert (galphot[m].averef == i, "not sorted");
     555    for (j = 0; j < average[i].Ngalphot - 1; j++, N++) {
     556      myAssert (galphot[m+j+1].averef == i, "not sorted");
     557      next_galp[N] = N + 1;
     558      if (N >= Ngalphot) {
     559        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     560      }
     561    }
     562    next_galp[N] = -1;
     563    if (N >= Ngalphot) {
     564      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     565    }
     566
     567    if (N >= Ngalphot) {
     568      fprintf (stderr, "overflow in init_galphot_links\n");
     569      abort ();
     570    }
     571    N++;
     572  }
     573  return (next_galp);
     574}
     575
     576/* construct galphot links which are valid FOR THIS LOAD
     577 * - if we have a full load, we will get links which can
     578 *   be used by other programs (eg, relphot, etc)
     579 * - if we have a partial load, the links are only valid
     580 *   for that partial load
     581 */
     582
     583off_t *build_galphot_links (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot) {
     584
     585  off_t i, m, k, Nm, averef;
     586  off_t *next_galp;
     587
     588  ALLOCATE (next_galp, off_t, Ngalphot);
     589
     590  /* reset the Nm, offset values for average */
     591  for (i = 0; i < Naverage; i++) {
     592    average[i].galphotOffset = -1;
     593    average[i].Ngalphot     =  0;
     594  }
     595
     596  for (Nm = 0; Nm < Ngalphot; Nm++) {
     597    averef = galphot[Nm].averef;
     598    m = average[averef].galphotOffset; 
     599    next_galp[Nm] = -1;
     600
     601    if (m == -1) { /* no links yet for source */
     602      average[averef].galphotOffset = Nm;
     603      average[averef].Ngalphot     = 1;
     604      continue;
     605    }
     606
     607    for (k = 0; next_galp[m] != -1; k++) {
     608      m = next_galp[m];
     609      if (m >= Ngalphot) {
     610        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     611      }
     612    }
     613
     614    average[averef].Ngalphot = k + 2;
     615    next_galp[m] = Nm;
     616    if (m >= Ngalphot) {
     617      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     618    }
     619  }
     620  return (next_galp);
     621}
     622
     623/* average[].galphotOffset, average[].Ngalphot are valid within an addstar run */
     624int add_galp_link (Average *average, off_t *next_galp, off_t Ngalphot, off_t NGALPHOT) {
     625
     626  off_t k, m;
     627
     628  /* if we have trouble, check validity of next_galp[m] : m < Ngalphot */
     629  m = average[0].galphotOffset; 
     630
     631  for (k = 0; k < average[0].Ngalphot - 1; k++)  {
     632    m = next_galp[m];
     633    if (m >= NGALPHOT) {
     634      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     635    }
     636  }
     637
     638  /* set up references */
     639  next_galp[Ngalphot] = -1;
     640  if (Ngalphot >= NGALPHOT) {
     641    fprintf (stderr, "WARNING: Ngalphot out of bounds (1)\n");
     642  }
     643
     644  // if Ngalphot is 0, m may have been mis-set; add to the end
     645  if ((average[0].Ngalphot == 0) || (m == -1)) {
     646    average[0].galphotOffset = Ngalphot;
     647  } else {
     648    next_galp[m] = Ngalphot;
     649    if (m >= NGALPHOT) {
     650      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     651    }
     652  }
     653
     654  return (TRUE);
     655}
     656
     657GalPhot *sort_galphot (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next_galp) {
     658
     659  off_t i, k, n, np, N;
     660  GalPhot *tmpgalphot;
     661
     662  /*
     663  for (i = 0; i < Naverage; i++) {
     664    if (average[i].Ngalphot != 4) {
     665      fprintf (stderr, "check %d %d %d\n", (int) i, (int) average[i].Ngalphot, (int) average[i].galphotOffset);
     666    }
     667  }
     668  */
     669
     670  /* fix order of GalPhot (memory intensive, but fast) */
     671  np = -1;
     672  N = 0;
     673  ALLOCATE (tmpgalphot, GalPhot, Ngalphot);
     674  for (i = 0; i < Naverage; i++) {
     675    if (!average[i].Ngalphot) continue;
     676    n = average[i].galphotOffset;
     677    average[i].galphotOffset = N;
     678    for (k = 0; k < average[i].Ngalphot; k++, N++) {
     679      if (n == -1) {
     680        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     681        abort();
     682      }
     683      tmpgalphot[N] = galphot[n];
     684      if (galphot[n].averef != i) abort();
     685      tmpgalphot[N].averef = i;
     686      np = n;
     687      n = next_galp[n];
     688    }
     689  }
     690  free (galphot);
     691  return (tmpgalphot);
     692}
     693
  • trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r38553 r39142  
    234234    catalog[0].lensing[i].imageID = newID;
    235235  }
     236
     237  // NOTE galphot also carries an imageID, but it is actually the EXTERNAL image ID reference.  Do NOT update it.
     238
    236239  return TRUE;
    237240}
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_new.c

    r38441 r39142  
    1111 
    1212  off_t i, j, offset;
    13   off_t NAVERAGE, NMEASURE, NLENSING, NSTARPAR, Naverage, Nmeasure, Nlensing, Nstarpar, NsecfiltIn, NsecfiltOut, Nm;
     13  off_t NAVERAGE, NMEASURE, NLENSING, NSTARPAR, NGALPHOT, Naverage, Nmeasure, Nlensing, Nstarpar, Ngalphot, NsecfiltIn, NsecfiltOut, Nm;
    1414
    1515  Naverage = output[0].Naverage;
     
    1717  Nlensing = output[0].Nlensing;
    1818  Nstarpar = output[0].Nstarpar;
     19  Ngalphot = output[0].Ngalphot;
    1920
    2021  NsecfiltOut = output[0].Nsecfilt;
     
    2526  NLENSING = Nlensing + 1000;
    2627  NSTARPAR = Nstarpar + 1000;
     28  NGALPHOT = Ngalphot + 1000;
    2729
    2830  REALLOCATE (output[0].average, Average, NAVERAGE);
     
    3133  REALLOCATE (output[0].lensing, Lensing, NLENSING);
    3234  REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     35  REALLOCATE (output[0].galphot, GalPhot, NGALPHOT);
    3336
    3437  // add all of these entries to the existing catalog
     
    100103      output[0].average[Naverage].Nstarpar = Nm;
    101104
     105      Nm = 0;
     106      for (j = 0; j < input[0].average[i].Ngalphot; j++) {
     107          offset = input[0].average[i].galphotOffset + j;
     108
     109          output[0].galphot[Ngalphot] = input[0].galphot[offset];
     110          output[0].galphot[Ngalphot].averef = Naverage;
     111
     112          Ngalphot ++;
     113          Nm ++;
     114          if (Ngalphot == NGALPHOT) {
     115              NGALPHOT += 1000;
     116              REALLOCATE (output[0].galphot, GalPhot, NGALPHOT);
     117          }
     118      }
     119      output[0].average[Naverage].Ngalphot = Nm;
     120
    102121      Naverage ++;
    103122      if (Naverage == NAVERAGE) {
     
    111130  REALLOCATE (output[0].lensing, Lensing, MAX (Nlensing, 1));
    112131  REALLOCATE (output[0].starpar, StarPar, MAX (Nstarpar, 1));
     132  REALLOCATE (output[0].galphot, GalPhot, MAX (Ngalphot, 1));
    113133  REALLOCATE (output[0].secfilt, SecFilt, NsecfiltOut*MAX (Naverage, 1));
    114134  output[0].Naverage = Naverage;
    115135  output[0].Nlensing = Nlensing;
    116136  output[0].Nstarpar = Nstarpar;
     137  output[0].Ngalphot = Ngalphot;
    117138  output[0].Nsecfilt_mem = Naverage * NsecfiltOut;
    118139
     
    124145 
    125146  if (VERBOSE) {
    126       fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures, "OFF_T_FMT" lensing) for catalog\n",
     147      fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures, "OFF_T_FMT" lensing, "OFF_T_FMT" starpar, "OFF_T_FMT" galphot) for catalog\n",
    127148                i,
    128149                output[0].Naverage,
    129150                output[0].Nmeasure,
    130                 output[0].Nlensing);
     151                output[0].Nlensing,
     152                output[0].Nstarpar,
     153                output[0].Ngalphot);
    131154  }
    132155  return (TRUE);
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r39139 r39142  
    1414  double *X1, *Y1, *X2, *Y2;
    1515  double dX, dY, dR;
    16   off_t *N1, *N2, *next_meas, *next_lens, *next_star;
    17   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS, Nstar, NSTAR;
     16  off_t *N1, *N2, *next_meas, *next_lens, *next_star, *next_galp;
     17  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS, Nstar, NSTAR, Ngalp, NGALP;
    1818  int NsecfiltIn;
    1919  int NsecfiltOut;
     
    199199      NGALP = Ngalp + input[0].average[N].Ngalphot + 1000;
    200200      REALLOCATE (next_galp, off_t, NGALP);
    201       REALLOCATE (output[0].galphot, Galphot, NGALP);
     201      REALLOCATE (output[0].galphot, GalPhot, NGALP);
    202202    }
    203203
     
    222222      if (REPLACE_BY_PHOTCODE) {
    223223        // index to first measure for this object
    224         // XXX this does not support lensing measurements
     224        // XXX this does not support lensing, starpar, or galphot measurements
    225225        if (replace_match (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[offset])) {
    226226          input[0].found_t[N] = output[0].average[n].measureOffset; 
     
    315315    }
    316316
     317    // if galphot measurements exist, add them too
     318    if (output[0].galphot) {
     319      for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin++) {
     320        /* add to end of galphot list */
     321        add_galp_link (&output[0].average[n], next_galp, Ngalp, NGALP);
     322       
     323        // set the new galphot
     324        off_t galpoff = input[0].average[N].galphotOffset + Nin;
     325        output[0].galphot[Ngalp] = input[0].galphot[galpoff];
     326
     327        output[0].galphot[Ngalp].averef   = n;
     328        output[0].galphot[Ngalp].objID    = output[0].average[n].objID;
     329        output[0].galphot[Ngalp].catID    = output[0].catID;
     330        output[0].average[n].Ngalphot ++;
     331        Ngalp ++;
     332      }
     333    }
     334
    317335    // update the average properties to reflect the incoming entries:
    318336    // if the original value is NAN but the input value is not, accept the input:
     
    365383      REALLOCATE (output[0].starpar, StarPar, NSTAR);
    366384    }
     385    if (Ngalp + input[0].average[N].Ngalphot >= NGALP) {
     386      NGALP = Ngalp + input[0].average[N].Ngalphot + 1000;
     387      REALLOCATE (next_galp, off_t, NGALP);
     388      REALLOCATE (output[0].galphot, GalPhot, NGALP);
     389    }
    367390    if (Nave >= NAVE) {
    368391      NAVE = Nave + 1000;
     
    488511    }
    489512
     513    /** add galphot for this input average object **/
     514    if (output[0].galphot) {
     515      output[0].average[Nave].galphotOffset  = Ngalp;
     516      for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin ++) {
     517        // supply the galphot values from this detection
     518        off_t galpoff = input[0].average[N].galphotOffset + Nin;
     519        output[0].galphot[Ngalp]           = input[0].galphot[galpoff];
     520
     521        // the following galphot elements cannot be set until here:
     522        output[0].galphot[Ngalp].averef   = Nave;
     523        output[0].galphot[Ngalp].objID    = output[0].average[Nave].objID;
     524        output[0].galphot[Ngalp].catID    = output[0].catID;
     525
     526        // as we add galphot, update Ngalphot to match
     527        output[0].average[Nave].Ngalphot ++;
     528
     529        /* we set next[Ngalp] to -1 here, and update correctly below */
     530        next_galp[Ngalp] = -1;
     531        Ngalp ++;
     532      }
     533      int Ngroup = input[0].average[N].Ngalphot;
     534      for (j = 0; j < Ngroup - 1; j++) {
     535        next_galp[Ngalp - Ngroup + j] = Ngalp - Ngroup + j + 1;
     536      }
     537    }
     538
    490539    Nave ++;
    491540  }
     
    497546  REALLOCATE (output[0].lensing, Lensing, Nlens);
    498547  REALLOCATE (output[0].starpar, StarPar, Nstar);
     548  REALLOCATE (output[0].galphot, GalPhot, Ngalp);
    499549 
    500550# define NOSORT 0
     
    506556    output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens);
    507557    output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star);
     558    output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalp, next_galp);
    508559  }
    509560
     
    523574  output[0].Nlensing = Nlens;
    524575  output[0].Nstarpar = Nstar;
     576  output[0].Ngalphot = Ngalp;
    525577  output[0].Nsecfilt_mem = Nave*NsecfiltOut;
    526   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Nmatch);
     578  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens, Ngalp: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Ngalp, Nmatch);
    527579
    528580  free (next_meas);
    529581  free (next_lens);
    530582  free (next_star);
     583  free (next_galp);
    531584
    532585  free (X2);
Note: See TracChangeset for help on using the changeset viewer.