Changeset 28304 for branches/czw_branch/20100519/ppStack/src/ppStackMatch.c
- Timestamp:
- Jun 10, 2010, 6:28:51 PM (16 years ago)
- Location:
- branches/czw_branch/20100519
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppStack/src/ppStackMatch.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20100519
- Property svn:mergeinfo changed
-
branches/czw_branch/20100519/ppStack/src/ppStackMatch.c
r27426 r28304 13 13 #define MAG_IGNORE 50 // Ignore magnitudes fainter than this --- they're not real! 14 14 #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 sources17 #define NOISE_FRACTION 0.01 // Set minimum flux to this fraction of noise18 15 #define COVAR_FRAC 0.01 // Truncation fraction for covariance matrix 19 16 … … 49 46 #endif 50 47 51 // Get coordinates from a source52 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 filter68 int exclusion // Exclusion zone, pixels69 )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 sources77 psVector *x = psVectorAlloc(num, PS_TYPE_F32), *y = psVectorAlloc(num, PS_TYPE_F32); // Coordinates78 int numGood = 0; // Number of good sources79 for (int i = 0; i < num; i++) {80 pmSource *source = sources->data[i]; // Source of interest81 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 tree90 91 psArray *filtered = psArrayAllocEmpty(numGood); // Filtered list of sources92 psVector *coords = psVectorAlloc(2, PS_TYPE_F64); // Coordinates of source93 int numFiltered = 0; // Number of filtered sources94 for (int i = 0; i < num; i++) {95 pmSource *source = sources->data[i]; // Source of interest96 if (!source) {97 continue;98 }99 float xSource, ySource; // Coordinates of source100 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 zone106 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 zone110 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 }124 48 125 49 // Add background into the fake image … … 202 126 203 127 204 bool ppStackMatch(pmReadout *readout, ppStackOptions *options, int index, const pmConfig *config) 128 bool ppStackMatch(pmReadout *readout, const psImage *target, ppStackOptions *options, 129 int index, const pmConfig *config) 205 130 { 206 131 assert(readout); … … 286 211 } else { 287 212 #endif 288 289 213 // 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"); 292 215 293 216 int order = psMetadataLookupS32(NULL, ppsub, "SPATIAL.ORDER"); // Spatial polynomial order … … 341 264 } 342 265 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); 376 268 fake->mask = psImageCopy(NULL, readout->mask, PS_TYPE_IMAGE_MASK); 377 269 … … 420 312 psFree(fake); 421 313 psFree(optWidths); 422 psFree(stampSources);423 314 psFree(conv); 424 315 if (threads > 0) { … … 436 327 psFree(fake); 437 328 psFree(optWidths); 438 psFree(stampSources);439 329 psFree(conv); 440 330 psFree(widthsCopy); … … 446 336 447 337 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, 449 339 orders, inner, ringsOrder, binning, penalty, 450 340 optimum, optWidths, optOrder, optThresh, iter, rej, normFrac, … … 454 344 psFree(fake); 455 345 psFree(optWidths); 456 psFree(stampSources);457 346 psFree(conv); 458 347 psFree(widthsCopy); … … 492 381 psFree(fake); 493 382 psFree(optWidths); 494 psFree(stampSources);495 383 496 384 if (threads > 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
