IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35282


Ignore:
Timestamp:
Mar 9, 2013, 6:33:50 AM (13 years ago)
Author:
eugene
Message:

working on high-speed pm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130306/Ohana/src/relastro/src/hpm_objects.c

    r35281 r35282  
    11# include "relastro.h"
    22
    3 # define NEXT_I { i++; continue; }
     3# define NEXT_I { if (Ngroup < 2) slowMoving[ni] = TRUE; newI = TRUE; i++; continue; }
    44# define NEXT_J { j++; continue; }
    55
    6 int high_speed_objects (SkyRegion *region, Catalog *catalog) {
     6int hpm_objects (SkyRegion *region, Catalog *catalog) {
    77
    88  off_t i, j, m, J, ni, nj, *N1;
     
    1515  Coords tcoords;
    1616  Catalog catalogOut;
     17  Catalog testcat;
    1718
    1819  int Nsecfilt;
    1920  char filename[1024];
    2021
     22  // XXX are we saving these in an hpm dvodb?
    2123  snprintf (filename, 1024, "%s/%s.cpt", HIGH_SPEED_DIR, region[0].name);
    2224  fprintf (stderr, "%s\n",filename);
     
    4951  REALLOCATE (catalogOut.secfilt, SecFilt, NAVERAGE*Nsecfilt);
    5052
    51   // high-speed between different surveys (easier case):
    52   // we have two sets of photcodes (A) and (B) and are looking for objects
    53   // with detections in only (A) and separately only (B).
     53  // testcat is used to determine the fit for a single object group
     54  // objects which do not have a high-quality testcat fit are not kept
     55  dvo_catalog_init (&testcat, TRUE);
     56  testcat.Naverage = 1; // this is fixed -- only one obj in testcat
     57  NMEASURE_TEST = 1000;
     58  REALLOCATE (catalogOut.average, Average, 1);
     59  REALLOCATE (catalogOut.measure, Measure, NMEASURE_TEST);
     60  REALLOCATE (catalogOut.secfilt, SecFilt, Nsecfilt);
    5461
    5562  // we need at least 2 objects if we are going to match anything...
     
    5966  ALLOCATE (slowMoving, int, catalog[0].Naverage);
    6067  memset (slowMoving, 0, catalog[0].Naverage*sizeof(int));
    61 
    62   // record to which photcode group the object belongs:
    63   NgroupA = 0;
    64   ALLOCATE (groupA, int, catalog[0].Naverage);
    65   memset (groupA, 0, catalog[0].Naverage*sizeof(int));
    66 
    67   NgroupB = 0;
    68   ALLOCATE (groupB, int, catalog[0].Naverage);
    69   memset (groupB, 0, catalog[0].Naverage*sizeof(int));
    7068
    7169  if (VERBOSE) fprintf (stderr, "checking "OFF_T_FMT" objects\n",  catalog[0].Naverage);
     
    8482    }
    8583
    86     // do any of the measures for this object match group A?
    87     m = catalog[0].average[i].measureOffset;
    88     foundA = FALSE;
    89     for (j = 0; !foundA && (j < catalog[0].average[i].Nmeasure); j++, m++) {
    90 
    91       if (MeasMatchesPhotcode(&catalog[0].measure[m], photcodesGroupA, NphotcodesGroupA)) {
    92         foundA = TRUE;
    93       }
    94     }
    95 
    96     // do any of the measures for this object match group B?
    97     m = catalog[0].average[i].measureOffset;
    98     foundB = FALSE;
    99     for (j = 0; !foundB && (j < catalog[0].average[i].Nmeasure); j++, m++) {
    100          
    101       if (MeasMatchesPhotcode(&catalog[0].measure[m], photcodesGroupB, NphotcodesGroupB)) {
    102         foundB = TRUE;
    103       }
    104     }
    105 
    106     // object found in both - mark as slow moving
    107     if (foundA && foundB) {
     84    // selection criteria:
     85    // (Nps1 > 2) && (Trange < 180)
     86    if (catalog[0].average[i].Trange > MAX_TRANGE) {
    10887      slowMoving[i] = TRUE;
    10988      Nslow ++;
    11089      continue;
    11190    }
    112 
    113     // Apply additional constraints:
    114     if (foundA && !foundB) {
    115         if (applyConstraintsA(catalog, i)) {
    116             groupA[i] = TRUE;
    117             NgroupA++;
    118             continue;
    119         } else {
    120             NgroupAbad ++;
    121             // fprintf (stderr, "skip "OFF_T_FMT" (group A)\n",  i);
    122         }
    123         continue;
    124     }
    125     if (foundB && !foundA) {
    126         if (applyConstraintsB(catalog, i)) {
    127             groupB[i] = TRUE;
    128             NgroupB++;
    129             continue;
    130         } else {
    131             NgroupBbad++;
    132         }
    133         continue;
    134     }
    135     // this object does not have a detection matching the contraints from either gorupA or groupB -- skip as if slow
    136     slowMoving[i] = TRUE;
    137     Ninvalid ++;
    138   }
    139 
    140   fprintf (stderr, OFF_T_FMT" slow, "OFF_T_FMT" invalid, ("OFF_T_FMT" group A, "OFF_T_FMT" group B), "OFF_T_FMT" total objects; "OFF_T_FMT" in group A, "OFF_T_FMT" in group B\n",  Nslow,  Ninvalid, NgroupAbad, NgroupBbad, catalog[0].Naverage,  NgroupA,  NgroupB);
     91    // count the PS1 detections via explicit photcode ranges?
     92    // XXX this is a total hard-wired hack...
     93    int Nps1 = 0;
     94    for (j = 0; i < 5; j++) {
     95      Nps1 += catalog[0].secfilt[Nsecfilt*i+j].Ncode;
     96    }
     97    if (Nps1 < MIN_PS1_DET) {
     98      slowMoving[i] = TRUE;
     99      Nslow ++;
     100      continue;
     101    }     
     102  }
     103
     104  fprintf (stderr, OFF_T_FMT" slow, "OFF_T_FMT" total objects; "OFF_T_FMT" possible fast\n",  Nslow,  catalog[0].Naverage,  catalog[0].Naverage - Nslow);
    141105   
    142106  // double loop over unmarked objects (sorted in RA / X)
     
    175139  RADIUS2 = SQ(RADIUS);
    176140
    177   // mark (exclude) objects with both sets of target photcodes
     141  // group is a list of objects that are within a clump.  this set will be tested
     142  // via a clipped fit to the measurements after the group is identified
     143  Ngroup = 0;
     144  NGROUP = 100;
     145  ALLOCATE (group, int, NGROUP);
     146
     147  // in the loop below, we need to do a bunch of things when we go to the next main object
     148  newI = TRUE;
     149
     150  // mark (skip) objects with both sets of target photcodes
     151  // the loop below is attempting to find associations of multiple objects which have
     152  // passed the cuts above.  the index i is following the primary object of interest
     153  // the index j is used to explore possible near neighbors. 
     154  // When we go to the next object 'i', Nmatch is reset
    178155  for (i = j = 0; (i < catalog[0].Naverage) && (j < catalog[0].Naverage);) {
    179156
    180157    ni = N1[i];
    181158    nj = N1[j];
     159
     160    if (newI) {
     161      Nmatch = 0;
     162      Ngroup = 1;
     163      group[0] = ni;
     164      newI = FALSE;
     165    }
    182166
    183167    XVERB  = (catalog[0].average[ni].objID == OBJ_ID_SRC) && (catalog[0].average[ni].catID == CAT_ID_SRC);
     
    190174    if (slowMoving[nj]) NEXT_J;
    191175
    192     // i => groupA, j => groupB
    193     if (!groupA[ni]) NEXT_I;
    194     if (!groupB[nj]) NEXT_J;
    195 
    196176    if (!finite(X1[i]) || !finite(Y1[i])) NEXT_I;
    197177    if (!finite(X1[j]) || !finite(Y1[j])) NEXT_J;
     
    209189    for (J = j; (dX > -1.02*RADIUS) && (J < catalog[0].Naverage); J++) {     
    210190      if (J == i) continue;  // avoid auto-matches
     191      nj = N1[J];
    211192
    212193      dX = X1[i] - X1[J];
    213194
    214       nj = N1[J];
    215       if (!groupB[nj]) continue;
     195      if (slowMoving[nj]) continue;
    216196
    217197      XVERB  = (catalog[0].average[ni].objID == OBJ_ID_SRC) && (catalog[0].average[ni].catID == CAT_ID_SRC);
     
    226206      if (dR > RADIUS2) continue;
    227207
    228       /*** a match is found (just print it for the moment) ***/
    229       /*Define a vector of matched indices and set averages in new catalogue*/
    230       Nepoch=2;
    231       FIT_MODE = FIT_PM_ONLY;
    232       nv[0]=ni; /*THESE SHOULD BE CHANGED FOR MULTIPLE EPOCHS AS SHOULD nv*/
    233       nv[1]=nj;
    234 
    235       catalogOut.average[Nmatch]=catalog[0].average[nv[0]];
    236       /*Loop over index values and set measurements in new catalogue*/
    237       Nmatchmeasobj=0;
    238       catalogOut.average[Nmatch].measureOffset=Nmatchmeas;
    239       for(l=0;l<Nepoch;l++) {
    240           m = catalog[0].average[nv[l]].measureOffset;
    241           for(i1=0;i1<catalog[0].average[nv[l]].Nmeasure;i1++) {
    242               catalogOut.measure[Nmatchmeas]=catalog[0].measure[m+i1];
    243               /*Set offset RA and Dec wrt correct average value*/
    244               catalogOut.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
    245               catalogOut.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
    246               catalogOut.measure[Nmatchmeas].averef = Nmatch;
    247               Nmatchmeasobj++;
    248               Nmatchmeas++;
    249 
    250               if (Nmatchmeas == NMEASURE - 1) {
    251                 NMEASURE += 10000;
    252                 REALLOCATE (catalogOut.measure, Measure, NMEASURE);
    253               }
    254           }
     208      /*** a match is found ***/
     209      group[Ngroup] = nj;
     210      Ngroup ++;
     211      CHECK_REALLOCATE (group, int, NGROUP, Ngroup, 100);
     212    }
     213
     214    if (Ngroup < 2) NEXT_I;
     215
     216    // we now have spatially associated group of objects.  now we need to see if the set of
     217    // measurements can be fitted reasonably with a proper motion (& parallax?)
     218
     219    // the mean object will start with info from the primary object
     220    // remember: testcat.Naverage = 1 -- does not change
     221    testcat.average[0] = catalog[0].average[group[0]];
     222    testcat.average[0].measureOffset = 0;
     223    Nmatchmeas = 0;
     224    I = group[0];
     225    for (J = 0; J < Ngroup; J++) {
     226      J = group[J];
     227      m = catalog[0].average[Nj].measureOffset;
     228      for (k = 0; k < catalog[0].average[Nj].Nmeasure; k++) {
     229        testcat.measure[Nmatchmeas] = catalog[0].measure[m+k];
     230        /* Set offset RA and Dec wrt correct average value*/
     231        testcat.measure[Nmatchmeas].dR = catalog[0].measure[m+k].dR + 3600.0*(catalog[0].average[I].R - catalog[0].average[J].R);
     232        testcat.measure[Nmatchmeas].dD = catalog[0].measure[m+k].dD + 3600.0*(catalog[0].average[I].D - catalog[0].average[J].D);
     233        testcat.measure[Nmatchmeas].averef = 0;
     234        Nmatchmeas++;
     235        CHECK_REALLOCATE (testcat.measure, Measure, NMEASURE_TEST, Nmatchmeas, 1000);
    255236      }
    256       catalogOut.average[Nmatch].Nmeasure = Nmatchmeasobj;
    257       Nmatch ++;
    258 
    259       if (Nmatch == NAVERAGE - 1) {
    260         NAVERAGE += 1000;
    261         REALLOCATE (catalogOut.average, Average, NAVERAGE);
    262         REALLOCATE(catalogOut.secfilt, SecFilt, NAVERAGE*Nsecfilt);
     237    }
     238    testcat.average[0].Nmeasure = Nmatchmeas;
     239
     240    // we have now accumulated the measurements for this group, let's try a fit
     241    // this needs to be a (fairly robust) clipped fit or we will have a hard time
     242    // distinguishing a bad fit from a fit with 1 or 2 bad points
     243    FIT_MODE = FIT_PM_ONLY;
     244    UpdateObjects (&testcat, 1);
     245
     246    // logic for keeping the fit:
     247    if (testcat.average[0].ChiSqPM < XXX) good = TRUE;
     248    if (testcat.average[0].Npos > 0.X * testcat.average[0].Nmeasure) good = TRUE;
     249    // what else?
     250
     251    if (good) {
     252      // save the new object on catalogOut
     253      {
     254        catalogOut.average[Nout] = testcat.average[0];
     255        catalogOut.average[Nout].measureOffset = Nmatchmeas;
     256        m = testcat.average[0].measureOffset;
     257        for (k = 0; k < testcat.average[0].Nmeasure; k++) {
     258          catalogOut.measure[Noutmeas] = testcat.measure[m+k];
     259          catalogOut.measure[Noutmeas].averef = Nout;
     260        }
     261        Nout ++;
     262        CHECK_REALLOCATE (catalogOut.average, Average, NAVERAGE, Nout, 100);
    263263      }
    264264    }
    265     i++;
    266   }
     265    NEXT_I;
     266  }
     267
    267268  catalogOut.Naverage=Nmatch;
    268269  catalogOut.Nmeasure=Nmatchmeas;
Note: See TracChangeset for help on using the changeset viewer.