IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 18, 2010, 2:59:19 PM (16 years ago)
Author:
eugene
Message:

update psf-convolved model fitting to be a bit more consistent with other psphot fitting, and a bit more flexible; fix the diff stats

Location:
branches/eam_branches/ipp-20100621/psphot/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/psphot/src/psphotExtendedSourceFits.c

    r28643 r28687  
    210210          pmModel *modelFit = NULL;
    211211          if (convolved) {
    212               modelFit = psphotPSFConvModel (readout, source, modelType, maskVal, markVal, psfSize);
     212              modelFit = psphotFitPCM (readout, source, fitOptions, modelType, maskVal, markVal, psfSize);
    213213              if (!modelFit) {
    214214                  psTrace ("psphot", 5, "failed to fit psf-conv model for object at %f, %f", source->moments->Mx, source->moments->My);
  • branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c

    r28677 r28687  
    476476}
    477477
     478pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) {
     479
     480    pmSourceFitOptions options = *fitOptions;
     481
     482    NfitPCM ++;
     483
     484    // maskVal is used to test for rejected pixels, and must include markVal
     485    maskVal |= markVal;
     486
     487    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
     488
     489    // use the source moments, etc to guess basic model parameters
     490    pmModel *EXT = pmSourceModelGuess (source, modelType);
     491    if (!EXT) {
     492        psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy);
     493        return NULL;
     494    }
     495
     496    if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) {
     497        psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy);
     498    }
     499
     500    // for sersic models, use a grid search to choose an index, then float the params there
     501    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
     502        psphotFitSersicIndexPCM (source, EXT, fitOptions, maskVal);
     503    }
     504
     505    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
     506        options.mode = PM_SOURCE_FIT_NO_INDEX;
     507    } else {
     508        options.mode = PM_SOURCE_FIT_EXT;
     509    }
     510    pmSourceFitPCM (source, EXT, &options, maskVal);
     511
     512    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
     513    return (EXT);
     514}
     515
    478516// note that these should be 1/2n of the standard sersic index
    479517float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083};
     518define N_INDEX_GUESS 6
    480519
    481520// A sersic model is very sensitive to the index.  attempt to find the index first by grid search in just the index
     
    491530    options.nIter = 3;
    492531
    493     float xMin, chiSquare[3];
     532    float xMin, chiSquare[N_INDEX_GUESS];
    494533    int iMin;
    495534
    496     for (int i = 0; i < 3; i++) {
     535    for (int i = 0; i < N_INDEX_GUESS; i++) {
    497536        model->params->data.F32[PM_PAR_7] = indexGuess[i];
    498537        model->modelGuess(model, source);
     
    516555    return true;
    517556}
     557
     558// A sersic model is very sensitive to the index.  attempt to find the index first by grid search in just the index
     559// for a sersic model, attempt to fit just the index and normalization with a modest number of iterations
     560bool psphotFitSersicIndexPCM (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal) {
     561
     562    assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
     563
     564    pmSourceFitOptions options = *fitOptions;
     565   
     566    // fit EXT (not PSF) model (set/unset the pixel mask)
     567    options.mode = PM_SOURCE_FIT_NO_INDEX;
     568    options.nIter = 3;
     569
     570    float xMin, chiSquare[N_INDEX_GUESS];
     571    int iMin;
     572
     573    for (int i = 0; i < N_INDEX_GUESS; i++) {
     574        model->params->data.F32[PM_PAR_7] = indexGuess[i];
     575        model->modelGuess(model, source);
     576        pmSourceFitPCM (source, model, &options, maskVal);
     577        chiSquare[i] = model->chisq;
     578        if (i == 0) {
     579            xMin = chiSquare[i];
     580            iMin = i;
     581        } else {
     582            if (chiSquare[i] < xMin) {
     583                xMin = chiSquare[i];
     584                iMin = i;
     585            }
     586        }
     587    }
     588
     589    model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it
     590    model->params->data.F32[PM_PAR_7] = indexGuess[iMin];
     591    model->modelGuess(model, source);
     592
     593    return true;
     594}
Note: See TracChangeset for help on using the changeset viewer.