IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/psphot

  • branches/simtest_nebulous_branches/psphot/src

    • Property svn:ignore
      •  

        old new  
        1818psphotVersionDefinitions.h
        1919psphotMomentsStudy
         20psphotPetrosianStudy
         21psphotForced
         22psphotMakePSF
         23psphotStack
  • branches/simtest_nebulous_branches/psphot/src/psphotReadout.c

    r24890 r27840  
    33// this should be called by every program that links against libpsphot
    44bool psphotInit (void) {
    5 
    65    psphotErrorRegister();              // register our error codes/messages
    76    psphotModelClassInit ();            // load implementation-specific models
     
    1211bool psphotReadout(pmConfig *config, const pmFPAview *view) {
    1312
    14     // measure the total elapsed time in psphotReadout.  XXX the current threading plan
    15     // for psphot envisions threading within psphotReadout, not multiple threads calling
    16     // the same psphotReadout.  In the current plan, this dtime is the elapsed time used
    17     // jointly by the multiple threads, not the total time used by all threads.
     13    // measure the total elapsed time in psphotReadout.  dtime is the elapsed time used jointly
     14    // by the multiple threads, not the total time used by all threads.
    1815    psTimerStart ("psphotReadout");
     16
     17    pmModelClassSetLimits(PM_MODEL_LIMITS_LAX);
    1918
    2019    // select the current recipe
     
    2423        return false;
    2524    }
     25    // optional break-point for processing
     26    char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
     27    psAssert (breakPt, "configuration error: set BREAK_POINT");
    2628
    2729    // set the photcode for this image
    28     if (!psphotAddPhotcode (recipe, config, view, "PSPHOT.INPUT")) {
     30    if (!psphotAddPhotcode (config, view)) {
    2931        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    3032        return false;
    3133    }
    3234
    33     // find the currently selected readout
    34     pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
    35     PS_ASSERT_PTR_NON_NULL (readout, false);
    36 
    37     // optional break-point for processing
    38     char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
    39     PS_ASSERT_PTR_NON_NULL (breakPt, false);
    40 
    4135    // Generate the mask and weight images, including the user-defined analysis region of interest
    42     psphotSetMaskAndVariance (config, readout, recipe);
     36    if (!psphotSetMaskAndVariance (config, view)) {
     37        return psphotReadoutCleanup(config, view);
     38    }
    4339    if (!strcasecmp (breakPt, "NOTHING")) {
    44         return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL);
    45     }
    46 
    47     // display the image, weight, mask (ch 1,2,3)
    48     psphotVisualShowImage (readout);
     40        return psphotReadoutCleanup(config, view);
     41    }
    4942
    5043    // generate a background model (median, smoothed image)
    51     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
    52         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    53     }
    54     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
    55         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
     44    if (!psphotModelBackground (config, view)) {
     45        return psphotReadoutCleanup (config, view);
     46    }
     47    if (!psphotSubtractBackground (config, view)) {
     48        return psphotReadoutCleanup (config, view);
    5649    }
    5750    if (!strcasecmp (breakPt, "BACKMDL")) {
    58         return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    59     }
    60 
    61     // display the backsub and backgnd images
    62     psphotVisualShowBackground (config, view, readout);
    63    
    64     // run a single-model test if desired (exits from here if test is run)
    65     psphotModelTest (config, view, recipe);
    66 
    67     // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
    68     pmPSF *psf = psphotLoadPSF (config, view, recipe);
    69 
    70     // several functions below behave differently if we have a PSF model already
    71     bool havePSF = (psf != NULL);
     51        return psphotReadoutCleanup (config, view);
     52    }
     53
     54    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are determined and saved on
     55    // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT
     56    if (!psphotLoadPSF (config, view)) {
     57        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
     58        return psphotReadoutCleanup (config, view);
     59    }
    7260
    7361    // find the detections (by peak and/or footprint) in the image.
    74     pmDetections *detections = psphotFindDetections (NULL, readout, recipe);
    75     if (!detections) {
    76         psLogMsg ("psphot", 3, "unable to find detections in this image");
    77         return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
    78     }
    79 
    80     // construct sources and measure basic stats
    81     psArray *sources = psphotSourceStats (config, readout, detections);
    82     if (!sources) return false;
     62    if (!psphotFindDetections (config, view, true)) { // pass 1
     63        // this only happens if we had an error in psphotFindDetections
     64        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
     65        return psphotReadoutCleanup (config, view);
     66    }
     67
     68    // construct sources and measure basic stats (saved on detections->newSources)
     69    if (!psphotSourceStats (config, view, true)) { // pass 1
     70        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
     71        return psphotReadoutCleanup (config, view);
     72    }
    8373    if (!strcasecmp (breakPt, "PEAKS")) {
    84         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    85     }
    86 
    87     // find blended neighbors of very saturated stars
    88     // XXX merge this with Basic Deblend?
    89     psphotDeblendSatstars (readout, sources, recipe);
    90 
    91     // mark blended peaks PS_SOURCE_BLEND
    92     if (!psphotBasicDeblend (sources, recipe)) {
    93         psLogMsg ("psphot", 3, "failed on deblend analysis");
    94         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    95     }
    96 
    97     // classify sources based on moments, brightness
    98     if (!psphotRoughClass (readout, sources, recipe, havePSF)) {
    99         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    100         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     74        return psphotReadoutCleanup(config, view);
     75    }
     76
     77    // find blended neighbors of very saturated stars (detections->newSources)
     78    if (!psphotDeblendSatstars (config, view)) {
     79        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
     80        return psphotReadoutCleanup (config, view);
     81    }
     82
     83    // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
     84    if (!psphotBasicDeblend (config, view)) {
     85        psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
     86        return psphotReadoutCleanup (config, view);
     87    }
     88
     89    // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
     90    // clump defined for it is used not measured (detections->newSources)
     91    if (!psphotRoughClass (config, view)) { // pass 1
     92        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     93        return psphotReadoutCleanup (config, view);
     94    }
     95    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     96    if (!psphotImageQuality (config, view)) { // pass 1
     97        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
     98        return psphotReadoutCleanup(config, view);
    10199    }
    102100    if (!strcasecmp (breakPt, "MOMENTS")) {
    103         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    104     }
    105 
    106     if (!havePSF && !psphotImageQuality (recipe, sources)) {
    107         psLogMsg("psphot", 3, "failed to measure image quality");
    108         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    109     }
    110 
    111     // if we were not supplied a PSF, choose one here
    112     if (psf == NULL) {
    113         // use bright stellar objects to measure PSF
    114         // XXX if we do not have enough stars to generate the PSF, build one
    115         // from the SEEING guess and model class
    116         psf = psphotChoosePSF (readout, sources, recipe);
    117         if (psf == NULL) {
    118             psLogMsg ("psphot", 3, "failure to construct a psf model");
    119             return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    120         }
    121         havePSF = true;
     101        return psphotReadoutCleanup(config, view);
     102    }
     103
     104    // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
     105    // this step is skipped
     106    if (!psphotChoosePSF (config, view)) { // pass 1
     107        psLogMsg ("psphot", 3, "failure to construct a psf model");
     108        return psphotReadoutCleanup (config, view);
    122109    }
    123110    if (!strcasecmp (breakPt, "PSFMODEL")) {
    124         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    125     }
    126 
    127     psphotVisualShowPSFModel (readout, psf);
     111        return psphotReadoutCleanup (config, view);
     112    }
    128113
    129114    // include externally-supplied sources
    130     psphotLoadExtSources (config, view, sources);
    131 
    132     // construct an initial model for each object
    133     psphotGuessModels (config, readout, sources, psf);
    134 
    135     // XXX test output of models
    136     // psphotTestSourceOutput (readout, sources, recipe, psf);
    137 
    138     // linear PSF fit to source peaks
    139     psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE);
    140 
    141     // We have to place these visualizations here because the models are not realized until
    142     // psphotGuessModels or fitted until psphotFitSourcesLinear.
    143     psphotVisualShowPSFStars (recipe, psf, sources);
    144     psphotVisualShowSatStars (recipe, psf, sources);
    145 
    146     // identify CRs and extended sources
    147     psphotSourceSize (config, readout, sources, recipe, 0);
     115    // XXX fix this in the new multi-input context
     116    // psphotLoadExtSources (config, view); // pass 1
     117
     118    // construct an initial model for each object, set the radius to fitRadius, set circular
     119    // fit mask (detections->newSources)
     120    psphotGuessModels (config, view); // pass 1
     121
     122    // merge the newly selected sources into the existing list
     123    // NOTE: merge OLD and NEW
     124    psphotMergeSources (config, view);
     125
     126    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
     127    psphotFitSourcesLinear (config, view, false); // pass 1 (detections->allSources)
     128
     129    // identify CRs and extended sources (only unmeasured sources are measured)
     130    psphotSourceSize (config, view, true); // pass 1 (detections->allSources)
    148131    if (!strcasecmp (breakPt, "ENSEMBLE")) {
    149132        goto finish;
     
    151134
    152135    // non-linear PSF and EXT fit to brighter sources
    153     psphotBlendFit (config, readout, sources, psf);
     136    // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
     137    psphotBlendFit (config, view); // pass 1 (detections->allSources)
    154138
    155139    // replace all sources
    156     psphotReplaceAllSources (sources, recipe);
    157 
    158     // linear fit to include all sources
    159     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     140    psphotReplaceAllSources (config, view); // pass 1 (detections->allSources)
     141
     142    // linear fit to include all sources (subtract again)
     143    // NOTE : apply to ALL sources (extended + psf)
     144    psphotFitSourcesLinear (config, view, true); // pass 2 (detections->allSources)
    160145
    161146    // if we only do one pass, skip to extended source analysis
    162     if (!strcasecmp (breakPt, "PASS1")) {
    163         goto pass1finish;
    164     }
    165 
    166     // XXX for the moment, drop the re-calc of the background (prove this works)
    167     // replace background in residual image
    168     // psphotSkyReplace (config, view);
    169     // re-measure background model (median, smoothed image)
    170     // psphotImageMedian (config, view);
     147    if (!strcasecmp (breakPt, "PASS1")) goto pass1finish;
     148
     149    // NOTE: possibly re-measure background model here with objects subtracted / or masked
    171150
    172151    // add noise for subtracted objects
    173     psphotAddNoise (readout, sources, recipe);
    174 
    175     // find fainter sources (pass 2)
    176     detections = psphotFindDetections (detections, readout, recipe);
     152    psphotAddNoise (config, view); // pass 1 (detections->allSources)
     153
     154    // find fainter sources
     155    // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections
     156    psphotFindDetections (config, view, false); // pass 2 (detections->peaks, detections->footprints)
    177157
    178158    // remove noise for subtracted objects (ie, return to normal noise level)
    179     psphotSubNoise (readout, sources, recipe);
     159    // NOTE: this needs to operate only on the OLD sources
     160    psphotSubNoise (config, view); // pass 1 (detections->allSources)
    180161
    181162    // define new sources based on only the new peaks
    182     psArray *newSources = psphotSourceStats (config, readout, detections);
     163    // NOTE: new sources are saved on detections->newSources
     164    psphotSourceStats (config, view, false); // pass 2 (detections->newSources)
    183165
    184166    // set source type
    185     if (!psphotRoughClass (readout, newSources, recipe, havePSF)) {
     167    // NOTE: apply only to detections->newSources
     168    if (!psphotRoughClass (config, view)) { // pass 2 (detections->newSources)
    186169        psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    187         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    188     }
    189 
    190     // create full input models
    191     psphotGuessModels (config, readout, newSources, psf);
     170        return psphotReadoutCleanup (config, view);
     171    }
     172
     173    // create full input models, set the radius to fitRadius, set circular fit mask
     174    // NOTE: apply only to detections->newSources
     175    psphotGuessModels (config, view); // pass 2 (detections->newSources)
    192176
    193177    // replace all sources so fit below applies to all at once
    194     psphotReplaceAllSources (sources, recipe);
     178    // NOTE: apply only to OLD sources (which have been subtracted)
     179    psphotReplaceAllSources (config, view); // pass 2
    195180
    196181    // merge the newly selected sources into the existing list
    197     psphotMergeSources (sources, newSources);
    198     psFree (newSources);
    199 
    200     // linear fit to all sources
    201     psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
     182    // NOTE: merge OLD and NEW
     183    // XXX check on free of sources...
     184    psphotMergeSources (config, view); // (detections->newSources + detections->allSources -> detections->allSources)
     185
     186    // NOTE: apply to ALL sources
     187    psphotFitSourcesLinear (config, view, true); // pass 3 (detections->allSources)
    202188
    203189pass1finish:
    204190
    205191    // measure source size for the remaining sources
    206     psphotSourceSize (config, readout, sources, recipe, 0);
    207 
    208     psphotExtendedSourceAnalysis (readout, sources, recipe);
    209 
    210     psphotExtendedSourceFits (readout, sources, recipe);
     192    // NOTE: applies only to NEW (unmeasured) sources
     193    psphotSourceSize (config, view, false); // pass 2 (detections->allSources)
     194
     195    psphotExtendedSourceAnalysis (config, view); // pass 1 (detections->allSources)
     196    psphotExtendedSourceFits (config, view); // pass 1 (detections->allSources)
    211197
    212198finish:
     
    216202
    217203    // measure aperture photometry corrections
    218     if (!psphotApResid (config, readout, sources, psf)) {
     204    if (!psphotApResid (config, view)) { // pass 1 (detections->allSources)
    219205        psLogMsg ("psphot", 3, "failed on psphotApResid");
    220         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     206        return psphotReadoutCleanup (config, view);
    221207    }
    222208
    223209    // calculate source magnitudes
    224     psphotMagnitudes(config, readout, view, sources, psf);
     210    psphotMagnitudes(config, view); // pass 1 (detections->allSources)
     211
     212    if (!psphotEfficiency(config, view)) { // pass 1
     213        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
     214        psErrorClear();
     215    }
    225216
    226217    // replace failed sources?
     
    228219
    229220    // replace background in residual image
    230     psphotSkyReplace (config, view);
     221    psphotSkyReplace (config, view); // pass 1
    231222
    232223    // drop the references to the image pixels held by each source
    233     psphotSourceFreePixels (sources);
     224    psphotSourceFreePixels (config, view); // pass 1
    234225
    235226    // create the exported-metadata and free local data
    236     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     227    return psphotReadoutCleanup(config, view);
    237228}
    238 
Note: See TracChangeset for help on using the changeset viewer.