IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32157


Ignore:
Timestamp:
Aug 21, 2011, 10:44:17 AM (15 years ago)
Author:
eugene
Message:

distinguish window used for moment calculation and window used for model fitting more clearly; re-generate the cached model after PCM fitting using new function (instead of caching the fit models); add function to set window which shrinks as well as expands as needed

Location:
branches/eam_branches/ipp-20110710/psphot/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110710/psphot/src

    • Property svn:ignore
      •  

        old new  
        2222psphotMakePSF
        2323psphotStack
         24psphotModelTest
  • branches/eam_branches/ipp-20110710/psphot/src/psphot.h

    r32023 r32157  
    1919    PSPHOT_FORCED,
    2020    PSPHOT_MAKE_PSF,
     21    PSPHOT_MODEL_TEST,
    2122} psphotImageLoopMode;
    2223
     
    328329bool psphotMakePSFReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
    329330
     331pmConfig *psphotModelTestArguments(int argc, char **argv);
     332bool psphotModelTestReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
     333
    330334int psphotFileruleCount(const pmConfig *config, const char *filerule);
    331335bool psphotFileruleCountSet(const pmConfig *config, const char *filerule, int num);
     
    476480
    477481bool psphotSetRadiusMoments (float *fitRadius, float *windowRadius, pmReadout *readout, pmSource *source, psImageMaskType markVal);
     482bool psphotSetRadiusMomentsExact (float *fitRadius, float *windowRadius, pmReadout *readout, pmSource *source, psImageMaskType markVal);
    478483
    479484#endif
  • branches/eam_branches/ipp-20110710/psphot/src/psphotExtendedSourceFits.c

    r32023 r32157  
    316316        Next ++;
    317317
    318         // set the radius based on the first radial moment (also sets the mask pixels)
    319         if (!psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal)) {
    320             fprintf (stderr, "skipping (1) %f, %f\n", source->peak->xf, source->peak->yf);
    321             pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    322             // XXX raise an error of some kind or set a flag bit
    323             continue;
    324         }
     318        // set the fit radius based on the first radial moment (also sets the mask pixels)
     319        psphotSetRadiusMomentsExact(&fitRadius, &windowRadius, readout, source, markVal);
    325320
    326321        // Recalculate the source moments using the larger extended-source moments radius.  At
     
    332327            fprintf (stderr, "skipping (2) %f, %f\n", source->peak->xf, source->peak->yf);
    333328            *source->moments = psfMoments;
     329
     330            // probably need to bump up the size for subtraction
    334331            pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    335332            // XXX raise an error flag of some kind
    336333            continue;
    337334        }
    338 
    339         // save the PSF-based modelFlux here in case we need to subtract it (for failure).  If
    340         // it does not exist, attempt to generate it.  Give up if we cannot even do that.
    341         psImage *modelFluxStart = psMemIncrRefCounter (source->modelFlux);
    342         if (!modelFluxStart) {
    343             pmSourceCacheModel (source, maskVal);
    344             modelFluxStart = psMemIncrRefCounter (source->modelFlux);
    345             if (!modelFluxStart) {
    346                 fprintf (stderr, "skipping (3) %f, %f\n", source->peak->xf, source->peak->yf);
    347                 *source->moments = psfMoments;
    348                 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    349                 // XXX raise an error of some kind?
    350                 continue;
    351             }
    352         }
    353        
    354         // array to store the pointers to the model flux images while the models are being fitted
    355         psArray *modelFluxes = psArrayAllocEmpty (models->list->n);
    356335
    357336        // allocate the array to store the model fits
     
    417396                  continue;
    418397              }
    419               pmSourceCacheModel (source, maskVal);
    420398              psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f (npix: %d, niter: %d)\n",
    421399                       source->moments->Mx, source->moments->My, pmModelClassGetName (modelFit->type), modelFit->chisq, modelFit->nPix, modelFit->nIter);
     
    426404              }
    427405          }
    428 
    429           // save each of the model flux images for now, and (below) store the best
    430           psArrayAdd (modelFluxes, 4, source->modelFlux);
    431406
    432407          pmSourceExtFitPars *extFitPars = pmSourceExtFitParsAlloc();
     
    477452          psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->Mx, source->moments->My);
    478453
    479           // replace original model, subtract it
    480           psFree (source->modelFlux);
    481           source->modelFlux = modelFluxStart;
     454          // ensure the modelEXT is cached
     455          pmSourceCacheModel (source, maskVal);
    482456
    483457          *source->moments = psfMoments;
    484458          pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    485 
    486           psFree (modelFluxes);
    487459
    488460          continue;
     
    493465        source->modelEXT = psMemIncrRefCounter (source->modelFits->data[minModel]);
    494466
    495         // save the modelFlux for the best model
    496         psFree (source->modelFlux);
    497         source->modelFlux = psMemIncrRefCounter (modelFluxes->data[minModel]);
     467        // adjust the window so the subtraction covers the faint wings
     468        psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal);
     469
     470        // cache the model flux
     471        if (source->modelEXT->isPCM) {
     472            pmPCMCacheModel (source, maskVal, psfSize);
     473        } else {
     474            pmSourceCacheModel (source, maskVal);
     475        }
    498476
    499477        // replace the original moments
     
    502480        // subtract the best fit from the object, leave local sky
    503481        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    504 
    505         // the initial model flux is no longer needed
    506         psFree (modelFluxStart);
    507         psFree (modelFluxes);
    508482
    509483        psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->Mx, source->moments->My, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq);
  • branches/eam_branches/ipp-20110710/psphot/src/psphotKronMasked.c

    r31673 r32157  
    9696        if (!source->moments) continue;
    9797
     98        float windowRadius = RADIUS;
     99        if (source->moments->KronFlux / source->moments->KronFluxErr > 10.0) {
     100            windowRadius = PS_MAX (RADIUS, 10*source->moments->Mrf);
     101        }
     102
     103        // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
     104        pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2);
     105
     106        pmMoments psfMoments = *source->moments;
     107
    98108        // replace object in image
    99109        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
     
    101111        }
    102112
    103         psphotKronMag (source, RADIUS, MIN_KRON_RADIUS, maskVal);
     113        psphotKronMag (source, windowRadius, MIN_KRON_RADIUS, maskVal);
    104114
    105115        // re-subtract the object, leave local sky
     
    136146        }
    137147    }           
     148
    138149    // psphotSaveImage (NULL, kronMask, "kronmask.fits");
    139150    psLogMsg ("psphot.kron", PS_LOG_DETAIL, "measure masked kron magnitudes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n);
  • branches/eam_branches/ipp-20110710/psphot/src/psphotRadiusChecks.c

    r31990 r32157  
    144144# define MIN_WINDOW 5.0
    145145# define SCALE1 5.0
    146 # define SCALE2 12.5
     146# define SCALE2 12.0
    147147
    148148// call this function whenever you (re)-define the EXT model
     149// XXX this function does not shrink the window
    149150bool psphotSetRadiusMoments (float *fitRadius, float *windowRadius, pmReadout *readout, pmSource *source, psImageMaskType markVal) {
    150151
     
    160161    // redefine the pixels if needed
    161162    pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, *windowRadius);
     163
     164    // set the mask to flag the excluded pixels
     165    psImageKeepCircle (source->maskObj, source->peak->xf, source->peak->yf, *fitRadius, "OR", markVal);
     166
     167    return true;
     168}
     169# undef SCALE1
     170# undef SCALE2
     171# undef MIN_WINDOW
     172
     173# define MIN_WINDOW 5.0
     174# define SCALE1 5.0
     175# define PAD_WINDOW 3.0
     176
     177// call this function whenever you (re)-define the EXT model
     178// XXX alternate function to set exactly the desired window size
     179bool psphotSetRadiusMomentsExact (float *fitRadius, float *windowRadius, pmReadout *readout, pmSource *source, psImageMaskType markVal) {
     180
     181    psRegion newRegion;
     182
     183    psAssert (source, "source not defined??");
     184    psAssert (source->moments, "moments not defined??");
     185
     186    *fitRadius = SCALE1 * source->moments->Mrf;
     187    *fitRadius = PS_MIN (PS_MAX(*fitRadius, MIN_WINDOW), EXT_FIT_MAX_RADIUS);
     188
     189    *windowRadius = *fitRadius + PAD_WINDOW;
     190
     191    // check to see if new region is completely contained within old region
     192    newRegion = psRegionForSquare (source->peak->xf, source->peak->yf, *windowRadius);
     193    newRegion = psRegionForImage (readout->image, newRegion);
     194
     195    // redefine the pixels to match
     196    pmSourceRedefinePixelsByRegion (source, readout, newRegion);
    162197
    163198    // set the mask to flag the excluded pixels
  • branches/eam_branches/ipp-20110710/psphot/src/psphotReadout.c

    r31452 r32157  
    137137    }
    138138
    139     // construct sources and measure basic stats (saved on detections->newSources)
     139    // construct sources and measure moments and other basic stats (saved on detections->newSources)
     140    // all sources use the auto-scaled window appropriate to a PSF, except for the saturated
     141    // stars : these use a larger window (3x the basic window)
    140142    if (!psphotSourceStats (config, view, filerule, true)) { // pass 1
    141143        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     
    200202    psphotDumpChisqs (config, view, filerule);
    201203
    202     // XXX re-measure the kron mags with models subtracted
     204    // re-measure the kron mags with models subtracted.  this pass uses a circular window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments)
     205   
     206    // but this is chosen above to be appropriate for the PSF objects (not galaxies)
    203207    psphotKronMasked(config, view, filerule);
    204208
     
    214218    psphotDumpChisqs (config, view, filerule);
    215219
     220    // XXX note above the extended sources have their moments remeasured with a larger window,
     221    // but the result is replaced with the original PSF-scaled window
     222
    216223    // replace all sources
    217224    psphotReplaceAllSources (config, view, filerule); // pass 1 (detections->allSources)
     
    240247        psphotSubNoise (config, view, filerule); // pass 1 (detections->allSources)
    241248
    242         // define new sources based on only the new peaks
     249        // define new sources based on only the new peaks & measure moments
    243250        // NOTE: new sources are saved on detections->newSources
    244251        psphotSourceStats (config, view, filerule, false); // pass 2 (detections->newSources)
     
    313320
    314321    // XXX re-measure the kron mags with models subtracted
     322    // Note that this uses the PSF_MOMENTS_RADIUS as a window
    315323    psphotKronMasked(config, view, filerule);
    316324
  • branches/eam_branches/ipp-20110710/psphot/src/psphotSourceFits.c

    r32023 r32157  
    511511}
    512512
    513 # define TIMING 0
     513# define TIMING 1
    514514
    515515pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
     
    583583
    584584    if (TIMING) {
    585         fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d, t1: %6.4f, t2: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, t1, t2, t4, t5);
     585        int nPixBig = source->pixels->numCols * source->pixels->numRows;
     586        fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t4, t5);
    586587    }
    587588
Note: See TracChangeset for help on using the changeset viewer.