IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38396


Ignore:
Timestamp:
Jun 5, 2015, 2:31:52 PM (11 years ago)
Author:
bills
Message:

cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotStackUpdateReadout.c

    r38383 r38396  
    1010bool psphotStackUpdateReadout (pmConfig *config, const pmFPAview *view) {
    1111
    12     psArray *objects = NULL; // used below after 'pass1finish' label
     12    psArray *objects = NULL;
    1313
    1414    // measure the total elapsed time in psphotReadout.  dtime is the elapsed time used jointly
     
    7979        return psphotReadoutCleanup (config, view, STACK_RAW);
    8080    }
    81 
    82 #ifdef MEASURE_PSF
    83     if (!psphotChoosePSF (config, view, STACK_RAW, true)) {
    84         psLogMsg ("psphot", 3, "failure to construct a psf model");
    85         return psphotReadoutCleanup (config, view, STACK_RAW);
    86     }
    87     if (!strcasecmp (breakPt, "PSFMODEL")) {
    88         return psphotReadoutCleanup (config, view, STACK_RAW);
    89     }
    90 #endif
    9181
    9282    if (!psphotDeblendSatstars (config, view, STACK_RAW)) {
     
    327317    for (int i = 0; i < sources->n; i++) {
    328318        pmSource *source = sources->data[i];
    329         source->imageID = index;     // XXX is this necessary?
     319        source->imageID = index;    // XXX: This is usually set in psphotSourceStatsReadout
    330320        pmModel *modelPSF = source->modelPSF;
    331321        // free any previous radial aperture measurements
     
    339329        if (!(source->mode & PM_SOURCE_MODE_PSFMODEL)) {
    340330            // The cmf loaders unconditionallly create psf models even if the source did not have one.
    341             fprintf(stderr, "source %d %5d should not have a psf model 0x%08X%08X\n", index, source->seq, source->mode2, source->mode);
     331            // fprintf(stderr, "source %d %5d should not have a psf model 0x%08X%08X\n", index, source->seq, source->mode2, source->mode);
    342332            psFree(source->modelPSF) ;
    343333        }
     
    361351        // for anything except psphotStack -updatemode.
    362352        if (modelPSF && isfinite(source->psfFlux)) {
    363             // The cmf reader is incorrectly setting the sky parameter for psf models
    364             modelPSF->params->data.F32[PM_PAR_SKY] = 0.0;
     353            // The cmf reader was incorrectly setting the sky parameter for psf models
     354            modelPSF->params->data.F32[PM_PAR_SKY]  = 0.0;
    365355            modelPSF->dparams->data.F32[PM_PAR_SKY] = 0.0;
     356
    366357            // Calculate flux for normalized model
    367             float saveI0 = modelPSF->params->data.F32[PM_PAR_I0];
    368358            modelPSF->params->data.F32[PM_PAR_I0] = 1.0;
    369359            float normFlux = modelPSF->class->modelFlux(modelPSF->params);
    370360            float psfFlux = source->psfFlux;
    371 #define APPLY_APCORR
    372 #ifdef APPLY_APCORR
     361            // back out the ApTrend
    373362            double apTrend = pmTrend2DEval (psf->ApTrend, (float)source->peak->x, (float)source->peak->y);
    374363            double adjustment = pow(10.0, -0.4*apTrend);
    375             if (isfinite(adjustment) && adjustment != 0.0) {
    376                 psfFlux = psfFlux / adjustment;
    377             } else {
    378                 fprintf(stderr, "apTrend adjustment for source %5d invalid: %f\n", source->seq, adjustment);
    379             }
    380 #endif
     364            psAssert ( (isfinite(adjustment) && adjustment != 0.0), "Invalid adjustment value: %f", adjustment);
     365
     366            psfFlux = psfFlux / adjustment;
    381367            float newI0 =  psfFlux / normFlux;
    382             if (isfinite (newI0) ) {
    383                 // psf model looks to be good.
    384                 modelPSF->params->data.F32[PM_PAR_I0] = newI0;
    385 #ifdef USE_SAVED_I0
    386                 // I am testing with a modified cmf that saves PM_PAR_I0
    387                 modelPSF->params->data.F32[PM_PAR_I0] = saveI0;
    388 #endif
    389                 // fprintf (stderr, "%5d %12f %12f %12f\n", source->seq, saveI0, newI0, saveI0 - newI0);
    390                 goodModel = true;
    391             } else {
    392                 psAssert(isfinite (modelPSF->params->data.F32[PM_PAR_I0]), "got infinite I0 for psf model");
    393             }
    394         }
    395 
    396         // It is rather expensive initializing all of the extended models. Lets only initialize
    397         // the extended model that will be used if any.
     368
     369            psAssert(isfinite (newI0) , "got infinite I0 for psf model");
     370
     371            // new I0 for psf model looks good.
     372            modelPSF->params->data.F32[PM_PAR_I0] = newI0;
     373            goodModel = true;
     374        }
     375
     376        // It is rather expensive setting the I0 all of the extended models. Lets only initialize
     377        // the extended model if it will be used for subtraction.
    398378
    399379        bool isPSF = false;
     
    403383            goodModel = false;
    404384            // calculate flux from the previously measured model magnitude. It will be nan if the
    405             // flux was negative unfortunately.
     385            // flux was negative unfortunately so we lose those.
    406386            if (isfinite(model->mag)) {
    407387                float modelFlux = pow(10., -0.4 * model->mag);
    408388
    409                 // XXX: We are assuming here that we only use PCM models. Get from recipe.
     389                // XXX: We are assuming here that we only use PCM models. Should get that information from the recipe.
    410390                pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
    411391                if (!pcm) {
     
    421401                    goodModel = true;
    422402                    // Usually this it is set when doing the fit. Since we are instantiating the model we
    423                     // set it explicitly.
     403                    // set it explicitly here.
    424404                    model->isPCM = true;
    425405                }
     
    430410                // The original flux was probably negative.
    431411                // This is somewhat rare. I saw it in about .2% of extended sources in my first test.
    432                 // Set source type to star to prevent source subtraction from crashing.
    433                 // this may cause model psf to be used in places.
    434                 // XXX However we aren't going to cache it below.
     412                // Set source type to star to prevent source subtraction from crashing by trying to use
     413                // an incomplete extended model.
     414                // XXX: this may cause model psf to be used in places.
     415                // XXX However we aren't going to cache it below so...
    435416                source->type = PM_SOURCE_TYPE_STAR;
    436417                model = NULL;
     
    443424            // Is this a reasonable guess?
    444425            source->moments->nPixels = source->modelPSF->nPix;
     426            source->tmpFlags |= PM_SOURCE_TMPF_CANDIDATE_PSFSTAR;
    445427        }
    446428
     
    449431        source->moments->SN = 0;
    450432        if (isfinite(kronFlux) && isfinite(source->moments->KronFluxErr) && isfinite(source->psfMag)) {
    451             // This is how we set the SN column in the CFF files
     433            // This is how we set the SN column in the CFF files...
    452434            source->moments->SN = kronFlux/source->moments->KronFluxErr;
    453435        } else if (isfinite(source->psfFlux) && isfinite(source->psfFluxErr)) {
     436            // kron no good try this. It's just used for sorting
    454437            source->moments->SN = source->psfFlux/source->psfFluxErr;
    455438        }
    456439
    457440        if (goodModel && model) {
     441            // Yipee! cache the model
    458442            if (model->isPCM) {
    459443                pmPCMCacheModel (source, maskVal, psfSize, fitNsigmaConv);
     
    465449
    466450    psFree(fitOptions);
    467 
    468 #ifdef MEASURE_PSF
    469     // need to drop the psf model in order for it to be re-measured
    470     // Hmm, will this invalidate the results from above where we used the loaded one?
    471     psMetadataRemoveKey(readout->analysis, "PSPHOT.PSF");
    472 #endif
    473451
    474452    return true;
Note: See TracChangeset for help on using the changeset viewer.