IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 16, 2005, 6:02:29 AM (21 years ago)
Author:
eugene
Message:

improved galaxy model guesses, better handling of errors

File:
1 edited

Legend:

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

    r4251 r4574  
    33// fit selected galaxy model (GAUSS) to all bright objects of type GALAXY
    44
    5 bool fit_galaxies (psImage *image, psMetadata *config, psArray *sources)
     5bool fit_galaxies (psImageData *imdata, psMetadata *config, psArray *sources, psStats *skyStats)
    66{
    77    bool  status;
     8    float x;
     9    float y;
     10    float sky;
    811    int   Nfit = 0;
     12    int   Nfail = 0;
    913    int   Niter = 0;
    1014
     15    float MOMENT_R = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS");
    1116    float RADIUS   = psMetadataLookupF32 (&status, config, "FIT_RADIUS");
    1217    float snFaint  = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
    13     psModelType modelType = psModelSetType ("PS_MODEL_PGAUSS");
     18    float OUTER    = psMetadataLookupF32 (&status, config, "OUTER_RADIUS");
     19    float FIT_NSIGMA  = psMetadataLookupF32 (&status, config, "FIT_NSIGMA");
     20    float FIT_PADDING = psMetadataLookupF32 (&status, config, "FIT_PADDING");
     21
     22    float FLUX_LIMIT  = FIT_NSIGMA * skyStats->sampleStdev;
     23
     24    psModelType   modelType   = psModelSetType ("PS_MODEL_RGAUSS");
     25    psModelRadius modelRadius = psModelRadius_GetFunction (modelType);
     26
     27    psTraceSetLevel (".psModules.pmSourceMoments", 5);
    1428
    1529    psTimerStart ("psphot");
     
    1933        if (source->moments->SN < snFaint) continue;
    2034
     35        // recalculate the source moments using the galaxy radius (larger)
     36        status = pmSourceMoments (source, MOMENT_R);
     37
     38        // use the source moments, etc to guess basic model parameters
     39        psModel  *model  = pmSourceModelGuess (source, modelType);
     40
     41        x = model->params->data.F32[2];
     42        y = model->params->data.F32[3];
     43
    2144        // need a better model guess and a better radius choice
    2245        // when radius is not fixed, we will need to check if new radius fits on image
    23 # if (0)
     46
     47        // set the fit radius based on the object flux limit and the model
     48        // FLUX_LIMIT should be set based on local sky model (not global median)
     49        // model->radius = 25.0;
     50        model->radius = modelRadius (model->params, FLUX_LIMIT) + FIT_PADDING;
     51        if (isnan(model->radius)) {
     52          fprintf (stderr, "error in radius\n");
     53          continue;
     54        }
    2455        if (model->radius > OUTER) {
    2556          // allocate image, noise, mask arrays for each peak (square of radius OUTER)
    26           pmSourceDefinePixels (source, imdata, x, y, OUTER);
     57          pmSourceDefinePixels (source, imdata, x, y, model->radius);
    2758        }
    28 # endif
    29         psModel  *model  = pmSourceModelGuess (source, modelType);
    3059
    3160        // fit as FLT, not PSF (skip poor fits)
    32         if (!pmSourceFitModel (source, model, false)) continue;
     61        psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80);
     62        status = pmSourceFitModel (source, model, false);
     63        psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f);
     64        if (!status || (model->params->data.F32[1] < 0)) {
     65          // if the fit fails, we need to change the classification
     66          psLogMsg ("psphot", 3, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);
     67          source->type = PS_SOURCE_OTHER;  // better choice?
     68          Nfail ++;
     69          continue;
     70        }
     71
    3372        source->modelFLT = model;
    34 
    3573        Niter += model[0].nIter;
    3674        Nfit++;
     75
     76        // subtract object, leave local sky
     77        sky = model->params->data.F32[0];
     78        model->params->data.F32[0] = 0;
     79        pmSourceSubModel (source->pixels, source->mask, model, false);
     80        model->params->data.F32[0] = sky;
     81
    3782    }
    38     psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d total iterations)\n", psTimerMark ("psphot"), Nfit, Niter);
     83    psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d failures, %d total iterations)\n", psTimerMark ("psphot"), Nfit, Nfail, Niter);
    3984    return (true);
    4085}
Note: See TracChangeset for help on using the changeset viewer.