IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 9, 2010, 10:56:32 AM (16 years ago)
Author:
eugene
Message:

changed pmSourceFitModel and related APIs to pass a structure of fit options; this lets us change the options between soruces within the multithreaded context; also re-organized the include orders to avoid conflicts

File:
1 edited

Legend:

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

    r26894 r28643  
    22
    33// given a source with an existing modelPSF, attempt a full PSF fit, subtract if successful
    4 // XXX this function does not call pmSourceFitModelInit : fix this?
    54
    65static int NfitPSF = 0;
     
    2221}
    2322
    24 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
     23bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) {
    2524
    2625    float x, y, dR;
     26
     27    pmSourceFitOptions options = *fitOptions;
    2728
    2829    // maskVal is used to test for rejected pixels, and must include markVal
     
    3132    // if this source is not a possible blend, just fit as PSF
    3233    if ((source->blends == NULL) || (source->mode & PM_SOURCE_MODE_SATSTAR)) {
    33         bool status = psphotFitPSF (readout, source, psf, maskVal, markVal);
     34        bool status = psphotFitPSF (readout, source, psf, fitOptions, maskVal, markVal);
    3435        return status;
    3536    }
     
    9192
    9293    // fit PSF model
    93     pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF, maskVal);
     94    options.mode = PM_SOURCE_FIT_PSF;
     95    pmSourceFitSet (source, modelSet, &options, maskVal);
    9496
    9597    // clear the circular mask
     
    154156}
    155157
    156 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
     158bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) {
    157159
    158160    double chiTrend;
     161    pmSourceFitOptions options = *fitOptions;
    159162
    160163    // maskVal is used to test for rejected pixels, and must include markVal
     
    171174
    172175    // fit PSF model (set/unset the pixel mask)
    173     pmSourceFitModel (source, PSF, PM_SOURCE_FIT_PSF, maskVal);
     176    options.mode = PM_SOURCE_FIT_PSF;
     177    pmSourceFitModel (source, PSF, &options, maskVal);
    174178
    175179    if (!isfinite(PSF->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");
     
    213217}
    214218
    215 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
     219bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) {
    216220
    217221    bool okEXT, okDBL;
     
    246250
    247251    // XXX need to handle failures better here
    248     EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal);
     252    EXT = psphotFitEXT (readout, source, fitOptions, modelTypeEXT, maskVal, markVal);
    249253    if (!EXT) goto escape;
    250254    if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) goto escape;
     
    254258
    255259    // DBL will always be defined, but DBL->data[n] might not
    256     DBL = psphotFitDBL (readout, source, maskVal, markVal);
     260    DBL = psphotFitDBL (readout, source, fitOptions, maskVal, markVal);
    257261    if (!DBL) goto escape;
    258262    if (!DBL->n) goto escape;
     
    379383
    380384// fit a double PSF source to an extended blob
    381 psArray *psphotFitDBL (pmReadout *readout, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) {
     385psArray *psphotFitDBL (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) {
    382386
    383387    float dx, dy;
     
    387391    psEllipseMoments moments;
    388392    psArray *modelSet;
     393
     394    pmSourceFitOptions options = *fitOptions;
    389395
    390396    NfitDBL ++;
     
    426432
    427433    // fit PSF model (set/unset the pixel mask)
    428     pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF, maskVal);
     434    options.mode = PM_SOURCE_FIT_PSF;
     435    pmSourceFitSet (source, modelSet, &options, maskVal);
    429436    return (modelSet);
    430437}
    431438
    432 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) {
     439pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) {
     440
     441    pmSourceFitOptions options = *fitOptions;
    433442
    434443    NfitEXT ++;
     
    436445    // maskVal is used to test for rejected pixels, and must include markVal
    437446    maskVal |= markVal;
     447
     448    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
    438449
    439450    // use the source moments, etc to guess basic model parameters
     
    448459    }
    449460
     461    // 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    // }
     466
    450467    // fit EXT (not PSF) model (set/unset the pixel mask)
    451     pmSourceFitModel (source, EXT, PM_SOURCE_FIT_EXT, maskVal);
     468    options.mode = PM_SOURCE_FIT_EXT;
     469    pmSourceFitModel (source, EXT, &options, maskVal);
     470
     471    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
    452472    return (EXT);
    453473}
     474
     475// 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// }
Note: See TracChangeset for help on using the changeset viewer.