IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18353


Ignore:
Timestamp:
Jun 27, 2008, 4:30:13 PM (18 years ago)
Author:
Paul Price
Message:

Applying mask to sources to weed out CRs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackSources.c

    r18346 r18353  
    1515    psRegion *bounds;                   // Bounding box for sources
    1616    psArray *sources;                   // Sources within region
     17    psVector *indices;                  // Indices from tree to sources
    1718    psTree *tree;                       // kd tree with sources
    1819} ppStackSourceList;
     
    4243    psFree(list->bounds);
    4344    psFree(list->sources);
     45    psFree(list->indices);
    4446    psFree(list->tree);
    4547}
     
    4850// Returns number of valid sources
    4951static long stackSourcesParse(psRegion **bounds, // Region to update with bounding box
    50                               psVector **x, psVector **y, // Vectors to return
     52                              psVector **x, psVector **y, // Coordinate vectors to return
     53                              psVector **indices, // Source indices to return
    5154                              const psArray *sources // Input sources
    5255    )
     
    5457    psAssert(bounds, "Must be given a region for bounding box");
    5558    psAssert(x && y, "Must be given vectors");
     59    psAssert(indices, "Must be given indices");
    5660    psAssert(sources, "Must be given sources");
    5761
    58     long num = sources->n;              // Number of sources
    59     *x = psVectorRecycle(*x, num, PS_TYPE_F32);
    60     *y = psVectorRecycle(*y, num, PS_TYPE_F32);
     62    long numSources = sources->n;              // Number of sources
     63    *x = psVectorRecycle(*x, numSources, PS_TYPE_F32);
     64    *y = psVectorRecycle(*y, numSources, PS_TYPE_F32);
     65    *indices = psVectorRecycle(*indices, numSources, PS_TYPE_U32);
    6166    float xMin = INFINITY, xMax = -INFINITY, yMin = INFINITY, yMax = -INFINITY; // Bounds of sources
    62     long numValid = 0;                  // Number of valid sources
    63     for (long i = 0; i < num; i++) {
     67    long num = 0;                       // Number of valid sources
     68    for (long i = 0; i < numSources; i++) {
    6469        pmSource *source = sources->data[i]; // Source of interest
    65         if (!source) {
     70        if (!source || source->mode & SOURCE_MASK) {
    6671            continue;
    6772        }
    6873
    69         numValid++;
    7074        float xSrc, ySrc;               // Coordinates of source
    7175        coordsFromSource(&xSrc, &ySrc, source);
     
    7478        if (ySrc < yMin) yMin = ySrc;
    7579        if (ySrc > yMax) yMax = ySrc;
    76     }
     80
     81        (*x)->data.F32[num] = xSrc;
     82        (*y)->data.F32[num] = ySrc;
     83        (*indices)->data.U32[num] = i;
     84        num++;
     85    }
     86    (*x)->n = num;
     87    (*y)->n = num;
     88    (*indices)->n = num;
    7789
    7890    if (*bounds) {
     
    8597    }
    8698
    87     return numValid;
     99    psTrace("ppStack.sources", 8, "%ld sources: bounds are [%.2f:%.2f,%.2f:%.2f]\n",
     100            num, xMin, xMax, yMin, yMax);
     101
     102    return num;
    88103}
    89104
     
    100115    list->sources = psMemIncrRefCounter(sources);
    101116    list->bounds = NULL;
     117    list->indices = NULL;
    102118
    103119    psVector *x = NULL, *y = NULL;      // Source coordinates
    104     stackSourcesParse(&list->bounds, &x, &y, sources);
     120    stackSourcesParse(&list->bounds, &x, &y, &list->indices, sources);
    105121    list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources
    106122    psFree(x);
     
    123139
    124140    list->sources = oldSources = psArrayRealloc(oldSources, numOld + numNew);
     141    for (long i = 0; i < numNew; i++) {
     142        psArrayAdd(oldSources, 1, newSources->data[i]);
     143    }
    125144    psFree(list->tree);
    126145
    127146    psVector *x = NULL, *y = NULL;      // Source coordinates
    128     stackSourcesParse(&list->bounds, &x, &y, list->sources);
     147    stackSourcesParse(&list->bounds, &x, &y, &list->indices, list->sources);
    129148    list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources
    130149    psFree(x);
     
    158177    psArray *sources = *sourcesPtr;     // Sources to compare with list
    159178    psVector *x = NULL, *y = NULL;      // Coordinates of sources
     179    psVector *indices = NULL;           // Indices for sources
    160180    psRegion *bounds = NULL;            // Bounding box for sources
    161     long numSources = sources->n;       // Number of sources
    162     stackSourcesParse(&bounds, &x, &y, sources);
     181    long numSources = stackSourcesParse(&bounds, &x, &y, &indices, sources); // Number of (good) sources
    163182
    164183    if (bounds->x0 > list->bounds->x1 || bounds->x1 < list->bounds->x0 ||
    165184        bounds->x0 > list->bounds->x1 || bounds->x1 < list->bounds->x0) {
    166185        // Bounds don't overlap, so the sources don't either
     186        psTrace("ppStack.sources", 7, "Bounds don't overlap\n");
    167187        psFree(x);
    168188        psFree(y);
     189        psFree(indices);
    169190        psFree(bounds);
    170191        return 0;
     
    179200    psArray *outside = psArrayAllocEmpty(numSources); // Sources that don't correlate
    180201    for (long i = 0; i < numSources; i++) {
    181         pmSource *source = sources->data[i]; // New source
    182         if (!source) {
    183             continue;
    184         }
    185202        coords->data.F32[0] = x->data.F32[i];
    186203        coords->data.F32[1] = y->data.F32[i];
     
    189206            numOut++;
    190207            if (outside) {
    191                 psArrayAdd(outside, 1, source);
     208                psArrayAdd(outside, 1, sources->data[indices->data.U32[i]]);
    192209            }
    193210            continue;
    194211        }
    195212
    196         pmSource *listSource = list->sources->data[match]; // Source in list
     213        pmSource *listSource = list->sources->data[list->indices->data.U32[match]]; // Source in list
     214        pmSource *source = sources->data[indices->data.U32[i]]; // Source of interest
    197215        float listMag = listSource->psfMag; // Magnitude of source in list
    198216        float sourceMag = source->psfMag; // Magnitude of source
     
    207225    psFree(x);
    208226    psFree(y);
     227
     228    psTrace("ppStack.sources", 7, "%ld sources (vs %d) overlap list %d\n", numIn, minOverlap, listIndex);
    209229
    210230    if (numIn > minOverlap) {
     
    220240        }
    221241        float meanDiff = stats->clippedMean; // Mean magnitude difference
     242        psTrace("ppStack.sources", 7, "Magnitude difference is %f\n", meanDiff);
    222243        psFree(stats);
    223244
     
    235256
    236257            // Suck sources from this list into the first one we found.
     258            psTrace("ppStack.sources", 4, "Bridge found: Merging lists.");
     259
    237260            ppStackSourceListExtend(*merge, list->sources);
    238261            psFree(list);
     
    245268            }
    246269            // Put the sources that didn't correlate into the list
     270            psTrace("ppStack.sources", 4, "Extending list");
    247271            ppStackSourceListExtend(list, outside);
    248272            *merge = list;
     
    306330    if (!merge) {
    307331        // The source list is disjoint, so throw them into a new list
     332        psTrace("ppStack.sources", 4, "Disjoint source: Creating new list");
    308333        ppStackSourceList *list = ppStackSourceListAlloc(sources);
    309334        psArrayAdd(lists, 1, list);
     
    371396            if (numIn == 0) {
    372397                // It doesn't match anything at all.  Merge it in to the first list.
     398                psTrace("ppStack.sources", 4, "Disjoint list: Merging into first");
    373399                ppStackSourceListExtend(firstList, list->sources);
    374400            }
     
    380406        FILE *srcFile = fopen("sources.txt", "w");
    381407        for (long i = 0; i < firstList->sources->n; i++) {
     408            pmSource *source = firstList->sources->data[i];
     409            if (source->mode & SOURCE_MASK) {
     410                continue;
     411            }
    382412            float x, y;
    383             coordsFromSource(&x, &y, firstList->sources->data[i]);
     413            coordsFromSource(&x, &y, source);
    384414            fprintf(srcFile, "%f\t%f\n", x, y);
    385415        }
Note: See TracChangeset for help on using the changeset viewer.