Changeset 34542
- Timestamp:
- Oct 24, 2012, 8:52:34 AM (14 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 4 edited
-
psphot.h (modified) (1 diff)
-
psphotKronIterate.c (modified) (12 diffs)
-
psphotSourceMatch.c (modified) (2 diffs)
-
psphotStackReadout.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphot.h
r34528 r34542 372 372 bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, const char *filerule, int index); 373 373 bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS); 374 bool psphot DropBadMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);374 bool psphotFilterMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects); 375 375 376 376 bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final); -
trunk/psphot/src/psphotKronIterate.c
r34418 r34542 2 2 3 3 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool oldWindow); 4 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, bool applyWeight, psImage *smoothedPixels );4 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, bool applyWeight, psImage *smoothedPixels, bool measureRadius); 5 5 6 6 … … 185 185 } 186 186 187 if (pass == 3) { 188 KRON_SMOOTH = false; 189 KRON_ITERATIONS = 1; 190 } 191 187 192 // We measure the Kron Radius on a smoothed copy of the readout image 188 193 psImage *smoothedImage = NULL; … … 311 316 float KRON_SB_MIN_DIVISOR = PS_SCALAR_VALUE(job->args->data[12],F32); 312 317 int pass = PS_SCALAR_VALUE(job->args->data[13],S32); 313 #ifndef REVERT_ON_BAD_MEASUREMENT 314 (void) pass; 315 #endif 318 319 bool measureRadius = true; 320 if (pass == 3) { 321 measureRadius = false; 322 } 316 323 317 324 for (int j = 0; j < KRON_ITERATIONS; j++) { … … 320 327 pmSource *source = sources->data[i]; 321 328 if (!source->peak) continue; // XXX how can we have a peak-less source? 329 330 if (pass == 3) { 331 // in pass 3 we only measure the flux for matched sources 332 if (!(source->mode2 & PM_SOURCE_MODE2_MATCHED)) { 333 continue; 334 } 335 } 322 336 323 337 # if (0) … … 331 345 # endif 332 346 333 // check status of this source's moments 334 if (!source->moments) continue; 335 if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue; 336 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 347 if (measureRadius) { 348 // check status of this source's moments 349 if (!source->moments) continue; 350 if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue; 351 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 352 } 353 337 354 if (!isfinite(source->moments->Mrf)) { 338 355 // Once we save a bad Mrf measurement we give up on this source … … 358 375 // On first iteration set window radius to sky radius (if valid). We also use this on subsequent 359 376 // iterations if we cannot find a better limit 360 float maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 377 float maxWindow; 378 if (measureRadius) { 379 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 380 } else { 381 maxWindow = source->moments->Mrf; 382 } 361 383 if (j > 0) { 362 384 // on subsequent iterations we use a factor times the previous radial moment value … … 402 424 // does not meet the requirements for measuring the Kron Radius or Magnitude. 403 425 // Note: that it performs the cuts even if KRON_APPLY_WINDOW is false 404 if ( psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) {426 if (!measureRadius || psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) { 405 427 406 428 // this function populates moments->Mrf,KronFlux,KronFluxErr 407 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, KRON_APPLY_WEIGHT, smoothedPixels); 429 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, 430 KRON_APPLY_WEIGHT, smoothedPixels, measureRadius); 431 408 432 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 409 433 … … 444 468 445 469 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, 446 bool applyWeight, psImage *smoothedPixels ) {470 bool applyWeight, psImage *smoothedPixels, bool measureRadius) { 447 471 448 472 PS_ASSERT_PTR_NON_NULL(source, false); … … 495 519 psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA; 496 520 497 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 498 499 psF32 yDiff = row - yCM; 500 if (fabs(yDiff) > radius) continue; 501 502 // coordinate of mirror pixel 503 int yFlip = yCM - yDiff; 504 if (yFlip < 0) continue; 505 if (yFlip >= source->pixels->numRows) continue; 506 507 for (psS32 col = 0; col < source->pixels->numCols ; col++) { 508 // check mask and value for this pixel 509 if (vMsk && (vMsk[row][col] & maskVal)) continue; 510 if (isnan(vPix[row][col])) continue; 511 512 psF32 xDiff = col - xCM; 513 if (fabs(xDiff) > radius) continue; 514 515 // coordinate of mirror pixel 516 int xFlip = xCM - xDiff; 517 if (xFlip < 0) continue; 518 if (xFlip >= source->pixels->numCols) continue; 519 520 // check mask and value for mirror pixel 521 if (vMsk && (vMsk[yFlip][xFlip] & maskVal)) continue; 522 if (isnan(vPix[yFlip][xFlip])) continue; 523 524 // radius is just a function of (xDiff, yDiff) 525 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 526 if (r2 > R2) continue; 527 528 // flux * window 529 float z = r2 * rsigma2; 530 assert (z >= 0.0); 531 532 // weight by window image and wide Gaussian 533 float weight1 = vWin[row+Ywo][col+Xwo]*exp(-z); 534 float weight2 = vWin[yFlip+Ywo][xFlip+Xwo]*exp(-z); 535 536 float fDiff1 = vPix[row][col]*weight1; 537 float fDiff2 = vPix[yFlip][xFlip]*weight2; 538 539 float pDiff = (fDiff1 > 0.0) ? sqrt(fabs(fDiff1*fDiff2)) : -sqrt(fabs(fDiff1*fDiff2)); 540 541 // Kron Flux uses the 1st radial moment (maybe Gaussian windowed?) 542 psF32 rf = pDiff * sqrt(r2); 543 psF32 rs = 0.5 * (fDiff1 + fDiff2); 544 545 RF += rf; 546 RS += rs; 547 } 548 } 549 550 float MrfTry = RF/RS; 551 if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) { 552 // We did not get a good measurement 553 source->moments->Mrf = NAN; 554 source->moments->KronFlux = NAN; 555 source->moments->KronFluxErr = NAN; 556 return false; 557 } 558 559 float Mrf = MAX(minKronRadius, MrfTry); 560 // Saturate the 1st radial moment 561 if (sqrt(source->peak->detValue) < 10.0) { 562 Mrf = MIN (radius, Mrf); 521 if (measureRadius) { 522 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 523 524 psF32 yDiff = row - yCM; 525 if (fabs(yDiff) > radius) continue; 526 527 // coordinate of mirror pixel 528 int yFlip = yCM - yDiff; 529 if (yFlip < 0) continue; 530 if (yFlip >= source->pixels->numRows) continue; 531 532 for (psS32 col = 0; col < source->pixels->numCols ; col++) { 533 // check mask and value for this pixel 534 if (vMsk && (vMsk[row][col] & maskVal)) continue; 535 if (isnan(vPix[row][col])) continue; 536 537 psF32 xDiff = col - xCM; 538 if (fabs(xDiff) > radius) continue; 539 540 // coordinate of mirror pixel 541 int xFlip = xCM - xDiff; 542 if (xFlip < 0) continue; 543 if (xFlip >= source->pixels->numCols) continue; 544 545 // check mask and value for mirror pixel 546 if (vMsk && (vMsk[yFlip][xFlip] & maskVal)) continue; 547 if (isnan(vPix[yFlip][xFlip])) continue; 548 549 // radius is just a function of (xDiff, yDiff) 550 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 551 if (r2 > R2) continue; 552 553 // flux * window 554 float z = r2 * rsigma2; 555 assert (z >= 0.0); 556 557 // weight by window image and wide Gaussian 558 float weight1 = vWin[row+Ywo][col+Xwo]*exp(-z); 559 float weight2 = vWin[yFlip+Ywo][xFlip+Xwo]*exp(-z); 560 561 float fDiff1 = vPix[row][col]*weight1; 562 float fDiff2 = vPix[yFlip][xFlip]*weight2; 563 564 float pDiff = (fDiff1 > 0.0) ? sqrt(fabs(fDiff1*fDiff2)) : -sqrt(fabs(fDiff1*fDiff2)); 565 566 // Kron Flux uses the 1st radial moment (maybe Gaussian windowed?) 567 psF32 rf = pDiff * sqrt(r2); 568 psF32 rs = 0.5 * (fDiff1 + fDiff2); 569 570 RF += rf; 571 RS += rs; 572 } 573 } 574 575 float MrfTry = RF/RS; 576 if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) { 577 // We did not get a good measurement 578 source->moments->Mrf = NAN; 579 source->moments->KronFlux = NAN; 580 source->moments->KronFluxErr = NAN; 581 return false; 582 } 583 584 float Mrf = MAX(minKronRadius, MrfTry); 585 // Saturate the 1st radial moment 586 if (sqrt(source->peak->detValue) < 10.0) { 587 Mrf = MIN (radius, Mrf); 588 } 589 source->moments->Mrf = Mrf; 563 590 } 564 591 565 592 // Calculate the Kron magnitude (make this block optional?) 566 float radKron = 2.5 *Mrf;593 float radKron = 2.5 * source->moments->Mrf; 567 594 float radKron2 = radKron*radKron; 568 595 … … 575 602 // smoothed image above) 576 603 vPix = source->pixels->data.F32; 577 578 604 579 605 for (psS32 row = 0; row < source->pixels->numRows ; row++) { … … 607 633 } 608 634 609 source->moments->Mrf = Mrf;610 635 source->moments->KronFlux = Sum; 611 636 source->moments->KronFluxErr = sqrt(Var); … … 621 646 if (source->type == PM_SOURCE_TYPE_DEFECT) return false; 622 647 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 648 if (source->mode2 & PM_SOURCE_MODE2_MATCHED) return true; 649 623 650 if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) return false; 624 651 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) return false; -
trunk/psphot/src/psphotSourceMatch.c
r34354 r34542 559 559 } 560 560 561 bool psphot DropBadMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects) {561 bool psphotFilterMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects) { 562 562 563 563 bool status = false; 564 564 565 psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Drop BadMatched Sources ---");565 psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Filter Matched Sources ---"); 566 566 567 567 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); … … 615 615 psFree(dropped); 616 616 617 // find the "best" Mrf from the detected sources. 618 // Currently we use the smallest positive value 619 for (int i=0; i< objects->n; i++) { 620 pmPhotObj *obj = objects->data[i]; 621 622 float minMrf = 1000.; 623 bool hasMatched = false; 624 for (int j = 0; j < obj->sources->n; j++) { 625 pmSource *source = obj->sources->data[j]; 626 if (source->mode2 & PM_SOURCE_MODE2_MATCHED) { 627 hasMatched = true; 628 continue; 629 } 630 float Mrf = source->moments->Mrf; 631 if (isfinite(Mrf) && Mrf < minMrf && Mrf > 0) { 632 minMrf = Mrf; 633 } 634 } 635 636 if (!hasMatched || minMrf > 120.) { 637 continue; 638 } 639 640 // set Mrf for matched sources to the value found above 641 for (int j = 0; j < obj->sources->n; j++) { 642 pmSource *source = obj->sources->data[j]; 643 if (source->mode2 & PM_SOURCE_MODE2_MATCHED) { 644 source->moments->Mrf = minMrf; 645 } 646 } 647 } 648 617 649 return true; 618 650 } -
trunk/psphot/src/psphotStackReadout.c
r34418 r34542 369 369 psMemDump("psfstats"); 370 370 371 // drop matched sources without any useful measurements 372 psphotDropBadMatchedSources (config, view, STACK_SRC, objects); 371 // drop matched sources without any useful measurements and set kron radii for the ones 372 // we decide to keep 373 psphotFilterMatchedSources (config, view, STACK_SRC, objects); 374 375 // measure kron fluxes for the matched sources only 376 psphotKronIterate(config, view, STACK_SRC, 3); 373 377 374 378 // measure elliptical apertures, petrosians (objects sorted by S/N)
Note:
See TracChangeset
for help on using the changeset viewer.
