IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2008, 10:58:27 PM (17 years ago)
Author:
Paul Price
Message:

Filter source list used for stamps to remove sources that have nearby neighbours. We don't want to choose as stamps something that isn't a real source, but more like a ton of unresolved sources.

File:
1 edited

Legend:

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

    r20752 r20753  
    4747#endif
    4848
     49static psArray *stackSourcesFilter(psArray *sources, // Source list to filter
     50                                   int exclusion // Exclusion zone, pixels
     51    )
     52{
     53    psAssert(sources && sources->n > 0, "Require array of sources");
     54    if (exclusion <= 0) {
     55        return psMemIncrRefCounter(sources);
     56    }
     57
     58    int num = sources->n;               // Number of sources
     59    psVector *x = psVectorAlloc(num, PS_TYPE_F32), *y = psVectorAlloc(num, PS_TYPE_F32); // Coordinates
     60    int numGood = 0;                    // Number of good sources
     61    for (int i = 0; i < num; i++) {
     62        pmSource *source = sources->data[i]; // Source of interest
     63        if (!source) {
     64            continue;
     65        }
     66        x->data.F32[numGood] = source->peak->xf;
     67        y->data.F32[numGood] = source->peak->yf;
     68        numGood++;
     69    }
     70    x->n = y->n = numGood;
     71
     72    psTree *tree = psTreePlant(2, 2, x, y); // kd tree
     73
     74    psArray *filtered = psArrayAllocEmpty(numGood); // Filtered list of sources
     75    psVector *coords = psVectorAlloc(2, PS_TYPE_F64); // Coordinates of source
     76    int numFiltered = 0;                // Number of filtered sources
     77    for (int i = 0; i < num; i++) {
     78        pmSource *source = sources->data[i]; // Source of interest
     79        if (!source) {
     80            continue;
     81        }
     82        coords->data.F32[0] = source->peak->xf;
     83        coords->data.F32[1] = source->peak->yf;
     84        if (psTreeWithin(tree, coords, exclusion) == 1) {
     85            // Only itself inside the exclusion zone
     86            filtered = psArrayAdd(filtered, filtered->n, source);
     87        } else {
     88            numFiltered++;
     89        }
     90    }
     91    psFree(coords);
     92    psFree(tree);
     93
     94    psLogMsg("ppStack", PS_LOG_INFO, "Filtered out %d of %d sources", numFiltered, numGood);
     95
     96    return filtered;
     97}
     98
     99
    49100bool ppStackMatch(pmReadout *readout, psArray **regions, psArray **kernels, float *chi2, float *weighting,
    50                   const psArray *sources, const pmPSF *psf, psRandom *rng, const pmConfig *config)
     101                  psArray *sources, const pmPSF *psf, psRandom *rng, const pmConfig *config)
    51102{
    52103    assert(readout);
     
    247298            }
    248299
     300            // For the sake of stamps, remove nearby sources
     301            psArray *stampSources = stackSourcesFilter(sources, footprint); // Filtered list of sources
     302
    249303            if (threads > 0) {
    250304                pmSubtractionThreadsInit(readout, fake);
     
    253307            // Do the image matching
    254308            if (!pmSubtractionMatch(output, NULL, readout, fake, footprint, stride, regionSize, spacing,
    255                                     threshold, sources, stampsName, type, size, order, widths, orders, inner,
    256                                     ringsOrder, binning, penalty, optimum, optWidths, optOrder, optThresh,
    257                                     iter, rej, sysError, maskVal, maskBad, maskPoor, poorFrac, badFrac,
    258                                     PM_SUBTRACTION_MODE_1)) {
     309                                    threshold, stampSources, stampsName, type, size, order, widths, orders,
     310                                    inner, ringsOrder, binning, penalty, optimum, optWidths, optOrder,
     311                                    optThresh, iter, rej, sysError, maskVal, maskBad, maskPoor, poorFrac,
     312                                    badFrac, PM_SUBTRACTION_MODE_1)) {
    259313                psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
    260314                psFree(fake);
    261315                psFree(optWidths);
     316                psFree(stampSources);
    262317                psFree(output);
    263318                return false;
     
    286341            psFree(fake);
    287342            psFree(optWidths);
     343            psFree(stampSources);
    288344
    289345            if (threads > 0) {
Note: See TracChangeset for help on using the changeset viewer.