IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17314


Ignore:
Timestamp:
Apr 2, 2008, 8:04:05 PM (18 years ago)
Author:
eugene
Message:

fit each model, validate model selections in recipe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080324/psphot/src/psphotExtendedSourceFits.c

    r17276 r17314  
    66    bool status;
    77    int Next = 0;
     8    int Nconvolve = 0;
     9    int Nplain = 0;
    810
    911    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    4648        psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, modelType);
    4749      }
     50      psMetadataAddS32 (model, PS_LIST_TAIL, "MODEL_TYPE", PS_META_REPLACE, "", modelType);
    4851
    4952      // check on the SNLIM, set a float value
     
    7275    float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
    7376
     77    // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box)
     78    int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
     79    if (!status) {
     80        psfSize = 2;
     81    }
     82
    7483    // source analysis is done in S/N order (brightest first)
    7584    sources = psArraySort (sources, pmSourceSortBySN);
     
    8493        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
    8594        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
    86 
    87         // limit selection to some SN limit
    88         // XXX move this inside model loop
    89         assert (source->peak); // how can a source not have a peak?
    90         if (source->peak->SN < SN_LIM) continue;
    9195
    9296        // XXX this should use peak?
     
    119123          assert (status);
    120124
    121           if (X < SNlim) {
    122             continue;
    123           }
     125          // limit selection to some SN limit
     126          assert (source->peak); // how can a source not have a peak?
     127          if (source->peak->SN < SNlim) continue;
    124128
    125129          // check on the model type
    126           char *modelName = psMetadataLookupStr (&status, model, "MODEL");
     130          pmModelType modelType = psMetadataLookupS32 (&status, model, "MODEL_TYPE");
    127131          assert (status);
    128132
     
    134138          // XXX use the values above, rework this function
    135139          if (convolved) {
    136             pmModel *EXT = psphotPSFConvModel (source, recipe, maskVal);
     140            pmModel *EXT = psphotPSFConvModel (readout, source, modelType, maskVal, psfSize);
     141            Nconvolve ++;
    137142          } else {
    138             pmModel *EXT = psphotFitExt (readout, source, maskVal);
     143            pmModel *EXT = psphotFitExt (readout, source, modelType, maskVal);
     144            Nplain ++;
    139145          }
    140146          if (!EXT) {
     
    143149          }
    144150
    145           // XXX do something with the resulting fit
     151          if (source->modelFits == NULL) {
     152              source->modelFits = psArrayAllocEmpty (5);
     153          }
    146154         
    147          
    148 
     155          // test for fit quality / result
     156          psArrayAdd (source->modelFits, 5, EXT);
    149157        }
    150158
    151159        // evaluate the relative quality of the models, choose one
     160        float minChisq = 0;0;
     161        int minModel = -1;
     162        for (int i = 0; i < source->modelFits->n; i++) {
     163            pmModel *model = source->modelFits->data[i];
     164           
     165            if (!(model->flags & PM_MODEL_STATUS_FITTED)) continue;
     166           
     167            if (model->flags & (PM_MODEL_STATUS_BADARGS)) continue;
     168            if (model->flags & (PM_MODEL_STATUS_NONCONVERGE)) continue;
     169            if (model->flags & (PM_MODEL_STATUS_OFFIMAGE)) continue;
     170
     171            if ((minModel < 0) || (model->chisq < minChisq)) {
     172                minChisq = model->chisq;
     173                minModel = i;
     174            }
     175        }           
     176
     177        if (minModel == -1) {
     178            psAbort ("failed to fit extended source model");
     179        }       
     180
     181        // XXX probably need to free the current value
     182        psFree (source->modelEXT);
     183        source->modelEXT = source->modelFits->data[minModel];
    152184
    153185        // cache only the chosen model
    154186        pmSourceCacheModel (source, maskVal); // XXX put this in the source model function?
    155187        psTrace ("psphot", 5, "psf-convolved model for source at %7.1f, %7.1f", source->moments->x, source->moments->y);
    156         Nconvolve ++;
    157188
    158189        // re-subtract the object, leave local sky
     
    163194    psLogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot"), Next);
    164195    psLogMsg ("psphot", PS_LOG_INFO, "  %d convolved models\n", Nconvolve);
    165     psLogMsg ("psphot", PS_LOG_INFO, "  %d petrosian\n", Npetro);
    166     psLogMsg ("psphot", PS_LOG_INFO, "  %d isophotal\n", Nisophot);
    167     psLogMsg ("psphot", PS_LOG_INFO, "  %d annuli\n", Nannuli);
    168     psLogMsg ("psphot", PS_LOG_INFO, "  %d kron\n", Nkron);
     196    psLogMsg ("psphot", PS_LOG_INFO, "  %d plain models\n", Nplain);
    169197    return true;
    170198}
Note: See TracChangeset for help on using the changeset viewer.