IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 27, 2005, 3:26:57 PM (21 years ago)
Author:
eugene
Message:

various tests and changes

File:
1 edited

Legend:

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

    r4582 r4630  
    11# include "psphot.h"
    2 
    3 // fit selected galaxy model (GAUSS) to all bright objects of type GALAXY
    42
    53bool fit_galaxies (psImageData *imdata, psMetadata *config, psArray *sources, psStats *skyStats)
    64{
    7     bool  status;
     5    bool  status, goodfit;
    86    float x;
    97    float y;
     
    1311    int   Niter = 0;
    1412
    15     float MOMENT_R = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS");
    16     // float RADIUS   = psMetadataLookupF32 (&status, config, "FIT_RADIUS");
    17     float snFaint  = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
    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");
     13    float  MOMENT_R    = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS");
     14    float  snFaint     = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
     15    float  OUTER       = psMetadataLookupF32 (&status, config, "OUTER_RADIUS");
     16    float  FIT_NSIGMA  = psMetadataLookupF32 (&status, config, "FIT_NSIGMA");
     17    float  FIT_PADDING = psMetadataLookupF32 (&status, config, "FIT_PADDING");
     18    char  *modelName   = psMetadataLookupPtr (&status, config, "GAL_MODEL");
    2119
    2220    float FLUX_LIMIT  = FIT_NSIGMA * skyStats->sampleStdev;
    2321
    24     psModelType   modelType   = psModelSetType ("PS_MODEL_SGAUSS");
     22    psModelType   modelType   = psModelSetType (modelName);
    2523    psModelRadius modelRadius = psModelRadius_GetFunction (modelType);
    26 
    27     psTraceSetLevel (".psModules.pmSourceMoments", 5);
    2824
    2925    psTimerStart ("psphot");
    3026    for (int i = 0; i < sources->n; i++) {
    3127        psSource *source = sources->data[i];
    32         if (source->type != PS_SOURCE_GALAXY) continue;
    33         if (source->moments->SN < snFaint) continue;
     28
     29        // sources which should not be fitted
     30        // skip all valid stars
     31        if (source->type == PS_SOURCE_PSFSTAR) continue;
     32        if (source->type == PS_SOURCE_SATSTAR) continue;
     33        if (source->type == PS_SOURCE_GOODSTAR) continue;
     34        // skip all likely defects
     35        if (source->type == PS_SOURCE_DEFECT) continue;
     36        if (source->type == PS_SOURCE_SATURATED) continue;
     37        //
     38        if (source->type == PS_SOURCE_FAINTSTAR) continue;
     39        if (source->type == PS_SOURCE_POOR_FIT_PSF) continue;
     40
     41        // XXX when do we pick these up again?
     42        if (source->moments->SN < snFaint) {
     43          source->type = PS_SOURCE_FAINT_GALAXY;  // better choice?
     44          continue;
     45        }
    3446
    3547        // recalculate the source moments using the galaxy radius (larger)
    3648        status = pmSourceMoments_EAM (source, MOMENT_R);
    3749        if (!status) {
    38           fprintf (stderr, "invalid moments, skipping\n");
     50          source->type = PS_SOURCE_DROP_GALAXY;  // better choice?
    3951          continue;
    4052        }
     
    4658        y = model->params->data.F32[3];
    4759
    48         // need a better model guess and a better radius choice
    49         // when radius is not fixed, we will need to check if new radius fits on image
    50 
    5160        // set the fit radius based on the object flux limit and the model
    5261        // FLUX_LIMIT should be set based on local sky model (not global median)
    53         // model->radius = 25.0;
    5462        model->radius = modelRadius (model->params, FLUX_LIMIT) + FIT_PADDING;
    55         if (isnan(model->radius)) {
    56           fprintf (stderr, "error in radius\n");
    57           continue;
    58         }
     63        if (isnan(model->radius)) psAbort ("fit_galaxies", "error in radius");
     64
    5965        if (model->radius > OUTER) {
    6066          // allocate image, noise, mask arrays for each peak (square of radius OUTER)
     
    6470        // fit as FLT, not PSF (skip poor fits)
    6571        psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80);
    66         status = pmSourceFitModel (source, model, false);
     72        status = pmSourceFitModel_EAM (source, model, false);
    6773        psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f);
    68         if (!status || (model->params->data.F32[1] < 0)) {
     74        if (!status) {
    6975          // if the fit fails, we need to change the classification
    7076          psLogMsg ("psphot", 3, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);
    71           source->type = PS_SOURCE_OTHER;  // better choice?
     77          source->type = PS_SOURCE_FAIL_FIT_GAL;  // better choice?
     78          source->modelFLT = model;
    7279          Nfail ++;
    7380          continue;
    7481        }
    7582
     83        goodfit = pmModelFitStatus (model);
     84        if (!goodfit) {
     85          // if the fit fails, we need to change the classification
     86          psLogMsg ("psphot", 3, "GAL fit poor for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);
     87          source->type = PS_SOURCE_POOR_FIT_GAL;  // better choice?
     88          source->modelFLT = model;
     89          Nfail ++;
     90          continue;
     91        }
     92
     93        source->type = PS_SOURCE_GALAXY;
    7694        source->modelFLT = model;
    7795        Niter += model[0].nIter;
Note: See TracChangeset for help on using the changeset viewer.