Changeset 28253
- Timestamp:
- Jun 7, 2010, 4:52:17 PM (16 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 1 added
- 5 edited
-
Makefile.am (modified) (1 diff)
-
ppStack.h (modified) (2 diffs)
-
ppStackConvolve.c (modified) (10 diffs)
-
ppStackFiles.c (modified) (2 diffs)
-
ppStackMatch.c (modified) (10 diffs)
-
ppStackTarget.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/Makefile.am
r27037 r28253 48 48 ppStackPhotometry.c \ 49 49 ppStackFinish.c \ 50 ppStackTarget.c \ 50 51 ppStackErrorCodes.c 51 52 -
trunk/ppStack/src/ppStack.h
r27427 r28253 26 26 typedef enum { 27 27 PPSTACK_FILES_PREPARE, // Files for preparation 28 PPSTACK_FILES_TARGET, // Files for target generation 28 29 PPSTACK_FILES_CONVOLVE, // Files for convolution 29 30 PPSTACK_FILES_STACK, // Stack files … … 115 116 void ppStackVersionPrint(void); 116 117 118 /// Generate target PSF image 119 psImage *ppStackTarget(ppStackOptions *options, // Options for stacking 120 pmConfig *config // Configuration 121 ); 122 117 123 /// Convolve image to match specified seeing 118 124 bool ppStackMatch(pmReadout *readout, // Readout to be convolved; replaced with output 125 const psImage *target, // Target PSF image 119 126 ppStackOptions *options, // Options for stacking 120 127 int index, // Index of image to match -
trunk/ppStack/src/ppStackConvolve.c
r28182 r28253 45 45 options->convCovars = psArrayAlloc(num); // Covariance matrices 46 46 47 psImage *target = NULL; // Target PSF image 48 if (options->convolve) { 49 target = ppStackTarget(options, config); 50 if (!target) { 51 psError(psErrorCodeLast(), false, "Unable to produce stack target image"); 52 return false; 53 } 54 } 55 47 56 psVector *renorms = psVectorAlloc(num, PS_TYPE_F32); // Renormalisation values for variances 48 57 psVectorInit(renorms, NAN); … … 71 80 psFree(fpaList); 72 81 psFree(cellList); 82 psFree(target); 73 83 return false; 74 84 } … … 87 97 psFree(fpaList); 88 98 psFree(cellList); 99 psFree(target); 89 100 return false; 90 101 } … … 93 104 psTimerStart("PPSTACK_MATCH"); 94 105 options->origCovars->data[i] = psMemIncrRefCounter(readout->covariance); 95 if (!ppStackMatch(readout, options, i, config)) {106 if (!ppStackMatch(readout, target, options, i, config)) { 96 107 // XXX many things can cause a failure of ppStackMatch -- should some be handled differently? 97 108 psErrorCode error = psErrorCodeLast(); // Error code … … 102 113 case PPSTACK_ERR_IO: 103 114 psError(error, false, "Unable to match image %d due to fatal error.", i); 115 psFree(rng); 116 psFree(fpaList); 117 psFree(cellList); 118 psFree(target); 104 119 return false; 105 120 // Non-fatal errors … … 154 169 psFree(cellList); 155 170 psFree(rng); 171 psFree(target); 156 172 return false; 157 173 } … … 164 180 psFree(rng); 165 181 psFree(maskHeader); 182 psFree(target); 166 183 return false; 167 184 } … … 172 189 psFree(cellList); 173 190 psFree(rng); 191 psFree(target); 174 192 return false; 175 193 } … … 222 240 psFree(cellList); 223 241 psFree(rng); 242 psFree(target); 224 243 return false; 225 244 } … … 229 248 } 230 249 psFree(rng); 250 psFree(target); 231 251 232 252 psFree(options->sourceLists); options->sourceLists = NULL; -
trunk/ppStack/src/ppStackFiles.c
r27417 r28253 16 16 static char *filesPrepare[] = { "PPSTACK.INPUT.PSF", "PPSTACK.INPUT.SOURCES", "PPSTACK.TARGET.PSF", NULL }; 17 17 18 /// Files required for generating convolution target 19 static char *filesTarget[] = { "PPSTACK.INPUT.VARIANCE", "PPSTACK.INPUT.MASK", NULL }; 20 18 21 /// Files required for the convolution 19 22 static char *filesConvolve[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", NULL }; 20 21 // "PPSTACK.CONV.KERNEL", NULL };22 23 23 24 /// Regular (convolved) stack files … … 41 42 switch (list) { 42 43 case PPSTACK_FILES_PREPARE: return filesPrepare; 44 case PPSTACK_FILES_TARGET: return filesTarget; 43 45 case PPSTACK_FILES_CONVOLVE: return filesConvolve; 44 46 case PPSTACK_FILES_STACK: return filesStack; -
trunk/ppStack/src/ppStackMatch.c
r27426 r28253 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.
