Changeset 35383
- Timestamp:
- Apr 9, 2013, 1:33:36 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
ppStack/src/ppStackMatch.c (modified) (7 diffs)
-
ppStack/src/ppStackSources.c (modified) (11 diffs)
-
ppStack/src/ppStackTarget.c (modified) (2 diffs)
-
psModules/src/objects/pmSourceMatch.c (modified) (3 diffs)
-
psModules/src/objects/pmSourceMatch.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackMatch.c
r34089 r35383 8 8 // #define TESTING // Enable debugging output 9 9 // #define TESTING_REUSE_CONV // Enable debugging for re-using convolved outputs from previous run 10 11 // #define TESTING_CZW 10 12 11 13 #ifdef TESTING_REUSE_CONV … … 264 266 // Add the background into the target image 265 267 psImage *bgImage = stackBackgroundModel(readout, config); // Image of background 266 psBinaryOp(fake->image, fake->image, "+", bgImage);268 psBinaryOp(fake->image, fake->image, "+", bgImage); 267 269 psFree(bgImage); 268 270 #endif 269 271 270 #ifdef TESTING 272 #ifdef TESTING_CZW 271 273 { 272 274 pmHDU *hdu = pmHDUFromCell(readout->parent); 273 275 psString name = NULL; 274 psStringAppend(&name, " fake_%03d.fits", index);276 psStringAppend(&name, "/local/tmp/fake_%03d.fits", index); 275 277 pmStackVisualPlotTestImage(fake->image, name); 276 278 psFits *fits = psFitsOpen(name, "w"); … … 282 284 pmHDU *hdu = pmHDUFromCell(readout->parent); 283 285 psString name = NULL; 284 psStringAppend(&name, " real_%03d.fits", index);286 psStringAppend(&name, "/local/tmp/real_%03d.fits", index); 285 287 pmStackVisualPlotTestImage(readout->image, name); 286 288 psFits *fits = psFitsOpen(name, "w"); 287 289 psFree(name); 288 290 psFitsWriteImage(fits, hdu->header, readout->image, 0, NULL); 291 psFitsClose(fits); 292 } 293 { 294 pmHDU *hdu = pmHDUFromCell(readout->parent); 295 psString name = NULL; 296 psStringAppend(&name, "/local/tmp/real_var_%03d.fits", index); 297 pmStackVisualPlotTestImage(readout->variance, name); 298 psFits *fits = psFitsOpen(name, "w"); 299 psFree(name); 300 psFitsWriteImage(fits, hdu->header, readout->variance, 0, NULL); 289 301 psFitsClose(fits); 290 302 } … … 355 367 356 368 357 #ifdef TESTING 369 #ifdef TESTING_CZW 358 370 { 359 371 pmHDU *hdu = pmHDUFromCell(readout->parent); 360 372 psString name = NULL; 361 psStringAppend(&name, " conv_%03d.fits", index);373 psStringAppend(&name, "/local/tmp/conv_%03d.fits", index); 362 374 pmStackVisualPlotTestImage(conv->image, name); 363 375 psFits *fits = psFitsOpen(name, "w"); … … 369 381 pmHDU *hdu = pmHDUFromCell(readout->parent); 370 382 psString name = NULL; 371 psStringAppend(&name, "diff_%03d.fits", index); 383 psStringAppend(&name, "/local/tmp/conv_var_%03d.fits", index); 384 pmStackVisualPlotTestImage(conv->variance, name); 385 psFits *fits = psFitsOpen(name, "w"); 386 psFree(name); 387 psFitsWriteImage(fits, hdu->header, conv->variance, 0, NULL); 388 psFitsClose(fits); 389 } 390 { 391 pmHDU *hdu = pmHDUFromCell(readout->parent); 392 psString name = NULL; 393 psStringAppend(&name, "/local/tmp/diff_%03d.fits", index); 372 394 pmStackVisualPlotTestImage(fake->image, name); 373 395 psFits *fits = psFitsOpen(name, "w"); … … 510 532 } 511 533 512 if (!stackRenormaliseReadout(config, readout)) { 513 psFree(rng); 514 psFree(bg); 515 return false; 516 } 517 534 #ifdef TESTING_CZW 535 // CZW begin check of weight before renormalize step 518 536 // Measure the variance level for the weighting 519 537 if (psMetadataLookupBool(NULL, recipe, "WEIGHTS")) { … … 529 547 options->weightings->data.F32[index] = 1.0; 530 548 } 531 psLogMsg("ppStack", PS_LOG_INFO, "Weighting for image %d is %f\n", 532 index, options->weightings->data.F32[index]); 549 psLogMsg("ppStack", PS_LOG_INFO, "Prenorm Weighting for image %d is %g covar %g median %g\n", 550 index, options->weightings->data.F32[index],psImageCovarianceFactor(readout->covariance), 551 psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN)); 552 // CZW end 553 #endif 554 if (!stackRenormaliseReadout(config, readout)) { 555 psFree(rng); 556 psFree(bg); 557 return false; 558 } 559 560 // Measure the variance level for the weighting 561 if (psMetadataLookupBool(NULL, recipe, "WEIGHTS")) { 562 if (!psImageBackground(bg, NULL, readout->variance, readout->mask, maskVal | maskBad, rng)) { 563 psError(PPSTACK_ERR_DATA, false, "Can't measure mean variance for image."); 564 psFree(rng); 565 psFree(bg); 566 return false; 567 } 568 options->weightings->data.F32[index] = 1.0 / (psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN) * 569 psImageCovarianceFactor(readout->covariance)); 570 } else { 571 options->weightings->data.F32[index] = 1.0; 572 } 573 psLogMsg("ppStack", PS_LOG_INFO, "Weighting for image %d is %g covar %g median %g\n", 574 index, options->weightings->data.F32[index],psImageCovarianceFactor(readout->covariance), 575 psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN)); 533 576 534 577 psFree(rng); -
trunk/ppStack/src/ppStackSources.c
r34174 r35383 11 11 #endif 12 12 13 #ifdef TESTING 13 // #define TESTING_CZW 14 15 #ifdef TESTING_CZW 14 16 // Dump matches to a file 15 17 static void dumpMatches(const char *filename, // File to which to dump … … 28 30 psVectorInit(magErr, NAN); 29 31 for (int j = 0; j < match->num; j++) { 32 if (match->mask) { 30 33 if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) { 31 continue; 32 } 34 continue; 35 } 36 } 33 37 int index = match->image->data.U32[j]; // Image index 34 38 mag->data.F32[index] = match->mag->data.F32[j] - zp->data.F32[index]; … … 39 43 } 40 44 for (int j = 0; j < num; j++) { 41 fprintf(outMatches, "%f (%f) ", mag->data.F32[j], magErr->data.F32[j]); 45 fprintf(outMatches, "%f %f %f %f %f %f\t", 46 match->mag->data.F32[j], 47 zp->data.F32[j], 48 trans ? trans->data.F32[j] : NAN, 49 magErr->data.F32[j], 50 match->x->data.F32[j], 51 match->y->data.F32[j]); 42 52 } 43 53 fprintf(outMatches, "\n"); … … 271 281 return false; 272 282 } 273 274 #ifdef TESTING 283 options->sources = psMemIncrRefCounter(matches); 284 psArray *matchedSources = psArrayAlloc(0); 285 286 #ifdef TESTING_CZW 275 287 dumpMatches("source_match.dat", num, matches, zp, NULL); 276 288 #endif 277 289 278 290 if (options->matchZPs) { 279 psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1, 291 292 psVector *trans = pmSourceMatchRelphot(matches, matchedSources, zp, tol, iter1, starRej1, starSys1, 280 293 iter2, starRej2, starSys2, starLimit, 281 294 transIter, transRej, transThresh); // Transparencies per image … … 324 337 325 338 // m_inst_o - m_inst_i = zp[i] - zpTarget - c1 * airmassTarget - 2.5log(sumExpTime) - trans_i 326 339 #ifdef TESTING_CZW 340 dumpMatches("source_match2.dat", num, matches, zp, trans); 341 #endif 327 342 if (options->matchZPs) { 328 343 options->norm = psVectorAlloc(num, PS_TYPE_F32); 329 344 for (int i = 0; i < num; i++) { 330 if (inputMask->data.U8[i] ||!isfinite(trans->data.F32[i])) {331 continue;332 }345 if (!isfinite(trans->data.F32[i])) { 346 continue; 347 } 333 348 psArray *sources = sourceLists->data[i]; // Sources of interest 334 349 float magCorr = zp->data.F32[i] - trans->data.F32[i] - 2.5*log10(options->sumExposure) - airmassTerm * airmassTarget; … … 341 356 options->norm->data.F32[i] = magCorr; 342 357 psLogMsg("ppStack", PS_LOG_INFO, 343 "Applying scale correction to image %d: %f mag (%f) \n",344 i, magCorr, trans->data.F32[i] );358 "Applying scale correction to image %d: %f mag (%f) (with inputMask value %d)\n", 359 i, magCorr, trans->data.F32[i],inputMask->data.U8[i]); 345 360 346 361 for (int j = 0; j < sources->n; j++) { 347 362 pmSource *source = sources->data[j]; // Source of interest 363 source->psfMag += magCorr; 364 source->apMag += magCorr; 365 348 366 if (!source) { 349 367 continue; 350 368 } 351 369 // XXX need to apply to apMag as well 352 source->psfMag += magCorr; 353 source->apMag += magCorr; 370 psTrace("ppStack",5,"Source corrections: %d %d %f %f %f %f %f %f %f %f\n",i,j, 371 source->peak->xf,source->peak->yf, 372 source->psfMag,source->psfMagErr, 373 airmassTerm,airmassTarget,2.5 * log10(options->sumExposure), 374 source->psfMag + magCorr); 354 375 } 355 376 } 356 377 } 378 matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches 357 379 358 380 if (zpExpNum == numGoodImages) { … … 366 388 367 389 368 #ifdef TESTING369 dumpMatches("source_mags.dat", num, matches, zp, trans);370 #endif371 390 psFree(trans); 372 391 373 #ifdef TESTING 392 #ifdef TESTING_CZW 374 393 // Double check: all transparencies should be zero 375 394 { 376 395 psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches 396 psArray *matchedSources = psArrayAlloc(matches->n); 377 397 if (!matches) { 378 398 psError(PPSTACK_ERR_DATA, false, "Unable to match sources"); … … 380 400 return false; 381 401 } 382 psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1,402 psVector *trans = pmSourceMatchRelphot(matches, matchedSources, zp, tol, iter1, starRej1, starSys1, 383 403 iter2, starRej2, starSys2, starLimit, 384 404 transIter, transRej, transThresh); // Transparencies … … 386 406 fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]); 387 407 } 408 388 409 psFree(trans); 389 410 psFree(matches); 390 } 391 #endif 392 } 393 394 psFree(zp); 411 psFree(matchedSources); 412 } 413 #endif 414 } 415 416 395 417 psFree(zpExp); 396 418 397 419 #ifdef ASTROMETRY 420 // CZW: This is off by default. 398 421 // Position offsets 399 422 { … … 436 459 437 460 #if (defined TESTING && defined ASTROMETRY) 461 // CZW: This is off by default. 438 462 // Double check: all offsets should be zero 439 463 { … … 458 482 if (options->photometry) { 459 483 // Save best matches for future photometry 460 psArray *sourcesBest = options->sources = psArrayAllocEmpty(matches->n); 461 484 psArray *sourcesBest = options->sources = psArrayAllocEmpty(matches->n); 462 485 // XXX something of a hack: require at least 2 detections or the nominated fraction of the max possible 463 486 //int minMatches = PS_MAX(2, fracMatch * num);// Minimum number of matches required 464 487 //MEH - if many poor images, will hit oddity with num fraction. use numGoodImages instead 465 int minMatches = PS_MAX(2, fracMatch * numGoodImages);// Minimum number of matches required 466 467 int good0 = 0; 468 for (int i = 0; i < num; i++) { 469 if (inputMask->data.U8[i]) { 470 continue; 471 } 472 good0 = i; 473 break; 488 int minMatches = PS_MAX(2, fracMatch * numGoodImages);// Minimum number of matches required 489 490 int good0 = 0; 491 for (int i = 0; i < num; i++) { 492 if (inputMask->data.U8[i]) { 493 continue; 474 494 } 475 476 for (int i = 0; i < matches->n; i++) { 477 pmSourceMatch *match = matches->data[i]; // Match of interest 478 if (match->num < minMatches) { 479 continue; 480 } 481 482 // We need to grab a single instance of this source: just take the first available 483 // MEH - if first available is a rejected image, then problem. so take first non-rejected instance above 484 //int image = match->image->data.S32[0]; // Index of image 485 //int index = match->index->data.S32[0]; // Index of source within image 486 int image = match->image->data.S32[good0]; // Index of image 487 int index = match->index->data.S32[good0]; // Index of source within image 488 psArray *sources = sourceLists->data[image]; // Sources for image 489 pmSource *source = sources->data[index]; // Source of interest 490 491 psArrayAdd(sourcesBest, sourcesBest->n, source); 492 } 493 psLogMsg("ppStack", PS_LOG_INFO, "Selected %ld sources for photometry analysis", sourcesBest->n); 494 } 495 495 good0 = i; 496 break; 497 } 498 499 for (int i = 0; i < matches->n; i++) { 500 pmSourceMatch *match = matches->data[i]; // Match of interest 501 if (match->num < minMatches) { 502 continue; 503 } 504 505 // We need to grab a single instance of this source: just take the first available 506 // MEH - if first available is a rejected image, then problem. so take first non-rejected instance above 507 // int image = match->image->data.S32[0]; // Index of image 508 // int index = match->index->data.S32[0]; // Index of source within image 509 int image = match->image->data.S32[good0]; // Index of image 510 int index = match->index->data.S32[good0]; // Index of source within image 511 psArray *sources = sourceLists->data[image]; // Sources for image 512 pmSource *source = sources->data[index]; // Source of interest 513 514 // CZW: Accept the first source for all properties, except for the magnitudes. 515 // We have average magnitudes from relphot, so we should use those 516 pmSource *photsource = matchedSources->data[i]; 517 if ((photsource)&&(isfinite(photsource->psfMag))) { 518 // CZW: photsource is the average relphot mag, which is equal to <m_i + zpIN_j> 519 // (primed are averaged values for this discussion) 520 // Therefore, the correct magnitude for psfMag' is: 521 // psfMag' = (photsource - zpIN_j + magCorr) 522 // apMag - psfMag should be retained, so: 523 // apMag - psfMag = apMag' - psfMag' 524 // apMag' = apMag + psfMag' - psfMag 525 source->apMag = source->apMag + (photsource->psfMag + options->norm->data.F32[image] - zp->data.F32[image] - source->psfMag); 526 source->psfMag = photsource->psfMag + options->norm->data.F32[image] - zp->data.F32[image]; 527 528 psTrace("ppStack", 5, "Best Source %d/%ld @ %f %f %f %f %f %d",i,sourcesBest->n,source->peak->xf,source->peak->yf, 529 source->psfMag, 530 photsource->psfMag + options->norm->data.F32[image] - zp->data.F32[image] , 531 source->psfMagErr,-1); 532 psArrayAdd(sourcesBest, sourcesBest->n, source); 533 } 534 } 535 psLogMsg("ppStack", PS_LOG_INFO, "Selected %ld sources for photometry analysis", sourcesBest->n); 536 537 } 538 psFree(zp); 496 539 psFree(matches); 497 540 -
trunk/ppStack/src/ppStackTarget.c
r34089 r35383 60 60 } 61 61 float xSource, ySource; // Coordinates of source 62 coordsFromSource(&xSource, &ySource, NULL, source); 62 float Smag; // magnitude of source 63 coordsFromSource(&xSource, &ySource, &Smag, source); 63 64 64 65 coords->data.F64[0] = xSource; … … 66 67 67 68 psVector *indices = psTreeAllWithin(tree, coords, exclusion); // Number within exclusion zone 68 psTrace("ppStack", 9, "Source at %.0lf,%.0lf has %ld sources in exclusion zone",69 coords->data.F64[0], coords->data.F64[1], indices->n);69 psTrace("ppStack", 5, "Filtering: Source at %.0lf %.0lf with mag %f has %ld sources in exclusion zone", 70 coords->data.F64[0], coords->data.F64[1], Smag, indices->n); 70 71 if (indices->n == 1) { 71 72 // Only itself inside the exclusion zone -
trunk/psModules/src/objects/pmSourceMatch.c
r35240 r35383 630 630 631 631 psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches 632 psArray *matchedSources, // Array of averaged sources 632 633 const psVector *zp, // Zero points for each image (including airmass term) 633 634 float tol, // Relative tolerance for convergence … … 648 649 PS_ASSERT_VECTOR_TYPE(zp, PS_TYPE_F32, NULL); 649 650 PS_ASSERT_FLOAT_LARGER_THAN(transClip, 0.0, NULL); 650 651 PS_ASSERT_ARRAY_NON_NULL(matchedSources, NULL); 652 651 653 sys1 *= sys1; 652 654 sys2 *= sys2; … … 742 744 } 743 745 746 for (int i = 0; i < matches->n; i++) { 747 pmSource *source = pmSourceAlloc(); 748 source->psfMag = stars->data.F32[i]; 749 psArrayAdd(matchedSources,matchedSources->n,source); 750 } 751 744 752 psFree(photo); 745 753 psFree(badImage); -
trunk/psModules/src/objects/pmSourceMatch.h
r35240 r35383 74 74 /// Perform relative photometry to calibrate images 75 75 psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches 76 psArray *matchedSources, // Array of average sources 76 77 const psVector *zp, // Zero points for each image (including airmass term) 77 78 float tol, // Relative tolerance for convergence
Note:
See TracChangeset
for help on using the changeset viewer.
