IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17340


Ignore:
Timestamp:
Apr 6, 2008, 10:14:53 AM (18 years ago)
Author:
eugene
Message:

test output

File:
1 edited

Legend:

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

    r17314 r17340  
    1 # include "psphot.h"
     1# include "psphotInternal.h"
    22
    33// non-linear model fitting for extended sources
     
    88    int Nconvolve = 0;
    99    int Nplain = 0;
     10    bool savePics = true;
    1011
    1112    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    4041      }
    4142
    42       psMetadata *model = (psMetadata *) item->data;
     43      psMetadata *model = (psMetadata *) item->data.md;
    4344
    4445      // check on the model type
    4546      char *modelName = psMetadataLookupStr (&status, model, "MODEL");
    46       int modelType = psModelClassGetType (modelName);
     47      int modelType = pmModelClassGetType (modelName);
    4748      if (modelType < 0) {
    48         psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, modelType);
     49        psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, modelName);
    4950      }
    5051      psMetadataAddS32 (model, PS_LIST_TAIL, "MODEL_TYPE", PS_META_REPLACE, "", modelType);
     
    6162      char *convolvedWord = psMetadataLookupStr (&status, model, "PSF_CONVOLVED");
    6263      if (!status || (strcasecmp (convolvedWord, "true") && strcasecmp (convolvedWord, "false"))) {
    63         psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name, modelType);
     64        psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name);
    6465      }
    6566      bool convolved = !strcasecmp (convolvedWord, "true");
    6667      psMetadataAddBool (model, PS_LIST_TAIL, "PSF_CONVOLVED_VALUE", PS_META_REPLACE, "", convolved);
    6768    }
     69    psFree (iter);
    6870
    6971    // option to limit analysis to a specific region
     
    7274    if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined");
    7375
    74     // S/N limit to perform full non-linear fits
    75     float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
    76 
    7776    // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box)
    7877    int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
    79     if (!status) {
    80         psfSize = 2;
    81     }
     78    assert (status);
    8279
    8380    // source analysis is done in S/N order (brightest first)
     
    110107        Next ++;
    111108
     109        if (savePics) {
     110          psphotSaveImage (NULL, readout->image, "image.xp.fits");
     111        }
     112
    112113        // loop here over the models chosen for each source (exclude by S/N)
    113114        psMetadataIterator *iter = psMetadataIteratorAlloc (models, PS_LIST_HEAD, NULL);
     
    117118          // XXX this should have been forced above
    118119          assert (item->type == PS_DATA_METADATA);
    119           psMetadata *model = (psMetadata *) item->data;
     120          psMetadata *model = (psMetadata *) item->data.md;
    120121
    121122          // check the SNlim and skip model if source is too faint
     
    135136          assert (status);
    136137
     138          psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6);
     139
    137140          // fit the model as convolved or not
    138           // XXX use the values above, rework this function
     141          pmModel *modelFit = NULL;
    139142          if (convolved) {
    140             pmModel *EXT = psphotPSFConvModel (readout, source, modelType, maskVal, psfSize);
     143            modelFit = psphotPSFConvModel (readout, source, modelType, maskVal, psfSize);
     144            psTrace ("psphot", 4, "fit psf-conv model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (modelFit->type), modelFit->chisq);
    141145            Nconvolve ++;
    142146          } else {
    143             pmModel *EXT = psphotFitExt (readout, source, modelType, maskVal);
     147            modelFit = psphotFitEXT (readout, source, modelType, maskVal);
     148            psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (modelFit->type), modelFit->chisq);
    144149            Nplain ++;
    145150          }
    146           if (!EXT) {
    147             psError(PSPHOT_ERR_UNKNOWN, false, "failure to fit extended model");
    148             return false;
     151          if (!modelFit) {
     152            psTrace ("psphot", 5, "failed to generate model guess for object at %f, %f", source->moments->x, source->moments->y);
     153            continue;
    149154          }
     155
     156          if (savePics) {
     157            pmModel *saveModel = source->modelEXT;
     158            source->modelEXT = modelFit;
     159            pmSourceCacheModel (source, maskVal); // XXX put this in the source model function?
     160            pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     161
     162            psphotSaveImage (NULL, readout->image, "image.xf.fits");
     163
     164            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     165            source->modelEXT = saveModel;
     166
     167            char key[10];
     168            fprintf (stdout, "continue? ");
     169            fgets (key, 8, stdin);
     170            if (key[0] == 'n') {
     171              savePics = false;
     172            }
     173          }
    150174
    151175          if (source->modelFits == NULL) {
     
    154178         
    155179          // test for fit quality / result
    156           psArrayAdd (source->modelFits, 5, EXT);
     180          psArrayAdd (source->modelFits, 5, modelFit);
     181          psFree (modelFit);
    157182        }
     183        psFree (iter);
    158184
    159185        // evaluate the relative quality of the models, choose one
    160         float minChisq = 0;0;
     186        float minChisq = NAN;
    161187        int minModel = -1;
    162188        for (int i = 0; i < source->modelFits->n; i++) {
     
    176202
    177203        if (minModel == -1) {
    178             psAbort ("failed to fit extended source model");
     204          // re-subtract the object, leave local sky
     205          psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->x, source->moments->y);
     206          pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     207          source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     208
     209          if (savePics) {
     210            psphotSaveImage (NULL, readout->image, "image.xp.fits");
     211            char key[10];
     212            fprintf (stdout, "continue? ");
     213            fgets (key, 8, stdin);
     214            if (key[0] == 'n') {
     215              savePics = false;
     216            }
     217          }
     218
     219          continue;
    179220        }       
    180221
    181222        // XXX probably need to free the current value
    182223        psFree (source->modelEXT);
    183         source->modelEXT = source->modelFits->data[minModel];
     224        source->modelEXT = psMemIncrRefCounter (source->modelFits->data[minModel]);
     225
     226        psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq);
    184227
    185228        // cache only the chosen model
     
    190233        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    191234        source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     235
     236        if (savePics) {
     237          psphotSaveImage (NULL, readout->image, "image.xm.fits");
     238          char key[10];
     239          fprintf (stdout, "continue? ");
     240          fgets (key, 8, stdin);
     241          if (key[0] == 'n') {
     242            savePics = false;
     243          }
     244        }
    192245    }
    193246
Note: See TracChangeset for help on using the changeset viewer.