IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2010, 2:59:09 PM (16 years ago)
Author:
Paul Price
Message:

Merging trunk in advance of reintegrating into trunk.

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ppStack/src/ppStackMatch.c

    r27426 r28484  
    1313#define MAG_IGNORE 50                   // Ignore magnitudes fainter than this --- they're not real!
    1414#define FAKE_SIZE 1                     // Size of fake convolution kernel
    15 #define SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_DEFECT | PM_SOURCE_MODE_SATURATED | \
    16                      PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT) // Mask to apply to input sources
    17 #define NOISE_FRACTION 0.01             // Set minimum flux to this fraction of noise
    1815#define COVAR_FRAC 0.01                 // Truncation fraction for covariance matrix
    1916
     
    4946#endif
    5047
    51 // Get coordinates from a source
    52 static void coordsFromSource(float *x, float *y, const pmSource *source)
    53 {
    54     assert(x && y);
    55     assert(source);
    56 
    57     if (source->modelPSF) {
    58         *x = source->modelPSF->params->data.F32[PM_PAR_XPOS];
    59         *y = source->modelPSF->params->data.F32[PM_PAR_YPOS];
    60     } else {
    61         *x = source->peak->xf;
    62         *y = source->peak->yf;
    63     }
    64     return;
    65 }
    66 
    67 static psArray *stackSourcesFilter(psArray *sources, // Source list to filter
    68                                    int exclusion // Exclusion zone, pixels
    69     )
    70 {
    71     psAssert(sources && sources->n > 0, "Require array of sources");
    72     if (exclusion <= 0) {
    73         return psMemIncrRefCounter(sources);
    74     }
    75 
    76     int num = sources->n;               // Number of sources
    77     psVector *x = psVectorAlloc(num, PS_TYPE_F32), *y = psVectorAlloc(num, PS_TYPE_F32); // Coordinates
    78     int numGood = 0;                    // Number of good sources
    79     for (int i = 0; i < num; i++) {
    80         pmSource *source = sources->data[i]; // Source of interest
    81         if (!source) {
    82             continue;
    83         }
    84         coordsFromSource(&x->data.F32[numGood], &y->data.F32[numGood], source);
    85         numGood++;
    86     }
    87     x->n = y->n = numGood;
    88 
    89     psTree *tree = psTreePlant(2, 2, PS_TREE_EUCLIDEAN, x, y); // kd tree
    90 
    91     psArray *filtered = psArrayAllocEmpty(numGood); // Filtered list of sources
    92     psVector *coords = psVectorAlloc(2, PS_TYPE_F64); // Coordinates of source
    93     int numFiltered = 0;                // Number of filtered sources
    94     for (int i = 0; i < num; i++) {
    95         pmSource *source = sources->data[i]; // Source of interest
    96         if (!source) {
    97             continue;
    98         }
    99         float xSource, ySource;         // Coordinates of source
    100         coordsFromSource(&xSource, &ySource, source);
    101 
    102         coords->data.F64[0] = xSource;
    103         coords->data.F64[1] = ySource;
    104 
    105         long numWithin = psTreeWithin(tree, coords, exclusion); // Number within exclusion zone
    106         psTrace("ppStack", 9, "Source at %.0lf,%.0lf has %ld sources in exclusion zone",
    107                 coords->data.F64[0], coords->data.F64[1], numWithin);
    108         if (numWithin == 1) {
    109             // Only itself inside the exclusion zone
    110             filtered = psArrayAdd(filtered, filtered->n, source);
    111         } else {
    112             numFiltered++;
    113         }
    114     }
    115     psFree(coords);
    116     psFree(tree);
    117     psFree(x);
    118     psFree(y);
    119 
    120     psLogMsg("ppStack", PS_LOG_INFO, "Filtered out %d of %d sources", numFiltered, numGood);
    121 
    122     return filtered;
    123 }
    12448
    12549// Add background into the fake image
     
    202126
    203127
    204 bool ppStackMatch(pmReadout *readout, ppStackOptions *options, int index, const pmConfig *config)
     128bool ppStackMatch(pmReadout *readout, const psImage *target, ppStackOptions *options,
     129                  int index, const pmConfig *config)
    205130{
    206131    assert(readout);
     
    286211        } else {
    287212#endif
    288 
    289213            // Normal operations here
    290             psAssert(options->psf, "Require target PSF");
    291             psAssert(options->sourceLists && options->sourceLists->data[index], "Require source list");
     214            psAssert(target, "Require target PSF image");
    292215
    293216            int order = psMetadataLookupS32(NULL, ppsub, "SPATIAL.ORDER"); // Spatial polynomial order
     
    341264            }
    342265
    343             pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
    344 
    345             psStats *bg = psStatsAlloc(PS_STAT_ROBUST_STDEV); // Statistics for background
    346             psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    347             if (!psImageBackground(bg, NULL, readout->image, readout->mask, maskVal | maskBad, rng)) {
    348                 psError(PPSTACK_ERR_DATA, false, "Can't measure background for image.");
    349                 psFree(fake);
    350                 psFree(optWidths);
    351                 psFree(conv);
    352                 psFree(bg);
    353                 psFree(rng);
    354                 return false;
    355             }
    356             float minFlux = NOISE_FRACTION * bg->robustStdev; // Minimum flux level for fake image
    357             psFree(rng);
    358             psFree(bg);
    359 
    360             // For the sake of stamps, remove nearby sources
    361             psArray *stampSources = stackSourcesFilter(options->sourceLists->data[index],
    362                                                        footprint); // Filtered list of sources
    363 
    364             bool oldThreads = pmReadoutFakeThreads(true); // Old threading state
    365             if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows,
    366                                           stampSources, SOURCE_MASK, NULL, NULL, options->psf,
    367                                           minFlux, footprint + size, false, true)) {
    368                 psError(PPSTACK_ERR_DATA, false, "Unable to generate fake image with target PSF.");
    369                 psFree(fake);
    370                 psFree(optWidths);
    371                 psFree(conv);
    372                 return false;
    373             }
    374             pmReadoutFakeThreads(oldThreads);
    375 
     266            pmReadout *fake = pmReadoutAlloc(NULL);
     267            fake->image = psImageCopy(NULL, target, PS_TYPE_F32);
    376268            fake->mask = psImageCopy(NULL, readout->mask, PS_TYPE_IMAGE_MASK);
    377269
     
    420312                    psFree(fake);
    421313                    psFree(optWidths);
    422                     psFree(stampSources);
    423314                    psFree(conv);
    424315                    if (threads > 0) {
     
    436327                    psFree(fake);
    437328                    psFree(optWidths);
    438                     psFree(stampSources);
    439329                    psFree(conv);
    440330                    psFree(widthsCopy);
     
    446336
    447337                if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing,
    448                                         threshold, stampSources, stampsName, type, size, order, widthsCopy,
     338                                        threshold, options->sources, stampsName, type, size, order, widthsCopy,
    449339                                        orders, inner, ringsOrder, binning, penalty,
    450340                                        optimum, optWidths, optOrder, optThresh, iter, rej, normFrac,
     
    454344                    psFree(fake);
    455345                    psFree(optWidths);
    456                     psFree(stampSources);
    457346                    psFree(conv);
    458347                    psFree(widthsCopy);
     
    492381            psFree(fake);
    493382            psFree(optWidths);
    494             psFree(stampSources);
    495383
    496384            if (threads > 0) {
Note: See TracChangeset for help on using the changeset viewer.