IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 16, 2012, 2:38:37 PM (14 years ago)
Author:
bills
Message:

Several changes to psphot and psphotStack

  1. Add function to compute the memory used by all of the sources
  2. Add function to log memory stats in psphotStack
  3. Don't load or psf match the convolved images into psphotStack unless they are needed.

This saves a lot of time if RADIAL_APERTURES are not enabled and we are measuring on the raw images

  1. Several improvements to the error handling in the Kron measurements. In particular the Mrf value

was being treated as positive when both the numerator and denomiator were negative. This is the cause
of many of the very large kron radius measurements. Set Mrf to NAN in these cases.

  1. Skip kron measurments for source if the previous Mrf measurement was NAN earlier in the process.

This saves memory by not expanding the source images when the kron measurements were actually going
to be skipped

  1. Remove the hack cut on fwhmMaj. Managing the kron radius measurements better fixes the memory explosion

that that helped to reduce.

File:
1 edited

Legend:

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

    r34311 r34317  
    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
     
    236247            PS_ARRAY_ADD_SCALAR(job->args, KRON_SMOOTH_SIGMA,  PS_TYPE_F32);
    237248            PS_ARRAY_ADD_SCALAR(job->args, KRON_SB_MIN_DIVISOR,PS_TYPE_F32);
     249            PS_ARRAY_ADD_SCALAR(job->args, pass,               PS_TYPE_S32);
    238250
    239251// set this to 0 to run without threading
     
    298310    float KRON_SMOOTH_SIGMA         = PS_SCALAR_VALUE(job->args->data[11],F32);
    299311    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
    300316
    301317    for (int j = 0; j < KRON_ITERATIONS; j++) {
     
    309325            if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
    310326            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            }
    311332
    312333            // replace object in image
     
    322343            }
    323344
    324             // On first iteration set window radius to sky radius (if valid) on second iteration
    325             // use a factor times the previous radial moment value up to a maximum value that
    326             // depends on the surface brightness of the source
    327             float maxWindow;
    328             if (j == 0) {
    329                 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS;
    330             } else {
     345            // On first iteration set window radius to sky radius (if valid). We also use this on subsequent
     346            // iterations if we cannot find a better limit
     347            float maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS;
     348            if (j > 0) {
     349                // on subsequent iterations we use a factor times the previous radial moment value
     350                // limited to a maximum value that depends on the surface brightness of the source
    331351                if (KRON_SB_MIN_DIVISOR) {
    332352                    // Limit window radius based on surface brightness if we have a good measurement of kron flux
    333                     if (isfinite(source->moments->Mrf) && source->moments->Mrf > 0 &&
    334                         isfinite(source->moments->KronFlux)  && (source->moments->KronFlux > 0)) {
     353                    if (isfinite(source->moments->KronFlux)  && (source->moments->KronFlux > 0)) {
    335354                        float Rmax = sqrt(source->moments->KronFlux) / KRON_SB_MIN_DIVISOR;
    336355
    337                         maxWindow = PS_MIN(6.0*source->moments->Mrf, Rmax);
    338                     } else {
    339                         maxWindow = RADIUS;
     356                        if (isfinite(source->moments->Mrf) && source->moments->Mrf > 0) {
     357                            maxWindow = PS_MIN(6.0*source->moments->Mrf, Rmax);
     358                        } else {
     359                            maxWindow = PS_MIN(Rmax, maxWindow);
     360                        }
    340361                    }
    341362                } else {
     
    345366            }
    346367            float windowRadius = PS_MAX(RADIUS, maxWindow);
     368
     369#ifdef REVERT_ON_BAD_MEASURMENT
     370            // save previous measurements. We might revert back to them if this round fails
     371            float MrfPrior = source->moments->Mrf;
     372            float KronFluxPrior = source->moments->KronFlux;
     373            float KronFluxErrPrior = source->moments->KronFluxErr;
     374#endif
    347375
    348376            // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
     
    371399            }
    372400
     401#ifdef REVERT_ON_BAD_MEASUREMENT
     402            // on pass 2 if we get an invalid measurement on a pass 1 source where we had a good one previously
     403            // in pass 1 keep that measurement
     404            bool reverted = false;
     405            if (pass > 1 && !isfinite(source->moments->Mrf) && (source->mode2 & PM_SOURCE_MODE2_PASS1_SRC)) {
     406                source->moments->Mrf = MrfPrior;    // This is finite otherwise we wouldn't have gotten here
     407                source->moments->KronFlux = KronFluxPrior;
     408                source->moments->KronFluxErr = KronFluxErrPrior;
     409                reverted = true;
     410            }
     411#endif
     412#ifdef DUMP_KRS
     413#ifndef REVERT_ON_BAD_MEASUREMENT
     414            bool reverted = false;
     415#endif
     416            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);
     417#endif
     418
    373419            // if we subtracted it above, re-subtract the object, leave local sky
    374420            if (reSubtract) {
     
    490536
    491537    float MrfTry = RF/RS;
    492     if (!isfinite(MrfTry)) {
    493         // We did not get a successul measurement of the kron radius.
    494         // Leave the current values unchanged.
     538    if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) {
     539        // We did not get a good measurement
     540        source->moments->Mrf = NAN;
     541        source->moments->KronFlux  = NAN;
     542        source->moments->KronFluxErr  = NAN;
    495543        return false;
    496544    }
     
    546594    }
    547595
    548     source->moments->Mrf = Mrf;
     596    source->moments->Mrf         = Mrf;
    549597    source->moments->KronFlux    = Sum;
    550598    source->moments->KronFluxErr = sqrt(Var);
     
    564612    psAssert(kronWindow, "need a window");
    565613
    566     // If we are not applying the window then we don't need to check for valid Mrf here.
     614    // XXX: If we are not applying the window then we don't need to check for valid Mrf here.
    567615    // We should give the this module a chance to measure a good value.
    568     // Not yet though. We need to test the effect of this
     616    // However experiments show that it hardly ever succeeds in getting a better value
    569617    if (!isfinite(source->moments->Mrf) || source->moments->Mrf < 0 ) return false;
    570618
Note: See TracChangeset for help on using the changeset viewer.