- Timestamp:
- Jan 11, 2012, 11:19:21 PM (15 years ago)
- Location:
- branches/meh_branches/ppsub_test
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (2 props)
-
psphot/src/psphotSourceFits.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppsub_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppsub_test/psphot
- Property svn:mergeinfo changed
-
branches/meh_branches/ppsub_test/psphot/src
- Property svn:ignore
-
old new 22 22 psphotMakePSF 23 23 psphotStack 24 psphotModelTest
-
- Property svn:mergeinfo set to
- Property svn:ignore
-
branches/meh_branches/ppsub_test/psphot/src/psphotSourceFits.c
r31452 r33098 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; … … 217 217 pmModel *EXT = NULL; 218 218 psArray *DBL = NULL; 219 pmMoments psfMoments;219 // pmMoments psfMoments; 220 220 221 221 // skip the source if we don't think it is extended … … 225 225 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 226 226 227 # define TEST_X -420.0 228 # define TEST_Y 300.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; 229 230 // XXX note that this changes the source moments that are published... 231 // XXX all published moments should use the same measurement 232 // recalculate the source moments using the larger extended-source moments radius 233 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 234 // this uses the footprint to judge both radius and aperture? 235 // XXX save the psf-based moments for output 236 psfMoments = *source->moments; 237 if (!pmSourceMoments (source, radius, 0.0, 0.5, 0.0, maskVal)) { 238 *source->moments = psfMoments; 239 return false; 240 } 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); 241 240 242 241 psTrace ("psphot", 5, "trying blob...\n"); … … 258 257 okDBL = psphotEvalDBL (tmpSrc, DBL->data[0]); 259 258 okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]); 259 okDBL = false; // XXX this is failing badly... 260 260 // XXX should I keep / save the flags set in the eval functions? 261 261 … … 263 263 ONE = DBL->data[0]; 264 264 if (ONE) { 265 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");265 psAssert (isfinite(ONE->params->data.F32[PM_PAR_I0]), "nan in fit"); 266 266 chiDBL = ONE->chisqNorm; // save chisq for double-star/galaxy comparison 267 ONE->fitRadius = radius;267 ONE->fitRadius = fitRadius; 268 268 } 269 269 … … 271 271 ONE = DBL->data[1]; 272 272 if (ONE) { 273 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");274 ONE->fitRadius = radius;273 psAssert (isfinite(ONE->params->data.F32[PM_PAR_I0]), "nan in fit"); 274 ONE->fitRadius = fitRadius; 275 275 } 276 276 } … … 284 284 okEXT = psphotEvalEXT (tmpSrc, EXT); 285 285 chiEXT = EXT ? EXT->chisqNorm : NAN; 286 EXT->fitRadius = fitRadius; 286 287 } 287 288 … … 294 295 295 296 if (okEXT && okDBL) { 296 psTrace ("psphot", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL);297 297 // XXX EAM : a bogus bias: need to examine this better 298 298 if (3*chiEXT > chiDBL) goto keepDBL; … … 303 303 if (!okEXT && okDBL) goto keepDBL; 304 304 305 psTrace ("psphot", 4, "both failed: blob chisq: %f vs %f for %f,%f\n", chiEXT, chiDBL, source->peak->xf, source->peak->yf); 306 305 307 // both models failed; reject them both 306 308 // XXX -- change type flags to psf in this case, and make sure we subtract it? 307 309 // reset the psf moments 308 *source->moments = psfMoments;310 // XXX *source->moments = psfMoments; 309 311 310 312 psFree (EXT); … … 313 315 314 316 keepEXT: 317 psTrace ("psphot", 4, "goto EXT : blob chisq: %f vs %f for %f,%f\n", chiEXT, chiDBL, source->peak->xf, source->peak->yf); 315 318 // sub EXT 316 319 psFree (DBL); … … 338 341 339 342 // reset the psf moments 340 *source->moments = psfMoments;343 // XXX *source->moments = psfMoments; 341 344 return true; 342 345 343 346 keepDBL: 347 psTrace ("psphot", 4, "goto DBL : blob chisq: %f vs %f for %f,%f\n", chiEXT, chiDBL, source->peak->xf, source->peak->yf); 344 348 // sub DLB 345 349 psFree (EXT); … … 354 358 pmSource *newSrc = pmSourceCopy (source); 355 359 newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]); 360 newSrc->peak->footprint = source->peak->footprint; // just a reference; the peak does not own the footprint 361 psArrayAdd(newSrc->peak->footprint->peaks, 1, newSrc->peak); // the footprint owns the peak 356 362 357 363 // build cached models and subtract … … 372 378 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, source->modelPSF->params->data.F32[i], source->modelPSF->dparams->data.F32[i]); 373 379 } 374 psphotVisualShowResidualImage (readout, false);375 380 } 376 381 # endif 377 378 // reset the (original) psf moments379 *source->moments = psfMoments;380 *newSrc->moments = psfMoments;381 382 382 383 psArrayAdd (newSources, 100, newSrc); … … 386 387 387 388 escape: 388 // reset the psf moments389 *source->moments = psfMoments;390 389 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 391 390 psFree (tmpSrc); … … 476 475 // for sersic models, use a grid search to choose an index, then float the params there 477 476 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 477 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 478 } 486 479 … … 494 487 pmSourceFitModel (source, model, &options, maskVal); 495 488 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 496 497 489 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 490 498 491 return (model); 499 492 } 493 494 # define TIMING 0 500 495 501 496 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { … … 517 512 return NULL; 518 513 } 514 515 # define TEST_X -540.0 516 # define TEST_Y 540.0 517 518 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 519 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 5); 520 } 521 522 float t1, t2, t4, t5; 523 if (TIMING) { psTimerStart ("psphotFitPCM"); } 519 524 520 525 pmPCMdata *pcm = pmPCMinit (source, &options, model, maskVal, psfSize); … … 524 529 return model; 525 530 } 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 531 if (TIMING) { t1 = psTimerMark ("psphotFitPCM"); } 532 533 // NOTE : 65 allocs to here 534 // get the guess for sersic models 535 535 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)) { 536 // use the source moments, etc to guess basic model parameters 537 if (!psphotSersicModelClassGuessPCM (pcm, source)) { 540 538 psFree (pcm); 541 539 model->flags |= PM_MODEL_STATUS_BADARGS; 542 540 return model; 543 541 } 544 } 545 546 if (!psphotSetRadiusModel (model, readout, source, markVal, true)) { 547 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 1.0); 548 } 542 } else { 543 // use the source moments, etc to guess basic model parameters 544 if (!pmSourceModelGuessPCM (pcm, source, maskVal, markVal)) { 545 psFree (pcm); 546 model->flags |= PM_MODEL_STATUS_BADARGS; 547 return model; 548 } 549 } 550 551 if (TIMING) { t2 = psTimerMark ("psphotFitPCM"); } 549 552 550 553 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { … … 555 558 // update the pcm elements if we have changed the circumstance (options.mode or source->pixels) 556 559 pmPCMupdate(pcm, source, &options, model); 560 if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); } 557 561 558 562 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 559 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); 563 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); // NOTE : 1687 allocs in here 564 if (TIMING) { t5 = psTimerMark ("psphotFitPCM"); } 565 566 if (TIMING) { 567 int nPixBig = source->pixels->numCols * source->pixels->numRows; 568 fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t4, t5); 569 } 570 571 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 572 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 0); 573 } 561 574 562 575 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); … … 566 579 } 567 580 581 # undef TEST_X 582 # undef TEST_Y 583 568 584 // 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 585 // 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}; 586 // float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083}; 587 float indexGuess[] = {1.0, 2.0, 3.0, 4.0}; 588 # define N_INDEX_GUESS 4 571 589 572 590 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index … … 586 604 float chiSquare[N_INDEX_GUESS]; 587 605 606 # define TEST_X -540.0 607 # define TEST_Y 540.0 608 609 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 610 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 5); 611 } 612 588 613 for (int i = 0; i < N_INDEX_GUESS; i++) { 589 model->params->data.F32[PM_PAR_7] = indexGuess[i];614 model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[i]; 590 615 591 616 if (!model->modelGuess(model, source)) { … … 594 619 } 595 620 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 621 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);622 // fprintf (stderr, "index: %f, chisq: %f, nIter: %d, radius: %f, npix: %d\n", indexGuess[i], model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 604 623 605 624 chiSquare[i] = model->chisqNorm; … … 616 635 assert (iMin >= 0); 617 636 637 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 638 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 0); 639 } 640 618 641 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];642 model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[iMin]; 620 643 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 644 627 645 return true; … … 648 666 float xMin = NAN; 649 667 float chiSquare[N_INDEX_GUESS]; 668 669 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 670 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 5); 671 } 650 672 651 673 for (int i = 0; i < N_INDEX_GUESS; i++) { … … 657 679 } 658 680 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 681 # if (0) 682 // this block is to test the relative speed of straight and PCM fits 666 683 pmSourceFitModel (source, model, &options, maskVal); 667 684 # else … … 669 686 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 670 687 # endif 688 fprintf (stderr, "index: %f, chisq: %f, nIter: %d, radius: %f, npix: %d\n", indexGuess[i], model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 671 689 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 672 690 … … 684 702 assert (iMin >= 0); 685 703 704 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 705 psTraceSetLevel("psModules.objects.pmPCM_MinimizeChisq", 0); 706 } 707 686 708 model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it 687 709 model->params->data.F32[PM_PAR_7] = indexGuess[iMin];
Note:
See TracChangeset
for help on using the changeset viewer.
