- Timestamp:
- Aug 3, 2011, 10:30:02 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110710/psphot/src/psphotSourceFits.c
r31452 r31990 211 211 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 212 212 213 float radius;213 float fitRadius, windowRadius; 214 214 bool okEXT, okDBL; 215 215 pmModel *ONE = NULL; … … 225 225 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 226 226 227 # define TEST_X -540.0 228 # define TEST_Y 540.0 229 230 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 231 fprintf (stderr, "test galaxy\n"); 232 } 233 234 # undef TEST_X 235 # undef TEST_Y 236 227 237 // set the radius based on the footprint (also sets the mask pixels) 228 if (!psphotSetRadiusFootprint(&radius, readout, source, markVal, 1.0)) return false; 238 if (!psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal)) return false; 239 // fprintf (stderr, "rad: %6.1f %6.1f | %5.2f %5.2f %5.2f ", source->peak->xf, source->peak->yf, source->moments->Mrf, fitRadius, windowRadius); 229 240 230 241 // XXX note that this changes the source moments that are published... … … 234 245 // this uses the footprint to judge both radius and aperture? 235 246 // XXX save the psf-based moments for output 247 // XXX do not limit to pixels in the marked circle 236 248 psfMoments = *source->moments; 237 if (!pmSourceMoments (source, radius, 0.0, 0.5, 0.0, maskVal)) {249 if (!pmSourceMoments (source, windowRadius, 0.0, 0.5, 0.0, maskVal & PS_NOT_IMAGE_MASK(markVal))) { 238 250 *source->moments = psfMoments; 251 fprintf (stderr, "skip (bad moments)\n"); 239 252 return false; 240 253 } 254 // fprintf (stderr, "r1: %f\n", source->moments->Mrf); 255 256 // XXX note that we do not re-try to measure the moments if the resulting Mrf is large compared 257 // to the initial value 241 258 242 259 psTrace ("psphot", 5, "trying blob...\n"); … … 263 280 ONE = DBL->data[0]; 264 281 if (ONE) { 265 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");282 psAssert (isfinite(ONE->params->data.F32[PM_PAR_I0]), "nan in fit"); 266 283 chiDBL = ONE->chisqNorm; // save chisq for double-star/galaxy comparison 267 ONE->fitRadius = radius;284 ONE->fitRadius = fitRadius; 268 285 } 269 286 … … 271 288 ONE = DBL->data[1]; 272 289 if (ONE) { 273 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");274 ONE->fitRadius = radius;290 psAssert (isfinite(ONE->params->data.F32[PM_PAR_I0]), "nan in fit"); 291 ONE->fitRadius = fitRadius; 275 292 } 276 293 } … … 284 301 okEXT = psphotEvalEXT (tmpSrc, EXT); 285 302 chiEXT = EXT ? EXT->chisqNorm : NAN; 303 EXT->fitRadius = fitRadius; 286 304 } 287 305 … … 476 494 // for sersic models, use a grid search to choose an index, then float the params there 477 495 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 478 // for the test fits, use a somewhat smaller radius479 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5);480 496 psphotFitSersicIndex (model, readout, source, fitOptions, maskVal, markVal); 481 }482 483 if (!psphotSetRadiusModel (model, readout, source, markVal, true)) {484 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 1.0);485 497 } 486 498 … … 499 511 } 500 512 513 # define TIMING 0 514 501 515 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 502 516 … … 517 531 return NULL; 518 532 } 533 534 # define TEST_X -540.0 535 # define TEST_Y 540.0 536 537 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 538 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 5); 539 } 540 541 float t1, t2, t4, t5; 542 if (TIMING) { psTimerStart ("psphotFitPCM"); } 519 543 520 544 pmPCMdata *pcm = pmPCMinit (source, &options, model, maskVal, psfSize); … … 524 548 return model; 525 549 } 526 527 // use the source moments, etc to guess basic model parameters 528 if (!pmSourceModelGuessPCM (pcm, source, maskVal, markVal)) { 529 psFree (pcm); 530 model->flags |= PM_MODEL_STATUS_BADARGS; 531 return model; 532 } 533 534 // for sersic models, use a grid search to choose an index, then float the params there 550 if (TIMING) { t1 = psTimerMark ("psphotFitPCM"); } 551 552 // get the guess for sersic models 535 553 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 536 // for the test fits, use a somewhat smaller radius 537 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5); 538 539 if (!psphotFitSersicIndexPCM (pcm, readout, source, fitOptions, maskVal, markVal, psfSize)) { 554 // use the source moments, etc to guess basic model parameters 555 if (!psphotSersicModelClassGuessPCM (pcm, source)) { 540 556 psFree (pcm); 541 557 model->flags |= PM_MODEL_STATUS_BADARGS; 542 558 return model; 543 559 } 544 } 545 546 if (!psphotSetRadiusModel (model, readout, source, markVal, true)) { 547 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 1.0); 548 } 560 } else { 561 // use the source moments, etc to guess basic model parameters 562 if (!pmSourceModelGuessPCM (pcm, source, maskVal, markVal)) { 563 psFree (pcm); 564 model->flags |= PM_MODEL_STATUS_BADARGS; 565 return model; 566 } 567 } 568 569 if (TIMING) { t2 = psTimerMark ("psphotFitPCM"); } 549 570 550 571 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { … … 555 576 // update the pcm elements if we have changed the circumstance (options.mode or source->pixels) 556 577 pmPCMupdate(pcm, source, &options, model); 578 if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); } 557 579 558 580 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 559 581 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 560 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 582 if (TIMING) { t5 = psTimerMark ("psphotFitPCM"); } 583 584 if (TIMING) { 585 fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d, t1: %6.4f, t2: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, t1, t2, t4, t5); 586 } 587 588 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 589 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 0); 590 } 561 591 562 592 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); … … 566 596 } 567 597 598 # undef TEST_X 599 # undef TEST_Y 600 568 601 // note that these should be 1/2n of the standard sersic index 569 float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083}; 570 # define N_INDEX_GUESS 6 602 // float indexGuess[] = {0.8, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0}; 603 // float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083}; 604 float indexGuess[] = {1.0, 2.0, 3.0, 4.0}; 605 # define N_INDEX_GUESS 4 571 606 572 607 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index … … 586 621 float chiSquare[N_INDEX_GUESS]; 587 622 623 # define TEST_X -540.0 624 # define TEST_Y 540.0 625 626 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 627 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 5); 628 } 629 588 630 for (int i = 0; i < N_INDEX_GUESS; i++) { 589 model->params->data.F32[PM_PAR_7] = indexGuess[i];631 model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[i]; 590 632 591 633 if (!model->modelGuess(model, source)) { … … 594 636 } 595 637 596 // each time we change the model guess, we need to adjust the radius597 // XXX this did not work : we do not need such a large radius -- just uses moments-based radius598 if (false && !psphotSetRadiusModel (model, readout, source, markVal, false)) {599 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5);600 }601 602 638 pmSourceFitModel (source, model, &options, maskVal); 603 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);639 fprintf (stderr, "index: %f, chisq: %f, nIter: %d, radius: %f, npix: %d\n", indexGuess[i], model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 604 640 605 641 chiSquare[i] = model->chisqNorm; … … 616 652 assert (iMin >= 0); 617 653 654 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 655 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 0); 656 } 657 618 658 model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it 619 model->params->data.F32[PM_PAR_7] = indexGuess[iMin];659 model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[iMin]; 620 660 model->modelGuess(model, source); 621 622 // each time we change the model guess, we need to adjust the radius623 // if (!psphotSetRadiusModel (model, readout, source, markVal, true)) {624 // psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal);625 // }626 661 627 662 return true; … … 648 683 float xMin = NAN; 649 684 float chiSquare[N_INDEX_GUESS]; 685 686 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 687 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 5); 688 } 650 689 651 690 for (int i = 0; i < N_INDEX_GUESS; i++) { … … 657 696 } 658 697 659 // each time we change the model guess, we need to adjust the radius660 // XXX this did not work : we do not need such a large radius -- just uses moments-based radius661 if (false && !psphotSetRadiusModel (model, readout, source, markVal, false)) {662 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5);663 }664 665 698 # if (0) 699 // this block is to test the relative speed of straight and PCM fits 666 700 pmSourceFitModel (source, model, &options, maskVal); 667 701 # else … … 669 703 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 670 704 # endif 705 fprintf (stderr, "index: %f, chisq: %f, nIter: %d, radius: %f, npix: %d\n", indexGuess[i], model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 671 706 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 672 707 … … 684 719 assert (iMin >= 0); 685 720 721 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 722 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 0); 723 } 724 686 725 model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it 687 726 model->params->data.F32[PM_PAR_7] = indexGuess[iMin];
Note:
See TracChangeset
for help on using the changeset viewer.
