IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 13, 2005, 6:43:44 AM (21 years ago)
Author:
eugene
Message:

substantial work on ensemble PSF fitting, better functions for evaluation, overall code cleanups

File:
1 edited

Legend:

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

    r5131 r5772  
    22
    33// fit psf model to all objects
    4 // PSFSTAR objects will be refitted
    5 // run this function to a specific flux limit?
    6 
    74bool psphotApplyPSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky)
    85{
    9     bool  status;
    106    float x;
    117    float y;
    12     int   Nfit = 0;
    13     int   Nsub = 0;
     8    int   Nfit  = 0;
     9    int   Nsub  = 0;
    1410    int   Niter = 0;
    1511
    1612    psTimerStart ("psphot");
    1713
    18     // we may set this differently here from the value used to mark likely saturated stars
    19     float SATURATION   = psMetadataLookupF32 (&status, config, "SATURATION");
    20     float OUTER_RADIUS = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS");
    21 
    22     float PSF_MIN_SN       = psMetadataLookupF32 (&status, config, "PSF_MIN_SN");
    23     float PSF_MAX_CHI      = psMetadataLookupF32 (&status, config, "PSF_MAX_CHI");
    24     float PSF_FIT_NSIGMA   = psMetadataLookupF32 (&status, config, "PSF_FIT_NSIGMA");
    25     float PSF_FIT_PADDING  = psMetadataLookupF32 (&status, config, "PSF_FIT_PADDING");
    26     float PSF_SHAPE_NSIGMA = psMetadataLookupF32 (&status, config, "PSF_SHAPE_NSIGMA");
    27 
    28     // set the object surface-brightness limit for fitted pixels
    29     float FLUX_LIMIT  = PSF_FIT_NSIGMA * sky->sampleStdev;
    30     psLogMsg ("psphot.apply_psf_model", 4, "fitting pixels with at least %f object counts\n", FLUX_LIMIT);
    31 
    32     // this function specifies the radius at this the model hits the given flux
    33     pmModelRadius modelRadius = pmModelRadius_GetFunction (psf->type);
     14    psphotInitLimitsPSF (config);
     15    psphotInitRadiusPSF (config, sky, psf->type);
    3416
    3517    for (int i = 0; i < sources->n; i++) {
     
    3820
    3921        // skip non-astronomical objects (very likely defects)
    40         // XXX EAM : should we try these anyway?
     22        if (source->mode  & PM_SOURCE_BLEND) continue;
    4123        if (source->type == PM_SOURCE_DEFECT) continue;
    4224        if (source->type == PM_SOURCE_SATURATED) continue;
     
    4729        // set PSF parameters for this model
    4830        pmModel *model = pmModelFromPSF (modelFLT, psf);
     31        psFree (modelFLT);
     32
     33        source->modelPSF = model;
     34
     35        // sets the model radius (via source->model) and adjusts pixels as needed
     36        psphotCheckRadiusPSF (imdata, source);
     37
    4938        x = model->params->data.F32[2];
    5039        y = model->params->data.F32[3];
    51         psFree (modelFLT);
    5240
    53         // set the fit radius based on the object flux limit and the model
    54         // XXX EAM : FLUX_LIMIT should be set based on local sky model (not global median)
    55         model->radius = modelRadius (model->params, FLUX_LIMIT) + PSF_FIT_PADDING;
    56         if (isnan(model->radius)) {
    57           psAbort ("apply_psf_model", "error in radius");
    58         }
    59        
    60         // check if we need to redefine the pixels
    61         // XXX EAM : a better test would examine the source pixels
    62         if (model->radius > OUTER_RADIUS) {
    63           // (re)-allocate image, weight, mask arrays for each peak (square of radius OUTER)
    64             psphotDefinePixels (source, imdata, x, y, model->radius);
    65         }
    66 
    67         // if (i > 66) psTraceSetLevel (".psLib.dataManip.psMinimizeLMChi2", 5);
    68            
    6941        // fit PSF model (set/unset the pixel mask)
    7042        psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED);
    71         status = pmSourceFitModel (source, model, true);
     43        pmSourceFitModel (source, model, true);
    7244        psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED);
    7345
    74         if (!status || (model->params->data.F32[1] < 0)) {
    75           psLogMsg ("psphot", 5, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter);
    76           source->type = PM_SOURCE_FAIL_FIT_PSF;  // better choice?
    77           psFree (model);
    78           continue;
    79         }
    80         // XXX EAM : this was an attempt to correct for fit-sky biases
    81         // pmModelSkyOffset (model, x, y, model->radius);
    82 
    83         // model succeeded : tentatively keep it
    84         source->modelPSF = model;
    8546        Niter += model[0].nIter;
    8647        Nfit ++;
    8748
    88         // is it a good model?
    89         psphotMarkPSF (source, PSF_SHAPE_NSIGMA, PSF_MIN_SN, PSF_MAX_CHI, SATURATION);
    90         if (psphotSubtractPSF (source)) {
    91           Nsub ++;
     49        // check if model fit is acceptable
     50        if (psphotEvalPSF (source)) {
     51            pmSourceSubModel (source->pixels, source->mask, source->modelPSF, false, false);
     52            source->mode |= PM_SOURCE_SUBTRACTED;
     53            Nsub ++;
    9254        }
    9355    }
    9456
    9557    psLogMsg ("psphot", 3, "fit PSF models: %f sec for %d objects (%d total iterations)\n", psTimerMark ("psphot"), Nfit, Niter);
    96     psLogMsg ("psphot", 4, "subtracted %d PSF objects\n", Nsub);
     58    psLogMsg ("psphot", 4, "subtracted %d PSF models\n", Nsub);
    9759    return (true);
    9860}
Note: See TracChangeset for help on using the changeset viewer.