IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 22, 2013, 2:43:04 PM (13 years ago)
Author:
bills
Message:

add saveResults argument to psphotGalaxyShapeSource, if false don't save
the results in the vectors just update the model (used to save the best one)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130904/psphot/src/psphotGalaxyShape.c

    r36247 r36304  
    253253    }
    254254
     255    float fRmajorBest = NAN;
     256    float fRminorBest = NAN;
     257    float chisqBest = NAN;
    255258    for (float fRmajor = opt->fRmajorMin; fRmajor < opt->fRmajorMax + 0.5*opt->fRmajorDel; fRmajor += opt->fRmajorDel) {
    256259        for (float fRminor = opt->fRminorMin; fRminor < opt->fRminorMax + 0.5*opt->fRminorDel; fRminor += opt->fRminorDel) {
     
    262265            pmPSF_AxesToModel (PAR, testAxes, modelType);
    263266           
    264             // where do the results go??
    265             psphotGalaxyShapeSource (pcm, source, maskVal, psfSize);
     267            psphotGalaxyShapeSource (pcm, source, maskVal, psfSize, true);
     268
     269            int i = source->galaxyFits->chisq->n - 1;
     270            float thisChisq = source->galaxyFits->chisq->data.F32[i];
     271            if (isfinite(thisChisq) && (!isfinite(chisqBest) || thisChisq < chisqBest)) {
     272                chisqBest = thisChisq;
     273                fRmajorBest = fRmajor;
     274                fRminorBest = fRminor;
     275            }
    266276        }
     277    }
     278
     279    if (isfinite(chisqBest)) {
     280        // now save the best fitting model as the source's extended model
     281        psEllipseAxes testAxes = guessAxes;
     282        testAxes.major = guessAxes.major * fRmajorBest;
     283        testAxes.minor = guessAxes.minor * fRminorBest;
     284       
     285        pmPSF_AxesToModel (PAR, testAxes, modelType);
     286       
     287        psphotGalaxyShapeSource (pcm, source, maskVal, psfSize, false);
     288
     289        psFree (source->modelEXT);
     290
     291        source->modelEXT = psMemIncrRefCounter (pcm->modelConv);
     292        source->type = PM_SOURCE_TYPE_EXTENDED;
     293        source->mode |= PM_SOURCE_MODE_EXTMODEL;
     294        source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     295
     296        // adjust the window so the subtraction covers the faint wings
     297        // psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal);
     298
     299        // cache the model flux
     300        pmPCMCacheModel (source, maskVal, psfSize);
    267301    }
    268302
     
    273307// fit the given model to the source and find chisq & normalization
    274308// XXX is this a single-component model? sersic with a supplied index, Reff, axis ratio, and theta?
    275 bool psphotGalaxyShapeSource (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, int psfSize) {
     309bool psphotGalaxyShapeSource (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, int psfSize, bool saveResults) {
    276310
    277311    PS_ASSERT_PTR_NON_NULL(source, false);
     
    326360    float dflux = flux * (dIo / Io);
    327361
    328 // Set this to be the model of choice.
    329 // XXX: Maybe: figure out which is the best and save that one.
    330 {
    331     psFree (source->modelEXT);
    332 
    333     source->modelEXT = psMemIncrRefCounter (pcm->modelConv);
    334     source->type = PM_SOURCE_TYPE_EXTENDED;
    335     source->mode |= PM_SOURCE_MODE_EXTMODEL;
    336     source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    337 
    338     // adjust the window so the subtraction covers the faint wings
    339     // psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal);
    340 
    341     // cache the model flux
    342     pmPCMCacheModel (source, maskVal, psfSize);
    343 }
    344 
    345     psVectorAppend (source->galaxyFits->Flux, flux);
    346     psVectorAppend (source->galaxyFits->dFlux, dflux);
    347     psVectorAppend (source->galaxyFits->chisq, Chisq);
    348     source->galaxyFits->nPix = nPix;
     362
     363    if (saveResults) {
     364        psVectorAppend (source->galaxyFits->Flux, flux);
     365        psVectorAppend (source->galaxyFits->dFlux, dflux);
     366        psVectorAppend (source->galaxyFits->chisq, Chisq);
     367        source->galaxyFits->nPix = nPix;
     368    }
    349369
    350370    return true;
Note: See TracChangeset for help on using the changeset viewer.