IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 17, 2011, 1:09:10 PM (15 years ago)
Author:
eugene
Message:

correctly handle the second pass in the detection image: the code was creating duplicate detections in 2 ways: 1) the source subtraction before the second pass was only being applied to the SRC, not the DET image, thus all 1st pass detections were also found as 2nd pass detections; 2) the DBL star fitting function was causing trouble, with the two positions merging to a single object -- this was considered a success, but left behind flux in the subtracted image (and garbage detections in general); Ive turned off the DBL fitting for now as I am not convinced that code is ready

File:
1 edited

Legend:

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

    r32685 r32689  
    11# include "psphotInternal.h"
    2 
    3 static int replace_pass = 0;
    4 static int remove_pass = 0;
    52
    63// replace the flux for sources which failed
     
    4340        }
    4441    }
    45     replace_pass ++;
    4642    return true;
    4743}
     
    6056    psAssert (readout, "missing readout?");
    6157
    62     char name[128];
    63     snprintf (name, 128, "testadd.neg.%02d.%02d.fits", replace_pass, index);
    64     psphotSaveImage (NULL, readout->image, name);
     58    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     59    psAssert (detections, "missing detections?");
     60
     61    psArray *sources = detections->allSources;
     62    psAssert (sources, "missing sources?");
     63
     64    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     65    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     66    psAssert (maskVal, "missing mask value?");
     67
     68    // bit-mask to mark pixels not used in analysis
     69    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     70    assert (markVal);
     71
     72    // maskVal is used to test for rejected pixels, and must include markVal
     73    maskVal |= markVal;
     74
     75    for (int i = 0; i < sources->n; i++) {
     76        pmSource *source = sources->data[i];
     77
     78        if (ignoreState) {
     79            // rely on the type of source to decide if we subtract it or not
     80
     81            // skip non-astronomical objects (very likely defects)
     82            if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
     83            if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     84     
     85            // do not include CRs in the full ensemble fit
     86            if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
     87       
     88            // do not include MOMENTS_FAILURES in the fit
     89            if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     90        } else {
     91            // if we respect the state, do not replace unsubtracted sources
     92            if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
     93        }
     94
     95        pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     96    }
     97
     98    psphotVisualShowImage(readout);
     99    psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     100    return true;
     101}
     102
     103// for now, let's store the detections on the readout->analysis for each readout
     104bool psphotRemoveAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState)
     105{
     106    bool status = true;
     107
     108    // select the appropriate recipe information
     109    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     110    psAssert (recipe, "missing recipe?");
     111
     112    int num = psphotFileruleCount(config, filerule);
     113
     114    // loop over the available readouts
     115    for (int i = 0; i < num; i++) {
     116        if (!psphotRemoveAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) {
     117            psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
     118            return false;
     119        }
     120    }
     121    return true;
     122}
     123
     124bool psphotRemoveAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) {
     125
     126    bool status;
     127
     128    psTimerStart ("psphot.replace");
     129
     130    // find the currently selected readout
     131    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     132    psAssert (file, "missing file?");
     133
     134    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     135    psAssert (readout, "missing readout?");
    65136
    66137    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     
    98169        } else {
    99170            // 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);
    108 
    109     psphotVisualShowImage(readout);
    110     psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
    111     return true;
    112 }
    113 
    114 // for now, let's store the detections on the readout->analysis for each readout
    115 bool 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 
    136 bool 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        
     171            if ((source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
     172        }
     173
    186174        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    187175    }
    188 
    189     snprintf (name, 128, "testsub.neg.%02d.%02d.fits", remove_pass, index);
    190     psphotSaveImage (NULL, readout->image, name);
    191176
    192177    psphotVisualShowImage(readout);
Note: See TracChangeset for help on using the changeset viewer.