IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 17, 2011, 5:41:38 AM (15 years ago)
Author:
eugene
Message:

psphotStack is generating duplicate detections because the detection removal before the second pass only occurs on the SRC, not DET image; working on fixing this by modifying the removal process

Location:
branches/eam_branches/ipp-20111110/psphot/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111110/psphot/src/psphot.h

    r32633 r32685  
    108108bool            psphotBlendFit_Threaded (psThreadJob *job);
    109109
    110 bool            psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule);
    111 bool            psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
     110bool            psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState);
     111bool            psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool ignoreState);
    112112
    113113bool            psphotAddNoise (pmConfig *config, const pmFPAview *view, const char *filerule);
     
    176176
    177177// in psphotReplaceUnfit.c:
    178 bool            psphotRemoveAllSources (const psArray *sources, const psMetadata *recipe);
     178bool            psphotRemoveAllSourcesByArray (const psArray *sources, const psMetadata *recipe);
     179bool            psphotRemoveAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState);
     180bool            psphotRemoveAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState);
    179181bool            psphotReplaceUnfitSources (psArray *sources, psImageMaskType maskVal);
    180182
  • branches/eam_branches/ipp-20111110/psphot/src/psphotEfficiency.c

    r32348 r32685  
    255255
    256256    // remove all sources, adding noise for subtracted sources
    257     psphotRemoveAllSources(realSources, recipe);
     257    psphotRemoveAllSourcesByArray(realSources, recipe);
    258258
    259259#if TESTING
  • branches/eam_branches/ipp-20111110/psphot/src/psphotFake.c

    r26894 r32685  
    166166
    167167    // remove all sources, adding noise for subtracted sources
    168     psphotRemoveAllSources(realSources, recipe);
     168    psphotRemoveAllSourcesByArray(realSources, recipe);
    169169    psphotAddNoise(readout, realSources, recipe);
    170170
  • branches/eam_branches/ipp-20111110/psphot/src/psphotOutput.c

    r32348 r32685  
    407407    return true;
    408408}
     409
     410// for now, let's store the detections on the readout->analysis for each readout
     411bool psphotDumpTest (pmConfig *config, const pmFPAview *view, const char *filerule)
     412{
     413    static int npass = 0;
     414    char filename[64];
     415
     416    // XXX uncomment to disreturn true;
     417
     418    bool status = true;
     419
     420    int num = psphotFileruleCount(config, filerule);
     421
     422    snprintf (filename, 64, "testdump.%02d.dat", npass);
     423    FILE *f = fopen (filename, "w");
     424
     425    // loop over the available readouts
     426    for (int i = 0; i < num; i++) {
     427
     428        // find the currently selected readout
     429        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     430        psAssert (file, "missing file?");
     431
     432        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     433        psAssert (readout, "missing readout?");
     434
     435        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     436        psAssert (detections, "missing detections?");
     437
     438        psArray *sources = detections->newSources ? detections->newSources : detections->allSources;
     439        psAssert (sources, "missing sources?");
     440
     441        if (detections->newSources) {
     442            fprintf (f, "## --- from new sources ---\n");
     443        } else {
     444            fprintf (f, "## --- from all sources ---\n");
     445        }
     446
     447        for (int i = 0; i < sources->n; i++) {
     448            pmSource *source = sources->data[i];
     449            if (!source) continue;
     450
     451            pmPeak *peak = source->peak;
     452            if (!peak) continue;
     453
     454            // XXX only dump a given region
     455            if (peak->xf < 20) continue;
     456            if (peak->yf < 20) continue;
     457            if (peak->xf > 40) continue;
     458            if (peak->yf > 70) continue;
     459
     460            float Msum = source->moments ? source->moments->Sum : NAN;
     461            float Mx   = source->moments ? source->moments->Mx : NAN;
     462            float My   = source->moments ? source->moments->My : NAN;
     463            float Npix = source->moments ? source->moments->nPixels : NAN;
     464            fprintf (f, "%f %f  : %f %f : %f %f\n", peak->xf, peak->yf, Mx, My, Msum, Npix);
     465        }
     466    }
     467    fclose (f);
     468    npass ++;
     469
     470    return true;
     471}
     472
     473# if (0)
    409474bool psphotDumpTest (pmConfig *config, const pmFPAview *view, const char *filerule, char *filename) {
    410475
     
    449514    return true;
    450515}
    451 
     516# endif
  • branches/eam_branches/ipp-20111110/psphot/src/psphotRadialApertures.c

    r32633 r32685  
    156156
    157157            // set this to 0 to run without threading
    158 # if (1)           
     158# if (0)           
    159159            if (!psThreadJobAddPending(job)) {
    160160                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
  • branches/eam_branches/ipp-20111110/psphot/src/psphotReadout.c

    r32633 r32685  
    11# include "psphotInternal.h"
     2bool psphotDumpTest (pmConfig *config, const pmFPAview *view, const char *filerule);
    23
    34// this should be called by every program that links against libpsphot
     
    910}
    1011
    11 // for now, let's store the detections on the readout->analysis for each readout
    12 bool psphotDumpChisqs (pmConfig *config, const pmFPAview *view, const char *filerule)
    13 {
    14     static int npass = 0;
    15     char filename[64];
    16 
    17     return true;
    18 
    19     bool status = true;
    20 
    21     int num = psphotFileruleCount(config, filerule);
    22 
    23     snprintf (filename, 64, "chisq.%02d.dat", npass);
    24     FILE *f = fopen (filename, "w");
    25 
    26     // loop over the available readouts
    27     for (int i = 0; i < num; i++) {
    28 
    29         // find the currently selected readout
    30         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
    31         psAssert (file, "missing file?");
    32 
    33         pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    34         psAssert (readout, "missing readout?");
    35 
    36         pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    37         psAssert (detections, "missing detections?");
    38 
    39         psArray *sources = detections->allSources;
    40         psAssert (sources, "missing sources?");
    41 
    42         for (int i = 0; i < sources->n; i++) {
    43             pmSource *source = sources->data[i];
    44             if (!source) continue;
    45 
    46             pmModel *model = pmSourceGetModel (NULL, source);
    47             if (!model) continue;
    48        
    49             if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {
    50                 fprintf (f, "%f %f %f %d %d %f  1 NONLINEAR\n", model->mag, model->params->data.F32[1], model->chisq, model->nDOF, model->nPix, model->chisqNorm);
    51             } else {
    52                 fprintf (f, "%f %f %f %d %d %f  0 LINEAR\n", model->mag, model->params->data.F32[1], model->chisq, model->nDOF, model->nPix, model->chisqNorm);
    53             }
    54         }
    55     }
    56     fclose (f);
    57     npass ++;
    58 
    59     return true;
    60 }
    61 
    6212bool psphotReadout(pmConfig *config, const pmFPAview *view, const char *filerule) {
    6313
     
    13383        return psphotReadoutCleanup (config, view, filerule);
    13484    }
     85    psphotDumpTest (config, view, filerule);
    13586
    13687    // find blended neighbors of very saturated stars (detections->newSources)
     
    188139    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    189140    psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources)
    190     psphotDumpChisqs (config, view, filerule);
     141    psphotDumpTest (config, view, filerule);
    191142
    192143    // measure the radial profiles to the sky
     
    208159    // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
    209160    psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources)
    210     psphotDumpChisqs (config, view, filerule);
    211161
    212162    // replace all sources
    213     psphotReplaceAllSources (config, view, filerule); // pass 1 (detections->allSources)
     163    psphotReplaceAllSources (config, view, filerule, false); // pass 1 (detections->allSources)
    214164
    215165    // linear fit to include all sources (subtract again)
    216166    // NOTE : apply to ALL sources (extended + psf)
    217167    psphotFitSourcesLinear (config, view, filerule, true); // pass 2 (detections->allSources)
    218     psphotDumpChisqs (config, view, filerule);
    219168
    220169    // if we only do one pass, skip to extended source analysis
     
    239188        // NOTE: new sources are saved on detections->newSources
    240189        psphotSourceStats (config, view, filerule, false); // pass 2 (detections->newSources)
     190        psphotDumpTest (config, view, filerule);
    241191
    242192        // set source type
     
    253203        // replace all sources so fit below applies to all at once
    254204        // NOTE: apply only to OLD sources (which have been subtracted)
    255         psphotReplaceAllSources (config, view, filerule); // pass 2
     205        psphotReplaceAllSources (config, view, filerule, false); // pass 2
    256206
    257207        // merge the newly selected sources into the existing list
     
    259209        // XXX check on free of sources...
    260210        psphotMergeSources (config, view, filerule); // (detections->newSources + detections->allSources -> detections->allSources)
     211        psphotDumpTest (config, view, filerule);
    261212
    262213        // NOTE: apply to ALL sources
    263214        psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources)
    264         psphotDumpChisqs (config, view, filerule);
    265215    }
    266216
     
    295245        // replace all sources so fit below applies to all at once
    296246        // NOTE: apply only to OLD sources (which have been subtracted)
    297         psphotReplaceAllSources (config, view, filerule); // pass 2
     247        psphotReplaceAllSources (config, view, filerule, false); // pass 2
    298248
    299249        // merge the newly selected sources into the existing list
  • branches/eam_branches/ipp-20111110/psphot/src/psphotReplaceUnfit.c

    r31452 r32685  
    11# include "psphotInternal.h"
     2
     3static int replace_pass = 0;
     4static int remove_pass = 0;
    25
    36// replace the flux for sources which failed
     
    912
    1013    for (int i = 0; i < sources->n; i++) {
    11       source = sources->data[i];
    12 
    13       // replace other sources?
    14       if (source->mode & PM_SOURCE_MODE_FAIL) goto replace;
    15       continue;
     14        source = sources->data[i];
     15
     16        // replace other sources?
     17        if (source->mode & PM_SOURCE_MODE_FAIL) goto replace;
     18        continue;
    1619
    1720    replace:
     
    2326
    2427// for now, let's store the detections on the readout->analysis for each readout
    25 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule)
     28bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState)
    2629{
    2730    bool status = true;
     
    3538    // loop over the available readouts
    3639    for (int i = 0; i < num; i++) {
    37         if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe)) {
     40        if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) {
    3841            psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
    3942            return false;
    4043        }
    4144    }
    42     return true;
    43 }
    44 
    45 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) {
     45    replace_pass ++;
     46    return true;
     47}
     48
     49bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) {
    4650
    4751    bool status;
    48     pmSource *source;
    4952
    5053    psTimerStart ("psphot.replace");
     
    5760    psAssert (readout, "missing readout?");
    5861
     62    char name[128];
     63    snprintf (name, 128, "testadd.neg.%02d.%02d.fits", replace_pass, index);
     64    psphotSaveImage (NULL, readout->image, name);
     65
    5966    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    6067    psAssert (detections, "missing detections?");
     
    7582
    7683    for (int i = 0; i < sources->n; i++) {
    77       source = sources->data[i];
    78 
    79       // replace other sources?
    80       if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
    81 
    82       pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    83     }
     84        pmSource *source = sources->data[i];
     85
     86        if (ignoreState) {
     87            // rely on the type of source to decide if we subtract it or not
     88
     89            // skip non-astronomical objects (very likely defects)
     90            if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
     91            if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     92     
     93            // do not include CRs in the full ensemble fit
     94            if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
     95       
     96            // do not include MOMENTS_FAILURES in the fit
     97            if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     98        } else {
     99            // if we respect the state, only remove unsubtracted sources
     100            if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
     101        }
     102
     103        pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     104    }
     105
     106    snprintf (name, 128, "testadd.pos.%02d.%02d.fits", replace_pass, index);
     107    psphotSaveImage (NULL, readout->image, name);
    84108
    85109    psphotVisualShowImage(readout);
     
    88112}
    89113
    90 bool psphotRemoveAllSources (const psArray *sources, const psMetadata *recipe) {
     114// for now, let's store the detections on the readout->analysis for each readout
     115bool psphotRemoveAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState)
     116{
     117    bool status = true;
     118
     119    // select the appropriate recipe information
     120    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     121    psAssert (recipe, "missing recipe?");
     122
     123    int num = psphotFileruleCount(config, filerule);
     124
     125    // loop over the available readouts
     126    for (int i = 0; i < num; i++) {
     127        if (!psphotRemoveAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) {
     128            psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
     129            return false;
     130        }
     131    }
     132    remove_pass ++;
     133    return true;
     134}
     135
     136bool psphotRemoveAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) {
     137
     138    bool status;
     139
     140    psTimerStart ("psphot.replace");
     141
     142    // find the currently selected readout
     143    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     144    psAssert (file, "missing file?");
     145
     146    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     147    psAssert (readout, "missing readout?");
     148
     149    char name[128];
     150    snprintf (name, 128, "testsub.pos.%02d.%02d.fits", remove_pass, index);
     151    psphotSaveImage (NULL, readout->image, name);
     152
     153    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     154    psAssert (detections, "missing detections?");
     155
     156    psArray *sources = detections->allSources;
     157    psAssert (sources, "missing sources?");
     158
     159    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     160    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     161    psAssert (maskVal, "missing mask value?");
     162
     163    // bit-mask to mark pixels not used in analysis
     164    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     165    assert (markVal);
     166
     167    // maskVal is used to test for rejected pixels, and must include markVal
     168    maskVal |= markVal;
     169
     170    for (int i = 0; i < sources->n; i++) {
     171        pmSource *source = sources->data[i];
     172
     173        // skip non-astronomical objects (very likely defects)
     174        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
     175        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     176       
     177        // do not include CRs in the full ensemble fit
     178        if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
     179       
     180        // do not include MOMENTS_FAILURES in the fit
     181        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     182       
     183        // if we respect the state, only remove unsubtracted sources
     184        if (!ignoreState && (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
     185       
     186        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     187    }
     188
     189    snprintf (name, 128, "testsub.neg.%02d.%02d.fits", remove_pass, index);
     190    psphotSaveImage (NULL, readout->image, name);
     191
     192    psphotVisualShowImage(readout);
     193    psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     194    return true;
     195}
     196
     197bool psphotRemoveAllSourcesByArray (const psArray *sources, const psMetadata *recipe) {
    91198
    92199    bool status;
     
    100207
    101208    for (int i = 0; i < sources->n; i++) {
    102       source = sources->data[i];
    103 
    104       // replace other sources?
    105       if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;
    106 
    107       pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     209        source = sources->data[i];
     210
     211        // replace other sources?
     212        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;
     213
     214        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    108215    }
    109216    psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     
    158265
    159266    for (int i = 0; i < sources->n; i++) {
    160       source = sources->data[i];
    161 
    162       // sources have not yet been subtracted in this image (but this flag may be raised)
    163       source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    164       if (!source->modelPSF) continue;
    165 
    166       float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
    167       float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
    168       float radius = source->modelPSF->fitRadius;
    169 
    170       // force a redefine to this image
    171       pmSourceFreePixels(source);
    172       pmSourceRedefinePixels (source, readout, Xo, Yo, radius);
     267        source = sources->data[i];
     268
     269        // sources have not yet been subtracted in this image (but this flag may be raised)
     270        source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     271        if (!source->modelPSF) continue;
     272
     273        float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     274        float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     275        float radius = source->modelPSF->fitRadius;
     276
     277        // force a redefine to this image
     278        pmSourceFreePixels(source);
     279        pmSourceRedefinePixels (source, readout, Xo, Yo, radius);
    173280    }
    174281    return true;
     
    229336
    230337    for (int i = 0; i < sources->n; i++) {
    231       source = sources->data[i];
    232 
    233       // *** we need to cache the 'best' model, and we have 3 cases:
    234       // 1) model is the psf model --> generate from the new psf
    235       // 2) model is an unconvolved extended model --> just cache the copy (not perfect)
    236       // 3) model is a convolved extended model --> re-generate
    237 
    238       // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits
    239       bool isPSF = false;
    240       pmModel *model = pmSourceGetModel(&isPSF, source);
    241       if (!model) continue;
    242 
    243       float radius = model->fitRadius; // save for future use below
    244 
    245       // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM
    246       if (isPSF || model->isPCM) {
    247           // the guess central intensity comes from the peak:
    248           float Io = source->peak->rawFlux;
    249           float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
    250           float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
    251 
    252           // generate a model for this object with Io = 1.0
    253           pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io);
    254           if (modelPSF == NULL) {
    255               psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo);
    256               continue;
    257           }
    258 
    259           // set the source PSF model
    260           psFree (source->modelPSF);
    261           source->modelPSF = modelPSF;
    262           source->modelPSF->fitRadius = radius;
    263       }
    264 
    265       if (model->isPCM) {
    266           psAssert(false, "this section is not complete");
    267 
    268           pmSourceCachePSF (source, maskVal);
    269 
    270           psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize);
    271           if (!psfKernel) {
    272               psWarning ("no psf kernel");
    273           }
    274 
    275           // generate an image of the right size
    276           psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32);
    277           psImageInit (rawModelFlux, 0.0);
     338        source = sources->data[i];
     339
     340        // *** we need to cache the 'best' model, and we have 3 cases:
     341        // 1) model is the psf model --> generate from the new psf
     342        // 2) model is an unconvolved extended model --> just cache the copy (not perfect)
     343        // 3) model is a convolved extended model --> re-generate
     344
     345        // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits
     346        bool isPSF = false;
     347        pmModel *model = pmSourceGetModel(&isPSF, source);
     348        if (!model) continue;
     349
     350        float radius = model->fitRadius; // save for future use below
     351
     352        // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM
     353        if (isPSF || model->isPCM) {
     354            // the guess central intensity comes from the peak:
     355            float Io = source->peak->rawFlux;
     356            float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     357            float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     358
     359            // generate a model for this object with Io = 1.0
     360            pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io);
     361            if (modelPSF == NULL) {
     362                psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo);
     363                continue;
     364            }
     365
     366            // set the source PSF model
     367            psFree (source->modelPSF);
     368            source->modelPSF = modelPSF;
     369            source->modelPSF->fitRadius = radius;
     370        }
     371
     372        if (model->isPCM) {
     373            psAssert(false, "this section is not complete");
     374
     375            pmSourceCachePSF (source, maskVal);
     376
     377            psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize);
     378            if (!psfKernel) {
     379                psWarning ("no psf kernel");
     380            }
     381
     382            // generate an image of the right size
     383            psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32);
     384            psImageInit (rawModelFlux, 0.0);
    278385         
    279           // insert the model image normalized to 1.0
    280           pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
    281 
    282           psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);
     386            // insert the model image normalized to 1.0
     387            pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
     388
     389            psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);
    283390         
    284           psFree (psfKernel);
    285           psFree (rawModelFlux);
    286       }
    287 
    288       pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
     391            psFree (psfKernel);
     392            psFree (rawModelFlux);
     393        }
     394
     395        pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
    289396    }
    290397
  • branches/eam_branches/ipp-20111110/psphot/src/psphotStackReadout.c

    r32633 r32685  
    11# include "psphotInternal.h"
     2bool psphotDumpTest (pmConfig *config, const pmFPAview *view, const char *filerule);
    23
    34// we have 3 possible real filesets:
     
    130131        return psphotReadoutCleanup (config, view, STACK_SRC);
    131132    }
     133    psphotDumpTest (config, view, STACK_SRC);
    132134    psMemDump("sourcestats");
    133135
     
    170172    psphotFitSourcesLinear (config, view, STACK_SRC, false);
    171173    psphotStackVisualFilerule(config, view, STACK_SRC);
     174    psphotDumpTest (config, view, STACK_SRC);
    172175
    173176    // measure the radial profiles to the sky
     
    186189    psphotBlendFit (config, view, STACK_SRC); // pass 1 (detections->allSources)
    187190
    188     // replace all sources
    189     psphotReplaceAllSources (config, view, STACK_SRC); // pass 1 (detections->allSources)
     191    // replace all sources (do NOT ignore subtraction state)
     192    psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources)
    190193
    191194    // if we only do one pass, skip to extended source analysis
     
    194197    // linear fit to include all sources (subtract again)
    195198    // NOTE : apply to ALL sources (extended + psf)
     199    // NOTE 2 : this function subtracts the models from the given filerule (SRC)
    196200    psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 2 (detections->allSources)
    197201
     
    200204    // NOTE: this block performs the 2nd pass low-significance PSF detection stage
    201205    {
     206        //  subtract all sources from DET (this will subtract using the psf model for SRC, which
     207        //  will somewhat oversubtract the sources -- this is OK
     208        psphotRemoveAllSources (config, view, STACK_DET, true); // ignore subtraction state for sources
     209
    202210        // add noise for subtracted objects
    203211        psphotAddNoise (config, view, STACK_DET); // pass 1 (detections->allSources)
     
    212220
    213221        // if DET and SRC are different images, copy the detections from DET to SRC
     222        // (this operation just ensures the metadata container has a view on SRC as well
    214223        if (strcmp(STACK_SRC, STACK_DET)) {
    215             // XXX how does this handle 1st vs 2nd pass sources?
    216224            if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) {
    217225                psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
     
    220228        }
    221229
     230        // replace all sources in DET
     231        psphotReplaceAllSources (config, view, STACK_DET, true); // ignore subtraction state for sources
     232
    222233        // define new sources based on only the new peaks & measure moments
    223234        // NOTE: new sources are saved on detections->newSources
    224235        psphotSourceStats (config, view, STACK_SRC, false); // pass 2 (detections->newSources)
     236        psphotDumpTest (config, view, STACK_SRC);
    225237
    226238        // set source type
     
    237249        // replace all sources so fit below applies to all at once
    238250        // NOTE: apply only to OLD sources (which have been subtracted)
    239         psphotReplaceAllSources (config, view, STACK_SRC); // pass 2
     251        psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 2
    240252
    241253        // merge the newly selected sources into the existing list
     
    243255        // XXX check on free of sources...
    244256        psphotMergeSources (config, view, STACK_SRC); // (detections->newSources + detections->allSources -> detections->allSources)
     257        psphotDumpTest (config, view, STACK_SRC);
    245258    }
    246259
     
    256269
    257270    psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects);
     271    psphotDumpTest (config, view, STACK_SRC);
    258272
    259273    // NOTE: apply to ALL sources
     
    295309    int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT);
    296310
     311    psphotDumpTest (config, view, STACK_SRC);
     312
    297313    for (int entry = 1; entry < nRadialEntries; entry++) {
    298314        // NOTE: entry 0 is the unmatched image set
     
    312328
    313329        // replace the flux in the image so it is returned to its original state
    314         psphotReplaceAllSources (config, view, STACK_OUT);
     330        psphotReplaceAllSources (config, view, STACK_OUT, false);
    315331
    316332        // smooth to the next FWHM, or set 'smoothAgain' to false if no more
Note: See TracChangeset for help on using the changeset viewer.