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/psphotFitGalaxies.c

    r5672 r5772  
    33bool psphotFitGalaxies (eamReadout *imdata, psMetadata *config, psArray *sources, psStats *skyStats)
    44{
    5     bool  status, goodfit;
     5    bool  status;
    66    float x;
    77    float y;
    8     int   Nfit = 0;
    9     int   Nfail = 0;
     8    int   Nfit  = 0;
     9    int   Nsub = 0;
    1010    int   Niter = 0;
    1111
    12     float OUTER_RADIUS     = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS");
     12    psTimerStart ("psphot");
    1313
    1414    float GAL_MIN_SN       = psMetadataLookupF32 (&status, config, "GAL_MIN_SN");
    15     float GAL_FIT_NSIGMA   = psMetadataLookupF32 (&status, config, "GAL_FIT_NSIGMA");
    16     float GAL_FIT_PADDING  = psMetadataLookupF32 (&status, config, "GAL_FIT_PADDING");
    1715    float GAL_MOMENTS_RAD  = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS");
     16    char       *modelName  = psMetadataLookupPtr (&status, config, "GAL_MODEL");
     17    pmModelType modelType  = pmModelSetType (modelName);
    1818
    19     float FLUX_LIMIT       = GAL_FIT_NSIGMA * skyStats->sampleStdev;
    20 
    21     char         *modelName   = psMetadataLookupPtr (&status, config, "GAL_MODEL");
    22     pmModelType   modelType   = pmModelSetType (modelName);
    23     pmModelRadius modelRadius = pmModelRadius_GetFunction (modelType);
    24 
    25     psTimerStart ("psphot");
     19    psphotInitRadiusFLT (config, skyStats, modelType);
    2620
    2721    for (int i = 0; i < sources->n; i++) {
    2822        pmSource *source = sources->data[i];
    2923
    30         // sources which should not be fitted
    31         // skip all valid stars
    32         if (source->type == PM_SOURCE_PSFSTAR) continue;
    33         if (source->type == PM_SOURCE_SATSTAR) continue;
    34         if (source->type == PM_SOURCE_GOODSTAR) continue;
     24        // only fit suspected extended sources
     25        if (source->type != PM_SOURCE_GALAXY) continue;
     26        if (source->mode  & PM_SOURCE_BLEND) continue;
    3527
    36         // skip all likely defects
    37         if (source->type == PM_SOURCE_DEFECT) continue;
    38         if (source->type == PM_SOURCE_SATURATED) continue;
    39 
    40         // skip poorly fitted stars
    41         if (source->type == PM_SOURCE_FAINTSTAR) continue;
    42         if (source->type == PM_SOURCE_POOR_FIT_PSF) continue;
    43 
    44         // XXX EAM when do we pick these up again?
    45         if (source->moments->SN < GAL_MIN_SN) {
    46           source->type = PM_SOURCE_FAINT_GALAXY;  // better choice?
    47           continue;
    48         }
     28        // skip possible extended sources below fit threshold
     29        if (source->moments->SN < GAL_MIN_SN) continue;
    4930
    5031        // recalculate the source moments using the larger galaxy moments radius
    5132        status = pmSourceMoments (source, GAL_MOMENTS_RAD);
    5233        if (!status) {
    53           source->type = PM_SOURCE_DROP_GALAXY;  // better choice?
     34          source->mode |= PM_SOURCE_FAIL;  // better choice?
    5435          continue;
    5536        }
     
    5738        // use the source moments, etc to guess basic model parameters
    5839        pmModel  *model  = pmSourceModelGuess (source, modelType);
     40        source->modelFLT = model;
    5941        x = model->params->data.F32[2];
    6042        y = model->params->data.F32[3];
    6143
    62         // set the fit radius based on the object flux limit and the model
    63         // XXX EAM : FLUX_LIMIT should be set based on local sky model (not global median)
    64         model->radius = modelRadius (model->params, FLUX_LIMIT) + GAL_FIT_PADDING;
    65         if (isnan(model->radius)) psAbort ("fit_galaxies", "error in radius");
    66 
    67         // check if we need to redefine the pixels
    68         // XXX EAM : a better test would examine the source pixels
    69         if (model->radius > OUTER_RADIUS) {
    70           // (re)-allocate image, weight, mask arrays for each peak (square of radius OUTER)
    71           psphotDefinePixels (source, imdata, x, y, model->radius);
    72         }
     44        // sets the model radius (via source->model) and adjusts pixels as needed
     45        psphotCheckRadiusFLT (imdata, source);
    7346
    7447        // fit FLT (not PSF) model (set/unset the pixel mask)
    7548        psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED);
    76         status = pmSourceFitModel (source, model, false);
     49        pmSourceFitModel (source, model, false);
    7750        psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED);
    78         if (!status) {
    79           // if the fit fails, we need to change the classification
    80           psLogMsg ("psphot", 5, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);
    81           source->type = PM_SOURCE_FAIL_FIT_GAL;  // better choice?
    82           source->modelFLT = model;
    83           Nfail ++;
    84           continue;
    85         }
    8651
    87         // check if model fit is acceptable
    88         goodfit = pmModelFitStatus (model);
    89         if (!goodfit) {
    90           // if the fit fails, we need to change the classification
    91           psLogMsg ("psphot", 5, "GAL fit poor for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);
    92           source->type = PM_SOURCE_POOR_FIT_GAL;  // better choice?
    93           source->modelFLT = model;
    94           Nfail ++;
    95           continue;
    96         }
    97 
    98         // accept the model
    99         source->type = PM_SOURCE_GALAXY;
    100         source->modelFLT = model;
    10152        Niter += model[0].nIter;
    10253        Nfit++;
    10354
    104         // subtract object, leave local sky
    105         pmSourceSubModel (source->pixels, source->mask, model, false, false);
     55        // check if model fit is acceptable
     56        if (pmModelFitStatus (model)) {
     57            pmSourceSubModel (source->pixels, source->mask, model, false, false);
     58            source->mode |= PM_SOURCE_SUBTRACTED;
     59            Nsub ++;
     60        }
    10661    }
    107     psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d failures, %d total iterations)\n", psTimerMark ("psphot"), Nfit, Nfail, Niter);
     62    psLogMsg ("psphot", 3, "fit GAL models: %f sec for %d galaxies (%d total iterations)\n", psTimerMark ("psphot"), Nfit, Niter);
     63    psLogMsg ("psphot", 4, "subtracted %d GAL models\n", Nsub);
    10864    return (true);
    10965}
Note: See TracChangeset for help on using the changeset viewer.