IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17349


Ignore:
Timestamp:
Apr 6, 2008, 2:41:48 PM (18 years ago)
Author:
eugene
Message:

remove test outputs, fix leaks, fix subtraction

File:
1 edited

Legend:

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

    r17340 r17349  
    88    int Nconvolve = 0;
    99    int Nplain = 0;
    10     bool savePics = true;
     10    bool savePics = false;
    1111
    1212    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    1414    assert (maskVal);
    1515
    16     // perform full non-linear fits / extended source analysis?
     16    // perform full extended source non-linear fits?
    1717    if (!psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS")) {
    1818        psLogMsg ("psphot", PS_LOG_INFO, "skipping extended source measurements\n");
     
    107107        Next ++;
    108108
     109        // save the modelFlux here in case we need to subtract it (for failure)
     110        psImage *modelFluxStart = psMemIncrRefCounter (source->modelFlux);
     111
    109112        if (savePics) {
    110113          psphotSaveImage (NULL, readout->image, "image.xp.fits");
     114        }
     115
     116        // array to store the pointers to the model flux images while the models are being fitted
     117        psArray *modelFluxes = psArrayAllocEmpty (4);
     118   
     119        // allocate the array to store the model fits
     120        if (source->modelFits == NULL) {
     121            source->modelFits = psArrayAllocEmpty (4);
    111122        }
    112123
     
    136147          assert (status);
    137148
    138           psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6);
     149          // XXX psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6);
     150          // XXX psTraceSetLevel ("psphot.psphotModelWithPSF_LMM", 6);
    139151
    140152          // fit the model as convolved or not
     
    145157            Nconvolve ++;
    146158          } else {
     159              psFree (source->modelFlux);
     160              source->modelFlux = NULL;
    147161            modelFit = psphotFitEXT (readout, source, modelType, maskVal);
     162            pmSourceCacheModel (source, maskVal);
    148163            psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (modelFit->type), modelFit->chisq);
    149164            Nplain ++;
     
    154169          }
    155170
    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           }
    174 
    175           if (source->modelFits == NULL) {
    176               source->modelFits = psArrayAllocEmpty (5);
    177           }
    178          
     171          // save each of the model flux images and store the best
     172          psArrayAdd (modelFluxes, 4, source->modelFlux);
     173
    179174          // test for fit quality / result
    180           psArrayAdd (source->modelFits, 5, modelFit);
     175          psArrayAdd (source->modelFits, 4, modelFit);
     176
    181177          psFree (modelFit);
    182178        }
     
    204200          // re-subtract the object, leave local sky
    205201          psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->x, source->moments->y);
     202
     203          // replace original model, subtract it
     204          psFree (source->modelFlux);
     205          source->modelFlux = modelFluxStart;
     206
    206207          pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    207208          source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     209
     210          psFree (modelFluxes);
    208211
    209212          if (savePics) {
     
    216219            }
    217220          }
    218 
    219221          continue;
    220222        }       
    221223
    222         // XXX probably need to free the current value
     224        // save the best extended model in modelEXT
    223225        psFree (source->modelEXT);
    224226        source->modelEXT = psMemIncrRefCounter (source->modelFits->data[minModel]);
    225227
    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);
    227 
    228         // cache only the chosen model
    229         pmSourceCacheModel (source, maskVal); // XXX put this in the source model function?
    230         psTrace ("psphot", 5, "psf-convolved model for source at %7.1f, %7.1f", source->moments->x, source->moments->y);
    231 
    232         // re-subtract the object, leave local sky
     228        // save the modelFlux for the best model
     229        psFree (source->modelFlux);
     230        source->modelFlux = psMemIncrRefCounter (modelFluxes->data[minModel]);
     231
     232        // subtract the best fit from the object, leave local sky
    233233        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    234234        source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     235
     236        // the initial model flux is no longer needed
     237        psFree (modelFluxStart);
     238        psFree (modelFluxes);
     239
     240        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);
     241        psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->x, source->moments->y);
    235242
    236243        if (savePics) {
Note: See TracChangeset for help on using the changeset viewer.