IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28657


Ignore:
Timestamp:
Jul 11, 2010, 3:21:36 PM (16 years ago)
Author:
eugene
Message:

add maxTol and maxChisqDOF to psMin to allow for better control over fit success and convergence; for SERSIC model, first do a grid search for the index

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

Legend:

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

    r28643 r28657  
    6565    assert (status && fitIter > 0);
    6666
    67     float fitTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_TOL"); // Fit tolerance
    68     assert (status && isfinite(fitTol) && fitTol > 0);
     67    float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance
     68    assert (status && isfinite(fitMinTol) && fitMinTol > 0);
     69
     70    float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance
     71    assert (status && isfinite(fitMaxTol) && fitMaxTol > 0);
    6972
    7073    bool poisson = psMetadataLookupBool(&status, recipe, "POISSON.ERRORS.PHOT.LMM"); // Poisson errors?
    7174    assert (status);
     75
     76    float maxChisqDOF = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_CHISQ"); // Fit tolerance
    7277
    7378    float skySig = psMetadataLookupF32(&status, recipe, "SKY_SIG");
     
    7782    pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
    7883    fitOptions->nIter         = fitIter;
    79     fitOptions->tol           = fitTol;
     84    fitOptions->minTol        = fitMinTol;
     85    fitOptions->maxTol        = fitMaxTol;
     86    fitOptions->maxChisqDOF   = maxChisqDOF;
    8087    fitOptions->poissonErrors = poisson;
    8188    fitOptions->weight        = PS_SQR(skySig);
  • branches/eam_branches/ipp-20100621/psphot/src/psphotChoosePSF.c

    r28643 r28657  
    138138        return false;
    139139    }
    140     float fitTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance
    141     if (!status || !isfinite(fitTol) || fitTol <= 0) {
    142         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PSF_FIT_TOL is not positive");
    143         return false;
    144     }
     140    float fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_MIN_TOL"); // Fit tolerance
     141    if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
     142        fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance
     143        if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
     144            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive");
     145            return false;
     146        }
     147    }
     148    float fitMaxTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_MAX_TOL"); // Fit tolerance
     149    if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) {
     150        fitMaxTol = 1.0;
     151    }
     152    float maxChisqDOF = psMetadataLookupF32 (&status, recipe, "PSF_FIT_MAX_CHISQ"); // Fit tolerance
    145153
    146154    // options which modify the behavior of the model fitting
    147155    options->fitOptions                = pmSourceFitOptionsAlloc();
    148156    options->fitOptions->nIter         = fitIter;
    149     options->fitOptions->tol           = fitTol;
     157    options->fitOptions->minTol        = fitMinTol;
     158    options->fitOptions->maxTol        = fitMaxTol;
     159    options->fitOptions->maxChisqDOF   = maxChisqDOF;
    150160    options->fitOptions->poissonErrors = options->poissonErrorsPhotLMM;
    151161    options->fitOptions->weight        = PS_SQR(SKY_SIG);
  • branches/eam_branches/ipp-20100621/psphot/src/psphotEllipticalContour.c

    r27819 r28657  
    8282    params->data.F32[PAR_RMIN]    = Rmin;
    8383
    84     psMinimization *myMin = psMinimizationAlloc (25, 0.001);
     84    psMinimization *myMin = psMinimizationAlloc (25, 0.01, 1.00);
    8585    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    8686   
  • branches/eam_branches/ipp-20100621/psphot/src/psphotModelWithPSF.c

    r21366 r28657  
    7373
    7474    // iterate until the tolerance is reached, or give up
    75     while ((min->iter < min->maxIter) && ((min->lastDelta > min->tol) || !isfinite(min->lastDelta))) {
     75    while ((min->iter < min->maxIter) && ((min->lastDelta > min->minTol) || !isfinite(min->lastDelta))) {
    7676        psTrace("psphot", 5, "Iteration number %d.  (max iterations is %d).\n", min->iter, min->maxIter);
    77         psTrace("psphot", 5, "Last delta is %f.  Min->tol is %f.\n", min->lastDelta, min->tol);
     77        psTrace("psphot", 5, "Last delta is %f.  Min->minTol is %f.\n", min->lastDelta, min->minTol);
    7878
    7979
     
    166166    psFree(pcm);
    167167
    168     if (min->iter == min->maxIter) {
    169         psTrace("psphot", 3, "---- end (false) ----\n");
    170         return(false);
    171     }
    172 
    173     psTrace("psphot", 3, "---- end (true) ----\n");
    174     return(true);
     168    // if the last improvement was at least as good as maxTol, accept the fit:
     169    if (min->lastDelta <= min->maxTol) {
     170        psTrace("psphot", 6, "---- end (true) ----\n");
     171        return(true);
     172    }
     173    psTrace("psphot", 6, "---- end (false) ----\n");
     174    return(false);
    175175}
    176176
  • branches/eam_branches/ipp-20100621/psphot/src/psphotPSFConvModel.c

    r26894 r28657  
    44// save as static values so they may be set externally
    55static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15;
    6 static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1;
     6static psF32 PM_SOURCE_FIT_MODEL_MIN_TOL = 0.1;
     7static psF32 PM_SOURCE_FIT_MODEL_MAX_TOL = 2.0;
    78
    89// input source has both modelPSF and modelEXT.  on successful exit, we set the
     
    9091
    9192    // set up the minimization process
    92     psMinimization *myMin = psMinimizationAlloc (PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_TOLERANCE);
     93    psMinimization *myMin = psMinimizationAlloc (PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_MIN_TOL, PM_SOURCE_FIT_MODEL_MAX_TOL);
    9394
    9495    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
  • branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c

    r28643 r28657  
    11# include "psphotInternal.h"
     2bool psphotFitSersicIndex (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal);
    23
    34// given a source with an existing modelPSF, attempt a full PSF fit, subtract if successful
     
    460461
    461462    // for sersic models, get the initial guess more carefully
    462     // if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
    463     //  psphotGuessSersic ();
    464     //  // test and return NULL on failure?
    465     // }
     463    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
     464        psphotFitSersicIndex (source, EXT, fitOptions, maskVal);
     465    }
    466466
    467467    // fit EXT (not PSF) model (set/unset the pixel mask)
     
    473473}
    474474
     475float indexGuess[] = {0.5, 0.25, 0.125};
     476
    475477// A sersic model is very sensitive to the index.  attempt to find the index first by grid search in just the index
    476 // bool psphotFitSersic (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) {
    477 //
    478 //     assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
    479 //
    480 //
    481 //     
    482 //     if (!model->modelGuess(model, source)) {
    483 //     }
    484 //     
    485 //
    486 // }
     478// for a sersic model, attempt to fit just the index and normalization with a modest number of iterations
     479bool psphotFitSersicIndex (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal) {
     480
     481    assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
     482
     483    pmSourceFitOptions options = *fitOptions;
     484   
     485    // fit EXT (not PSF) model (set/unset the pixel mask)
     486    options.mode = PM_SOURCE_FIT_NO_INDEX;
     487    options.nIter = 3;
     488
     489    float xMin, chiSquare[3];
     490    int iMin;
     491
     492    for (int i = 0; i < 3; i++) {
     493        model->params->data.F32[PM_PAR_7] = indexGuess[i];
     494        model->modelGuess(model, source);
     495        pmSourceFitModel (source, model, &options, maskVal);
     496        chiSquare[i] = model->chisq;
     497        if (i == 0) {
     498            xMin = chiSquare[i];
     499            iMin = i;
     500        } else {
     501            if (chiSquare[i] < xMin) {
     502                xMin = chiSquare[i];
     503                iMin = i;
     504            }
     505        }
     506    }
     507
     508    model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it
     509    model->params->data.F32[PM_PAR_7] = indexGuess[iMin];
     510    model->modelGuess(model, source);
     511
     512    return true;
     513}
Note: See TracChangeset for help on using the changeset viewer.