- Timestamp:
- Jul 22, 2010, 6:21:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c
r28692 r28702 479 479 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 480 480 481 // allocate the model 482 pmModel *model = pmModelAlloc(modelType); 483 if (!model) { 484 return NULL; 485 } 486 487 pmSourceFitOptions options = *fitOptions; 488 481 489 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 482 490 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); … … 489 497 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 490 498 // this uses the footprint to judge both radius and aperture? 491 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false; 492 493 pmSourceFitOptions options = *fitOptions; 499 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) { 500 // XXX set some mask bit/ 501 model->flags |= PM_MODEL_STATUS_BADARGS; 502 return model; 503 } 494 504 495 505 NfitPCM ++; … … 500 510 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 501 511 502 pmPCMdata *pcm = pmPCMinit (source, &options, model Type, maskVal, psfSize);512 pmPCMdata *pcm = pmPCMinit (source, &options, model, maskVal, psfSize); 503 513 if (!pcm) { 504 514 psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 505 return NULL; 506 } 507 // XXX check for nDOF too small515 model->flags |= PM_MODEL_STATUS_BADARGS; // XXX this is probably already set in pmPCMinit 516 return model; 517 } 508 518 509 519 // use the source moments, etc to guess basic model parameters … … 512 522 // for sersic models, use a grid search to choose an index, then float the params there 513 523 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 514 psphotFitSersicIndexPCM (pcm, source, fitOptions, maskVal, markVal );524 psphotFitSersicIndexPCM (pcm, source, fitOptions, maskVal, markVal, psfSize); 515 525 } 516 526 … … 520 530 options.mode = PM_SOURCE_FIT_EXT; 521 531 } 522 pmSourceFitPCM ( source, PCM, &options, maskVal);532 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 523 533 524 534 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 525 return (PCM); 535 psFree (pcm); 536 537 return model; 526 538 } 527 539 528 540 // note that these should be 1/2n of the standard sersic index 529 541 float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083}; 530 define N_INDEX_GUESS 6542 # define N_INDEX_GUESS 6 531 543 532 544 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index 533 545 // for a sersic model, attempt to fit just the index and normalization with a modest number of iterations 534 bool psphotFitSersicIndex (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 535 536 pmModel *model = pcm->modelConv; 546 bool psphotFitSersicIndex (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal) { 537 547 538 548 assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC")); … … 544 554 options.nIter = 3; 545 555 546 float xMin, chiSquare[N_INDEX_GUESS]; 547 int iMin; 556 int iMin = -1; 557 float xMin = NAN; 558 float chiSquare[N_INDEX_GUESS]; 548 559 549 560 for (int i = 0; i < N_INDEX_GUESS; i++) { 550 561 model->params->data.F32[PM_PAR_7] = indexGuess[i]; 551 pmSourceModelGuessPCM (pcm, source, maskVal, markVal); 552 553 pmSourceFitPCM (pcm, source, &options, maskVal); 562 563 model->modelGuess(model, source); 564 pmSourceFitModel (source, model, &options, maskVal); 565 554 566 chiSquare[i] = model->chisq; 555 567 if (i == 0) { … … 573 585 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index 574 586 // for a sersic model, attempt to fit just the index and normalization with a modest number of iterations 575 bool psphotFitSersicIndexPCM (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal) { 587 bool psphotFitSersicIndexPCM (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 588 589 pmModel *model = pcm->modelConv; 576 590 577 591 assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC")); … … 583 597 options.nIter = 3; 584 598 585 float xMin, chiSquare[N_INDEX_GUESS]; 586 int iMin; 587 588 // XXX we probably cannot be calling model->modelGuess() : this does not include the psf sigma 599 int iMin = -1; 600 float xMin = NAN; 601 float chiSquare[N_INDEX_GUESS]; 589 602 590 603 for (int i = 0; i < N_INDEX_GUESS; i++) { 591 604 model->params->data.F32[PM_PAR_7] = indexGuess[i]; 605 592 606 model->modelGuess(model, source); 593 pmSourceFitPCM (source, model, &options, maskVal); 607 pmSourceFitModel (source, model, &options, maskVal); 608 609 // pmSourceModelGuessPCM(pcm, source, maskVal, markVal); 610 // pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 611 594 612 chiSquare[i] = model->chisq; 595 613 if (i == 0) { … … 604 622 } 605 623 624 assert (iMin >= 0); 625 606 626 model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it 607 627 model->params->data.F32[PM_PAR_7] = indexGuess[iMin]; 608 model->modelGuess(model, source); 609 610 return true; 611 } 628 629 pmSourceModelGuessPCM(pcm, source, maskVal, markVal); 630 631 return true; 632 }
Note:
See TracChangeset
for help on using the changeset viewer.
