IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 5, 2012, 4:04:34 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20120805/psphot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120805/psphot

  • branches/eam_branches/ipp-20120805/psphot/src

  • branches/eam_branches/ipp-20120805/psphot/src/psphotKronIterate.c

    r34378 r34399  
    55
    66
    7 bool psphotKronIterate (pmConfig *config, const pmFPAview *view, const char *filerule)
     7bool psphotKronIterate (pmConfig *config, const pmFPAview *view, const char *filerule, int pass)
    88{
    99    bool status = true;
     
    4242        // psAssert (psf, "missing psf?");
    4343
    44         if (!psphotKronIterateReadout (config, recipe, view, filerule, readout, sources, psf, i)) {
     44        if (!psphotKronIterateReadout (config, recipe, view, filerule, readout, sources, psf, i, pass)) {
    4545            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
    4646            return false;
     
    5454bool psphotVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max);
    5555
    56 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index) {
     56#ifdef DUMP_KRS
     57FILE *dumpFile = NULL;
     58#endif
     59
     60bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index, int pass) {
    5761
    5862    bool status = false;
     63
     64#ifdef DUMP_KRS
     65    if (!dumpFile) {
     66        dumpFile = fopen("kr.txt", "w");
     67        psAssert (dumpFile, "failed to open kr.txt");
     68    }
     69    fprintf(dumpFile, "\n\n Input %d\n", index);
     70#endif
    5971
    6072    if (!sources->n) {
     
    6476
    6577    psTimerStart ("psphot.kron");
    66 
    6778
    6879    // determine the number of allowed threads
     
    160171
    161172    // generate the window image: multiply the flux by this to downweight neighbors
     173    // XXX: we don't need this image if we aren't going to apply the window
    162174    psImage *kronWindow = psImageAlloc (readout->image->numCols, readout->image->numRows, PS_TYPE_F32);
    163175    psImageInit (kronWindow, 1.0);
     
    235247            PS_ARRAY_ADD_SCALAR(job->args, KRON_SMOOTH_SIGMA,  PS_TYPE_F32);
    236248            PS_ARRAY_ADD_SCALAR(job->args, KRON_SB_MIN_DIVISOR,PS_TYPE_F32);
     249            PS_ARRAY_ADD_SCALAR(job->args, pass,               PS_TYPE_S32);
    237250
    238251// set this to 0 to run without threading
     
    297310    float KRON_SMOOTH_SIGMA         = PS_SCALAR_VALUE(job->args->data[11],F32);
    298311    float KRON_SB_MIN_DIVISOR       = PS_SCALAR_VALUE(job->args->data[12],F32);
     312    int pass                        = PS_SCALAR_VALUE(job->args->data[13],S32);
     313#ifndef REVERT_ON_BAD_MEASUREMENT
     314    (void) pass;
     315#endif
    299316
    300317    for (int j = 0; j < KRON_ITERATIONS; j++) {
     
    308325            if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
    309326            if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     327            if (!isfinite(source->moments->Mrf)) {
     328                // Once we save a bad Mrf measurement we give up on this source
     329                // checking here allows us to avoid adding and subtracting the model
     330                continue;
     331            }
    310332
    311333            // skip saturated stars modeled with a radial profile
     
    324346            }
    325347
    326             // On first iteration set window radius to sky radius (if valid) on second iteration
    327             // use a factor times the previous radial moment value up to a maximum value that
    328             // depends on the surface brightness of the source
    329             float maxWindow;
    330             if (j == 0) {
    331                 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS;
    332             } else {
     348            // On first iteration set window radius to sky radius (if valid). We also use this on subsequent
     349            // iterations if we cannot find a better limit
     350            float maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS;
     351            if (j > 0) {
     352                // on subsequent iterations we use a factor times the previous radial moment value
     353                // limited to a maximum value that depends on the surface brightness of the source
    333354                if (KRON_SB_MIN_DIVISOR) {
    334                     if (isfinite(source->moments->KronFlux) && (source->moments->KronFlux > 0)) {
    335                         // Limit window radius based on surface brightness
     355                    // Limit window radius based on surface brightness if we have a good measurement of kron flux
     356                    if (isfinite(source->moments->KronFlux)  && (source->moments->KronFlux > 0)) {
    336357                        float Rmax = sqrt(source->moments->KronFlux) / KRON_SB_MIN_DIVISOR;
    337358
    338                         if (source->moments->Mrf > 0) {
     359                        if (isfinite(source->moments->Mrf) && source->moments->Mrf > 0) {
    339360                            maxWindow = PS_MIN(6.0*source->moments->Mrf, Rmax);
    340361                        } else {
    341                             maxWindow = Rmax;
     362                            maxWindow = PS_MIN(Rmax, maxWindow);
    342363                        }
    343                     } else {
    344                         maxWindow = RADIUS;
    345364                    }
    346365                } else {
    347                     // old code
     366                    // old recipe, no surface brightness cut
    348367                    maxWindow = isfinite(source->moments->Mrf) ? 6.0*source->moments->Mrf : RADIUS;
    349368                }
    350369            }
    351370            float windowRadius = PS_MAX(RADIUS, maxWindow);
     371
     372#ifdef REVERT_ON_BAD_MEASURMENT
     373            // save previous measurements. We might revert back to them if this round fails
     374            float MrfPrior = source->moments->Mrf;
     375            float KronFluxPrior = source->moments->KronFlux;
     376            float KronFluxErrPrior = source->moments->KronFluxErr;
     377#endif
    352378
    353379            // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
     
    376402            }
    377403
     404#ifdef REVERT_ON_BAD_MEASUREMENT
     405            // on pass 2 if we get an invalid measurement on a pass 1 source where we had a good one previously
     406            // in pass 1 keep that measurement
     407            bool reverted = false;
     408            if (pass > 1 && !isfinite(source->moments->Mrf) && (source->mode2 & PM_SOURCE_MODE2_PASS1_SRC)) {
     409                source->moments->Mrf = MrfPrior;    // This is finite otherwise we wouldn't have gotten here
     410                source->moments->KronFlux = KronFluxPrior;
     411                source->moments->KronFluxErr = KronFluxErrPrior;
     412                reverted = true;
     413            }
     414#endif
     415#ifdef DUMP_KRS
     416#ifndef REVERT_ON_BAD_MEASUREMENT
     417            bool reverted = false;
     418#endif
     419            fprintf(dumpFile, "%7d %1d %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f %2d\n", source->id, reverted, source->moments->Mrf, MrfPrior, maxWindow, windowRadius, source->peak->xf, source->peak->yf, source->imageID);
     420#endif
     421
    378422            // if we subtracted it above, re-subtract the object, leave local sky
    379423            if (reSubtract) {
     
    494538    }
    495539
     540    float MrfTry = RF/RS;
     541    if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) {
     542        // We did not get a good measurement
     543        source->moments->Mrf = NAN;
     544        source->moments->KronFlux  = NAN;
     545        source->moments->KronFluxErr  = NAN;
     546        return false;
     547    }
     548
     549    float Mrf = MAX(minKronRadius, MrfTry);
    496550    // Saturate the 1st radial moment
    497     float Mrf = MAX(minKronRadius, RF/RS);
    498551    if (sqrt(source->peak->detValue) < 10.0) {
    499552        Mrf = MIN (radius, Mrf);
     
    544597    }
    545598
    546     source->moments->Mrf = Mrf;
     599    source->moments->Mrf         = Mrf;
    547600    source->moments->KronFlux    = Sum;
    548601    source->moments->KronFluxErr = sqrt(Var);
     
    562615    psAssert(kronWindow, "need a window");
    563616
     617    // XXX: If we are not applying the window then we don't need to check for valid Mrf here.
     618    // We should give the this module a chance to measure a good value.
     619    // However experiments show that it hardly ever succeeds in getting a better value
    564620    if (!isfinite(source->moments->Mrf) || source->moments->Mrf < 0 ) return false;
    565621
Note: See TracChangeset for help on using the changeset viewer.