IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 3, 2011, 10:30:02 AM (15 years ago)
Author:
eugene
Message:

add new window function using first radial moment; use new sersic guess function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110710/psphot/src/psphotExtendedSourceFits.c

    r31867 r31990  
    4545    int Nfail = 0;
    4646
     47    psphotSersicModelClassInit();
     48
    4749    psTimerStart ("psphot.extended");
    4850
     
    103105
    104106      if (item->type != PS_DATA_METADATA) {
     107        // XXX we could cull the bad entries or build a validated model folder
    105108        psAbort ("Invalid type for EXTENDED_SOURCE_MODEL entry %s, not a metadata folder", item->name);
    106         // XXX we could cull the bad entries or build a validated model folder
    107109      }
    108110
     
    247249    psFree(AnalysisRegion);
    248250
     251    psphotSersicModelClassCleanup();
     252
    249253    psLogMsg ("psphot", PS_LOG_INFO, "extended source model fits: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next);
    250254    psLogMsg ("psphot", PS_LOG_INFO, "  %d convolved models (%d passed)\n", Nconvolve, NconvolvePass);
     
    265269    int Nplain = 0;
    266270    int NplainPass = 0;
    267     bool savePics = false;
    268     float radius;
     271    float fitRadius, windowRadius;
    269272    psScalar *scalar = NULL;
    270273    pmMoments psfMoments;
     
    279282    psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
    280283
    281     // pthread_t tid = pthread_self();     // Thread identifier
    282 
    283284    // Define source fitting parameters for extended source fits
    284285    pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
     
    309310        if (source->peak->y > region->y1) continue;
    310311
    311         // if model is NULL, we don't have a starting guess
    312         // XXX use the parameters guessed from moments
    313         // if (source->modelEXT == NULL) continue;
    314 
    315         // fprintf (stderr, "fit %d,%d in thread %d\n", source->peak->x, source->peak->y, (int) tid);
    316 
    317312        // replace object in image
    318313        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
     
    321316        Next ++;
    322317
    323         // set the radius based on the footprint (also sets the mask pixels)
    324         if (!psphotSetRadiusFootprint(&radius, readout, source, markVal, 1.0)) {
     318        // set the radius based on the first radial moment (also sets the mask pixels)
     319        if (!psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal)) {
    325320            fprintf (stderr, "skipping (1) %f, %f\n", source->peak->xf, source->peak->yf);
    326321            pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    327             // XXX raise an error of some kind
     322            // XXX raise an error of some kind or set a flag bit
    328323            continue;
    329324        }
    330325
    331         // XXX note that this changes the source moments that are published...
    332         // recalculate the source moments using the larger extended-source moments radius
    333         // at this stage, skip Gaussian windowing, and do not clip pixels by S/N
    334         // this uses the footprint to judge both radius and aperture?
    335         // XXX save the psf-based moments for output
     326        // Recalculate the source moments using the larger extended-source moments radius.  At
     327        // this stage, skip Gaussian windowing, and do not clip pixels by S/N.  Save the
     328        // psf-based moments for output
    336329        psfMoments = *source->moments;
    337         if (!pmSourceMoments (source, radius, 0.0, 0.0, 0.0, maskVal)) {
     330        if (!pmSourceMoments (source, windowRadius, 0.0, 0.0, 0.0, maskVal & PS_NOT_IMAGE_MASK(markVal))) {
    338331            // subtract the best fit from the object, leave local sky
    339332            fprintf (stderr, "skipping (2) %f, %f\n", source->peak->xf, source->peak->yf);
     
    344337        }
    345338
    346         // save the modelFlux here in case we need to subtract it (for failure)
     339        // save the PSF-based modelFlux here in case we need to subtract it (for failure).  If
     340        // it does not exist, attempt to generate it.  Give up if we cannot even do that.
    347341        psImage *modelFluxStart = psMemIncrRefCounter (source->modelFlux);
    348342        if (!modelFluxStart) {
     
    358352        }
    359353       
    360         if (savePics) {
    361           psphotSaveImage (NULL, readout->image, "image.xp.fits");
    362         }
    363 
    364354        // array to store the pointers to the model flux images while the models are being fitted
    365355        psArray *modelFluxes = psArrayAllocEmpty (models->list->n);
     
    368358        if (source->modelFits == NULL) {
    369359            source->modelFits = psArrayAllocEmpty (models->list->n);
     360        }
     361        // extFitPars are the non-parametric data measured for this model fit (moments, kron, etc)
     362        if (source->extFitPars == NULL) {
     363            source->extFitPars = psArrayAllocEmpty (models->list->n);
    370364        }
    371365
     
    397391          bool convolved = psMetadataLookupBool (&status, model, "PSF_CONVOLVED_VALUE");
    398392          assert (status);
    399 
    400           // XXX psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6);
    401           // XXX psTraceSetLevel ("psphot.psphotModelWithPSF_LMM", 6);
    402 
    403           // XXX this does not make sense in a threaded context
    404           psTimerStart ("psphot.extended.fit");
    405393
    406394          // fit the model as convolved or not
     
    439427          }
    440428
    441           psLogMsg ("psphot", PS_LOG_INFO, "model fit: %7.5f sec, %5d npix, %2d iter, %s type\n", psTimerMark ("psphot.extended.fit"), modelFit->nPix, modelFit->nIter, pmModelClassGetName (modelFit->type));
    442 
    443           // save each of the model flux images and store the best
     429          // save each of the model flux images for now, and (below) store the best
    444430          psArrayAdd (modelFluxes, 4, source->modelFlux);
    445431
     432          pmSourceExtFitPars *extFitPars = pmSourceExtFitParsAlloc();
     433          extFitPars->Mxx = source->moments->Mxx;
     434          extFitPars->Mxy = source->moments->Mxy;
     435          extFitPars->Myy = source->moments->Myy;
     436          extFitPars->Mrf = source->moments->Mrf;
     437          extFitPars->Mrh = source->moments->Mrh;
     438          extFitPars->peakMag = (source->peak->rawFlux > 0) ? -2.5*log10(source->peak->rawFlux) : NAN;
     439         
     440          // save kron mag, but assign apMag & psfMag on output (not yet calculated)
     441          extFitPars->krMag = -2.5*log10(source->moments->KronFlux);
     442
     443          psArrayAdd (source->extFitPars, 4, extFitPars);
     444          psFree (extFitPars);
     445
    446446          // test for fit quality / result
    447           modelFit->fitRadius = radius;
     447          modelFit->fitRadius = fitRadius;
    448448          psArrayAdd (source->modelFits, 4, modelFit);
    449449
     
    470470        }
    471471
     472        // clear the circular mask
     473        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     474
    472475        if (minModel == -1) {
    473           // re-subtract the object, leave local sky
     476          // no valid extended fit; re-subtract the object, leave local sky
    474477          psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->Mx, source->moments->My);
    475478
     
    483486          psFree (modelFluxes);
    484487
    485           if (savePics) {
    486               psphotSaveImage (NULL, readout->image, "image.xp.fits");
    487               char key[10];
    488               fprintf (stdout, "continue? ");
    489               if (!fgets (key, 8, stdin)) {
    490                   psWarning("Couldn't read anything.");
    491               } else if (key[0] == 'n') {
    492                   savePics = false;
    493               }
    494           }
    495488          continue;
    496489        }
     
    516509        psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->Mx, source->moments->My, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq);
    517510        psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    518 
    519         if (savePics) {
    520           psphotSaveImage (NULL, readout->image, "image.xm.fits");
    521           char key[10];
    522           fprintf (stdout, "continue? ");
    523           if (!fgets (key, 8, stdin)) {
    524               psWarning("Couldn't read anything.");
    525           } else if (key[0] == 'n') {
    526               savePics = false;
    527           }
    528         }
    529511    }
    530512    psFree (fitOptions);
    531 
    532     // fprintf (stderr, "xfit : tried %ld objects\n", sources->n);
    533513
    534514    // change the value of a scalar on the array (wrap this and put it in psArray.h)
Note: See TracChangeset for help on using the changeset viewer.