IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38515


Ignore:
Timestamp:
Jun 22, 2015, 3:23:53 PM (11 years ago)
Author:
bills
Message:

Handle pcm extended source models correctly in psphotSourceChildrenByReadout and psphotResetModels.
Avoid extra model convolutions.

Location:
trunk/psphot/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphot.h

    r38388 r38515  
    513513bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc);
    514514bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index);
    515 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted);
     515psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleSrc, psArray *objectsSrc, bool sourcesSubtracted);
    516516
    517517bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc);
  • trunk/psphot/src/psphotExtendedSourceFits.c

    r37881 r38515  
    149149    fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON");
    150150    if (!status) fitOptions->poissonErrors = true;
     151
     152    // Save pointer to fitOptions for possible use later reinstantiating the pcm models on the output readout
     153    psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options",
     154        fitOptions);
    151155
    152156    // maskVal is used to test for rejected pixels, and must include markVal
  • trunk/psphot/src/psphotMergeSources.c

    r38389 r38515  
    853853// array containing the child sources.  XXX currently, this is only used by psphotStackReadout
    854854// (sources go on allSources so that psphotChoosePSF can be called repeatedly)
    855 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted) {
     855psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleSrc, psArray *objectsSrc, bool sourcesSubtracted) {
    856856
    857857    bool status;
    858858
    859     int nImages = psphotFileruleCount(config, filerule);
     859    int nImages = psphotFileruleCount(config, fileruleOut);
    860860
    861861    // generate look-up arrays for detections and readouts
    862862    psArray *detArrays = psArrayAlloc(nImages);
    863863    psArray *readouts = psArrayAlloc(nImages);
     864    psArray *fitOptionsArray = psArrayAlloc(nImages);
     865
     866    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     867    assert (recipe);
     868    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     869    assert (maskVal);
     870    int psfSize  = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
     871    assert (status);
    864872
    865873    for (int i = 0; i < nImages; i++) {
    866874
    867875        // find the currently selected readout
    868         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     876        pmFPAfile *file = pmFPAfileSelectSingle(config->files, fileruleOut, i); // File of interest
    869877        psAssert (file, "missing file?");
    870878
    871879        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    872880        psAssert (readout, "missing readout?");
     881
     882        pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, fileruleSrc, i); // File of interest
     883        psAssert (file, "missing file?");
     884
     885        pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa);
     886        psAssert (readoutSrc, "missing readout?");
     887
    873888
    874889        // create DETECTIONS containers for each image, in case one lacks it
     
    886901            psAssert (detections, "missing detections?");
    887902        }
     903        pmSourceFitOptions *fitOptions = psMetadataLookupPtr (&status, readoutSrc->analysis, "PCM_FIT_OPTIONS");
     904        psAssert (fitOptions, "missing pcm fit options");
     905        psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options", fitOptions);
    888906
    889907        // we need to save the new sources on the detection arrays of the appropriate image
    890908        detArrays->data[i] = psMemIncrRefCounter(detections);
    891909        readouts->data[i] = psMemIncrRefCounter(readout);
     910        fitOptionsArray->data[i] = psMemIncrRefCounter(fitOptions);
    892911    }
    893912
     
    932951            // does this copy all model data? (NO)
    933952            sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF);
    934             sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
    935 
     953
     954            bool foundModelEXT = false;
    936955            if (sourceSrc->modelFits) {
    937956                sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n);
    938957                for (int j = 0; j < sourceSrc->modelFits->n; j++) {
    939                     sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]);
    940                 }
     958                    pmModel *modelSrc = sourceSrc->modelFits->data[j];
     959                    pmModel *modelOut = sourceOut->modelFits->data[j] = pmModelCopy(modelSrc);
     960                    if (modelSrc == sourceSrc->modelEXT) {
     961                        foundModelEXT = true;
     962                        sourceOut->modelEXT = psMemIncrRefCounter (modelOut);
     963                    }
     964                    modelOut->isPCM = modelSrc->isPCM;
     965                }
    941966            }
     967            if (!foundModelEXT && sourceSrc->modelEXT) {
     968                // Will this ever happen?
     969                sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
     970            }
    942971
    943972            // drop the references to the original image pixels:
     
    949978            pmReadout *readout = readouts->data[index];
    950979
     980            pmSourceFitOptions *fitOptions = fitOptionsArray->data[index];
     981
    951982            // allocate image, weight, mask for the new image for each peak
    952983            if (sourceOut->modelPSF) {
    953984                pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y,
    954                                                                         sourceOut->modelPSF->fitRadius);
     985                                                                        sourceSrc->windowRadius);
    955986            } else {
    956987                // if we have no pixels we can't use it to determine the psf so make sure this bit is off
     
    965996            if (!sourcesSubtracted) {
    966997                sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    967             }
     998            } else {
     999                if (sourceSrc->modelFlux) {
     1000                    bool isPSF = false;
     1001                    pmModel *model = pmSourceGetModel (&isPSF, sourceOut);
     1002                    if (model->isPCM) {
     1003                        pmPCMdata *pcm = pmPCMinit (sourceOut, fitOptions, model, maskVal, psfSize);
     1004                        if (pcm) {
     1005                            // pmPCMMakeModel (sourceOut, model, pcm->nsigma, maskVal, psfSize);
     1006                            pmPCMCacheModel (sourceOut, maskVal, psfSize, pcm->nsigma);
     1007                            psFree(pcm);
     1008                        } else {
     1009                            // What to do here?
     1010                            psAssert (pcm, "pmPCMinit failed!");
     1011                        }
     1012                    } else {
     1013                        pmSourceCacheModel (sourceOut, maskVal);
     1014                    }
     1015                }
     1016            }
    9681017
    9691018            // set the output detections:
     
    9811030    psFree (detArrays);
    9821031    psFree (readouts);
     1032    psFree (fitOptionsArray);
    9831033
    9841034    return objectsOut;
  • trunk/psphot/src/psphotReplaceUnfit.c

    r35769 r38515  
    316316    }
    317317
     318    pmSourceFitOptions *fitOptions = psMetadataLookupPtr (&status, readout->analysis, "PCM_FIT_OPTIONS");
     319    psAssert (fitOptions, "missing pcm fit options");
    318320
    319321    // XXX the sources have already been copied (merge into here?)
     
    368370            source->modelPSF = modelPSF;
    369371            source->modelPSF->fitRadius = radius;
    370             model = source->modelPSF;
     372            //  model = source->modelPSF;
    371373        }
    372374
    373375        if (model->isPCM) {
     376#if 0
    374377            psAssert(false, "this section is not complete");
    375378
     
    389392
    390393            psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);
    391          
    392394            psFree (psfKernel);
    393395            psFree (rawModelFlux);
    394         }
    395 
    396         pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
     396#endif
     397           pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
     398            if (pcm) {
     399                // pmPCMMakeModel (source, model, pcm->nsigma, maskVal, psfSize);
     400                pmPCMCacheModel (source, maskVal, psfSize, pcm->nsigma);
     401                psFree(pcm);
     402            } else {
     403                psAssert (pcm, "pmPCMinit failed!");
     404            }
     405         
     406        } else {
     407            pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
     408        }
    397409    }
    398410
  • trunk/psphot/src/psphotStackUpdateReadout.c

    r38396 r38515  
    116116    // XXX NOTE : if we use the pre-20130914 psphotStackReadout code, we need to use 'false' for the
    117117    // sourcesSubtracted argument
    118     psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects, true);
     118    // XXX: do this here so that the variance is availble to rebuild the models
     119    psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
     120    psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, STACK_RAW, objects, true);
    119121    if (!objectsOut) {
    120122        psFree(objects);
     
    135137        // this forces photometry on the undetected sources from other images
    136138
    137         // set up the FWHM vector
    138         psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
     139//      Moved this up above
     140//      psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
    139141        psphotDumpImages (config, view, STACK_RAW, "raw.t0");
    140142        psphotDumpImages (config, view, STACK_OUT, "out.t0");
     
    177179                // and to subtract the sources
    178180                psphotFitSourcesLinear (config, view, STACK_OUT, false, false);
     181
     182#ifdef notyet
     183            psphotRemoveAllSources (config, view, STACK_OUT, false);
     184#endif
     185
    179186                snprintf (line, 256, "%s.%d", "out.t4", entry);
    180187                psphotDumpImages (config, view, STACK_OUT, line);
     
    221228        COPY_PARAM( "MSKY_NX" );
    222229        COPY_PARAM( "MSKY_NY" );
    223         COPY_PARAM( "CHIP_SEEING" );
     230        // COPY_PARAM( "CHIP_SEEING" );
    224231}
    225232
     
    312319    fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON");
    313320    if (!status) fitOptions->poissonErrors = true;
     321
    314322    int psfSize  = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
    315323    assert (status);
     324   
     325    // Remember these data for later
     326    psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options", fitOptions);
    316327
    317328    for (int i = 0; i < sources->n; i++) {
     
    331342            // fprintf(stderr, "source %d %5d should not have a psf model 0x%08X%08X\n", index, source->seq, source->mode2, source->mode);
    332343            psFree(source->modelPSF) ;
     344            modelPSF = NULL;
    333345        }
    334346
    335347        // make sure that the window radius is large enough. Should we do this regardless of whether
    336348        // or not the source is extended?
    337         if (source->modelEXT) {
    338             float fitRadius = NAN;
    339             float windowRadius = NAN;
     349        float fitRadius = NAN;
     350        float windowRadius = NAN;
     351        if (1 || source->modelEXT) {
    340352            if (!psphotSetRadiusMoments (&fitRadius, &windowRadius, readout, source, markVal)) {
    341353                psError (PSPHOT_ERR_UNKNOWN, false, "failed to set radius for ext source");
     
    387399                float modelFlux = pow(10., -0.4 * model->mag);
    388400
    389                 // XXX: We are assuming here that we only use PCM models. Should get that information from the recipe.
     401                model->fitRadius = fitRadius;
     402
     403                // XXX: We are assuming here that we only use PCM models.
     404                // I Should be getting that information from the recipe.
    390405                pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
    391406                if (!pcm) {
     
    394409                }
    395410                model->params->data.F32[PM_PAR_I0] = 1.0;
    396                 pmPCMMakeModel (source, model, pcm->nsigma, maskVal, psfSize);
     411                // XXX: this duplicates work that pmPCMCacheModel does
     412                // pmPCMMakeModel (source, model, pcm->nsigma, maskVal, psfSize);
    397413                float normFlux = model->class->modelFlux(model->params);
    398414                float I0 = modelFlux / normFlux;
Note: See TracChangeset for help on using the changeset viewer.